使用wsimport生成的客户端如何设置超时时间?
网上搜了很多方法都没解决
不是用CXF就是用jdk自带的s生成客户端,代码大致如下:
@WebServiceClient(name = "GeneralWeb", targetNamespace = "GeneralWeb", wsdlLocation = "GeneralWeb?wsdl")
public class GeneralWeb
extends Service
{
static {
URL url = null;
try {
URL baseUrl;
baseUrl = com.goodcol.webservice.oa.GeneralWeb.class.getResource(".");
//url = new URL(baseUrl, "GeneralWeb?wsdl");
url = new URL(baseUrl, PropertiesContent.get("pcoaurl"));
} catch (MalformedURLException e) {
logger.warning("Failed to create URL for the wsdl Location: "+PropertiesContent.get("pcoaurl")+", retrying as a local file");
logger.warning(e.getMessage());
}
GENERALWEB_WSDL_LOCATION = url;
}
public GeneralWeb(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public GeneralWeb() {
super(GENERALWEB_WSDL_LOCATION, new QName("GeneralWeb", "GeneralWeb"));
/*设置超时*/
// Service service = this.create(GENERALWEB_WSDL_LOCATION, new QName("GeneralWeb", "GeneralWeb"));
Map<String,Object> requestContext = ((javax.xml.ws.BindingProvider)this).getRequestContext();
requestContext.put("com.sun.xml.internal.ws.connect.timeout", 3000);
requestContext.put("com.sun.xml.internal.ws.request.timeout", 3000);
}
/**
*
* @return
* returns GeneralWebPortType
*/
@WebEndpoint(name = "GeneralWebHttpPort")
public GeneralWebPortType getGeneralWebHttpPort() {
return super.getPort(new QName("GeneralWeb", "GeneralWebHttpPort"), GeneralWebPortType.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns GeneralWebPortType
*/
@WebEndpoint(name = "GeneralWebHttpPort")
public GeneralWebPortType getGeneralWebHttpPort(WebServiceFeature... features) {
return super.getPort(new QName("GeneralWeb", "GeneralWebHttpPort"), GeneralWebPortType.class, features);
}
调用客户端:
GeneralWeb p = new GeneralWeb();
GeneralWebPortType pp = p.getGeneralWebHttpPort();
String recv = pp.oaManager(xml);
客户端代码里面加的那个超时时间没有用,该怎么设置超时时间啊???