java web 耗时请求,如何设置Web服务客户端的请求时间(java)

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

解决方案

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值