我如何修复java.net.SocketTimeoutException:读取超时

时间:2016-03-31 14:11:30

标签: java web-services soap axis2

我正在使用Axix2进行Web服务,我使用的是jboss 5.1。 我的应用程序运行正常,但现在我每次都

  

java.net.SocketTimeoutException:读取超时

Bellow是堆栈跟踪

Caused by: java.net.SocketTimeoutException: Read timed out
17:00:36,231 ERROR [STDERR] 	at java.net.SocketInputStream.socketRead0(Native Method)
17:00:36,231 ERROR [STDERR] 	at java.net.SocketInputStream.read(SocketInputStream.java:129)
17:00:36,231 ERROR [STDERR] 	at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:422)
17:00:36,231 ERROR [STDERR] 	at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:460)
17:00:36,231 ERROR [STDERR] 	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:863)
17:00:36,231 ERROR [STDERR] 	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:820)
17:00:36,231 ERROR [STDERR] 	at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
17:00:36,231 ERROR [STDERR] 	at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
17:00:36,231 ERROR [STDERR] 	at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
17:00:36,231 ERROR [STDERR] 	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
17:00:36,231 ERROR [STDERR] 	at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
17:00:36,241 ERROR [STDERR] 	at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)

我在网上搜索,并发现我需要增加套接字时间。

所以这是我从Apache foundation获得的解决方案

Timeout Configuration

Two timeout instances exist in the transport level, Socket timeout and Connection timeout. These can be configured either at deployment or run time. If configuring at deployment time, the user has to add the following lines in axis2.xml.

For Socket timeout:

<parameter name="SO_TIMEOUT">some_integer_value</parameter>

For Connection timeout:

 <parameter name="CONNECTION_TIMEOUT">some_integer_value</parameter>


For runtime configuration, it can be set as follows within the client stub:

...
Options options = new Options();
options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));

// or
options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
...

我尝试的第一件事就是这个。

options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);

在这样做之后我仍然得到了吼叫错误。

  

java.net.SocketTimeoutException:读取超时

第二种方法我尝试这样做是为了修改我的axis2.xml

所以,我检查了axis2-1.6.2.jar并查找了axis2.xml。

并尝试在axis2.xml

中查找bellow参数
<parameter name="SO_TIMEOUT">some_integer_value</parameter>
<parameter name="CONNECTION_TIMEOUT">some_integer_value</parameter>

贝娄是我axis2.xml的内容,但我没有看到上面的任何参数。

我已移除所有评论表单axis2.xml以缩短问题的长度。

<axisconfig name="AxisJava2.0">
  
    <parameter name="hotdeployment">true</parameter>
    <parameter name="hotupdate">false</parameter>
    <parameter name="enableMTOM">false</parameter>
    <parameter name="enableSwA">false</parameter>
    <parameter name="EnableChildFirstClassLoading">false</parameter>
    <parameter name="exposeServiceMetadata">true</parameter>
    <parameter name="ConfigContextTimeoutInterval">30000</parameter>
    <parameter name="sendStacktraceDetailsWithFaults">false</parameter>
    <parameter name="DrillDownToRootCauseForFaultReason">false</parameter>
    <parameter name="userName">admin</parameter>
    <parameter name="password">axis2</parameter>
    <parameter name="disableREST" locked="false">false</parameter>
    <parameter name="disableSOAP12" locked="true">false</parameter>
    <deployer extension=".class" directory="pojo" class="org.apache.axis2.deployment.POJODeployer"/>
    <deployer extension=".jar" directory="servicejars"
              class="org.apache.axis2.jaxws.framework.JAXWSDeployer"/>
    <deployer extension=".jar" directory="transports"
              class="org.apache.axis2.deployment.TransportDeployer"/>
    <parameter name="useGeneratedWSDLinJAXWS">false</parameter>
    <threadContextMigrators>
        <threadContextMigrator listId="JAXWS-ThreadContextMigrator-List"
                               class="org.apache.axis2.jaxws.addressing.migrator.EndpointContextMapMigrator"/>
    </threadContextMigrators>

    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-only"
                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-out"
                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
    </messageReceivers>
    <messageFormatters>
        <messageFormatter contentType="application/x-www-form-urlencoded"
                          class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
        <messageFormatter contentType="multipart/form-data"
                          class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
        <messageFormatter contentType="application/xml"
                          class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
        <messageFormatter contentType="text/xml"
                          class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
        <messageFormatter contentType="application/soap+xml"
                          class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
    </messageFormatters>
    <messageBuilders>
        <messageBuilder contentType="application/xml"
                        class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
        <messageBuilder contentType="application/x-www-form-urlencoded"
                        class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
        <messageBuilder contentType="multipart/form-data"
                        class="org.apache.axis2.builder.MultipartFormDataBuilder"/>
    </messageBuilders>

  
    <transportReceiver name="http"
                       class="org.apache.axis2.transport.http.SimpleHTTPServer">
        <parameter name="port">8080</parameter>
     
    </transportReceiver>

    <transportSender name="local"
                     class="org.apache.axis2.transport.local.LocalTransportSender"/>
    <transportSender name="http"
                     class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
        <parameter name="PROTOCOL">HTTP/1.1</parameter>
        <parameter name="Transfer-Encoding">chunked</parameter>

    </transportSender>

    <transportSender name="https"
                     class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
        <parameter name="PROTOCOL">HTTP/1.1</parameter>
        <parameter name="Transfer-Encoding">chunked</parameter>
    </transportSender>

    <module ref="addressing"/>
    <clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="false">
        <parameter name="AvoidInitiation">true</parameter>
        <parameter name="membershipScheme">multicast</parameter>
        <parameter name="domain">wso2.carbon.domain</parameter>
        <parameter name="synchronizeAll">true</parameter>
        <parameter name="maxRetries">10</parameter>
        <parameter name="mcastAddress">228.0.0.4</parameter>
        <parameter name="mcastPort">45564</parameter>
        <parameter name="mcastFrequency">500</parameter>
        <parameter name="memberDropTime">3000</parameter>
        <parameter name="mcastBindAddress">127.0.0.1</parameter>
        <parameter name="localMemberHost">127.0.0.1</parameter>
        <parameter name="localMemberPort">4000</parameter>
        <parameter name="preserveMessageOrder">true</parameter>
        <parameter name="atmostOnceMessageSemantics">true</parameter>
        <parameter name="properties">
            <property name="backendServerURL" value="https://${hostName}:${httpsPort}/services/"/>
            <property name="mgtConsoleURL" value="https://${hostName}:${httpsPort}/"/>
        </parameter>
        <members>
            <member>
                <hostName>127.0.0.1</hostName>
                <port>4000</port>
            </member>
            <member>
                <hostName>127.0.0.1</hostName>
                <port>4001</port>
            </member>
        </members>
        <groupManagement enable="false">
            <applicationDomain name="apache.axis2.application.domain"
                               description="Axis2 group"
                               agent="org.apache.axis2.clustering.management.DefaultGroupManagementAgent"/>
        </groupManagement>
        <nodeManager class="org.apache.axis2.clustering.management.DefaultNodeManager"
                         enable="true"/>
        <stateManager class="org.apache.axis2.clustering.state.DefaultStateManager"
                      enable="true">
            <replication>
                <defaults>
                    <exclude name="local_*"/>
                    <exclude name="LOCAL_*"/>
                </defaults>
                <context class="org.apache.axis2.context.ConfigurationContext">
                    <exclude name="local_*"/>
                </context>
                <context class="org.apache.axis2.context.ServiceGroupContext">
                    <exclude name="local_*"/>
                </context>
                <context class="org.apache.axis2.context.ServiceContext">
                    <exclude name="local_*"/>
                </context>
            </replication>
        </stateManager>
    </clustering>
    <phaseOrder type="InFlow">
        <!--  System predefined phases       -->
        <phase name="Transport">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
                <order phase="Transport"/>
            </handler>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher">
                <order phase="Transport"/>
            </handler>
        </phase>
        <phase name="Addressing">
            <handler name="AddressingBasedDispatcher"
                     class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
                <order phase="Addressing"/>
            </handler>
        </phase>
        <phase name="Security"/>
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
            <handler name="RequestURIOperationDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
            <handler name="SOAPMessageBodyBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
            <handler name="HTTPLocationBasedDispatcher"
                     class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
            <handler name="GenericProviderDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
            <handler name="MustUnderstandValidationDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
        </phase>
        <phase name="RMPhase"/>
        <phase name="OperationInPhase">
            <handler name="MustUnderstandChecker"
                     class="org.apache.axis2.jaxws.dispatchers.MustUnderstandChecker">
                <order phase="OperationInPhase"/>
            </handler>
        </phase>
        <phase name="soapmonitorPhase"/>
    </phaseOrder>
    <phaseOrder type="OutFlow">
    
        <phase name="soapmonitorPhase"/>
        <phase name="OperationOutPhase"/>
        <!--system predefined phase-->
        <!--these phase will run irrespective of the service-->
        <phase name="RMPhase"/>
        <phase name="PolicyDetermination"/>
        <phase name="MessageOut"/>
        <phase name="Security"/>
    </phaseOrder>
    <phaseOrder type="InFaultFlow">
        <phase name="Addressing">
            <handler name="AddressingBasedDispatcher"
                     class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
                <order phase="Addressing"/>
            </handler>
        </phase>
        <phase name="Security"/>
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
            <handler name="RequestURIOperationDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
            <handler name="SOAPMessageBodyBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
            <handler name="HTTPLocationBasedDispatcher"
                     class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
            <handler name="GenericProviderDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
            <handler name="MustUnderstandValidationDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
        </phase>
        <phase name="RMPhase"/>
        <!--      user can add his own phases to this area  -->
        <phase name="OperationInFaultPhase"/>
        <phase name="soapmonitorPhase"/>
    </phaseOrder>
    <phaseOrder type="OutFaultFlow">
        <!--      user can add his own phases to this area  -->
        <phase name="soapmonitorPhase"/>
        <phase name="OperationOutFaultPhase"/>
        <phase name="RMPhase"/>
        <phase name="PolicyDetermination"/>
        <phase name="MessageOut"/>
        <phase name="Security"/>
    </phaseOrder>
</axisconfig>

任何人都可以帮我配置axis2.xml以增加socket time outconnection time out

0 个答案:

没有答案