天天看點

使用wsimport生成的用戶端如何設定逾時時間

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

    }

    @WebEndpoint(name = "GeneralWebHttpPort")

    public GeneralWebPortType getGeneralWebHttpPort() {

        return super.getPort(new QName("GeneralWeb", "GeneralWebHttpPort"), GeneralWebPortType.class);

    }

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

用戶端代碼裡面加的那個逾時時間沒有用,該怎麼設定逾時時間啊???