java.net.SocketException: Connection reset in spring Rest template - java

I have a strange problem here.
The below code is working fine until I restart the tomcat server at client side. Once I restart the tomcat server (client program is there in the war file) with the latest war file of the same code, it throws the below error.
I am using JDK 8.
Below is the sample code. From the browser, I am able to get a response from the URL used in the below program. but not able to get the data using java program or Postman also.
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
#Component
public class TestService implements CommandLineRunner {
#Override
public void run(String... args) throws Exception {
download();
}
private void download() {
System.out.println("Started download");
try {
RestTemplate restTemplate = new RestTemplate();
String url = "https://www.nseindia.com/live_market/dynaContent/live_watch/stock_watch/niftyStockWatch.json";
byte[] forObject = restTemplate.getForObject(url, byte [].class);
System.out.println(forObject);
System.out.println("Downloaded");
} catch (Exception e) {
System.out.println("Exception " + e);
}
}
}
Here's the exception raised:
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://www.nseindia.com/live_market/dynaContent/live_watch/stock_watch/niftyStockWatch.json": Connection reset; nested exception is java.net.SocketException: Connection reset
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677)
at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:345)
at com.sudhasoft.service.impl.StocksServiceImpl.getNiftyData(StocksServiceImpl.java:183)
at com.sudhasoft.service.impl.StocksServiceImpl.getNifty500Data(StocksServiceImpl.java:154)
at com.sudhasoft.service.impl.PatternServiceImpl.getDataBySignal(PatternServiceImpl.java:444)
at com.sudhasoft.service.impl.PatternServiceImpl.loadDataOnInit(PatternServiceImpl.java:1090)
at com.sudhasoft.service.CacheServiceImpl.initCache(CacheServiceImpl.java:29)
at com.sudhasoft.scheduler.job.CacheJob.clearCache(CacheJob.java:41)
at com.sudhasoft.scheduler.job.CacheJob.executeJob(CacheJob.java:25)
at com.sudhasoft.scheduler.StockScheduler$1.run(StockScheduler.java:120)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:212)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at org.springframework.http.client.OkHttp3ClientHttpRequest.executeInternal(OkHttp3ClientHttpRequest.java:73)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742)
... 10 common frames omitted

The simplest answer is when you restart tomcat simply you close the socket and then you try to send more data to the closed socket.
that is why you get IO exception since you can't write data

This seems to be due to a firewall issue.
In order to solve this issue, you will need to use Proxy Server.
You can add proxy server and port using following 2 lines of code:
System.setProperty("proxyHost", "proxyServer.proxy.com");
System.setProperty("proxyPort", "9801");

This looks like proxy related error.
You need to provide proxy information in order to connect over that URL.
Its working in browser because an internet proxy might already be configured there, it needs to be explicitly provided at code level in order to connect over internet.
Same is the case with Postman. You have to provide proxy server information under Postman configuration.

Related

Manage Timeout with Apache Camel

I have the following Route definition:
#Override
public void configure() throws Exception {
from(String.format("direct:%s", this.connector))
.id("Route1")
.threads()
.maxPoolSize(10)
.keepAliveTime(3000)
.timeUnit(TimeUnit.MICROSECONDS)
.poolSize(1)
.rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
.log("Calling WS")
.maxQueueSize(1)
.to("http://10.8.4.9:8080/service");
}
And the request snipet above:
InputStream exchange = (InputStream) template
.requestBodyAndHeaders(url, AppUtil.parse(this.body, input), this.headers);
The endpoint is intentionally unavaliable. So, I expected my request wait for 3 seconds and throws some exception as response. Insted, the following behaviour happens:
2018-08-24 16:55:55,048 DEBUG http-nio-8081-exec-2 httpclient.HttpMethodDirector:443 - Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
... more stack...
at java.lang.Thread.run(Unknown Source)
2018-08-24 16:56:38,333 INFO http-nio-8081-exec-2 httpclient.HttpMethodDirector:445 - Retrying request
2018-08-24 16:56:38,417 DEBUG http-nio-8081-exec-2 httpclient.HttpConnection:692 - Open connection to 10.8.4.9:8080/service
Camel retries for 3 times and do not respect the timeout.
I've tried to use:
onException(ConnectException.class)
.maximumRedeliveries(0);
No success...
What I missed?
The .keepAliveTime(3000) is not for HTTP endpoints, its an API for the JVM thread pool in Java itself. You can read about this option in the Java API for thread pools, and there is also a bit of javadoc on that method in Camel DSL.
If you need HTTP connection timeout etc, then you need to set specific option on the http endpoint.
https://github.com/apache/camel/blob/master/components/camel-http4/src/main/docs/http4-component.adoc#using-client-timeout---so_timeout

Java HTTPS server code failing

I've been trying to implement a HTTPS/SSL server in Java, and I've tried using a number of different code examples, but they all seem to fail at the point that the server has read the request. Below is one example I've been working with, and when I run that with Firefox, I get this error:
[write] MD5 and SHA1 hashes: len = 16
0000: 14 00 00 0C 73 A7 11 73 AE 3C 41 C5 91 C7 E9 19 ....s..s.<A.....
Padded plaintext before ENCRYPTION: len = 16
0000: 14 00 00 0C 73 A7 11 73 AE 3C 41 C5 91 C7 E9 19 ....s..s.<A.....
main, WRITE: TLSv1.2 Handshake, length = 40
main, waiting for close_notify or alert: state 1
main, Exception while waiting for close java.net.SocketException: Software caused connection abort: recv failed
main, handling exception: java.net.SocketException: Software caused connection abort: recv failed
%% Invalidated: [Session-1, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256]
Priv exp --- null
Exception occurred .... java.net.SocketException: Software caused connection abort: recv failed
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.waitForClose(Unknown Source)
at sun.security.ssl.HandshakeOutStream.flush(Unknown Source)
at sun.security.ssl.Handshaker.sendChangeCipherSpec(Unknown Source)
at sun.security.ssl.ServerHandshaker.sendChangeCipherAndFinish(Unknown Source)
at sun.security.ssl.ServerHandshaker.clientFinished(Unknown Source)
at sun.security.ssl.ServerHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at SSLServer.main(SSLServer.java:65)
and, here's the code:
import java.io.*;
import java.security.Security;
import java.security.PrivilegedActionException;
import javax.net.ssl.*;
import com.sun.net.ssl.*;
import com.sun.net.ssl.internal.ssl.Provider;
/**
* #author Joe Prasanna Kumar
* This program simulates an SSL Server listening on a specific port for client requests
*
* Algorithm:
* 1. Regsiter the JSSE provider
* 2. Set System property for keystore by specifying the keystore which contains the server certificate
* 3. Set System property for the password of the keystore which contains the server certificate
* 4. Create an instance of SSLServerSocketFactory
* 5. Create an instance of SSLServerSocket by specifying the port to which the SSL Server socket needs to bind with
* 6. Initialize an object of SSLSocket
* 7. Create InputStream object to read data sent by clients
* 8. Create an OutputStream object to write data back to clients.
*
*/
public class SSLServer {
/**
* #param args
*/
public static void main(String[] args) throws Exception{
int intSSLport = 4443; // Port where the SSL Server needs to listen for new requests from the client
{
// Registering the JSSE provider
Security.addProvider(new Provider());
//Specifying the Keystore details
System.setProperty("javax.net.ssl.keyStore","C:\\Users\\test\\Eclipse-workspaces\\Test\\newkeystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
// Enable debugging to view the handshake and communication which happens between the SSLClient and the SSLServer
System.setProperty("javax.net.debug","all");
}
try {
// Initialize the Server Socket
SSLServerSocketFactory sslServerSocketfactory = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket = (SSLServerSocket)sslServerSocketfactory.createServerSocket(intSSLport);
SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
// Create Input / Output Streams for communication with the client
while(true)
{
PrintWriter out = new PrintWriter(sslSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(
sslSocket.getInputStream()));
String inputLine, outputLine;
System.out.println("Start reading socket");
while ((inputLine = in.readLine()) != null) {
//out.println(inputLine);
System.out.println(inputLine);
}
System.out.println("Finished reading socket");
// Send the response
// Send the headers
out.println("HTTP/1.0 200 OK");
out.println("Content-Type: text/html");
out.println("Server: Bot");
// this blank line signals the end of the headers
out.println("");
// Send the HTML page
out.println("<H1>Welcome to the Ultra Mini-WebServer</H2>");
out.flush();
// Close the streams and the socket
out.close();
in.close();
sslSocket.close();
sslServerSocket.close();
}
}
catch(Exception exp)
{
PrivilegedActionException priexp = new PrivilegedActionException(exp);
System.out.println(" Priv exp --- " + priexp.getMessage());
System.out.println(" Exception occurred .... " +exp);
exp.printStackTrace();
}
}
}
As I said, I've tried a bunch of other example programs that are similar, and they all seem to fail at the same area, after the read of the request.
NOTE that if I use openssl s_client and type the same input request in manually it works.
Can anyone help point me to what might be wrong?
Thanks,
Jim
EDIT:
I think that I've made some progress, with a different example server code, the one from here:
http://www.herongyang.com/JDK/HTTPS-Server-Test-Program-HttpsHello.html
First of all, again, if I run this app and hit it from "openssl s_client", it works fine when I manually enter a "GET".
But, if I try using Firefox, as soon as I send a request to https://192.168.0.6:8888 (FYI, doesn't matter if I use a hostname that matches cert), I get a popup asking me to add an exception and ALSO, I get at the app/server end:
Server started:
Server socket class: class sun.security.ssl.SSLServerSocketImpl
Socket address = 0.0.0.0/0.0.0.0
Socket port = 8888
Need client authentication = false
Want client authentication = false
Use client mode = false
Socket class: class sun.security.ssl.SSLSocketImpl
Remote address = /192.168.0.5
Remote port = 58972
Local socket address = /192.168.0.5:8888
Local address = /192.168.0.5
Local port = 8888
Need client authentication = false
Cipher suite = SSL_NULL_WITH_NULL_NULL
Protocol = NONE
Read=[null]
java.net.SocketException: Connection closed by remote host
at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at HttpsHello.main(HttpsHello.java:43)
So, I did something differently.
I started Firefox, then went to Options->Advanced->Certificates->Add Exception
For the exception, I put the URL to get the cert, https://192.168.0.5:8888
The app blew up as soon as I clicked "Get Certificate":
Server started:
Server socket class: class sun.security.ssl.SSLServerSocketImpl
Socket address = 0.0.0.0/0.0.0.0
Socket port = 8888
Need client authentication = false
Want client authentication = false
Use client mode = false
Socket class: class sun.security.ssl.SSLSocketImpl
Remote address = /192.168.0.5
Remote port = 59018
Local socket address = /192.168.0.5:8888
Local address = /192.168.0.5
Local port = 8888
Need client authentication = false
Cipher suite = SSL_NULL_WITH_NULL_NULL
Protocol = NONE
Read=[null]
java.net.SocketException: Connection closed by remote host
at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at HttpsHello.main(HttpsHello.java:43)
BUT, Firefox let me add a temporary exception at this point!!
Ok, then after adding the temporary exception, I restarted the app, and put in https://192.168.0.5:8888 into the Firefox address, and, at that point, IT WORKED, i.e., I got the "Hello world" web page in Firefox!!
Does anyone know why this is happening? Why is it that "openssl s_client" works, but it blows up with Firefox, APPARENTLY when Firefox is getting the cert from the app to add the cert as an exception?
EDIT 2:
I posted in comments that I got this working on one of my laptops, but I still haven't gotten it working on my main development machine.
I am pasting in the SSL debug log from a test I just did at:
http://pastebin.com/faVCjj3a
If anyone can see anything that might be causing this please let me know? I did this test after moving over the exact JKS file and certs from the working system. Also, I've installed the unlimited strength policy jars on this other system.
Thanks...
EDIT 3: I think I've finally found an example that seems to work:
http://www.mybinarylife.net/2012/06/java-ssl-threaded-echo-server.html
I modified that code slightly to send HTTP response instead of just echoing the request, and it seems to work even with a browser like Firefox.
It appears that the difference between hitting the server with openssl s_client and a browser is that when the first request is made, and the browser finds some problem like the hostname not matching the cert or other situations, and when the browser like Firefox is asking for an exception, there is an SSL error, so the server has to be able to handle that and continue handling the request/connection, rather than just dying, which this new example seems to do.

SocketException: Connection reset -

I know i am making a simple mistake but cannot figure out whats the mistake.
I have an external API where I need to post certain parameters. I tested this API using Advanced Rest Client and it works fine.
In my server side, i use
ResponseEntity<String> response = asyncRestTemplate.getRestOperations().postForEntity(URL, String.class);
But then this method always throws a exception for the particular URL that i am testing.
I tried other URLS and it works perfectly fine.
Is it possible that the connection reset might occur because the third party who provided me the URL is closing the connection. If it is so, how did Advanced Rest Client manage to get the result?
This is the stack Trace
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://1984.carpal.me/api/v1/quote/":Connection reset; nested exception is java.net.SocketException: Connection reset
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:580)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:357)
at sg.oddlefnb.common.helper.CarpalApiHelper.getRequestEntityForNewJob(CarpalApiHelper.java:115)
at sg.oddlefnb.common.helper.PartnerApiHelper.postNewJob(PartnerApiHelper.java:54)
at sg.oddlefnb.common.helper.PartnerApiHelper$$FastClassBySpringCGLIB$$b2958cff.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:110)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:251)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
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.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:81)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:569)
... 12 more

org.postgresql.util.PSQLException: The connection attempt failed

I am connecting to postgres data base using java web services (apache axis) with JDBC connections to get the data.But suddenly in most of times i am getting an exception of org.postgresql.util.PSQLException: The connection attempt failed. and some times it is working fine. Here I am using many prepared statements. My sample code is
Connection connection=null;
try
{
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
ps1=connection.prepareStatement("select * from emp");
rs1=ps1.executeQuery();
while(rs1.next())
{
ps2=connection.prepareStatement("select * from dept where dept_no="+rs1.getInt("dept_no"));
rs2=ps2.executeQuery();
while(rs2.next())
{
................
................
}
}
}
catch(Exception e)
{
System.out.println("Exception occurred is"+e.getMessage());
}
finally
{
try{if(rs1!=null)rs1.close();}catch(Exception e){ System.out.println("*1closing error--->"+e);}
try{if(ps1!=null)ps1.close();}catch(Exception e){ System.out.println("**1closing error--->"+e);}
try{if(rs2!=null)rs2.close();}catch(Exception e){ System.out.println("*2closing error--->"+e);}
try{if(ps2!=null)ps2.close();}catch(Exception e){ System.out.println("**2closing error--->"+e);}
try{if(connection!=null)connection.close();}catch(Exception e){ System.out.println("***closing error--->"+e);}
}
stack trace about this exception is
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:137)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:386)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.codon.service.WareHouseServer.get_picks(WareHouseServer.java:7415)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:135)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:104)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73)
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:259)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:254)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:95)
... 37 more
I checked the postgres logs and i found the following statements in different cases
1.WARNING: worker took too long to start; cancelled.
2.could not reattach to shared memory (key=...., addr=.....): 487.
3.could not receive data from client: No connection could be made because the target machine actively refused it.
4.unexpected EOF on client connection.
please help me.Thanks In advance
The real problem is:
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read
The connection was closed when Java tried to read from it. This can be caused by:
The PostgreSQL server being restarted
The PostgreSQL backend you were connected to being terminated
The PostgreSQL backend you were connected to crashing
Dodgy network connection
Badly behaved stateful firewalls
Idle connections timing out of the NAT connection tables of NAT firewall/routers
... and probably more. Check the PostgreSQL server logs to see if there's anything informative there; also consider doing some network tracing with a tool like Wireshark.
Try chekin Postgresql version, in my case I deployed my app with:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16</version>
</dependency>
But in local I used 42.2.18 and worked fine, so I din't know after checking version, so you should try another versions maybe.
Fixed for me:
hop onto the pg_hba.conf file and under IPV4 connection change its 127.xxxx to the 0.0.0.0/0
double check: hop onto the postgresql.conf and change the listenaddresses to * (im sure you know that you need to delete the starting # first in order to make it work)
Good luck!

ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error [duplicate]

This question already has answers here:
java.net.SocketException: Connection reset
(14 answers)
Closed 7 years ago.
I am getting the following error frequently while retrieving file object from database column. How can I resolve this problem?
May 8, 2009 3:18:14 PM org.apache.catalina.core.StandardHostValve status
WARNING: Exception Processing ErrorPage[errorCode=404, location=/error.jsp]
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:327)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:293)
at org.apache.catalina.connector.Response.flushBuffer(Response.java:537)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:286)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:746)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:304)
at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:991)
at org.apache.coyote.Response.action(Response.java:182)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:322)
... 13 more
Your HTTP client disconnected.
This could have a couple of reasons:
Responding to the request took too long, the client gave up
You responded with something the client did not understand
The end-user actually cancelled the request
A network error occurred
... probably more
You can fairly easily emulate the behavior:
URL url = new URL("http://example.com/path/to/the/file");
int numberOfBytesToRead = 200;
byte[] buffer = new byte[numberOfBytesToRead];
int numberOfBytesRead = url.openStream().read(buffer);
Your log indicates ClientAbortException, which occurs when your HTTP client drops the connection with the server and this happened before server could close the server socket Connection.
I have got this error on open page from Google Cache.
I think, cached page(client) disconnecting on page loading.
You can ignore this error log with try-catch on filter.
Windows Firewall could cause this exception, try to disable it or add a rule for port or even program (java)

Categories

Resources