Expand my Community achievements bar.

SOLVED

Not able to call sling service from component jsp

Avatar

Level 9

Hi All,

I have created a component jsp ,from which i need to call a sling service,this component page simply calls the methods of service.When i am trying to see the rendered page i am getting null pointer exception.

Can someone tell me what could be the reason,why could not instantiate the service.

Attaching jsp and service class.

 

<%@include file="/libs/foundation/global.jsp"%>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %>
<%@page import="com.sample.initiatewf.InvokeAEMWorkflow"%>
<h1>TemplatePDF Page</h1>
<%
//create a InvokeAEMWorkflow instance
com.sample.initiatewf.InvokeAEMWorkflow wfService = sling.getService(com.sample.initiatewf.InvokeAEMWorkflow.class);
%>
<h2>About to invoke an AEM workflow using the AEM workflow APIs</h2>
<h3><%=wfService.getStringMsg()%></h3>

 

Thanks,

Kishore

1 Accepted Solution

Avatar

Correct answer by
Level 7

[img]service.png[/img]Kishore,

Your code required below change in jsp file
com.sample.initiatewf.InvokeAEMWorkflow  wfService = sling.getService(com.sample.initiatewf.INvokeAEMWorkflowImp.class);

You were accessing your service with name "com.sample.initiatewf.INvokeAEMWorkflow.class" instead of "com.sample.initiatewf.INvokeAEMWorkflowImp.class"    

Because you registered your service in INvokeAEMWorkflowImp class as below 
@Service(value = {INvokeAEMWorkflowImp.class})
So it has to be accessed with INvokeAEMWorkflowImp.

Please see attached image for more clarification.

Regards
Brijesh

View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

[img]service.png[/img]Kishore,

Your code required below change in jsp file
com.sample.initiatewf.InvokeAEMWorkflow  wfService = sling.getService(com.sample.initiatewf.INvokeAEMWorkflowImp.class);

You were accessing your service with name "com.sample.initiatewf.INvokeAEMWorkflow.class" instead of "com.sample.initiatewf.INvokeAEMWorkflowImp.class"    

Because you registered your service in INvokeAEMWorkflowImp class as below 
@Service(value = {INvokeAEMWorkflowImp.class})
So it has to be accessed with INvokeAEMWorkflowImp.

Please see attached image for more clarification.

Regards
Brijesh

Avatar

Level 10

This is based on a community article. It looks like the OSGi bundle that contains the com.sample.initiatewf.InvokeAEMWorkflow service is not deployed and in an active state. 

Make sure to deploy the OSGI bundle and place the bundle into an Active state as discussed here:

http://scottsdigitalcommunity.blogspot.ca/2013/09/creating-workflows-for-adobe-experience.html

Avatar

Level 9

smacdonald2008 wrote...

This is based on a community article. It looks like the OSGi bundle that contains the com.sample.initiatewf.InvokeAEMWorkflow service is not deployed and in an active state. 

Make sure to deploy the OSGI bundle and place the bundle into an Active state as discussed here:

http://scottsdigitalcommunity.blogspot.ca/2013/09/creating-workflows-for-adobe-experience.html

 

 

i am able to deploy bundle and it is also in active state but i am not able to refer the bundle from my component page.