I write a rest ful web service that has formParam and return a list . and I test it in postman . but I get this error.HTTP Status 500.The server encountered an internal error that prevented it from fulfilling this request error. here is my service :
@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;
}
}
}
I test Weighting.LoadWeightingInSpecTimeInSpecPlate(startTime, endTime, plate)
and this work correctly . can eny one help me ?
stack trace :
Blockquote21-Aug-2015 17:44:31.133 WARNING [http-nio-8084-exec-197] org.glassfish.jersey.servlet.WebComponent.filterFormParameters A servlet request to the URI http://127.0.0.1:8084/fsc-access/rest/report/loadWeightingByPlate contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected. 21-Aug-2015 17:44:31.210 SEVERE [http-nio-8084-exec-197] org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/xml, type=class java.util.ArrayList, genericType=java.util.List.
now my service works well and I write a client to use this service but I get an error : 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));
how I can fix it ?