[英]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: 使用的类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. 根据这个想法,JSON应该由fromString()
方法自动解析为SubscriberSearchFormData类的对象。 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");
同时,还有System.out.println ("WE ARE HERE");
is not even invoked. 甚至没有被调用。 And it collapses, even before calling fromString ();
而且即使在调用fromString ();
之前它也会崩溃fromString ();
I dig for it the second day and can't solve. 我第二天就挖了,解决不了。
It looks like your URI cannot be parsed correctly because it contains illegal characters; 看起来您的URI无法正确解析,因为它包含非法字符; this issue was addressed here: IllegalArgumentException caught when parsing URL with JSON String 此问题已在此处解决: 使用JSON字符串解析URL时捕获了IllegalArgumentException
this could also be useful: http://docs.jboss.org/resteasy/docs/3.0.7.Final/userguide/html_single/index.html#_QueryParam 这也可能很有用: 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 您的问题还可以链接到: https : //issues.jboss.org/browse/RESTEASY-1718
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.