如何设置Web服务客户端的请求时间(java)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13878154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to set request time out of web service client(java)
提问by NoNaMe
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
我正在开发一个类似于投递箱的基于桌面的应用程序,我有一个功能downloadFile(long fileId)
可以从网络上为我下载文件,应用程序的桌面端是在 java 中,其中 web 服务是用 .Net 编写的
I have generated WS client using netbeans
我已经使用 netbeans 生成了 WS 客户端
The issue is:Some times it happens that downloadFile(long fileId)
function get stuck,
问题是:有时downloadFile(long fileId)
函数会卡住,
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?
无论其背后的原因是什么,我想要如果 Web 服务功能在给定时间之前没有给出任何响应,我将从该功能中夺回控制权并在一段时间后生成一个新调用。可以使用java吗?
EDITI 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
编辑我认为如果可以设置 Web 服务的请求时间,则可以完成,但我不知道如何在由 netbeans 生成的客户端中设置超时
回答by NoNaMe
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
在作为FileUpload
Web 服务的根类(由 netBeans 生成)的类中,有一些超类的类和函数的构造函数,其中之一用于创建SOAP
对象。那看起来像
@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);
回答by Anders R. Bystrup
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.
根据您用于调用 Web 服务的框架,将有某种方式设置 areadTimeout
导致调用失败并出现某种异常。
Cheers,
干杯,