18

WebServiceクライアントで作業していて、WebService呼び出しのタイムアウトを設定したいと思います。私はさまざまなアプローチを試しましたが、それでもこれを達成することはできません。WSDLからのコード生成にJAX-WSを使用しています。アプリケーションサーバーおよびJDK1.6.0_27としてJBoss-eap-5.1を使用しています。タイムアウトを設定するためのこれらのdiffアプローチを見つけましたが、どれも機能していません。

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

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

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();
        }
4

6 に答える 6

22

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

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。詳細については、このスレッドを参照してください。

于 2012-12-22T06:20:33.300 に答える
8

コロッサスが言ったように、次を使用する必要があります:

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
于 2013-04-23T09:05:51.813 に答える
5

私にとっては、問題を設定javax.xml.ws.client.connectionTimeoutしてjavax.xml.ws.client.receiveTimeout解決しました。

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

リンクを参照

于 2014-04-16T04:40:58.117 に答える
3

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

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

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

これは私のために働いた

于 2012-12-25T12:11:29.363 に答える
3

次のオプションを設定するとうまくいきます。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";
于 2014-09-25T21:01:48.437 に答える
0

この環境を持つ古いインストール ランタイムがあります: 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));

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

于 2019-07-11T13:15:44.677 に答える