Search code examples
javaeclipseweb-serviceswebsphere

Cannot set custom timeout on JAX-WS Eclipse generated client


I have an existing WSDL and from that used eclipse version 4.5 to generate a client. This gives me a code generated proxy provider. I have tried the following with no success (by the way im using java 7.079):

this.webservice = new ENC3WebAppServicePortProxy(username, password);
Descriptor desc = webservice._getDescriptor();
desc.setEndpoint(webserviceURL);

// Set timeout
BindingProvider bp = (BindingProvider) webservice._getDescriptor().getProxy();
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put("com.sun.xml.ws.connect.timeout", 120000); // Timeout in millis
requestContext.put("com.sun.xml.ws.request.timeout", 120000); // Timeout in millis

Any idea why this would not work?

FYI ive also tried the method of using the ibm-ws-bnd file to have Liberty override the timeout settings but this proved even more difficult as it was impossible to discover where they wanted me to place the @WebServiceRef annotation on the code generated client. The fact that the client is code generated removes my complete understanding of how it works without great effort on my part, and I do not have that kind of time.


Solution

  • this is the way i set endpoint, basic-auth and timeout. this code only differs from yours in the way you get the instance of the "service".

    import com.sun.xml.ws.developer.JAXWSProperties;
    import java.net.URL;
    import javax.xml.ws.BindingProvider;
    
    public void foo(Object service) {
        if (service instanceof BindingProvider) {
            BindingProvider bp = (BindingProvider)service;
            Map<String, Object> ctx = bp.getRequestContext();
            ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, new URL("http://localhost/url-to-endpoint"));
            ctx.put(JAXWSProperties.CONNECT_TIMEOUT, 10000);
            ctx.put(JAXWSProperties.REQUEST_TIMEOUT, 60000);
            ctx.put(BindingProvider.USERNAME_PROPERTY, "auth_user");
            ctx.put(BindingProvider.PASSWORD_PROPERTY, "auth_password");            
        }
    }