JAXWS - Help Needed to Set WSDL Request Timeout

Im using Metro 2.0 and J2SE5. The application that I wrote does not know about the external WebService at compile time, it finds them at runtime based on the XML business logic file, so I execute the WSDL request.

The sample code I wrote is as follows:

String wsdlServiceName = ...; String wsdlURL = ...; Document payload = ...;

final String nsURI = ...;
final QName serviceName = new QName(nsURI, wsdlServiceName + "Service");
final QName servicePort = new QName(nsURI, wsdlServiceName + "Port");

// Create service and the dispatcher for the SOAP message
Service service = Service.create(new URL(wsdlURL), serviceName);
dispatch = service.createDispatch(servicePort, SOAPMessage.class, Service.Mode.MESSAGE);

// Set timeouts
dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3000);
dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", 3000);

// Create the outgoing SOAP request
SOAPBinding soapBinding = (SOAPBinding) dispatch.getBinding();
request = soapBinding.getMessageFactory().createMessage();

SOAPBody requestBody = request.getSOAPBody();
requestBody.addDocument(payload);

// Invoke web service operation 
SOAPMessage response = dispatch.invoke(request);

code>

Timeout works correctly when calling a web service (dispatcher.invoke (request))

HOWEVER, if a WSDL request is requested before the timeout expires, and if the web service does not respond, then 90 seconds before the connection timeout.

Is it possible to set timeouts before a WSDL request? You need a dispatcher to set timeouts, but this is done AFTER creating a service that requests WSDL ?! (i.e. Service.create ())

+3
2

sun.net.client.defaultConnectTimeout 

,

WSDL .
, WSDL, .

+1

, , .

WSDL , URL.openConnection() ( : URLConnection.setConnectionTimeout() URLConnection.setReadTimeout()). URL- : File.toURI(). ToURL(), , URL-.

WSDL, . - , .

+1

Source: https://habr.com/ru/post/1779170/


All Articles