Kiryl A.
Kiryl A.

Reputation: 164

Invalid parameter passing to the URI

Attention! You may not strain the decision, just tell me: which direction I should think!

So, we have a very simple service:

    @GET
    @Path("/search")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response getSubscriber(@QueryParam("data") SubscriberSearchFormData data){   
        System.out.println(data);
        List <SubscrEntity> results = null  //list of results
        return Response.ok(results).build();
    }

Used class SubscriberSearchFormData:

public class SubscriberSearchFormData {
    private String name;
    private String street;
    private Integer contractNumber;

    public static SubscriberSearchFormData fromString(String jsonRepresentation) throws Exception { 
          System.out.println("WE ARE HERE");
          ObjectMapper mapper = new ObjectMapper(); // Jackson's JSON marshaller
          SubscriberSearchFormData obj = null;
          try {
           obj = mapper.readValue(decoded, SubscriberSearchFormData.class);
          } catch (IOException e) {
           throw new Exception("Wrong JSON parameters!");
          }
          return obj;
    }

    //all getters and setters
}

On the idea, JSON should be automatically parsed by the method fromString() to the object of the SubscriberSearchFormData class. And we'll continue to work with him. But when I invoke the service:

localhost:8080/application/rest/catalog/subscriber/search?data={
"name":"bbb",
"street":"eee",
"contractNumber":5
}

Everything falls due to an error:

11:24:04,050 WARN  [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-3) RESTEASY002130:
Failed to parse request.: javax.ws.rs.core.UriBuilderException: RESTEASY003330: 
Failed to create URI: http://localhost:8080/application/rest/catalog/subscriber/search?data={%20%22name%22:%22bbb%22,%20%22street%22:%22eee%22,%20%22contractNumber%22:%225%22}

And at the same time, System.out.println ("WE ARE HERE"); is not even invoked. And it collapses, even before calling fromString ();

I dig for it the second day and can't solve.

Upvotes: 0

Views: 3116

Answers (1)

UmshiniWami
UmshiniWami

Reputation: 69

It looks like your URI cannot be parsed correctly because it contains illegal characters; this issue was addressed here: IllegalArgumentException caught when parsing URL with JSON String

this could also be useful: http://docs.jboss.org/resteasy/docs/3.0.7.Final/userguide/html_single/index.html#_QueryParam

Your issue could also be linked to: https://issues.jboss.org/browse/RESTEASY-1718

Upvotes: 2

Related Questions