Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem creating a SOAP connection  RSS feed

 
Jeff Pavlocak
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been given the task of writing a client program to interact with a web service. I was able to download some sample code from the company that hosts the web service. The sample code uses a JSP to call on a servlet that interacts with the web service.

I've written JSP pages before, but I have never written client programs to interact with web services using SOAP. I've gone to a number of SOAP recources on the web, and I have been able to get their tutorials to work just fine. But, none of the "hello world" tutorials operate quite like the sample code I have.

I keep getting a Parsing Exception from Tomcat when the servlet tries to create a SOAPConnection. Any ideas as to what might be going wrong?

This is getting really frustrating now. Any help would be greatly appreciated.

Thanks,

Jeff

I am using tomcat-jwsdp-1.4
My classpath is :
"C:\tomcat-jwsdp-1.4\common\lib\axis.jar;C:\xml\xerces.jar;
c:\soap-2_3_1\webapps\soap;c:\soap-2_3_1\lib\soap.jar;
c:\soap-2_3_1\lib\mail.jar;c:\soap-2_3_1\lib\activation.jar;
C:\j2sdk_nb\j2sdk1.4.2\lib\tools.jar;c:\tomcat-jwsdp-1.4\bin\bootstrap.jar"

The exact error I get is:

exception

javax.servlet.ServletException: javax/mail/internet/ParseException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:822)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:755)
org.apache.jsp.TestUpc_jsp._jspService(TestUpc_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:268)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:258)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:205)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NoClassDefFoundError: javax/mail/internet/ParseException
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:1610)
java.lang.Class.getConstructor0(Class.java:1922)
java.lang.Class.newInstance0(Class.java:278)
java.lang.Class.newInstance(Class.java:261)
javax.xml.soap.FactoryFinder.newInstance(Unknown Source)
javax.xml.soap.FactoryFinder.find(Unknown Source)
javax.xml.soap.MessageFactory.newInstance(Unknown Source)
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.<init>(HttpSOAPConnection.java:53)
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory.createConnection(HttpSOAPConnectionFactory.java:25)
com.serviceobjects.dots.upc.UpcExample.getGetUPCInfo(UpcExample.java:167)
com.serviceobjects.dots.upc.UpcExample.invokeUPCInfo(UpcExample.java:34)
org.apache.jsp.TestUpc_jsp._jspService(TestUpc_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:268)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:258)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:205)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

The code that is giving me the problem is below:

private String getGetUPCInfo(String UPCCode, String key) {

String upcInfoXml = null;
String SERVICE_URI =
"http://ws2.theSite.net/upc/UPC.asmx";

try {

SOAPConnectionFactory soapConFac =
SOAPConnectionFactory.newInstance();

// The next line is the one kicking off the parsing exception
SOAPConnection soapCon = soapConFac.createConnection();
MessageFactory msgFac = MessageFactory.newInstance();
SOAPMessage soapMsg = msgFac.createMessage();
SOAPPart soapPart = soapMsg.getSOAPPart();
SOAPEnvelope soapEnv = soapPart.getEnvelope();
SOAPHeader soapHead = soapEnv.getHeader();
SOAPBody soapBody = soapEnv.getBody();
soapHead.detachNode();
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Always try to include the following jar files for running SOAP programs successfully.

1. soap.jar
2. activation.jar
3. mail.jar
4. xerces.jar

Try to compile & execute now..
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Pavlocak:
I am using tomcat-jwsdp-1.4


Why? That is a special version to run the Java Web Services Developer Pack. And the JWSDP was also never supported for production environments.

As you are only using SAAJ any normal Tomcat distribution should suffice. (SAAJ client "Java Web Services in a Nutshell" Sample: Chapter 3 SAAJ (PDF)).

Also more modern web service stacks like JAX-WS, Axis2 (successor of Axis 1.x) with client stub generating tools are available.

Mixing JAR files from Apache SOAP and Axis 1.x (the successor of Apache SOAP) could be causing its own set of problems. I'd suggest that you create a command line client for your web service interaction first - then you can find out which JAR files you actually need. Once you have that sorted out try to port it to a JSP/servlet.
[ December 10, 2008: Message edited by: Peer Reynders ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!