Lit*_*ode 9 java rest glassfish jersey jersey-2.0
如果发生错误,我正在尝试关注Jersey文档以启用非200响应(https://jersey.java.net/documentation/latest/representations.html#d0e3586)
我的代码看起来像:
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public ResponseBuilder getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) {
if(one.isEmpty() || two.isEmpty() || three.isEmpty()) {
logger.error("Missing params for getData");
throw new WebApplicationException(501);
}
return Response.ok();
}
}
Run Code Online (Sandbox Code Playgroud)
遗憾的是,这会产生以下错误:
[2015-02-01T16:13:02.157 + 0000] [glassfish 4.1] [SEVERE] [] [org.glassfish.jersey.message.internal.WriterInterceptorExecutor] [tid:_ThreadID = 27 _ThreadName = http-listener-1(2 )] [timeMillis:1422807182157] [levelValue:1000] [[找不到媒体类型= text/plain的MessageBodyWriter,类型= class org.glassfish.jersey.message.internal.OutboundJaxrsResponse $ Builder,genericType = class javax.ws.rs .core.Response $ ResponseBuilder.]
问题是您的方法的返回类型.它必须是Response代替ResponseBuilder.
将您的代码更改为以下内容,它应该工作:
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) {
if(one.isEmpty() || two.isEmpty() || three.isEmpty()) {
logger.error("Missing params for getData");
throw new WebApplicationException(501);
}
return Response.ok();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19286 次 |
| 最近记录: |