4

Hi i have a Spring Rest Webservice deployed in the weblogic service. I have advance rest client of google chrome which work perfectly over https I am trying to create to Client over https Client. I have ca certificate and client certificate. I created it from the below link Accessing secure restful web services using jersey client But i am getting exception below

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect
        at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
        at com.sun.jersey.api.client.Client.handle(Client.java:652)
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
        at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
        at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
        at org.app.last.JerseyClient.get_JSON(JerseyClient.java:39)
        at org.app.last.JerseyClient.main(JerseyClient.java:239)
    Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:564)
        at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
        at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:253)
        at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:153)
        ... 6 more
Community
  • 1
  • 1
ramesh027
  • 796
  • 1
  • 10
  • 27
  • Seems like whatever endpoint you're using is not valid or just not responding. – user2793390 Mar 13 '14 at 18:27
  • I can use those endpoint in chrome rest client works preflectly. – ramesh027 Mar 13 '14 at 18:29
  • Most probably you really have a timeout. This can happen either due to network issues (slow network, unresponsive server, etc...) I'd start with checking by trying this call from the same client computer to the same server, not from code (for example browser if that's a `GET`, or a tool like `curl` if that's `POST` or `PUT`) – Avi Mar 13 '14 at 18:29
  • 2
    I am doing application/json blank post request to the server. And method is public T get_JSON(Class responseType,String input) throws UniformInterfaceException { return webResource.accept(javax.ws.rs.core.MediaType.APPLICATION_JSON).post(responseType,input); } And the endpoint work perfeclty with advance rest client in chrome browser – ramesh027 Mar 13 '14 at 18:34
  • @ramesh027 Maybe your implementation in Java ends up with a URL that's just not valid. The API might be appending something after whatever URL you specified. – user2793390 Mar 13 '14 at 18:40
  • @user2793390 I am adding the input variable which is a StringEntity to the request. and it work fine with http call but it fail with https call – ramesh027 Mar 13 '14 at 19:41

4 Answers4

2

It seems like you still have a problem with the proxy. and also you can have problem with the certificate

  1. check whether you're configuring the proxy properly
  2. Check whether your certificate is expired. if expired, request a new one
  3. Check with fiddler whether you're sending the certificate to server
Gijs
  • 144
  • 1
  • 1
  • 11
1

Check your firewall settings to see if the outbound ports are blocked except for the browser. This happens occasionally depending on the company.

Outbound ports are by default opened, but this might have been changed by system administrators - see this answer.

Also the connection might be blocked at the level of your corporate proxy. For example in some companies you can only surf with one browser, and if you install and try to access the internet with another browser, you receive a message "It's only allowed to browser the internet with browser XX", or a timeout.

This works because the proxy checks for the User-Agent header.

Many proxies require authentication and only give access to authorized users. Chrome fils in your credentials automatically in some HTTP header while surfing, but your program does not do that.

To troubleshoot this, try the following possibilities:

  • print the Url to the console with System.out.println and confirm that it's exactly the same as you type in Chrome

  • use a non-browser based command line utility like curl or wget to check if you can access for example google and also the endpoint

  • check your firewall settings

Community
  • 1
  • 1
Angular University
  • 42,341
  • 15
  • 74
  • 81
  • 1
    I tried to use proxy connection even though i am getting the fallowing error Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155) at com.sun.jersey.api.client.Client.handle(Client.java:652) at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) at – ramesh027 Mar 17 '14 at 13:09
  • 1
    I worked on the ignore ssl it worked but it didnt work with ssl – ramesh027 Mar 17 '14 at 13:12
  • I post the question in the another question https://stackoverflow.com/questions/22452079/jersey-client-with-ignore-ssl-with-proxy-setting – ramesh027 Mar 17 '14 at 15:37
0

It is not a cert issue, else you would have seen SSL errors. Check your proxy settings. In Spring applications, you can add the following to the VM arguments to set your proxy: -Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080

henqdev
  • 21
  • 1
0

Add below property in your application.properies file in eureka server application:

eureka.server.peer-node-read-timeout-ms=6000

If it does not work, try to increase read time out.

This is working in my case.

jps
  • 20,041
  • 15
  • 75
  • 79
Guru
  • 21
  • 1