facebook

NullPointerException in Simple Web Service

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #306898 Reply

    Mork
    Participant

    I’ve been beating my head against a wall on this issue for a a couple weeks, but I can’t figure it out. I believe there must be a bug in MyEclipse’s Web Service implementation, the JAX-WS Libraries, or in the Tomcat container.

    If I create the extremely simple Web Service below with the @Resource annotation and then try to access the WebServiceContext, per lots of examples on the Web, I get a NullPointerException in the MyEclipse-generated client program.

    The MyEclipse-generated code does not work.

    Can you please take a look at this and see if you can reproduce this problem?

    Thank you!!!

    M

    —————————

    Very Simple Web Service:

    1.
    2. package servletws;
    3.
    4. import javax.annotation.Resource;
    5. import javax.jws.WebService;
    6. import javax.xml.ws.WebServiceContext;
    7.
    8. @WebService
    9. public class HelloServlet {
    10. @Resource WebServiceContext wsContext;
    11.
    12. public String hello(String msg) {
    13. return “Servlet WS: ” + wsContext.getUserPrincipal() // *** NullPointerException happens here! ***
    14. + “: ” + msg;
    15. }
    16. }

    The web service deploys and I can get to its WSDL in the browser.

    ************
    HOWEVER….
    ************

    As with my production web service, as soon as the client web service hits the line above where the wsContext.get UserPrincial() is, I get a NullPointerException….as with my previous postings.

    My really-simple Web Service Client is this:

    1.
    2.
    3. package servletws;
    4.
    5. public class WebServiceClient
    6. {
    7.
    8. /**
    9. * @param args
    10. */
    11. public static void main(String[] args)
    12. {
    13. HelloServletService service = new HelloServletService();
    14. HelloServletDelegate delegate = service.getHelloServletPort();
    15.
    16. delegate.hello(“hello there Test!”);
    17.
    18. }
    19. }

    package servletws; public class WebServiceClient { /** * @param args */ public static void main(String[] args) { HelloServletService service = new HelloServletService(); HelloServletDelegate delegate = service.getHelloServletPort(); delegate.hello(“hello there Test!”); } }

    =========

    The WSDL is this:

    1.
    2.
    3. <?xml version=”1.0″ encoding=”UTF-8″?>
    4. <!– Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI’s version is JAX-WS RI 2.1.3-hudson-390-. –>
    5. <definitions xmlns=”http://schemas.xmlsoap.org/wsdl/&#8221; xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/&#8221; xmlns:tns=”http://servletws/&#8221; xmlns:wsu=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; name=”HelloServletService” targetNamespace=”http://servletws/”&gt;
    6. <types>
    7. <xsd:schema>
    8. <xsd:import namespace=”http://servletws/&#8221; schemaLocation=”HelloServletService_schema1.xsd”/>
    9. </xsd:schema>
    10. </types>
    11. <message name=”hello”>
    12. <part element=”tns:hello” name=”parameters”/>
    13. </message>
    14. <message name=”helloResponse”>
    15. <part element=”tns:helloResponse” name=”parameters”/>
    16. </message>
    17. <portType name=”HelloServletDelegate”>
    18. <operation name=”hello”>
    19. <input message=”tns:hello”/>
    20. <output message=”tns:helloResponse”/>
    21. </operation>
    22. </portType>
    23. <binding name=”HelloServletPortBinding” type=”tns:HelloServletDelegate”>
    24. <soap:binding style=”document” transport=”http://schemas.xmlsoap.org/soap/http”/&gt;
    25. <operation name=”hello”>
    26. <soap:operation soapAction=””/>
    27. <input>
    28. <soap:body use=”literal”/>
    29. </input>
    30. <output>
    31. <soap:body use=”literal”/>
    32. </output>
    33. </operation>
    34. </binding>
    35. <service name=”HelloServletService”>
    36. <port binding=”tns:HelloServletPortBinding” name=”HelloServletPort”>
    37. <soap:address location=”http://localhost:8000/ResWebServiceTest/HelloServletPort”/&gt;
    38. </port>
    39. </service>
    40. </definitions>

    <?xml version=”1.0″ encoding=”UTF-8″?> <!– Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI’s version is JAX-WS RI 2.1.3-hudson-390-. –> <definitions xmlns=”http://schemas.xmlsoap.org/wsdl/&#8221; xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/&#8221; xmlns:tns=”http://servletws/&#8221; xmlns:wsu=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; name=”HelloServletService” targetNamespace=”http://servletws/”&gt; <types> <xsd:schema> <xsd:import namespace=”http://servletws/&#8221; schemaLocation=”HelloServletService_schema1.xsd”/> </xsd:schema> </types> <message name=”hello”> <part element=”tns:hello” name=”parameters”/> </message> <message name=”helloResponse”> <part element=”tns:helloResponse” name=”parameters”/> </message> <portType name=”HelloServletDelegate”> <operation name=”hello”> <input message=”tns:hello”/> <output message=”tns:helloResponse”/> </operation> </portType> <binding name=”HelloServletPortBinding” type=”tns:HelloServletDelegate”> <soap:binding style=”document” transport=”http://schemas.xmlsoap.org/soap/http”/&gt; <operation name=”hello”> <soap:operation soapAction=””/> <input> <soap:body use=”literal”/> </input> <output> <soap:body use=”literal”/> </output> </operation> </binding> <service name=”HelloServletService”> <port binding=”tns:HelloServletPortBinding” name=”HelloServletPort”> <soap:address location=”http://localhost:8000/ResWebServiceTest/HelloServletPort”/&gt; </port> </service> </definitions>

    ===============

    The web.xml is this:

    1.
    2.
    3. <?xml version=”1.0″ encoding=”UTF-8″?>
    4. <web-app version=”2.5″
    5. xmlns=”http://java.sun.com/xml/ns/javaee&#8221;
    6. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    7. xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
    8. http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”&gt;
    9. <servlet>
    10. <description>JAX-WS endpoint – HelloServletService</description>
    11. <display-name>HelloServletService</display-name>
    12. <servlet-name>HelloServletService</servlet-name>
    13. <servlet-class>
    14. com.sun.xml.ws.transport.http.servlet.WSServlet
    15. </servlet-class>
    16. <load-on-startup>1</load-on-startup>
    17. </servlet>
    18. <servlet-mapping>
    19. <servlet-name>HelloServletService</servlet-name>
    20. <url-pattern>/HelloServletPort</url-pattern>
    21. </servlet-mapping>
    22. <welcome-file-list>
    23. <welcome-file>index.jsp</welcome-file>
    24. </welcome-file-list>
    25. <listener>
    26. <listener-class>
    27. com.sun.xml.ws.transport.http.servlet.WSServletContextListener
    28. </listener-class>
    29. </listener></web-app>

    ============

    And the log error dump is:

    1.
    2. Exception in thread “main” javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
    3. at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:188)
    4. at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)
    5. at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
    6. at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
    7. at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
    8. at $Proxy34.hello(Unknown Source)
    9. at servletws.WebServiceClient.main(WebServiceClient.java:14)
    10. Caused by: java.lang.NullPointerException
    11. at servletws.HelloServlet.hello(HelloServlet.java:15)
    12. at servletws.HelloServletDelegate.hello(HelloServletDelegate.java:15)
    13. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    14. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    15. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    16. at java.lang.reflect.Method.invoke(Method.java:597)
    17. at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
    18. at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
    19. at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
    20. at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
    21. at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
    22. at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
    23. at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
    24. at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
    25. at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
    26. at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
    27. at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
    28. at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
    29. at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
    30. at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
    31. at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
    32. at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    33. at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    34. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    35. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    36. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    37. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    38. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    39. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    40. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    41. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    42. at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    43. at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    44. at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    45. at java.lang.Thread.run(Thread.java:619)
    46.
    47.

    I can send you the two MyEclipse projects if you would prefer.

    I’m using MyEclipse 7.5.

    Look forward to any possible reasons why I keep getting NullPointerExceptions.

    Thanks

    M

Viewing 1 post (of 1 total)
Reply To: NullPointerException in Simple Web Service

You must be logged in to post in the forum log in