2 Replies Latest reply on Jul 15, 2009 11:48 AM by Steam s

    sending Soap message with timeout

    Steam s Newbie

      Hi Folks,
      I have implemented a basic soap client (javax.xml.soap.*).

      
      public Message processSOAPRequest(Message message) {
       try {
       MessageFactory msgFactory = MessageFactory.newInstance();
       SOAPMessage soap = msgFactory.createMessage();
       SOAPPart soapPart = soap.getSOAPPart();
      
       byte[] buffer = ((String) message.getBody().get()).getBytes();
       ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
       StreamSource source = new StreamSource(stream);
       soapPart.setContent(source);
       String action = config.getAttribute(SOAP_ACTION);
       if (action != null) {
       MimeHeaders headers = soap.getMimeHeaders();
       headers.addHeader("SOAPAction", action);
       }
      
       /////////////////////////////////////////////////////////
      
       SOAPMessage reply = sendSOAPMessage(soap);
      
       /////////////////////////////////////////////////////////
      
       ByteArrayOutputStream out = new ByteArrayOutputStream();
       reply.writeTo(out);
       String soapMessage = new String(out.toByteArray());
       message.getBody().add(soapMessage);
      
       } catch (SOAPException e) {
       logger.error("SOAPException : " + e);
      
       } catch (IOException e) {
       logger.error("IOException : " + e);
       }
      
       return message;
      
       }
      
      
       private SOAPMessage sendSOAPMessage(SOAPMessage soap) {
       SOAPConnection connection = null;
       SOAPMessage reply = null;
       try {
       SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory
       .newInstance();
       connection = soapConnFactory.createConnection();
       String destination = config.getAttribute(URL_ENDPOINT);
      
       reply = connection.call(soap, destination);
      
      
      
       } catch (Exception e) {
       logger.error(e);
       } finally {
       try {
       if (connection != null) {
       connection.close();
       }
       } catch (SOAPException e) {
       logger.error(e);
       }
       }
      
       return reply;
       }
      
      


      The input message is JBossEsb message, which I convert to soap message and then send it using SOAPConnection, which works fine.

      The problem with SOAPConnection class is that it does not provide setTimeout(..) method. I read some where that there is another class SOAPConnectionImpl (by axis), which extends SOAPConnection and has this setTimeout method.

      I have tried to convert my existing implementation to SOAPConnectionImpl but i always get a classcast exceptions.

      Could somebody help me in suggesting a solution to this problem? My main concern is to include timeout feature that is my WS consumer/client should timeout after a certain period if the server does not reply.

      Any other soap message sending implementation with timeout feature are also good.

      I have included
      <dependency>
       <groupId>axis</groupId>
       <artifactId>axis</artifactId>
       <version>1.4</version>
      </dependency>
      


      maven dependencies for axis.

      Awaiting replies.

      Thanks.

        • 1. Re: sending Soap message with timeout
          Alessio Soldano Master

          The point here is SAAJ does not define an API for setting the timeout directly using the SOAPConnection. So you need to use some kind of proprietary stuff.
          Forget about Axis, you can't use it with JBossWS. Take a look at the JBossWS-Native (I assume that's what you're using) org.jboss.ws.core.client.HTTPRemotingConnection that is used under the hood by org.jboss.ws.core.soap.SOAPConnectionImpl (which in turn is the JBossWS-Native impl of SOAPConnection).
          HTTPRemotingConnection basically receives and endpoint object which can be an instance of EndpointInfo. That can contain a properties map including org.jboss.ws.timeout property. Setting that, you should be able to basically achieve what you get setting the same prop in the request context when performing a call through a ws port.

          • 2. Re: sending Soap message with timeout
            Steam s Newbie

            Thanks for your reply but i solved that problem using Jboss ESB's internal HTTP router class: org.jboss.soa.esb.actions.routing.http.HttpRouter

            One can send soap messages with it as well, and set connection/socket Timeouts (http properties) etc as well.

            Thanks.