JBoss 7.1.1上的Jersey客户端抛出了java.net.SocketException:IPv6地址不可用的协议族

时间:2013-07-22 10:59:38

标签: java jersey jboss7.x ipv6

我正在尝试使用Jersey Client连接到REST服务 当我使用IPv4地址时,一切正常 当我尝试用IPv6替换服务器地址时,抛出以下异常:

  

com.sun.jersey.api.client.ClientHandlerException:   java.net.SocketException:协议系列不可用           at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:128)           在com.sun.jersey.api.client.Client.handle(Client.java:551)           在com.sun.jersey.api.client.WebResource.handle(WebResource.java:556)           在com.sun.jersey.api.client.WebResource.access $ 200(WebResource.java:69)           在com.sun.jersey.api.client.WebResource $ Builder.put(WebResource.java:475)           在com.bmc.aps.agent.jersey.JerseyClient.put(JerseyClient.java:169)           在com.bmc.aps.agent.portal.PortalConnection.handshake(PortalConnection.java:304)           在com.bmc.aps.agent.portal.PortalConnection.run(PortalConnection.java:786)           at java.lang.Thread.run(Thread.java:636)引起:java.net.SocketException:协议族不可用           at java.net.PlainSocketImpl.socketConnect(Native Method)           at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)           at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)           at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)           在java.net.Socket.connect(Socket.java:537)           在java.net.Socket.connect(Socket.java:487)           在sun.net.NetworkClient.doConnect(NetworkClient.java:174)           在sun.net.www.http.HttpClient.openServer(HttpClient.java:409)           在sun.net.www.http.HttpClient.openServer(HttpClient.java:530)           在sun.net.www.http.HttpClient。(HttpClient.java:240)           在sun.net.www.http.HttpClient.New(HttpClient.java:321)           在sun.net.www.http.HttpClient.New(HttpClient.java:338)           在sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:806)           at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:747)           at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:672)           at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:850)           at com.sun.jersey.client.urlconnection.URLConnectionClientHandler $ 1 $ 1.getOutputStream(URLConnectionClientHandler.java:200)           在com.sun.jersey.api.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:114)           at com.sun.jersey.api.client.CommittingOutputStream.write(CommittingOutputStream.java:86)           at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:220)           at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:290)           at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:294)           at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:140)           在java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)           在java.io.BufferedWriter.flush(BufferedWriter.java:253)           at com.sun.jersey.core.util.ReaderWriter.writeToAsString(ReaderWriter.java:178)           at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeToAsString(AbstractMessageReaderWriterProvider.java:125)           at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:85)           at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:57)           at com.sun.jersey.api.client.TerminatingClientHandler.writeRequestEntity(TerminatingClientHandler.java:291)           at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:179)           at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:126)           ......还有8个

我尝试使用-Djava.net.preferIPv4Stack=false-Djava.net.preferIPv6Stack=true投放,但没有帮助。

与IPv6相同的代码在Weblogic上的同一台机器上运行。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

以这种方式启动JBoss

  

JBoss 7:./ standalone.sh -Djava.net.preferIPv4Stack = false

  

JBoss 7:./ standalone.sh -Djava.net.preferIPv6Stack = true

默认情况下,在Java中启用IPv4,您需要明确告知使用Ipv6

答案 1 :(得分:0)

这个问题确实可以通过设置-Djava.net.preferIPv4Stack=false来解决,但将其作为参数传递给./standalone.sh是不够的,因为此值会在standalone.confstandalone.sh中重写。

因此,应该做的是在两个文件中搜索-Djava.net.preferIPv4Stack=true并将其修改为-Djava.net.preferIPv4Stack=false