我正在构建一个通用的Web服务,需要将所有查询参数都抓取到一个字符串中以便以后解析.我怎样才能做到这一点?
我有一个奇怪的问题,我绝对不明白,使用Jersey 2.6.
我无法解释原因,但其中一个查询参数使得jersey抛出一个ModelValidationException
    @ApiOperation("Save")
    @PUT
    public Response save(
            @HeaderParam("token") final String token,
            @QueryParam("someValue") final SomeValueDTO someValue,
            @QueryParam("anotherParam") final int anotherParam) throws TechnicalException {
        return Response.ok().build();
    }
queryParam'ometValue'使jersey throw:
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.|[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response ch.rodano.studies.api.resources.PagesResource.save(java.lang.String,ch.rodano.studies.api.dto.JSONValueDTO,int) throws ch.rodano.studies.exceptions.RightException,ch.rodano.studies.configuration.exceptions.NoNodeException at index 1.; source='ResourceMethod{httpMethod=PUT, consumedTypes=[], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class ch.rodano.studies.api.resources.PagesResource, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@41ed3918]}, definitionMethod=public javax.ws.rs.core.Response ch.rodano.studies.api.resources.PagesResource.save(java.lang.String,ch.rodano.studies.api.dto.JSONValueDTO,int) throws ch.rodano.studies.exceptions.RightException,ch.rodano.studies.configuration.exceptions.NoNodeException, parameters=[Parameter [type=class java.lang.String, source=token, defaultValue=null], …我需要将动态查询参数发送到 REST Web 服务 GET 方法 [如下所示]。
主机:端口/应用程序?field1=XXX&value1=VVV&field2=XXX&value2=XXX ....
消费者最多可以发送 fieldn 和 valuen 参数。每个字段都映射到值。
对于这种类型的要求,我无法在服务器端方法上编写一组有限的 QueryParams。
是否有任何类型的 REST 库支持此功能?我检查了 RESTEasy 和 Jersey,他们似乎都不支持这一点 [据我检查]。
谢谢。
我需要使用RESTEasy设计RESTful服务.客户端可以使用他们想要的任意数量的查询参数来调用此公共服务.我的REST代码应该能够以某种方式读取这些查询参数.例如,如果我有书籍搜索服务,客户可以进行以下调用.
http://domain.com/context/rest/books/searchBook?bookName=someBookName
http://domain.com/context/rest/books/searchBook?authorName=someAuthor& pubName=somePublisher
http://domain.com/context/rest/books/searchBook?isbn=213243
http://domain.com/context/rest/books/searchBook?authorName=someAuthor
我必须写一个像下面这样的服务类来处理这个问题.
@Path("/books")
   public class BookRestService{
    // this is what I currently have, I want to change this method to in-take all the 
    // dynamic parameters that can come
    @GET
    @Path("/searchBook")
    public Response searchBook(@QueryParam("bookName") String bookName,@QueryParam("isbn") String isbn) {
     // fetch all such params
     // create a search array and pass to backend
    }
    @POST
    @Path("/addBook")
    public Response addBook(......) {
    //....
     }
    }
抱歉格式不好(我无法了解代码格式在这个编辑器中的工作方式!).如您所见,我需要更改方法searchBook(),以便它可以使用任意数量的查询参数.
我在这里看到了类似的帖子,但找不到合适的解决方案.
请问有人对此有所了解吗?