Bom dia a todos, estou tendo problemas com um webservice rest desde ontem e hoje resolvi postar aqui o meu problema.
Eu tenho o seguinte método post:
@Path("systemUpdate")
public class SystemUpdateServiceRest {
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@PermitAll
public Response add(SystemUpdate su) {
try {
SystemUpdateService service = FactoryService.getFactory().getSystemUpdateService();
service.Add(su);
return Response.ok(true).build();
} catch (Exception e) {
e.printStackTrace();
return Response.ok(false).build();
}
}`
O mesmo deve inserir um objeto na base de dados utilizando Hibernate e depois retornar um boolean. Até aí tudo bem, a inserção direto pelo DAO funciona normal, porém quando tento chamar o serviço web ele dá o seguinte erro:
javax.ws.rs.BadRequestException: HTTP 400 Bad Request
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:177)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:154)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:444)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:201)
at com.agfa.compactorgui.service.VersionService.insertSystemUpdate(VersionService.java:63)
public class VersionService {
public SystemUpdate insertSystemUpdate(SystemUpdate sysUpdate) {
try {
if (sysUpdate != null) {
Client client = ClientBuilder.newBuilder().register(SystemUpdate.class).build();
WebTarget target = client.target("http://localhost:8180/confidencial/rest/systemUpdate/")
.queryParam("mode", "json");
Boolean isInserted = target.request().accept(MediaType.APPLICATION_JSON)
.post(Entity.entity(sysUpdate, MediaType.APPLICATION_JSON), Boolean.class);
client.close();
} catch (Exception e) {
e.printStackTrace();
}
return isInserted;
}
Já tentei de tudo que imaginei e nada… Alguém saberia resolver esse problema?