2015-09-07 80 views
0

我使用SoapUi来测试我的Web服务。我想从SoapUi发送一个post方法的参数列表。这里就是我要处理的列表,但不工作的代码,我得到一个null pointer exception发送值列表作为参数

@POST 
    @Produces(MediaType.APPLICATION_JSON) 
    @Path("/subscribeList") 
    public Response subscribe(final MultivaluedMap<String, String> listoffields) 
    { 
     System.out.println("The list has: " + listoffields.size()); 
     return Response.ok().build(); 
    } 

soapui我送参数queryparam。 任何人都可以帮助我解决这个问题,并能够发送一个列表?

+0

什么是你输入的每个查询参数 - 你的邮件的正文? –

+0

我只是从'soapui'提出这个请求:'http:// localhost:8888:/ service/subscription/subscribeList?name = name5&age = age5' – dres

+0

你的意思是说,你需要名称和年龄作为多值映射 listoffields? –

回答

0

注入UriInfo作为方法参数,并得到UriInfo.getQueryParameters()的地图。

public Response subscribe(@Context UriInfo uriInfo) { 
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 
    String name = queryParams.getFirst("name"); 
} 

或者你可以明确指定方法签名

public Response subscribe(@QueryParam("name") String name, 
          @QueryParam("age") int age) { 
+0

谢谢,解决了我的问题! – dres