【发布时间】:2015-08-21 13:10:57
【问题描述】:
我编写了一个带有 formParam 并返回一个列表的 rest ful web 服务。我在 postman 中测试它。但我收到此错误。HTTP 状态 500。服务器遇到内部错误,阻止它完成此请求错误。 这是我的服务:
@Path("/report")
public class weightingResource {
@POST
@Path("/loadWeightingByPlate")
//@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public List<Weighting> LoadWeightingInSpecTimeInSpecPlate(
@FormParam("plate") String plate,
@FormParam("startTime") String _startTime,
@FormParam("endTime") String _endTime,
@Context HttpServletRequest req) {
Long startTime = new Long(_startTime);
Long endTime = new Long(_endTime);
try {
List<Weighting> weightings = Weighting.LoadWeightingInSpecTimeInSpecPlate(startTime, endTime, plate);
System.out.println("no error");
return weightings;
} catch (Exception ex) {
System.out.println("Exception = " + ex);
return null;
}
}
}
我测试了Weighting.LoadWeightingInSpecTimeInSpecPlate(startTime, endTime, plate) 并且这个工作正常。谁能帮帮我?
堆栈跟踪:
Blockquote21-Aug-2015 17:44:31.133 警告 [http-nio-8084-exec-197] org.glassfish.jersey.servlet.WebComponent.filterFormParameters 对 URI http://127.0.0.1:8084/fsc-access/rest/report/loadWeightingByPlate 的 servlet 请求在请求正文,但请求正文已被 servlet 或访问请求参数的 servlet 过滤器使用。只有使用 @FormParam 的资源方法才能按预期工作。通过其他方式消耗请求正文的资源方法将无法按预期工作。 2015 年 8 月 21 日 17:44:31.210 严重 [http-nio-8084-exec-197] org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/xml, type=类 java.util.ArrayList,genericType=java.util.List。
现在我的服务运行良好并且 我编写了一个客户端来使用此服务,但出现错误:HTTP 400 Bad Request :javax.ws.rs.BadRequestException
String webserviceURI = "http://localhost:8084/fsc-access";
ClientConfig clientConfig = new ClientConfig();
Client client = ClientBuilder.newClient(clientConfig);
URI serviceURI = UriBuilder.fromUri(webserviceURI).build();
WebTarget webTarget = client.target(serviceURI);
MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("plate", plate);
formData.add("startTime", start.toString());
formData.add("endTime", end.toString());
Weightings weightings = new Weightings();
weightings.getWeightings().addAll((Collection<? extends Weighting>) webTarget.path("rest").path("report").path("loadWeightingByPlate").
request().accept(MediaType.APPLICATION_XML).post(javax.ws.rs.client.Entity.form(formData), Weightings.class));
我该如何解决?
【问题讨论】:
-
如果有 500 响应,这通常意味着您的日志中会有堆栈跟踪。请在此处发布堆栈跟踪,以便我们更好地帮助您。
-
是的,有些事情:我提出了警告
标签: java web-services http post restful-url