28

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

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307

6 Answers6

17

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) 
vek
  • 15
  • 2
  • 5
Bob Flannigon
  • 1,204
  • 9
  • 8
12

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.

Jalal Sordo
  • 1,605
  • 3
  • 41
  • 68
9

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

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
2

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

enter image description here

Valeriy K.
  • 2,616
  • 1
  • 30
  • 53
0

In an API Key Authorization Scenario...

You may be performing the 2nd REST call after getting an AUTH_TOKEN and ENDPOINT_URL from the first REST call.

Check your concatenation of "<ENDPOINT_URL> + <API_METHOD_URI>", you may be sending only the API_METHOD_URI.

This happened to me using the Streamsets integration platform trying to connect to Oracle's Responsys API.

0

For me, I was getting this error, when configuation in yaml files, which composed my URL was changed. oops,

HellishHeat
  • 2,280
  • 4
  • 31
  • 37