public boolean delete(String token, String url, String resourcePath) { WebTarget target = client.target("https://" + url).path(resourcePath); Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); setHeaders(invocationBuilder, token); Response response = invocationBuilder.delete(); return response.getStatus() == Response.Status.OK.getStatusCode(); }
private Response getAPIResponse( String path, String method, List<Pair> queryParams, Object body, byte[] binaryBody, Map<String, String> headerParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames) throws ApiException { if (body != null && binaryBody != null) { throw new ApiException(500, "either body or binaryBody must be null"); } Client client = getClient(); Response response = null; StringBuilder b = new StringBuilder(); b.append("?"); if (queryParams != null) { for (Pair queryParam : queryParams) { if (!queryParam.getName().isEmpty()) { b.append(escapeString(queryParam.getName())); b.append("="); b.append(escapeString(queryParam.getValue())); b.append("&"); } } } String querystring = b.substring(0, b.length() - 1); WebTarget target = client.target(basePath + path + querystring); if (debugging) { target.register(new LoggingFilter()); } if (authentication != null) { authentication.setFilter(target); } Invocation.Builder builder; if (accept != null) { builder = target.request(accept); } else { builder = target.request(); } for (Map.Entry<String, String> entry : headerParams.entrySet()) { builder = builder.header(entry.getKey(), entry.getValue()); } for (Map.Entry<String, String> entry : defaultHeaderMap.entrySet()) { if (!headerParams.containsKey(entry.getKey())) { builder = builder.header(entry.getKey(), entry.getValue()); } } if ("GET".equals(method)) { response = builder.get(); } else if ("POST".equals(method)) { response = builder.post(Entity.entity(body, contentType)); } else if ("PUT".equals(method)) { if (body != null) { response = builder.put(Entity.entity(body, contentType)); } else { response = builder.put(Entity.text("")); } } else if ("DELETE".equals(method)) { response = builder.delete(); } else { throw new ApiException(500, "unknown method type " + method); } return response; }