• 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

SAAJ - Empty SOAP Response / Null Pointer Exception

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I try to exchange SOAP Messages between two Web services using SAAJ. I have followed the tutorial from this (http://www.ibm.com/developerworks/xml/library/x-jaxmsoap/) link. Surprisingly, the doesn't describe the process on the receiver of the SOAP message i.e. how the request is processed and a response SOAP message is generated and sent back. After hours of googling, I found this link (http://www.sentex.net/~pkomisar/WS/WS_A_SAAJ.html) which looked to be very promising (SAAJ Client With a JAXM Server Example).

But when I attempt to retrieve the contents of the SOAP message on client using SOAPPart respSOAP = response.getSOAPPart();, I get “Null Pointer Exception”. I wonder how the OnMessage method could not receive the communicated SOAP message. The server log is given below.

The log message is null.
java.lang.NullPointerException
at weather.WeatherService.onMessage(WeatherService.ja va:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.sun.enterprise.webservice.InstanceResolverImpl $1.invoke(InstanceResolverImpl.java:112)
at com.sun.xml.ws.server.InvokerTube$2.invoke(Invoker Tube.java:146)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.in voke(EndpointMethodHandler.java:257)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRe quest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:5 95)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:55 4)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539 )
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:4 36)
at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.pr ocess(AbstractTubeImpl.java:106)
at com.sun.enterprise.webservice.MonitoringPipe.proce ss(MonitoringPipe.java:147)
at com.sun.xml.ws.api.pipe.helper.PipeAdapter.process Request(PipeAdapter.java:115)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:5 95)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:55 4)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539 )
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:4 36)
at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.pr ocess(AbstractTubeImpl.java:106)
at com.sun.enterprise.webservice.CommonServerSecurity Pipe.processRequest(CommonServerSecurityPipe.java: 222)
at com.sun.enterprise.webservice.CommonServerSecurity Pipe.process(CommonServerSecurityPipe.java:133)
at com.sun.xml.ws.api.pipe.helper.PipeAdapter.process Request(PipeAdapter.java:115)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:5 95)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:55 4)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539 )
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:4 36)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSE ndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpTool kit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(H ttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapt er.handle(ServletAdapter.java:135)
at com.sun.enterprise.webservice.JAXWSServlet.doPost( JAXWSServlet.java:177)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:847)
at org.apache.catalina.core.ApplicationFilterChain.se rvletService(ApplicationFilterChain.java:427)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:315)
at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:287)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:218)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:593)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipel ine.java:94)
at com.sun.enterprise.web.PESessionLockingStandardPip eline.invoke(PESessionLockingStandardPipeline.java :98)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:222)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:1096)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:166)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:1096)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:288)
at com.sun.enterprise.web.connector.grizzly.DefaultPr ocessorTask.invokeAdapter(DefaultProcessorTask.jav a:647)
at com.sun.enterprise.web.connector.grizzly.DefaultPr ocessorTask.doProcess(DefaultProcessorTask.java:57 9)
at com.sun.enterprise.web.connector.grizzly.DefaultPr ocessorTask.process(DefaultProcessorTask.java:831)
at com.sun.enterprise.web.connector.grizzly.DefaultRe adTask.executeProcessorTask(DefaultReadTask.java:3 41)
at com.sun.enterprise.web.connector.grizzly.DefaultRe adTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultRe adTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.portunif.PortUnificationPip eline$PUTask.doTask(PortUnificationPipeline.java:3 80)
at com.sun.enterprise.web.connector.grizzly.TaskBase. run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWo rkerThread.run(SSLWorkerThread.java:106)


<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>java.lang.NullPointerException</faultstring>
</S:Fault>
</S:Body>
</S:Envelope>

Later, I give up the retrieving the SOAP message and tried to generate a new SOAP message and send it to the sender, as the return type of the connection.call method is SOAPMessage. Here, I could not get any SOAPFault or exceptions. However, when I write out the response to the console, I get a SOAP Message with empty body as shown below.

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2nMessageResponse xmlns:ns2="http://weather/">
<return/>
</ns2nMessageResponse>
</S:Body>
</S:Envelope>

Any help at the earliest would be really helpful.

Regards,
Arun.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
My guess is that there may be a namespace problem somewhere; for instance, an element has the wrong, or no, namespace.
I would use soapUI and test the web service. If you are able to send requests to the web service and receive correct answers, then you can compare the requests sent from soapUI with the requests sent from your client.
I guess there will be some discrepancy between the two requests. Upon finding any differences in the requests, you can try to modify your client to produce valid requests.
Best wishes!
 
Arun Adi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Krizsan wrote:Hi!
My guess is that there may be a namespace problem somewhere; for instance, an element has the wrong, or no, namespace.
I would use soapUI and test the web service. If you are able to send requests to the web service and receive correct answers, then you can compare the requests sent from soapUI with the requests sent from your client.
I guess there will be some discrepancy between the two requests. Upon finding any differences in the requests, you can try to modify your client to produce valid requests.
Best wishes!



Ivan,

I have tested the Web services with SOAPUI as you have suggested. But I could not figure out the problem. I provide be the client and server code along with the outcome I get as comments in bold fonts for your further suggestions. Please help me in fixing the problem.

$$$$$ WeatherClient generates a SOAP request message and communicates the request message to another Web service namely WeatherServer which is supposed to process the request and send back a SOAP response $$$$

package weather;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.messaging.*;
import javax.xml.soap.*;
import java.util.Iterator;
import javax.xml.namespace.QName;
@WebService()
public class WeatherClient
{

@WebMethod(operationName = "weatherRequest")
public void weatherRequest()
{
SOAPMessage response = null;
try {
SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
SOAPConnection conn = connFactory.createConnection();
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart msgSOAP = message.getSOAPPart();
SOAPEnvelope msgEnv = msgSOAP.getEnvelope();
SOAPBody msgBody = msgEnv.getBody();
COMMENT: OnMessage is the method on the WeatherServer which processes the SOAP Request
QName nameForecast = new QName("http://weather/","onMessage","w");
SOAPBodyElement beForecastBOS = msgBody.addBodyElement(nameForecast);
//SOAPBodyElement beForecastNYC = msgBody.addBodyElement(nameForecast);
Name nameCity = msgEnv.createName("City");
SOAPElement elCityBOS = beForecastBOS.addChildElement(nameCity);
elCityBOS.addTextNode("Boston");

System.out.println("[ Weather Forecast Request Message]");
COMMENT: Outcome of the following statement
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<w:onMessage xmlns:w="http://weather/">
<City>Boston</City>
</w:onMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

message.writeTo(System.out);
System.out.println("========================");

URLEndpoint destination = new URLEndpoint("http://10.106.26.199:8080/SAAJTestApp2/WeatherServiceService");
response = conn.call(message, destination);
conn.close();


System.out.println("[ Weather Forecast Received Response Message]");
PROBLEM POINT:
COMMENT: Outcome of the following statement
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:onMessageResponse xmlns:ns2="http://weather/">
<return/>
</ns2:onMessageResponse>
</S:Body>
</S:Envelope>


response.writeTo(System.out);
System.out.println("===========================================\n");
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}


$$$$$ WeatherServer generates a SOAP request message and communicates the response message to WeatherClient which processes the request and send back a SOAP response $$$$

package weather;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.messaging.*;
import javax.xml.soap.*;
import javax.xml.namespace.QName;

@WebService()
public class WeatherService extends JAXMServlet implements ReqRespListener
{

@WebMethod(operationName = "onMessage")
public SOAPMessage onMessage(@WebParam(name = "soapMessage")
SOAPMessage message)
{
System.out.println("Request Receive Check..");
try {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage response = messageFactory.createMessage();

COMMENT: Try to access the sent SOAP request using the following statement, but throws Null Pointer Exception
SOAPPart message = message.getSOAPPart();


SOAPPart respSOAP = response.getSOAPPart();
SOAPEnvelope respEnv = respSOAP.getEnvelope();
SOAPBody respBody = respEnv.getBody();

QName nameForecast = new QName("http://weather/","onMessage","w");
SOAPBodyElement beForecastBOS = respBody.addBodyElement(nameForecast);
Name nameCity = respEnv.createName("Temperature");
SOAPElement elCityBOS = beForecastBOS.addChildElement(nameCity);
//SOAPElement elCityNYC = beForecastNYC.addChildElement(nameCity);
elCityBOS.addTextNode("22 Deg. Celsius");
System.out.println("[ Weather Forecast Response Message]");
COMMENT: Outcome of the following statement
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<w:onMessage xmlns:w="http://weather/">
<Temperature>22 Deg. Celsius</Temperature>
</w:onMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

try {
response.writeTo(System.out);
} catch (IOException ex) {
Logger.getLogger(WeatherService.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("========================");
return response;
} catch (SOAPException se) {
System.err.println("SOAPException: " + se.getMessage());
return null;
}
}
}


Further details: I work with Netbeans IDE to create JAX-WS Web services. I am clueless about the way to fix this issue for more than 10 days and I desperately need to fix the problem. Please help me in fixing this problem.
 
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic