Hi, I am trying to write a simple SOAP application which is a quiz. The client (a java app) sends a SOAP message to a web service (a java class) requesting a question. The web service responds by sending a question to the client.
I have written the code for the client and web service. I have deployed the web service class using the SOAP admin screen. But...i get an error! When the client sends the first SOAP message to the web service, it does not appear to reach it (i put a system.out at the beginning of the web service code and nothing came out on the screen. Instead it comes back as a SOAP error message apparently from the messagerouter. Below i have added all the details i can. I am a newbie at this so i am sure that it is a simple mistake which someone should easily spot. Any help would be appreciated. And yes, I have checked that the messagerouter is there by going to the URL in IE. I have ensured Tomcat is running. I have JDK1.3.1 and soap.jar, activation.jar etc. etc. I have put my webservice class in the TomCat directory (i did not know exactly where it goes so i put it in every directory.) I did this with a previous example (XML RPC) and Tomcat was able to find it. P.S The first message sent to the webservice is now an XML file containing irrelevant data. Also the web service is simplified to help find the problem (i.e. it does not select and send back a question, instead it sends back anything). ------------------------------------- The error message ------------------------------------- <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Exception while handling service request: org/apache/soap/Envelope</faultstring> <faultactor>/soap/servlet/messagerouter</faultactor> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope> -------------------------------------------------------------------- The XML file read in by the client and then sent to the web service -------------------------------------------------------------------- <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <requestIn xmlns="qService"> <item> <productName>Baby Monitor</productName> <quantity>1</quantity> <price>39.98</price> <shipDate>1999-05-21</shipDate> </item> </requestIn> </s:Body> </s:Envelope> ------------------------------------------------------------------ The client code ------------------------------------------------------------------ package soapmessages; import java.util.*; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import java.net.*; import java.io.*; import org.xml.sax.*; import org.apache.soap.util.xml.XMLParserUtils; import org.apache.soap.*; import org.apache.soap.messaging.Message; import org.apache.soap.transport.SOAPTransport; /** * Title: Soap Client * Description: Client used in soap messaging * Copyright: Copyright (c) 2001 * Company: * @author Sandeep Heer * @version 1.0 */ public class soapClient { String name; int score = 0; int qNo = 0; static URL serviceURL; public static void main(String[] args) throws MalformedURLException { serviceURL = new URL("http://localhost:8080/soap/servlet/messagerouter"); soapClient sC = new soapClient(); sC.startup(); } public void startup() { try { System.out.println("Welcome to the...! \n"); System.out.println("Please enter... \n"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); name = br.readLine().trim(); askQuestions(); } catch(IOException e) { System.out.println("Incorrect value entered" + e); } } public void askQuestions() throws IOException { while(qNo < 11) { try{ String answer = getQuestion(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); if (answer.equals(br.readLine().trim())); score++; qNo++; } catch (SOAPException a) { System.out.println(a.toString()); } } System.out.println("Your score" + score); } public String getQuestion() throws IOException, SOAPException { Document doc = null; String answer = null; File file1 = new File("c:\\msg1.xml"); try { FileReader sr = new FileReader (file1); DocumentBuilder builder = XMLParserUtils.getXMLDocBuilder(); doc = builder.parse(new InputSource(sr)); if (doc==null) { throw new SOAPException("Error 01", "Error parsing XML message"); } Envelope msgEnvelope = Envelope.unmarshall(doc.getDocumentElement()); System.out.println(msgEnvelope.toString()); Message msg = new Message(); msg.send(serviceURL, "qService", msgEnvelope); SOAPTransport transport = msg.getSOAPTransport(); BufferedReader resReader = transport.receive(); if (resReader == null) throw new SOAPException("Error 02","Error receiving XML message"); SaxParserBean parser = new SaxParserBean(); String line=null; while((line=resReader.readLine()) != null) { System.out.println(line); } Enumeration theQuestion = parser.parse(resReader); System.out.println((String)theQuestion.nextElement()); answer = (String)theQuestion.nextElement(); } catch (SAXException f) { System.out.println("SAX Error" + f); } return answer; } } -------------------------------------------------------------- Web Service code -------------------------------------------------------------- package soapmessages; import org.apache.soap.*; import java.io.*; import java.util.*; import org.apache.soap.encoding.*; import org.apache.soap.encoding.soapenc.*; import org.apache.soap.rpc.*; import org.apache.soap.util.xml.*; import java.net.*; import javax.mail.*; import org.w3c.dom.*; /** * Title: qService * Description: Web service to talk to client * Copyright: Copyright (c) 2001 * Company: * @author Sandeep Heer * @version 1.0 */ public class qService { public void requestIn(Envelope env, SOAPContext req, SOAPContext res) throws IOException, MessagingException { System.out.println("Am i here yet?"); res.setRootPart("OK thanks, ", "text/xml"); } } ------------------------------------------------------------------- Deployed Service Information (soap admin screen) for web service ------------------------------------------------------------------- ID qService Scope Application Provider Type java Provider Class soapmessages.qService Use Static Class false Methods requestIn --------------------------------------------------------------------- E-mail Confidentiality Notice and Disclaimer This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to which they are addressed. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. E-mail messages are not necessarily secure. Hitachi does not accept responsibility for any changes made to this message after it was sent. Please note that Hitachi checks outgoing e-mail messages for the presence of computer viruses. ---------------------------------------------------------------------