I'm trying to connect using Jersey Client to a REST service.
When I'm using IPv4 address everything works fine.
When I'm trying to replace the server address with its IPv6 the following exception is thrown:
com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: Protocol family unavailable at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:128) at com.sun.jersey.api.client.Client.handle(Client.java:551) at com.sun.jersey.api.client.WebResource.handle(WebResource.java:556) at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:69) at com.sun.jersey.api.client.WebResource$Builder.put(WebResource.java:475) at com.bmc.aps.agent.jersey.JerseyClient.put(JerseyClient.java:169) at com.bmc.aps.agent.portal.PortalConnection.handshake(PortalConnection.java:304) at com.bmc.aps.agent.portal.PortalConnection.run(PortalConnection.java:786) at java.lang.Thread.run(Thread.java:636) Caused by: java.net.SocketException: Protocol family unavailable 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) at java.net.Socket.connect(Socket.java:537) at java.net.Socket.connect(Socket.java:487) at sun.net.NetworkClient.doConnect(NetworkClient.java:174) at sun.net.www.http.HttpClient.openServer(HttpClient.java:409) at sun.net.www.http.HttpClient.openServer(HttpClient.java:530) at sun.net.www.http.HttpClient.(HttpClient.java:240) at sun.net.www.http.HttpClient.New(HttpClient.java:321) at sun.net.www.http.HttpClient.New(HttpClient.java:338) at 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) at 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) at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) at 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 more
I tried running with -Djava.net.preferIPv4Stack=false
and -Djava.net.preferIPv6Stack=true
but it didn't help.
The same code with IPv6 works on the same machine on Weblogic.
Any suggestions?
Start JBoss in this way
or
By default IPv4 is enabled in Java, you need to tell explicitly to use Ipv6
This problem indeed resolves by setting
-Djava.net.preferIPv4Stack=false
, but passing it as an argument to./standalone.sh
is not enough as this value is rewritten instandalone.conf
andstandalone.sh
.Therefor, what should be done is searching for
-Djava.net.preferIPv4Stack=true
inside both files and modifying them to-Djava.net.preferIPv4Stack=false
.