0

I am unable to get my client to connect to a RESTful URI. I continue to get "java.net.SocketException: Connection reset" (see below). Below is my code and the error that I am getting. Any help would be appreciated.

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.api.client.filter.LoggingFilter;

HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter("username","password");
Client clientObj =  Client.create();    
clientObj.addFilter(authFilter);
clientObj.addFilter(new LoggingFilter());

WebResource webResourceObj = clientObj.resource(myUrl);
ClientResponse responseObj = webResourceObj.accept("text/html").get(ClientResponse.class);
if(responseObj.getStatus() == 200) 
String output = responseObj.getEntity(String.class);



Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: Connection reset
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
    at com.sun.jersey.api.client.filter.HTTPBasicAuthFilter.handle(HTTPBasicAuthFilter.java:105)
    at com.sun.jersey.api.client.filter.LoggingFilter.handle(LoggingFilter.java:217)
    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.get(WebResource.java:509)
Gaspar
  • 159
  • 7
  • 1
    Well apparently it can't talk to the URL you've specified... have you checked that the URL is valid? Can you connect to it e.g. via a browser on the same machine? It's hard to know what's wrong with so little information. – Jon Skeet Sep 01 '15 at 16:52
  • This does not seem to be a timing issue. The answer "http://stackoverflow.com/questions/23568641/connection-reset-with-jersey-client" does not work – Gaspar Sep 01 '15 at 17:36
  • Hello, I am able to connect to the URL via a browser so it is valid. I did find another solution so I can close this question. – Gaspar Sep 01 '15 at 19:41

0 Answers0