2

So to give you some background, I am trying to create a client that will interact with a third-party via SOAP. Initially I started to roll this out using javax.xml.soap SAAJ but then realized there are no options for timeouts when creating a SOAPConnection.

I considered AXIS which does have timeouts but have been warned to try and avoid and it's not great performance wise. My higher-ups seems to be putting this as a last restort.

Some have suggested that javax.xml.ws Web Service route works great as you can put in the context properties the time-out settings, only if it is a web service.

So here is the situation, the third-party I'm sending requests to doesn't really have a WSDL file or URL, the original idea was to build up the SOAP request and send it, would have worked great if SAAJ had timeout settings.

So I'm thinking and forgive me for my ignorance, is that could I model and implement the communication like a Web Service instead of the SAAJ javax.xml.soap method of building the request up? If so, can anyone really point me out? Most documents I find seem to rely on generating stubs and classes from a WSDL.

This is all really for the sake of setting a time-out setting for connections to this third-party SOAP API.

Also note, I've seen some people suggest to try and treat it like a HttpConnection where you can set timeouts but the downside I found was it no longer returns a SOAPMessage type object.

So basically I'm trying to change this:

    SOAPMessage soapMessage       = messageFactory.createMessage();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    SOAPPart soapPart         = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPHeader soapHeader     = soapEnvelope.getHeader();
    SOAPBody soapBody         = soapEnvelope.getBody();
    ....
    soapConnection.call(soapMessage, url);

Into something more like web service so I can do this:

requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 2000); 
requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 2000);

myService.callMyRemoteMethodWith(myParameter1, myparameter2);

I really am lacking knowledge about the javax.ws framework so please go lightly :)

halfer
  • 19,824
  • 17
  • 99
  • 186
iQ.
  • 3,811
  • 6
  • 38
  • 57
  • 3
    Considered creating a WSDL for the remote service? A lot of tooling is then available. – Thorbjørn Ravn Andersen May 03 '12 at 17:20
  • +1 And I recommend to generate the WSDL using the JAX-WS + JAXB annotations. – Puce May 03 '12 at 17:44
  • That's possibly an option, probably may look a bit odd generating a WSDL for a third-party out of my control but that is an option. – iQ. May 04 '12 at 08:49
  • What about the Java's system properties? i.e. sun.net.client.defaultConnectTimeout, are they respected by the SOAPConnection? – iQ. May 04 '12 at 09:26
  • I would not consider it odd to create a WSDL for the 3rd party service. The service has an interface which the 3rd party has apparently not elected to document. Your documentation of the interface in the form of a WSDL is a proactive approach (as much as can be expected) to formalizing the interface to give the tooling generation machinery something to chew on. Also, it will help you recognize if the interface changes in the future. The post at http://stackoverflow.com/questions/2148915/how-do-i-set-the-timeout-for-a-jax-ws-webservice-client provides a little detail on setting the timeout. – dcbyers May 18 '12 at 06:03
  • Have a look at https://stackoverflow.com/a/9687943/2131074 for "how to set a timeout on SAAJ". – GPI Jan 10 '18 at 11:39

1 Answers1

0

The client jar files (stubs) can't be created without a WSDL. Simply put, and I think you'd know this, WSDL is the nucleus around any web service implementation.

Creating a WSDL for the remote service would not be advisable until the remote service publishes it, simply because it may not be viable in the long run. Tomorrow if the parameters of this third party request change, would you be willing to spend effort and time for the corresponding changes in the WSDL? It would result in plenty of maintenance.

I think your basic need is that a SOAPMessage type object should be returned and I guess you should be looking at ways to implement the timeout keeping your current approach intact.

Aditya K
  • 487
  • 3
  • 11