web-dev-qa-db-ja.com

JAX-WS WebService呼び出しのタイムアウトを設定する方法

WebService Clientで作業しており、WebService Callのタイムアウトを設定したい。私はさまざまなアプローチを試みましたが、それでもこれを達成することはできません。 WSDLからのコード生成にJAX-WSを使用しています。私はJBoss-eap-5.1をApp ServerおよびJDK1.6.0_27として使用しています。私はタイムアウトを設定するためのこれらの差分アプローチを見つけましたが、それらのどれも私のために働いていません。

URL mbr_service_url = new URL(null,GlobalVars.MemberService_WSDL, new URLStreamHandler() {

            @Override
            protected URLConnection openConnection(URL url) throws IOException {
                URL clone_url = new URL(url.toString());
                HttpURLConnection clone_urlconnection = (HttpURLConnection) clone_url.openConnection();
                // TimeOut settings
                clone_urlconnection.setConnectTimeout(10000);
                clone_urlconnection.setReadTimeout(10000);
                return (clone_urlconnection);
            }
        });
        MemberService service = new MemberService(mbr_service_url);
        MemberPortType soap = service.getMemberPort();
        ObjectFactory factory = new ObjectFactory();
        MemberEligibilityWithEnrollmentSourceRequest request = factory.createMemberEligibilityWithEnrollmentSourceRequest();

        request.setMemberId(GlobalVars.MemberId);
        request.setEligibilityDate(value);

        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.ws.client.BindingProviderProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.ws.client.BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.internal.ws.client.BindingProviderProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.internal.ws.client.BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.ws.developer.JAXWSProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.ws.developer.JAXWSProperties.CONNECT_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.internal.ws.developer.JAXWSProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.Sun.xml.internal.ws.developer.JAXWSProperties.CONNECT_TIMEOUT, 10000);
        System.setProperty("Sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("Sun.net.client.defaultReadTimeout", "10000");

        MemberEligibilityWithEnrollmentSourceResponse response = soap.getMemberEligibilityWithEnrollmentSource(request);
        logger.log("Call to member service finished.");

今のところ、私が行ったことは、executor内からwebserviceメソッドを呼び出しました。私はそれが良いアプローチではないことを知っていますが、私のために働いています。みんな、適切な方法でそれをするのを手伝ってください。

logger.log("Parameters set for createorUpdateContact call.\nGoing in Executor Service.");
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    response = soap.getMemberEligibilityWithEnrollmentSource(request);
                } catch (MemberServiceException ex) {
                    logger.log("Exception in call to WebService", ex.fillInStackTrace());
                }
            }
        });
        executorService.shutdown();
        try {
            executorService.awaitTermination(GlobalVars.WSCallTimeOut, TimeUnit.SECONDS);
        } catch (InterruptedException ex) {
            logger.log("Thread Interrupted!", ex);
            executorService.shutdownNow();
        }
17
Sandeep Poonia

これらの設定を試すことができます(ペアで使用するためにペアになっています)

_BindingProviderProperties.REQUEST_TIMEOUT
BindingProviderProperties.CONNECT_TIMEOUT
_

BindingProviderPropertiesは_com.Sun.xml.internal.WS.client_からのものでなければなりません

または、文字列 JBossの場合

_javax.xml.ws.client.connectionTimeout
javax.xml.ws.client.receiveTimeout
_

getRequestContext()に設定するすべてのプロパティはミリ秒単位で。

_(BindingProvider)wsPort).getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, yourTimeoutInMillisec);
_

特にJBossの場合は、_StubExt.PROPERTY_CLIENT_TIMEOUT_のプロパティ_org.jboss.ws.core.StubExt_を使用できます。詳細については、 this thread を参照してください。

22
kolossus

コロッサスが言ったように、あなたは使うべきだ:

com.Sun.xml.internal.ws.client.BindingProviderProperties     

文字列値は次のとおりです。

com.Sun.xml.internal.ws.connect.timeout
com.Sun.xml.internal.ws.request.timeout

内部パッケージを使用するべきではありませんが、これはデフォルトのJDK6で作業する場合の唯一の方法です。したがって、この場合、受信と接続のタイムアウトの設定は次のようにして行う必要があります。

bindingProvider.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT,requestTimeoutMs);

bindingProvider.getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT,connectTimeoutMs);

ただし、他のJAXWS参照実装を使用している場合、つまりJAXWS-RT 2.1.4 BindingProviderProperties:は定数値が異なることに注意してください

com.Sun.xml.ws.client.BindingProviderProperties

rEQUEST_TIMEOUTとCONNECT_TIMEOUTに異なる文字列値があります。

com.Sun.xml.ws.request.timeout
com.Sun.xml.ws.connect.timeout
7
user2310395

私にとっては、javax.xml.ws.client.connectionTimeoutjavax.xml.ws.client.receiveTimeoutを設定することで問題が解決しました。

((BindingProvider)port).getRequestContext().put("javax.xml.ws.client.connectionTimeout", timeout);
((BindingProvider)port).getRequestContext().put("javax.xml.ws.client.receiveTimeout", timeout);

参照 リンク

5
Eqbal Murad

次のオプションを設定するとうまくいきます。 Metro JAXWS実装を使用しています。

((BindingProvider)portType).getRequestContext().put(JAXWSProperties.CONNECT_TIMEOUT, 10000);
((BindingProvider) portType).getRequestContext().put(JAXWSProperties.REQUEST_TIMEOUT, 50000);

portTypeは、Webサービスエンドポイントインターフェイスです。

Com.Sun.xml.internal.ws.developer.JAXWSPropertiesの上記フィールドの値

public static final Java.lang.String CONNECT_TIMEOUT = "com.Sun.xml.internal.ws.connect.timeout";
public static final Java.lang.String REQUEST_TIMEOUT = "com.Sun.xml.internal.ws.request.timeout";
3

Jbossws-nativeライブラリをアップグレードし、StubExt.PROPERTY_CLIENT_TIMEOUTを使用します

Jbossws-nativeをアップグレードするには、この link に従ってください。

* jbossws-native-3.4.0は、Jboss 5.1.0GAでサポートされている最新バージョンです。 JBossWS-サポートされるターゲットコンテナー を確認できます。

これは私のために働いた

3
mariami

この環境を持つ古いインストールランタイムがあります:Jdk-1.5、Jboss-4.2.3.GA、WSClientはJAX-WS仕様2.0によって作成されました。

soap Request Timeoutを有効にするには、次のコード((BindingProvider)port).getRequestContext().put(org.jboss.ws.core.StubExt.PROPERTY_CLIENT_TIMEOUT, String.valueOf(readTimeout));を使用します

jar jbossws-client.jarjboss-4.2.3.GA\server\default\lib\にコピーされました

0
Antonio Romano