我创建了rest应用程序来使用Restful Web服务,在这里我创建了通用方法来处理所有get调用
@GET
@Path("/get/{param}")
public Response get(@Context UriInfo ui, @PathParam("param") String sproc) {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String arg = null;
for (Entry<String, List<String>> entry : queryParams.entrySet()) {
logger.info(entry.getKey() + "/" + entry.getValue());
arg = entry.getValue().get(0);
}
return Response.status(returnCode).entity(output).build();
}
为此,我创建了如下的REST客户端
public JSONObject getWSResults(String url, String sp) {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url + sp);
logger.info(url + sp);
String json = null;
try {
CloseableHttpResponse response = httpclient.execute(httpGet);
json = EntityUtils.toString(response.getEntity());
httpclient.close();
logger.info(json);
} catch (Exception e) {
e.printStackTrace();
logger.info(e);
}
JSONObject jo = new JSONObject(json);
return jo;
}
以下是致电get客户的方式
JSONObject getContactsWSOutputJSONObject = ews.getWSResults(wsUrl,getContactsWS);
我具有通用删除方法的方式
@DELETE
@Path("/delete/{method}/{param}")
@Produces({ MediaType.APPLICATION_JSON })
public Response deletewithPath(@PathParam("method") String sproc, @PathParam("param") String arg) {
return Response.status(returnCode).entity(output).build();
}
如何创建一个休息客户端以使用此删除ws以及如何调用客户端