java - 415 删除操作不支持的媒体类型错误
问题描述
@Path("v2/test”)
Class Test{
@Path(“{id}/{version}”)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getvalue(@PathParam(“id”)
String id, @PathParam(“version”)
String version) {
//do some thing
}
@DELETE
@Path(“{testPath: .+}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam("testPath")
String testPath) throws Exception {
//do something
}
}
GET:http://localhost:8080/v2/test/testId/1.0 - 有效
删除:http://localhost:8080/v2/test/testId - 有效
删除:http://localhost:8080/v2/test/testId/1.0 - 405 方法不允许错误
当我添加两个删除路径时,我得到 415 错误(相同的 curl 没有版本)
@Path("v2/test”)
Class Test{
@Path(“{id}/{version}”)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getvalue(@PathParam(“id”)
String id, @PathParam(“version”)
String version) {
//do some thing
}
@DELETE
@Path(“{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam("id")
String id) throws Exception {
//do something
}
@DELETE
@Path(“{id}/{version}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam(“id”)
String id, @PathParam(“version”)
String version) throws Exception {
//do something
}
}
curl -X DELETE --header 'Content-Type: application/json' http://localhost:8080/v2/test/testId/1.0 - 给我错误'Error 415--Unsupported Media Type'
curl -X DELETE --header 'Content-Type: application/json' http://localhost:8080/v2/test/testId - 工作正常(即使没有 contentType 工作正常)
但是如果我删除带有 id 和版本的 Get 方法 DELETE 操作有效
@Path("v2/test”)
Class Test{
@DELETE
@Path(“{testPath: .+}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam("testPath")
String testPath) throws Exception {
//do something }
}
删除:http://localhost:8080/v2/test/testId - 有效
删除:http://localhost:8080/v2/test/testId/1.0 - 有效
有人可以帮忙解决这个问题吗?我想要上述格式的获取和删除方法,我该如何实现?
Jdk:1.6 泽西岛:1.10 服务器:weblogic
解决方案
使用与以下相同的参数创建另一个 DELETE 方法getValue
:
@Path("v2/test”)
Class Test{
@GET
@Path(“{id}/{version}”)
@Produces(MediaType.APPLICATION_JSON)
public Response getValue(
@PathParam(“id”) String id, @PathParam(“version”) String version
) {
//do something
}
@DELETE
@Path(“{id}/{version}”)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(
@PathParam(“id”) String id, @PathParam(“version”) String version
) throws Exception {
return this.deleteValue("/" + id + "/" + version);
}
@DELETE
@Path(“{testPath: .+}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(
@PathParam("testPath") String testPath
) throws Exception {
//do something
}
}
推荐阅读
- jakarta-mail - 连接outlook 365登录失败
- sql - 返回具有相同 ID 的行,但在第二列中排除一些行
- reactjs - React-Router加载页面,即使我们已经在该页面上
- typescript - Typescript. Correctly typing function parameter that depends on property in the same object literal
- java - Thread handling in a java application
- javascript - 为什么 v-bind 属性不能正常工作?
- kubernetes - 简单 RBAC 示例的问题
- java - 使用 Java 每 2 小时生成 CSV 文件
- javascript - 如果变量不存在,console.log 返回 html 元素
- java - 带有两个列表的 Java 8 流