3

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

SkorpEN
  • 2,491
  • 1
  • 22
  • 28
NoNaMe
  • 6,020
  • 30
  • 82
  • 110

2 Answers2

5

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);
NoNaMe
  • 6,020
  • 30
  • 82
  • 110
1

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,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • 1
    my WS is SOAP based and used netbeans to generate client to consume web service, can you explain how to set readTimeOut ??? – NoNaMe Dec 14 '12 at 13:26
  • 1
    `readTimeOut` is a property on the HTTP connection. I'm not familiar with Netbeans, but perhaps this thread is helpful: http://stackoverflow.com/questions/9536616/setting-socket-read-timeout-with-javax-xml-soap-soapconnection – Anders R. Bystrup Dec 14 '12 at 13:32