我已经实现了一个通用的 REST Web 服务客户端。除删除请求外,一切正常。它总是返回“404 -> NOT FOUND”错误,但是当使用其他工具(firefox poster & curl)时,我可以执行删除请求,因此 web 服务客户端正在工作和运行。
失败的方法:
private <T> Object sendDelete(String baseURL, String urlExtension, Class<T> returnClass, CustomHeaders customHeaders) throws WebServiceDeleteRequestException {
Validate.notNull(baseURL, "The specified Base URL is NULL!");
Validate.notEmpty(baseURL, "The specified Base URL is empty!");
Validate.notNull(urlExtension, "The specified URL Extension is NULL!");
Validate.notEmpty(urlExtension, "The specified URL Extension is Empty!");
Validate.notNull(returnClass, "The specified Class to return is NULL!");
WebResource webResource = null;
try {
webResource = getRESTClient().resource(baseURL);
} catch (ServiceClientException serviceClientException) {
throw new WebServiceDeleteRequestException("Couldn't execute the HTTP DELETE request! The ServiceRESTClient couldn't be created!", serviceClientException);
}
webResource.path(urlExtension);
try {
if(customHeaders == null) {
return webResource.delete(returnClass);
} else {
WebResource.Builder builder = webResource.getRequestBuilder();
if(customHeaders != null) {
for(Entry<String, String> headerValue : customHeaders.getCustomHeaders().entrySet()) {
builder.header(headerValue.getKey(), headerValue.getValue());
}
}
builder.accept(MediaType.APPLICATION_XML);
return builder.delete(returnClass);
}
} catch (Exception exception) {
throw new WebServiceDeleteRequestException("Couldn't execute the HTTP DELETE request!", exception);
}
}
执行 'builder.delete(returnClass)' 语句时,会出现 UniformInterfaceException。
com.sun.jersey.api.client.UniformInterfaceException: DELETE http://localhost:8080/db/ returned a response status of 404 Not Found
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:676)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.delete(WebResource.java:583)
webResource 与我的其他请求相同,所以这不是问题,变量(baseURL、urlExtension、returnClass 和 customHeaders)也不是正确的,当我在其他测试工具中使用这些值时,我得到了正确的响应。
有人知道为什么我总是收到这个 404 错误吗?