Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uri not Absolute exception getting while calling Restful Webservice

The below code snippet is using to call my web service using restful API.

ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    String uri= "https://127.0.0.1:8443/cas-server-webapp-3.5.0/login";
    WebResource resource = client.resource(URLEncoder.encode(uri));
      MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
       queryParams.add("username", "suresh");
       queryParams.add("password", "suresh");
       resource.queryParams(queryParams); 
       ClientResponse response = resource.type(
            "application/x-www-form-urlencoded").get(ClientResponse.class);
    String en = response.getEntity(String.class);
    System.out.println(en); 

And getting this exception while running the above code

com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: URI is not absolute

    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
    at com.sun.jersey.api.client.Client.handle(Client.java:648)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)

I googled many articles and did'nt get where i am doing wrong .

Side note :cas-server-webapp-3.5.0 war deployed on my machine in Apache tomacat7

like image 536
Suresh Atta Avatar asked Feb 13 '13 07:02

Suresh Atta


4 Answers

An absolute URI specifies a scheme; a URI that is not absolute is said to be relative.

http://docs.oracle.com/javase/8/docs/api/java/net/URI.html

So, perhaps your URLEncoder isn't working as you're expecting (the https bit)?

    URLEncoder.encode(uri) 
like image 121
Bob Flannigon Avatar answered Nov 08 '22 11:11

Bob Flannigon


The problem is likely that you are calling URLEncoder.encode() on something that already is a URI.

like image 8
Julian Reschke Avatar answered Nov 08 '22 10:11

Julian Reschke


For others who landed in this error and it's not 100% related to the OP question, please check that you are passing the value and it is not null in case of spring-boot: @Value annotation.

like image 7
Jalal Sordo Avatar answered Nov 08 '22 12:11

Jalal Sordo


Maybe the problem only in your IDE encoding settings. Try to set UTF-8 everywhere:

enter image description here

like image 2
Valeriy K. Avatar answered Nov 08 '22 12:11

Valeriy K.