java - 无法发送消息 : SocketTimeoutException : NotAuthorizedException

标签 java jetty cxf jax-rs

我正在使用 Jetty,并在我的构建服务器上遇到以下问题(我在我的开发计算机上没有遇到此问题)。

2013-07-22 14:19:20,647972350: WARN  : org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://rs.rtiservice.esi.v21.xxxx.com/}RTIServiceRSI has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
<SNIP>
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking http://localhost:25000/esi-rtiservice/ESI/RTIService/rs-rtiservice/addLineItem/: Read timed out
<SNIP>
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    ... 104 more
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
<SNIP>
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1308)
    ... 107 more
2013-07-22 14:19:20,654681221: ERROR : [qtp23135205-124] com.xxx.v21.mpos.MPOSEndPoint: System error
javax.ws.rs.NotAuthorizedException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
<SNIP>
    at java.lang.Thread.run(Thread.java:662)
2013-07-22 14:19:20,656234277: WARN  :  org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://mpos.v21.xxx.com/}MPOSEndPoint has thrown exception, unwinding now
java.lang.IllegalStateException: WRITER
    at org.eclipse.jetty.server.Response.getOutputStream(Response.java:673)
<SNIP>
    at java.lang.Thread.run(Thread.java:662)
2013-07-22 14:19:20,658931461: WARN  : [qtp23135205-124] org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://mpos.v21.xxx.com/}MPOSEndPoint has thrown exception, unwinding now
java.lang.IllegalStateException: WRITER
    at org.eclipse.jetty.server.Response.getOutputStream(Response.java:673)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:564)

现在我可以看到有些人说我需要在连接上设置ReceiveTimeout1 这些人似乎不像我一样有 NotAuthorizedException

我看到的所有例子都是这样的:

<http-conf:destination 
     name="{http://apache.org/hello_world_soap_http}SoapPort.http-destination">
    <http-conf:server ReceiveTimeout="30000"
                      HonorKeepAlive="true" />
  </http-conf:destination>

相反,我这样定义我的:

<jaxrs:client id="itemService" address="http://${itemservice.address}/esi-itemservice/ESI/ItemService" serviceClass="com.xxx.v21.esi.itemservice.rs.ItemServiceRSI" inheritHeaders="true">
        <jaxrs:headers>
            <entry key="Accept" value="application/xml" />
        </jaxrs:headers>
        <jaxrs:providers>
            <ref bean="jaxbextprovider" />
        </jaxrs:providers>
    </jaxrs:client>

有人可以告诉我如何在我的连接上设置 ReceiveTimeout - 或者请给我其他东西吗?

最佳答案

我还没有找到原因,但我采取的解决方法是在集成测试中从 Jetty 切换并开始使用 Cargo 下载 Tomcat、安装工件/wars 并运行测试。

Cargo 测试需要 5 秒,Jetty 需要 5 分钟!所以他们现在都跑了,跑了2分钟,而不是快一个小时了!

简而言之,看看 Cargo (cargo.codehaus.org)

      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.4.5</version>
        <configuration>
          <container>
            <containerId>tomcat7x</containerId>
            <zipUrlInstaller>
              <url>ftp://x.x.x.x/install_pack/Tomcat7/tomcat7.zip</url>
              <downloadDir>${project.build.directory}/cargo/downloads</downloadDir>
            </zipUrlInstaller>
            <output>${project.build.directory}/cargo/container.log</output>
            <append>false</append>
            <log>${project.build.directory}/cargo/cargo.log</log>
            <timeout>240000</timeout>
            <systemProperties>
              <logLevel>INFO</logLevel>
              <itemservice.address>localhost:9080</itemservice.address>
              <deviceservice.address>localhost:9080</deviceservice.address>
              <userservice.address>localhost:9080</userservice.address>
              <rtiservice.address>localhost:9080</rtiservice.address>
              <corporateservice.address>localhost:9080</corporateservice.address>
            </systemProperties>
          </container>
          <configuration>
            <properties>
              <cargo.servlet.port>9080</cargo.servlet.port>
              <cargo.tomcat.ajp.port>9085</cargo.tomcat.ajp.port>
              <cargo.jvmargs>-XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled</cargo.jvmargs>
              <cargo.logging>high</cargo.logging>
            </properties>
          </configuration>
          <deployables>
            <deployable>
              <groupId>com.test</groupId>
              <artifactId>test-war</artifactId>
              <type>war</type>
            </deployable>
          </deployables>
        </configuration>
        <executions>
          <execution>
            <id>start-server</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-server</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

关于java - 无法发送消息 : SocketTimeoutException : NotAuthorizedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17792444/

相关文章:

java - 在卡片布局中定位组件

java - 在 Java 中围绕 char 序列分割字符串

java - 作为 Windows 服务运行的 Jetty 在关闭后不会清理临时文件

java - OkHttp 与 GzipRequestInterceptor 导致来自 Jetty 服务器的 400 Bad Request

logging - logback 日志中的文本长度限制

java - 如何在 TomEE+ 中配置 Apache CXFignoreNamespaces?

java - 使用 CXF 拦截器进行错误处理 - 更改响应消息

java - Spring Batch 生成的项目列表的 Bean ID

java - 在Java中设置类路径

java - 通过链接的 docker 容器将正确的 ip 从 nginx 传递到 jetty