Java.net.SocketException: Verbindung nur auf Tomcat zurückgesetztJava

Java-Forum
Anonymous
 Java.net.SocketException: Verbindung nur auf Tomcat zurückgesetzt

Post by Anonymous »

Ich weiß, dass dies schon einmal gefragt wurde, und ich habe versucht, mir mindestens 30, wenn nicht mehr, Lösungen für Stackoverflow anzuschauen, aber bisher hat nichts funktioniert.

Ich habe einen Tomcat-Server, der eine Abfrage an eine REST-API sendet, um Daten abzurufen und zu speichern. Dadurch soll vermieden werden, dass die Daten jedes Mal, wenn meine App die Daten laden möchte, an die Remote-API abgefragt werden müssen. Die Daten ändern sich nur gelegentlich und daher dieser Aufwand.
Ich habe einen einfachen Code zum Verbinden

Code: Select all

final URL url = new URL("https://remote.site.com/api/request?apikey=");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.connect();
final InputStream inputStream = connection.getInputStream();
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
final Gson gson = new Gson();
MyJSONResponse myJSONResponse = gson.fromJson(inputStreamReader, MyJSONResponse.class);
Wenn ich diesen Code von einem Tomcat7-Server auf meinem MacBook ausführe, läuft er einwandfrei. Ich bekomme den JSON und alles ist in Ordnung. Also habe ich dies vom Tomcat7-Server auf meinem Ubuntu aus ausgeführt und erhalte fast sofort die SocketException.

Ich gebe zu, dass die Daten etwas lang sind, aber ich gehe davon aus, dass sie einige Sekunden warten, bevor diese Ausnahme ausgelöst wird. Diese Ausnahme wird jedoch in der Zeile

ausgelöst

Code: Select all

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
was für mich keinen Sinn ergibt.
Um es weiter zu testen, habe ich ein Einzelklassenprogramm erstellt, das nur diese Codezeilen enthält und den Eingabestream ausgibt, den ich von der Remote-API bekomme, und habe es auf meiner Ubuntu-Box ausgeführt und es läuft einwandfrei. An der Ubuntu-Box und ihrer Internetverbindung ist also nichts auszusetzen. Der Tomcat-Server scheint hier etwas durcheinander zu bringen.
Ich versuche jetzt seit 4–5 Stunden, mehrere Dinge zu tun, z. B. die Verbindung zurückzusetzen, sie im „finally“-Block nicht zu schließen und andere Dinge, aber nichts scheint zu funktionieren.
Jede Hilfe wäre wirklich dankbar.
Vielen Dank

Bearbeiten:
Protokolle für Zeitüberschreitung hinzufügen:

Code: Select all

*** Init called
May 22, 2016 11:23:21 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://www.data.gov.in:443: Connection reset
May 22, 2016 11:23:21 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://www.data.gov.in:443
May 22, 2016 11:23:22 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://www.data.gov.in:443: Connection reset
May 22, 2016 11:23:22 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://www.data.gov.in:443
May 22, 2016 11:23:24 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://www.data.gov.in:443: Connection reset
May 22, 2016 11:23:24 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://www.data.gov.in:443
java.net.SocketException:  C o n n e c t i o n   r e s e t < b r   / >         a t   j a v a . n e t . S o c k e t I n p u t S t r e a m . r e a d ( S o c k e t I n p u t S t r e a m . j a v a : 1 9 6 ) < b r   / >         a t   j a v a . n e t . S o c k e t I n p u t S t r e a m . r e a d ( S o c k e t I n p u t S t r e a m . j a v a : 1 2 2 ) < b r   / >         a t   s u n . s e c u r i t y . s s l . I n p u t R e c o r d . r e a d F u l l y ( I n p u t R e c o r d . j a v a : 4 4 2 ) < b r   / >         a t   s u n . s e c u r i t y . s s l . I n p u t R e c o r d . r e a d ( I n p u t R e c o r d . j a v a : 4 8 0 ) < b r   / >         a t   s u n . s e c u r i t y . s s l . S S L S o c k e t I m p l . r e a d R e c o r d ( S S L S o c k e t I m p l . j a v a : 9 4 6 ) < b r   / >         a t   s u n . s e c u r i t y . s s l . S S L S o c k e t I m p l . p e r f o r m I n i t i a l H a n d s h a k e ( S S L S o c k e t I m p l . j a v a : 1 3 4 4 ) < b r   / >         a t   s u n . s e c u r i t y . s s l . S S L S o c k e t I m p l . s t a r t H a n d s h a k e ( S S L S o c k e t I m p l . j a v a : 1 3 7 1 ) < b r   / >         a t   s u n . s e c u r i t y . s s l . S S L S o c k e t I m p l . s t a r t H a n d s h a k e ( S S L S o c k e t I m p l . j a v a : 1 3 5 5 ) < b r   / >         a t   o r g . a p a c h e . h t t p . c o n n . s s l . S S L C o n n e c t i o n S o c k e t F a c t o r y . c r e a t e L a y e r e d S o c k e t ( S S L C o n n e c t i o n S o c k e t F a c t o r y . j a v a : 3 9 4 ) < b r   / >         a t   o r g . a p a c h e . h t t p . c o n n . s s l . S S L C o n n e c t i o n S o c k e t F a c t o r y . c o n n e c t S o c k e t ( S S L C o n n e c t i o n S o c k e t F a c t o r y . j a v a : 3 5 3 ) < b r   / >         a t   o r g . a p a c h e . h t t p . i m p l . c o n n . D e f a u l t H t t p C l i e n t C o n n e c t i o n O p e r a t o r . c o n n e c t ( D e f a u l t H t t p C l i e n t C o n n e c t i o n O p e r a t o r . j a v a : 1 3 4 ) < b r   / >         a t   o r g . a p a c h e . h t t p . i m p l . c o n n . P o o l i n g H t t p C l i e n t C o n n e c t i o n M a n a g e r . c o n n e c t ( P o o l i n g H t t p C l i e n t C o n n e c t i o n M a n a g e r . j a v a : 3 5 3 ) < b r   / >         a t   o r g . a p a c h e . h t t p . i m p l . e x e c c h a i n . M a i n C l i e n t E x e c . e s t a b l i s h R o u t e ( M a i n C l i e n t E x e c . j a v a : 3 8 0 ) < b r   / >         a t   o r g . a p a c h e . h t t p . i m p l . e x e c c h a i n . M a i n C l i e n t E x e c . e x e c u t e ( M a i nClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
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:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.soulpatch.jersey.DataFetcher.init(DataFetcher.java:47)
at com.soulpatch.jersey.DataFetcher.getBloodBanks(DataFetcher.java:86)
at com.soulpatch.jersey.resources.BloodBanksResource.getBloodBanks(BloodBanksResource.java:28)
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.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
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)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post