【发布时间】:2015-07-18 09:24:35
【问题描述】:
我刚刚开始实施我的第一个 Drowizard 项目。这是我的第一个资源类:
@Path("/bill")
public class CommandResource {
//...
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/createBillForStudy")
public Response handleCreateBillForStudyCommand(CreateBillForStudyCommand cmd, @Context UriInfo uriInfo)
{
System.out.println("Creating bill for command: " + cmd);
UUID newId = billCreator.handle(cmd);
URI location = uriInfo.getBaseUriBuilder().path(CommandResource.class).path("/" + newId).build();
return Response.accepted(cmd).contentLocation(location).build();
}
}
我想使用 Postman 进行测试,但以下请求会导致 500 响应,我不知道为什么:
POST /bill/createBillForStudy HTTP/1.1
Host: localhost:8080
Content-Type: application/JSON
Cache-Control: no-cache
{ "idAccount": "123", "idStudy": "456", "timeStamp": "2014-01-01" }
这是我在 Dropwizard 控制台中看到的:
ERROR [2015-05-07 16:43:08,558] org.glassfish.jersey.message.internal.WriterInterceptorExecutor: MessageBodyWriter not found for media type=application/xml, type=class com.statista.billing.domain.commands.CreateBillForStudyCommand, genericType=class com.statista.billing.domain.commands.CreateBillForStudyCommand.
0:0:0:0:0:0:0:1 - - [07/Mai/2015:16:43:08 +0000] "POST /bill/createBillForStudy/ HTTP/1.1" 500 332 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36" 8
在我看来,这听起来好像 Content-Type 标头有问题或缺失,但正如您在上面看到的,它已正确设置为“application/JSON”。
有什么想法吗?
【问题讨论】:
标签: java jersey dropwizard postman