0 Replies Latest reply on Jul 11, 2007 12:05 PM by Hel Per

    Help in Setting up Servlet which receives/sends SOAP request

    Hel Per Newbie

      Hi, I'm fairly new in JBoss and I was wondering how to properly implement a JAXMServlet.

      Basically I needed a servlet which receives SOAP messages which is then passed to some EJBs.

      Here's my code, compiled with jaxm-api.jar and jboss-saaj.jar. The servlet just receives a soap message, prints it out, and replies with a dummy soap message:

      package com.app;

      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      import javax.xml.messaging.JAXMServlet;
      import javax.xml.messaging.ReqRespListener;
      import javax.xml.soap.*;

      public class SOAPServlet extends JAXMServlet implements ReqRespListener
      {
      public SOAPServlet()
      {
      }

      public void init(ServletConfig config) throws ServletException
      {
      super.init(config);
      }

      public void destroy() {}

      public String getServletInfo()
      {
      return null;
      }

      public javax.xml.soap.SOAPMessage onMessage(javax.xml.soap.SOAPMessage sOAPMessage)
      {

      System.out.println("Got a SOAP: "+sOAPMessage);

      SOAPMessage message = null;

      try
      {
      MessageFactory factory = MessageFactory.newInstance();
      message = factory.createMessage();
      SOAPPart soapPart = message.getSOAPPart();
      SOAPEnvelope envelope = soapPart.getEnvelope();
      SOAPBody body = envelope.getBody();
      Name bodyName = envelope.createName("Response");

      SOAPBodyElement gltp = body.addBodyElement(bodyName);
      Name nof = envelope.createName("blah");

      SOAPElement fileNumber = gltp.addChildElement(nof);
      fileNumber.addTextNode("123");
      }
      catch(Exception e)
      {
      System.out.println(e);
      }

      System.out.println("Returning message: "+message);

      return message;
      }
      }


      It compiles fine. But when I deployed it, it fired an error saying it couldn't find javax.xml.messaging.ReqRespListener. I assumed that the current filepath isn't finding the right classes, so what I did is dump the jaxm-api.jar in the jbosshome/lib/endorsed folder. It filed an error saying it couldn't find HttpServlet, so I added servlet-api.jar as well. Now the servlet deploys fine.

      But whenever I try to send a SOAP using a SOAPClient, the servlet fires an error saying:


      11:38:04,872 ERROR [[soapentrypoint]] Servlet.service() for servlet soapentrypoint threw exception
      javax.servlet.ServletException: JAXM POST failed setProperty must be overridden by all subclasses of SOAPMessage
      at javax.xml.messaging.JAXMServlet.doPost(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)


      Here's the SOAPClient code:

      package com.app;

      import javax.xml.soap.*;

      import java.net.URL;

      public class SOAPsender
      {
      public static void main(String[] args)
      {
      try
      {
      SOAPConnectionFactory soapConnectionFactory =
      SOAPConnectionFactory.newInstance();
      SOAPConnection connection = soapConnectionFactory.createConnection();
      SOAPFactory soapFactory = SOAPFactory.newInstance();

      MessageFactory factory =
      MessageFactory.newInstance();
      SOAPMessage message = factory.createMessage();

      SOAPHeader header = message.getSOAPHeader();
      SOAPBody body = message.getSOAPBody();
      header.detachNode();

      Name bodyName = soapFactory.createName("asd");
      SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

      Name name = soapFactory.createName("symbol");
      SOAPElement symbol = bodyElement.addChildElement(name);
      symbol.addTextNode("SUNW");

      URL endpoint = new URL ("http://localhost:8080/SOAPServlet/soap");
      SOAPMessage response = connection.call(message, endpoint);

      connection.close();

      SOAPBody soapBody = response.getSOAPBody();

      System.out.println(soapBody);
      }
      catch (Exception ex)
      {
      ex.printStackTrace();
      }
      }
      }


      Please, can anyone tell me what I'm doing wrong? An asap reply is very much appreciated, or maybe just a simple working .war example with all the necessary jars packed in it?

      I'm using jboss4.2.0, by the way.

      Thank you very much