• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where to use @EJB DI?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the deal.

I have an EJB3.1 application (session bean) deployed on Weblogic 10 and that is working perfectly when I am
invoking the client using JNDI lookup.

******************EventProcessor.java****************************
@Remote

public interface EventProcessor {
public String getVersion();

}

******************EventProcessorBean.java*************************
@Stateless(mappedName="EventProcessor")
public class EventProcessorBean implements EventProcessor {

@Resource
private SessionContext sessionContext;


@PersistenceContext(unitName = "actionBazaar")
private EntityManager em;

public String getVersion() {
return "v1.0";
}

}


Now on the same server rather on the same node I have a JAX-WS webservice deployed that is also working fine. Now
I have added one method to the service that will invoke this EJB.

************************Calculator.java*****************************
@WebService(name="CalculatorPortType",
targetNamespace = "http://test.com")
public interface Calculator {

@WebMethod
public int add(@WebParam(name = "value1") int value1,
@WebParam(name = "value2") int value2);

@WebMethod
public String getVersion();
}

****************************CalculatorService.java********************
@WebService(serviceName = "Calculator",
portName="CalculatorPort",
endpointInterface = "com.test.Calculator",
targetNamespace = "http://test.com"
)
public class CalculatorService implements Calculator {

@Resource
private WebServiceContext context;

@EJB(mappedName="EventProcessor")
private EventProcessor eventProcessor;

public int add(int value1, int value2) {
System.out.println("User Principal: " + context.getUserPrincipal());
return value1 + value2;
}

public String getVersion() {
System.out.println("Version : " + eventProcessor.getVersion());
return eventProcessor.getVersion();
}
}



When I am calling the getVersion() i.e. the method calling the EJB then I am getting a nullpointer exception.

Oct 28, 2011 5:02:20 PM com.sun.xml.ws.server.sei.EndpointMethodHandler invoke
SEVERE: null
java.lang.NullPointerException
at com.test.CalculatorService.getVersion(CalculatorService.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:134)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3504)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2186)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2092)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

The WebService and EJB is on the same node of the same server. Doesn't the DI thing work for remote EJBs?


 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer - no, but this might be helpful for you:

http://stackoverflow.com/questions/7839207/does-ejb-annotation-work-for-remote-call/7842345#7842345

Cheers!
 
Saurav Chatterjee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link!!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic