@Route(method = HttpMethod.GET, uri = "/{id}")
    public Result toggleBundle(@Parameter("id") long id) {
        Bundle bundle = context.getBundle(id);
        if (bundle == null) {
            return notFound("Bundle " + id + " not found");
        } else {
            if (! isFragment(bundle)) {
                if (bundle.getState() == Bundle.ACTIVE) {
                    try {
                        bundle.stop();
                    } catch (BundleException e) {
                        logger().error("Cannot stop bundle {}", bundle.getSymbolicName(), e);
                        return badRequest(e);
                    }
                } else if (bundle.getState() == Bundle.INSTALLED || bundle.getState() == Bundle.RESOLVED) {
                    try {
                        bundle.start();
                    } catch (BundleException e) {
                        logger().error("Cannot start bundle {}", bundle.getSymbolicName(), e);
                        return badRequest(e);
                    }
                }
            } else {
                if (bundle.getState() == Bundle.RESOLVED) {
                    try {
                        bundle.stop();
                    } catch (BundleException e) {
                        logger().error("Cannot stop bundle {}", bundle.getSymbolicName(), e);
                        return badRequest(e);
                    }
                }
            }
        }
        return ok();
    }
@ Route ( method = HttpMethod . GET , uri = "/{id}" ) public Result toggleBundle ( @ Parameter ( "id" ) long id ) { Bundle bundle = context . getBundle ( id ) ; if ( bundle == null ) { return notFound ( "Bundle " + id + " not found" ) ; } else { if ( ! isFragment ( bundle ) ) { if ( bundle . getState ( ) == Bundle . ACTIVE ) { try { bundle . stop ( ) ; } catch ( BundleException e ) { logger ( ) . error ( "Cannot stop bundle {}" , bundle . getSymbolicName ( ) , e ) ; return badRequest ( e ) ; } } else if ( bundle . getState ( ) == Bundle . INSTALLED || bundle . getState ( ) == Bundle . RESOLVED ) { try { bundle . start ( ) ; } catch ( BundleException e ) { logger ( ) . error ( "Cannot start bundle {}" , bundle . getSymbolicName ( ) , e ) ; return badRequest ( e ) ; } } } else { if ( bundle . getState ( ) == Bundle . RESOLVED ) { try { bundle . stop ( ) ; } catch ( BundleException e ) { logger ( ) . error ( "Cannot stop bundle {}" , bundle . getSymbolicName ( ) , e ) ; return badRequest ( e ) ; } } } } return ok ( ) ; }
Toggles the states of the bundle. If the bundle is active, the bundle is stopped. If the bundle is resolved or
installed, the bundle is started.

@param id the bundle's id
@return OK if everything is fine, BAD_REQUEST if the bundle cannot be started or stopped correctly,
NOT_FOUND if there are no bundles with the given id.