Unknown Host Exception Yet Website Is Accessible - java

I'm using IntelliJ IDEA to implement the Spring Guide for consuming REST services
https://spring.io/guides/gs/consuming-rest/
When I run the Application class I receive the following error
Exception in thread "main" org.springframework.web.client.ResourceAccessException:
I/O error on GET request for "https://gturnquist-quoters.cfapps.io/api/random":
gturnquist-quoters.cfapps.io;
nested exception is
java.net.UnknownHostException: gturnquist-quoters.cfapps.io
The URL itself (https://gturnquist-quoters.cfapps.io/api/random) opens fine in a browser and my HTTP Proxy settings in IntelliJ can connect to the site without any issues. Why would an UnknownHostException be thrown here?

Hey I know this is a bit late, but here is what I had to do to resolve this issue. Even if you are using system proxies, for whatever reason, using this type of GET request requires you to build out a proxy to use in the call, like so.
Example Image

Related

org.springframework.web.client.ResourceAccessException : I/O Error on POST Request

While trying to execute a REST call using restTemplate.postForEntity of spring framework i am getting the below error from weblogic
org.springframework.web.client.ResourceAccessException : I/O Error on POST Request
.
.
Caused By : Java.io.IOException : An established connection was aborted by the software in your host machine
Same REST Call is working from normal java main method.Method call from Java Main Method was also giving the same exception but its able to connect to the https url after adding the below two lines
System.setProperty("javax.net.ssl.keyStore","jks");
System.setProperty("javax.net.ssl.keyStorePassword","pass");
If adding the above lines resolved the issue in normal java project, what is the difference with weblogic?
How do i debug the certificate issue when code is deployed in weblogic server?

Tomcat closes websocket conection with an error

For a customer we build a HTML5 websocket application with Tomcat 8.0.29.
If we start the application from our network or from our home network all works fine. But if the customer starts the application from his network, after a certain time the websocket stops with a error. This can happen after 5 or 20 Minutes.
We have tested it with and without SSL and on two different servers. Only in the customer network the connection breaks with a error.
We also make a test with an websocket echo example which is included in Tomcat. the same as with our websocket. After a certain time the websocket stops with a error. But only if we start the application from the customer network.
When the echo example stops with an error the following message will written in server.log
08-Dec-2015 10:20:37.757 SEVERE [http-apr-8081-exec-2] org.apache.tomcat.websocket.pojo.PojoEndpointBase.onError No error handling configured for [websocket.echo.EchoAnnotation] and the following error occurred
java.io.IOException: Unexpected error [730,054] reading data from the APR/native socket [1,639,490,672] with wrapper [org.apache.tomcat.util.net.AprEndpoint$AprSocketWrapper#231e01e4:1639490672].<br/>
at org.apache.coyote.http11.upgrade.AprServletInputStream.doRead(AprServletInputStream.java:133)<br/>
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.read(AbstractServletInputStream.java:124)<br/>
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:51)<br/>
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:183)<br/>
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)<br/>
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)<br/>
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:669)<br/>
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)<br/>
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)<br/>
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)<br/>
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)<br/>
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)<br/>
at java.lang.Thread.run(Unknown Source)
If we starts the test on http://www.websocket.org/echo.html the connection will not closed with an error.
For me it looks like a problem with Tomcat. But what can I do to make it run properly?
Tomcat: 8.0.29 (also with earlier versions)
Windows 7: 64 Bit
Protocol: HTTP/1.1
I apologize to the readers who came here specifically because of websockets, but we had a similar error in our application while serving files over REST API from Spring. While searching for answers, one of the places I found first was this question. Here's what I was able to find out about the error:
The numbers in Unexpected error [730,054] are somehow significant and are some sort of error codes. In our case, the error looked like this:
java.io.IOException: Unexpected error [120,001] writing data to the APR/native socket [140,041,540,128,928] with wrapper [org.apache.tomcat.util.net.AprEndpoint$AprSocketWrapper#4f1861c:140041540128928].
I found that this supposedly means that the connection was interrupted by the client.
We were able to solve the issue by reimplementing the controller method to always return the generic ResponseEntity<Resource> object with ByteArrayResource body and content type application/octet-stream:
responseEntity = ResponseEntity.ok()
.headers(createHttpHeaders())
.contentLength(file.length())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(new FileSystemResource(file));
It appears that the errors in our case were caused by non-standard headers we were using, such as Content-Type: application/force-download. It's possible that it caused browsers to terminate the connection in a non-standard way.

WSDLException ... An error occurred trying to resolve schema ... Connection timed out: connect

First of all, my error is almost identical to what is reported in this question: WSDLException : An error occurred trying to resolve schema referenced at
Here is a snippet of my stack dump:
javax.wsdl.WSDLException: WSDLException (at /definitions/types/xs:schema/xs:schema): faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced at 'http://www.w3.org/2005/05/xmlmime', relative to 'http://server.subdom.domain.com:13080/SM/7/Common.xsd'.: java.net.ConnectException: Connection timed out: connect] MDC{}
2015-05-24 14:36:33,751 ERROR (c.d.g.w.c.ContexteApplicatif.contextInitialized) [main] catching MDC{}
javax.xml.rpc.ServiceException: Error processing WSDL document:
javax.wsdl.WSDLException: WSDLException (at /definitions/types/xs:schema/xs:schema): faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced at 'http://www.w3.org/2005/05/xmlmime', relative to 'http://server.subdom.domain.com:13080/SM/7/Common.xsd'.: java.net.ConnectException: Connection timed out: connect
at org.apache.axis.client.Service.initService(Service.java:250) ~[axis-1.4.jar:?]
This occurs in my embedded Tomcat server running from within Eclipse. It is running on a Windows machine and there is an httpProxy at the system level. However, the URL is an internal address for which no proxy is needed. Anyhow, I implemented programmatically a proxy with the following code just before the reference to the WSDL file:
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "proxyhost.subdom.domain.com");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "proxyhost.subdom.domain.com");
System.setProperty("https.proxyPort", "8080");
And now I am getting an HTTP 502 error which indicate a bad gateway. So, I suppose this solution is the wrong one since I shouldn't need a proxy in first place. I can access the page from within a browser, indistinctly if I enable or disable the proxy settings. In addition, there is a script to configure the proxy and if I use the proxy host shown above and hardcode it in my browser instead of "system proxy" or "automatic setting" I cannot access the page.
To summarize, it behaves like there is like it needs a proxy setup, however it doesn't. The problem is elsewhere and I have no idea how I can make significant progress to debug this problem.
Any hints? Something with Tomcat? Something with Eclipse?
I haven't tried yet on a standalone Tomcat server since my code is not yet ready for deployement.
NOTE: BTW, I tried the command from the quoted post and I am getting the same error as well. Connect timed out without system properties defined for the proxy and 502 code otherwise. At the same time, if I am launching the Web Service Explorer from Eclipse I am perfectly able to access the webservice and invoke operations.
Further investigation: I decided to use WireShark to see what is going on with the request and it appears both HTTP requests (the wsdl and the common types definitions) were fulfilled without a glitch and no connection timed out at all, not a single error. I can see the XML in WireShark and the HTTP status is 200 OK and everything is perfectly fine at this level.
So, what is going on here? I have the same problem on a Linux server while the message is a bit different. What wsdl2java is doing to believe there was a problem and abort?
After further investigation and testing with Axis2 and CXF, I finally found the problem, thanks to the CXF's version of the wsdl2java script which is giving a bit more details.
First of all, the original solution proposed was almost correct. I actually need to add all the proxy information, however I also needed to specify the non-proxy hosts otherwise I am getting the 502 error. The messages from the Axis script were not very detailed about the offending request, while CXF's version was very clear and enabled me to finally solve my problem.
So, in addition, if you modify the wsdl2java script, add -Dhttp.nonProxyHosts=... in addition to other options. The same thing if you need to specify a proxy programmatically.

Naming.lookup fails with Java WebStart

I have a Java application which I am in the process of converting to work with WebStart. It is supposed to connect to a server to do some authentication using Naming.lookup and this works fine when running as a standalone app. Unfortunately when running the same code as a WebStart app the call fails and throws:
java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.io.EOFException
This indicates an error at the Registry, possibly a security problem. You need to run the Registry with some debugging parameters to see what, such as -Djava.rmi.server.logCalls etc. See the properties pages linked from the RMI Home Page.

org.apache.cxf.interceptor.Fault: Marshalling Error: null

I have created a webservice using cxf 3.4.1
When I send a request to the webservice it works fine but sometimes for one
or other request it gives me error with the following stack trace on the
console.
I am using jdk 1.6 , jboss 5.1.0 GA , jbossws-cxf-3.4.1.GA
Can anybody help me resolving this issue?
I receive the following error:
org.apache.cxf.interceptor.Fault: Marshalling Error: null
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:252)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.jav:110)
Put the source code alongwith your questions for better responses.
This looks like the client has closed the connection for some reason. Either it timed out or the client ended or similar. Basically, the server is trying to write a response out, but the socket has been closed.
Nirmal is right. That's the typical error of CXF when the client closes the connection early.
But there can be too many causes to get the specific answer just putting the exception message.
I had the same error, and in my case the reason was that I had declared an abstract class of exception in the WS, so when the client tried to unmarshall it, an exception was thrown and client had closed the connection early.
My advice is to put a breakpoint in the cause exception and debug the error.

Categories

Resources