Tomcat 7上的Jersey抛出了java.net.SocketException:无效的参数

时间:2013-11-26 02:09:43

标签: java exception jersey tomcat7 socketexception

我已经构建了两个Jersey Web应用程序并在Tomcat 7上运行它们。为了简单起见,我将它们称为“App A”和“App B”。

“App A”上有一个端点,它在内部向“App B”发出HTTP请求。

在Java中的“App A”上使用此端点时,偶尔在尝试向“App B”发出请求时会返回以下异常:

java.net.SocketException: Invalid argument
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at org.apache.http.impl.conn.LoggingInputStream.read(LoggingInputStream.java:67)
    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:130)
    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:146)
    at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:259)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:58)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:262)
    at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)
    at com.sun.proxy.$Proxy141.receiveResponseHeader(Unknown Source)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:176)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:77)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:101)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)

异常发生在“App A”尝试向“App B”发出请求的地方。 Tomcat 7在Eclipse中运行,以及独立运行时也会发生这种情况。它同时适用于MacOSX 10.9和Centos 6

尝试使用Python发出相同的请求, ocassionally 会返回相同的异常:

  File "/Library/Python/2.7/site-packages/requests/api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 361, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 464, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 356, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: /mashape-apis-database-server/v1/tags/ (Caused by <class 'httplib.BadStatusLine'>: '')

我正在运行Java 1.7.0_25,Jersey 2.4.1,Tomcat 7和MacOSX 10.9(或Centos 6)。

1 个答案:

答案 0 :(得分:0)

在不同的虚拟机上运行应用程序解决了这个问题。