如何设置Web服务客户端的请求时间(java) [英] how to set request time out of web service client(java)

查看:580
本文介绍了如何设置Web服务客户端的请求时间(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于桌面的应用程序,例如投递箱,我有一个功能downloadFile(long fileId),可以从Web上为我下载文件,该应用程序的桌面端是Java,其中.net编写了Web服务

我已经使用netbeans生成了WS客户端

问题是:有时downloadFile(long fileId)函数卡住

无论出于什么原因,我都希望Web服务功能在给定的时间内没有给出任何响应,直到我从该功能中抢回控件并在一段时间后生成新调用.可以使用Java吗?

编辑我认为如果可以从Web服务中设置请求时间,那可以做到,但是我不知道如何在由netbeans生成的客户端中设置时间

解决方案

在作为Web服务根类(由netBeans生成)的类FileUpload中,有一些超类的类和函数的构造函数,一个我曾经用来创建SOAP对象的对象.看起来像

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

在此函数中,我进行了一些修改以设置超时参数,这变得像

@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;
}

问题已解决...

简而言之,这句话对我有很大帮助

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

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

这篇关于如何设置Web服务客户端的请求时间(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆