0
我的RESTful客戶端有這個方法:澤西島客戶。 MultivaluedMap轉爲空
public void testGetCateogrywiseData() {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.addFilter(new LoggingFilter(System.out));
WebResource service = client
.resource("http://localhost:8080/MyApp/rest/publicdata");
@SuppressWarnings("rawtypes")
MultivaluedMap queryParams = new MultivaluedMapImpl();
queryParams.add("latitude", "18.522387");
queryParams.add("longitude", "73.878437");
queryParams.add("categoryID", "2");
service.queryParams(queryParams);
ClientResponse response = service.get(ClientResponse.class);
System.out.println(response.getStatus());
System.out.println("Form response " + response.getEntity(String.class));
}
在服務器端的方法是這樣的:
@Path("publicdata")
@GET
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String getPublicData() throws JSONException {
MultivaluedMap<String, String> valueMap = uriInfo.getQueryParameters();
Long latString = Long.parseLong(valueMap.getFirst("latitude"));
Long lonString = Long.parseLong(valueMap.getFirst("longitude"));
Long categoryId = Long.parseLong(valueMap.getFirst("categoryID"));
// Do necessary stuff and return json string
return null;
}
我的問題是valueMap在服務器端始終是空的。它永遠不會獲得我從客戶端代碼發送的三個參數。我錯過了什麼?
您是否嘗試過不抑制客戶端中的警告並直接聲明MultivaluedMap?這可能只是一個編組問題,因爲您沒有聲明確切的預期類型。 –
2014-10-06 15:31:13
@DavidFleeman沒有。不起作用。 – rishi 2014-10-06 17:39:54