how to set request time out of web service client(java)

11,961

Solution 1

In the class FileUpload that is root class of web service(Generated by netBeans) there were some constructors of the class and function of the super class, one of them i was using to create SOAP object. That was looking like

@WebEndpoint(name = "FileUploadSoap")
public FileUploadSoap getFileUploadSoap() {
   return super.getPort(new QName("http://svc.qleapahead.com/", 
    "FileUploadSoap"), FileUploadSoap.class);
    }

in this function i made some modifications in order to set time out parameter and this became like

@WebEndpoint(name = "FileUploadSoap")
public FileUploadSoap getFileUploadSoap() {
    FileUploadSoap fileUploadSoap = super.getPort(new QName(
            "http://svc.qleapahead.com/", "FileUploadSoap"),
            FileUploadSoap.class);
    ((BindingProvider) fileUploadSoap).getRequestContext().put(
            "com.sun.xml.internal.ws.request.timeout", 1000 * 2 * 60);
    return fileUploadSoap;
}

and problem solved...

in short this statement helped me a lot

((BindingProvider) fileUploadSoap).getRequestContext().put(
                "com.sun.xml.internal.ws.request.timeout", 1000 * 2 * 60);

Solution 2

Depending on the framework you use for calling the webservice, there will be some way of setting a readTimeout causing the call to fail with some kind of exception.

Cheers,

Share:
11,961
NoNaMe
Author by

NoNaMe

Updated on June 04, 2022

Comments

  • NoNaMe
    NoNaMe almost 2 years

    I am working on a desktop based application that is like drop box, I have a function downloadFile(long fileId) that download file for me from web, desktop side of the application is in java where web service is written in .Net

    I have generated WS client using netbeans

    The issue is: Some times it happens that downloadFile(long fileId) function get stuck,

    What ever the reason behind it, I want if web service function does not give any response till a given time I snatch the control back from that function and generate a new call after some time. Is it possible using java?

    EDIT I think that it could be done if can set the request time out of the web service but i don't have idea how to set time out in the client generated by netbeans

  • NoNaMe
    NoNaMe over 11 years
    my WS is SOAP based and used netbeans to generate client to consume web service, can you explain how to set readTimeOut ???
  • Anders R. Bystrup
    Anders R. Bystrup over 11 years
    readTimeOut is a property on the HTTP connection. I'm not familiar with Netbeans, but perhaps this thread is helpful: stackoverflow.com/questions/9536616/…