[java] 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

This question is related to java web-services http servlets cas

The answer is


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.


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

enter image description here


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


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to web-services

How do I POST XML data to a webservice with Postman? How to send json data in POST request using C# org.springframework.web.client.HttpClientErrorException: 400 Bad Request How to call a REST web service API from JavaScript? The request was rejected because no multipart boundary was found in springboot Generating Request/Response XML from a WSDL How to send a POST request using volley with string body? How to send post request to the below post method using postman rest client How to pass a JSON array as a parameter in URL Postman Chrome: What is the difference between form-data, x-www-form-urlencoded and raw

Examples related to http

Access blocked by CORS policy: Response to preflight request doesn't pass access control check Axios Delete request with body and headers? Read response headers from API response - Angular 5 + TypeScript Android 8: Cleartext HTTP traffic not permitted Angular 4 HttpClient Query Parameters Load json from local file with http.get() in angular 2 Angular 2: How to access an HTTP response body? What is HTTP "Host" header? Golang read request body Angular 2 - Checking for server errors from subscribe

Examples related to servlets

Google Recaptcha v3 example demo Difference between request.getSession() and request.getSession(true) init-param and context-param java.lang.NoClassDefFoundError: org/json/JSONObject how to fix Cannot call sendRedirect() after the response has been committed? getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever? Create a simple Login page using eclipse and mysql Spring get current ApplicationContext insert data into database using servlet and jsp in eclipse What is WEB-INF used for in a Java EE web application?

Examples related to cas

Uri not Absolute exception getting while calling Restful Webservice