HTTPClient-java.net.SocketException: Unconnected sockets not implemented thrown - java

Iam using HTTPClient 4.0 to connect a remote server and transfer file using HTTPS.
When i tried to connect i get the exception "java.net.SocketException: Unconnected sockets not implemented".
Please look at the stack trace
java.net.SocketException: Unconnected sockets not implemented
at java.lang.Throwable.<init>(Throwable.java:196)
at java.lang.Exception.<init>(Exception.java:41)
at java.io.IOException.<init>(IOException.java:40)
at java.net.SocketException.<init>(SocketException.java:29)
at javax.net.SocketFactory.createSocket(SocketFactory.java:2)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(Unknown Source)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(Unknown Source)
at org.apache.commons.httpclient.HttpConnection.open(Unknown Source)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Unknown Source)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Unknown Source)
at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
at co.com.personalsoft.ftpseguro.utilidades.TransmisionHTTP.ejecutarTransmisionHTTP(TransmisionHTTP.java:107)
at co.com.personalsoft.ftpseguro.utilidades.TransmisionFTPNew.ejecutarTransmisionAuto(TransmisionFTPNew.java:483)
at co.com.personalsoft.ftpseguro.utilidades.TransmisionFTPNew.ejecutarTransmision(TransmisionFTPNew.java:1016)
at co.com.personalsoft.ftpautomatico.ConexionThread.run(ConexionThread.java:58)
at java.lang.Thread.run(Thread.java:595)
The same error is found while using HTTP Client 3.1.
My Environment
Application Server : Websphere application server 6.1.0.23
Java : JDK 1.5.0.16

Actually a more complete answer than suppressingfire is
Add com.ibm.ws.admin.client_7.0.0.jar to java build
This solves the java.lang.NoClassDefFoundError: com.ibm.ffdc.Manager error.
Add to setup:
import java.security.Security;
...
Security.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl");
This solves the Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory

When I enabled javax.net.debug, I noticed that there was a missing class com.ibm.websphere.com.ibm.websphere.ssl.protocol.SSLSocketFactory.
I was experiencing trouble in unit tests that invoke httpclient. What I ended up doing was to add this line to my TestClass.setUp()
Security.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl");

Related

Server closes connection when trying to connect Java application to Redshift database

I'm trying to connect a Java application to a Redshift database. When I run DriverManager.getConnection(), it sits for a long time (minutes) and finally throws an exception:
Exception in thread "main" java.sql.SQLException:
[Amazon](600001) The server closed the connection.
at com.amazon.support.channels.TLSSocketChannel.readBytes(Unknown Source)
at com.amazon.support.channels.TLSSocketChannel.doHandshake(Unknown Source)
at com.amazon.support.channels.TLSSocketChannel.<init>(Unknown Source)
at com.amazon.redshift.client.PGClient.checkSSL(Unknown Source)
at com.amazon.redshift.client.PGClient.<init>(Unknown Source)
at com.amazon.redshift.core.PGJDBCConnection.connect(Unknown Source)
at com.amazon.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.amazon.jdbc.common.AbstractDriver.connect(Unknown Source)
at com.amazon.redshift.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
I can connect using the same connection string and credentials from SQL Workbench on the same machine. Also, if I supply bad credentials to the connection, it gives an authentication error. So I don't believe this is an Amazon security issue, which seems to be the most common reason for an inability to connect.
Other ideas?
Update: The mystery deepens. Other members of the team are able to check out the code and run it successfully. We have the driver in our team's shared maven repository.
Well... not sure what the problem was. But I did an Eclipse update and it went away.

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

I am launching a JNLP downloaded from my web application.
After being prompted with a Java Security Warning prompt, the application can run successfully if the user response is within 2-3 seconds. However, if the user took more than 3 seconds to respond to the Java Security Warning prompt, the application fails to run with error with the following socket exception:
javax.net.ssl.SSLHandshakeException: Remote host closed connection during
handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake
(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake
(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake
(SSLSocketImpl.java:1323)
at sun.net.www.protocol.https.HttpsClient.afterConnect
(HttpsClient.java:563)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream
(HttpURLConnection.java:1300)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream
(HttpsURLConnectionImpl.java:254)
at com.sun.deploy.net.HttpUtils.followRedirects(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequestEX(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.checkUpdateAvailable
(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.isUpdateAvailable(Unknown
Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:482)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
... 19 more
Java Security Warning
Exception
Additional Info: I have checked the ports and they were pointing on the correct port numbers and TLS value also matched. The certificates were also added under cacerts.
Question: What causes the exception when response to the security prompt reaches more than 3-5 seconds? and how can I avoid the mentioned exception(possibly increase the waiting time)?
Actions done:
1. Add connectionTimeout attribute in Tomcat connector, but still, after 5 seconds of waiting time to respond to the Java Security Warning, the application still fails to launch.
This is most easily controlled by the https.protocols system property. This is how you are able to control what the factory method returns. Set to "TLSv1" for example.
It leads to problems when you want to use two protocols instead of one. For example, SSLv3 and TLSv1. This -Dhttps.protocols=TLSv1,SSLv3 will lead to exceptions if you try to connect either SSLv3 or TLSv1.
Please check this answer.
How to make Java 6, which fails SSL connection with "SSL peer shut down incorrectly", succeed like Java 7?
I was facing the same problem, then I switched from JRE1.7 to JRE1.8 of course for reason TLS1.2 More references

I am not able to pull files from SFTP file source while I am able to connect through FileZilla

I am getting "Failed to negotiate transport Component" in the log. Does anybody have any idea what can be the cause, because it doesn't seem to be any code side issue.
Thanks in advance.
Failed to negotiate a transport component [aes192-cbc] [arcfour] [Unknown cause]
at com.maverick.ssh2.TransportProtocol.B(Unknown Source)
at com.maverick.ssh2.TransportProtocol.C(Unknown Source)
at com.maverick.ssh2.TransportProtocol.processMessage(Unknown Source)
at com.maverick.ssh2.TransportProtocol.startTransportProtocol(Unknown Source)
at com.maverick.ssh2.Ssh2Client.connect(Unknown Source)
at com.maverick.ssh.SshConnector.connect(Unknown Source)
at com.maverick.ssh.SshConnector.connect(Unknown Source)
The server supports "arcfour" cipher only, while your client supports "aes192-cbc" only.
The j2ssh-maverick implements the "arcfour" too. You can enable it by using JCEComponentManager.installArcFourCiphers.
Though note that "arcfour" is a weak cipher and you should avoid it, if possible. Consider upgrading the server.

Unable to call Web Services after upgrading JRE to 8u65

I have a web service hosted on IIS on windows machine. Everything went fine until I upgraded Java to JRE 8u65.
Now it is throwing the below exception on invoking the web service.
Exception in thread "main" java.net.SocketException: Unexpected end of
file from server at
sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source) at
sun.net.www.http.HttpClient.parseHTTP(Unknown Source) at
sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source) at
sun.net.www.http.HttpClient.parseHTTP(Unknown Source) at
sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown
Source) at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source) at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown
Source)
Note : Previously I was using JRE 8u60. Any help in this regard is really helpful.
Thanks in advance!
The stacktrace you have shown us comes from a Java client for your web service. What is saying is that the server has closed the network connection before sending an HTTP response.
There is no evidence in this stacktrace to say why the web service did that. The evidence is probably in the service logs.

Axis2 SocketTimeoutException: Read Time Out

I am trying the build a SOAP client to access the National Weather Service NDFD SOAP Service. I'm using Axis2 1.6.2 with code generated with wsdl2java.
Every time I try to retrieve data, I receive a AxisFault saying Read timed out.
I have tried to increase the timeout time to up to 500 s, but all that does is make it wait longer before giving the same error.
Exception in thread "main" org.apache.axis2.AxisFault: [was class java.net.SocketTimeoutException] Read timed out
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at gov.weather.graphical.xml.dwmlgen.wsdl.ndfdxml_wsdl.NdfdXMLStub.fromOM(NdfdXMLStub.java:26499)
at gov.weather.graphical.xml.dwmlgen.wsdl.ndfdxml_wsdl.NdfdXMLStub.nDFDgen(NdfdXMLStub.java:595)
at he.andrew.ndfd.NDFDData.getData(NDFDData.java:47)
at he.andrew.ndfd.NDFDData.main(NDFDData.java:25)
Caused by: java.lang.RuntimeException: [was class java.net.SocketTimeoutException] Read timed out
at com.ctc.wstx.util.ExceptionUtil.throwRuntimeException(ExceptionUtil.java:18)
at com.ctc.wstx.sr.StreamScanner.throwLazyError(StreamScanner.java:731)
at com.ctc.wstx.sr.BasicStreamReader.safeFinishToken(BasicStreamReader.java:3657)
at com.ctc.wstx.sr.BasicStreamReader.getText(BasicStreamReader.java:809)
at com.ctc.wstx.sr.BasicStreamReader.getElementText(BasicStreamReader.java:679)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.getElementText(XMLStreamReaderWrapper.java:100)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.getElementText(XMLStreamReaderWrapper.java:100)
at org.apache.axiom.om.impl.llom.SwitchingWrapper.getElementText(SwitchingWrapper.java:936)
at javax.xml.stream.util.StreamReaderDelegate.getElementText(Unknown Source)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.getElementText(XMLStreamReaderWrapper.java:100)
at org.apache.axiom.util.stax.debug.XMLStreamReaderValidator.getElementText(XMLStreamReaderValidator.java:75)
at gov.weather.graphical.xml.dwmlgen.wsdl.ndfdxml_wsdl.NdfdXMLStub$NDFDgenResponse$Factory.parse(NdfdXMLStub.java:5612)
at gov.weather.graphical.xml.dwmlgen.wsdl.ndfdxml_wsdl.NdfdXMLStub.fromOM(NdfdXMLStub.java:26353)
... 3 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at org.apache.commons.httpclient.WireLogInputStream.read(WireLogInputStream.java:69)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:182)
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108)
at java.io.FilterInputStream.read(Unknown Source)
... more not included
The error seems to be the same as the one here: Exception in thread "main" org.apache.axis2.AxisFault: Read timed out. However, I don't quite understand any of the responses to that question.
One final note. In order to avoid a "411 Error: Length Required", I had to turn off the Chunked option. I'm not sure if this is relevant.
Does anyone know what might be the problem?
I ran into this error on a project, and the root cause was a proxy server setting. I had to modify the proxy to allow the communication to the service I was trying to hit. My code was running as part of a custom application that used its own proxy. So this may also be something to try.

Categories

Resources