Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to stop cq bundles programmatically?

Avatar

Level 7

Hi,

    CQ has its own bundles like com.day.crx.crxde-support . I would like stop this bundle programmatically. Please suggest. Your comments are welcome.

 

Thanks,

Arya

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Arya,

Curl is already build in you can invoke it by accessing particular url.e.g. http://balawcm.wordpress.com/2013/02/13/curl-it-out-adobe-cq5-curl-commands-and-usage/

Here are two examples of simple usage:

1) We stop the bundle that is currently being activated

 @Activate
   protected void activate(ComponentContext componentContext) throws BundleException {
      componentContext.getBundleContext().getBundle().stop();
   }

2) We stop some other bundle

@Activate
   protected void activate(ComponentContext componentContext) throws BundleException {
      Bundle[] bundles = componentContext.getBundleContext().getBundles();
      //find your bundle and assign it to int found;
      bundles[found].stop();
   }

View solution in original post

4 Replies

Avatar

Community Advisor

Hey Dinu,

 

You can stop by invoking a jmx with curl: curl -u admin:admin -F action=stop http://localhost:4502/system/console/bundles/$bundle symbolic name.

You can also stop from Java using the following example: http://stackoverflow.com/questions/7150874/how-to-stop-a-specific-apache-felix-bundle-using-java

 

Thanks,

Peter

Avatar

Level 7

PuzanovsP wrote...

Hey Dinu,

 

You can stop by invoking a jmx with curl: curl -u admin:admin -F action=stop http://localhost:4502/system/console/bundles/$bundle symbolic name.

You can also stop from Java using the following example: http://stackoverflow.com/questions/7150874/how-to-stop-a-specific-apache-felix-bundle-using-java

 

Thanks,

Peter

 


Hi Peter,

            Do I need to integrate curl and AEM for the first solution? If then how can I do that? Please suggest. Could you please share a sample snippet code for the 2nd solution?

 

Thanks,

Arya

Avatar

Correct answer by
Community Advisor

Hi Arya,

Curl is already build in you can invoke it by accessing particular url.e.g. http://balawcm.wordpress.com/2013/02/13/curl-it-out-adobe-cq5-curl-commands-and-usage/

Here are two examples of simple usage:

1) We stop the bundle that is currently being activated

 @Activate
   protected void activate(ComponentContext componentContext) throws BundleException {
      componentContext.getBundleContext().getBundle().stop();
   }

2) We stop some other bundle

@Activate
   protected void activate(ComponentContext componentContext) throws BundleException {
      Bundle[] bundles = componentContext.getBundleContext().getBundles();
      //find your bundle and assign it to int found;
      bundles[found].stop();
   }

Avatar

Level 7

Hi PuzanovsP,

    Thank you. It's working fine. Suppose if we want to get the bundles in jsp, how can I get them? I'm executing the following -

<% @ page import = "org.osgi.framework.Bundle" %>

<%

      Bundle[] bundles = componentContext.getBundleContext().getBundles();
      for(int i=0;i<bundles.length;i++) {
            %><%=bundles[i]%><%
      }

%>

But I'm getting the following error -

Caused by: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 14 in the jsp file: /apps/mysite/components/content/bundle/bundle.jsp
The method getBundleContext() is undefined for the type ComponentContext
11:
12: <%
13:
14:       Bundle[] bundles = componentContext.getBundleContext().getBundles();
15:       for(int i=0;i<bundles.length;i++) {
16:             %><%=bundles[i]%><%
17:       }

    at org.apache.sling.scripting.jsp.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    at org.apache.sling.scripting.jsp.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    at org.apache.sling.scripting.jsp.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:421)
    at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:312)
    at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:290)
    at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:277)
    at org.apache.sling.scripting.jsp.jasper.JspCompilationContext.compile(JspCompilationContext.java:501)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.prepareServlet(JspServletWrapper.java:427)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:486)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:265)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:87)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:465)
    at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361)
    ... 197 more

 

Is componentContext also implicit object? Is there any other way to get them from jsp? Your comments are welcome.

 

Thanks,

Arya.