【发布时间】:2016-02-17 11:23:00
【问题描述】:
我从 2 天开始尝试查找有关此问题的信息,但仍然不明白。我让我的 Maven 项目在 Wildfly 上运行。
休息代码:
@Override
@GET
@Path("{id}")
// @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Customer getOverId(@PathParam("id") String id) {
logger.info("put in " + this.getClass().getName() + " over id " + id);
// if (id != null) {
// Customer object = service.loadOneCustomer(new Integer(id));
// logger.info("found in " + this.getClass().getName());
// return Response.ok(object).build();
// }
Customer customer = service.loadOneCustomer(new Integer(id));
// logger.info("nix found");
if(customer == null) {
throw new NotFoundException("No customer found with the matching ID: " + id);
}
logger.info("Customer found: " + customer.getCustomerNumber());
// return Response.status(Status.BAD_REQUEST).build();
return customer;
}
客户端实现:
public Response readCustomer(String id){
log.info("Starting: Rest get a Customer with ID: " + id);
log.info(this.URL);
this.customerWebTarget = this.client.target(this.URL).path(id);
Response response = this.customerWebTarget.request().buildGet().invoke();
// TODO Customer cast application_xml auf Customer? Customer customer = response.readEntity(Customer.class);
Customer customer = response.readEntity(Customer.class);
log.info("Ending: Rest invoque a Customer with ID:" + customer.getCustomerNumber());
// System.out.println("Ending: Rest get a Customer with ID: " + response.readEntity(String.class));
return response;
}
J 单元测试:
@Test
public void testGetCustomerById() throws Exception {
Response response = this.customerRestClient.readCustomer("112");
System.out.println("--->" + response.getStatus());
Assert.assertTrue(response.getStatus() == 200);
}
一切正常,直到我尝试从我得到的 XML 中获取 Java 对象(客户 customer = response.readEntity(Customer.class);)
我错过了什么吗?我的意思是,我读取了 xml-File 并查看其中的所有数据...为什么我不能将其转换为 Java-Object?
我总是得到这个错误:
Javax.ws.rs.ProcessingException: Unable to find a MEssageBody of content-type-application/xml and type class de.....model.Customer
【问题讨论】:
-
发布代码时,请删除所有仅说明您的尝试和错误但无助于解释问题的陈述和cmet。
-
标签: wildfly resteasy java-ee-7