gpt4 book ai didi

java - RestEasy 客户端找不到内容类型应用程序/xml 类型的编写器

转载 作者:行者123 更新时间:2023-12-01 19:02:10 24 4
gpt4 key购买 nike

我正在为我的端点编写一个测试客户端,但它无法执行给出的连接

EXCEPTION : could not find writer for content-type application/xml type: com.gepower.gees.ifs.goet.porequest.model.CreatePOReq

在行

ClientResponse<CreatePOResp> clientResponse = client.post(CreatePOResp.class);

从 Postman 中,端点返回结果正常。我尝试在我的项目中添加所有 RestEasy jar,但它仍然给出相同的错误

public static CreatePOResp createUpdateALFPO(CreatePOReq req) {
CreatePOResp response = new CreatePOResp();
String operation = "createUpdatePO";

try {

String xmlReq = "";
try {
xmlReq = XmlUtils.marshalXmlToString(req);
System.out.println(operation + " - XML SOAP REQUEST: " + xmlReq);
} catch (Exception xmlex) {
System.out.println(xmlex.getMessage());
}
ClientRequest client = new ClientRequest("http://localhost/ofsrestws/fs/porequest/addpo");

client.body(MediaType.APPLICATION_XML, req);
System.out.println("URI ====" + client.getUri());
ClientResponse<CreatePOResp> clientResponse = client.post(CreatePOResp.class);
ResteasyProviderFactory.getInstance().addBuiltInMessageBodyReader(new JAXBXmlTypeProvider());

if (clientResponse.getStatus() == 200) {
response = clientResponse.getEntity();
System.out.println("web service is OK");
return response;
} else {
System.out.println("an issue has occure during the call of the web service: "
+ clientResponse.getResponseStatus());
// Object resp = clientResponse.getResponseStatus();

return null;
}
} catch (NullPointerException e) {
System.out.println("EXCEPTION : " + e.getMessage());
return null;
} catch (Exception e) {
System.out.println("EXCEPTION : " + e.getMessage());
return null;
} finally {}
}

堆栈跟踪:

java.lang.RuntimeException: could not find writer for content-type application/xml type: com.gepower.gees.ifs.goet.porequest.model.CreatePOReq
at org.jboss.resteasy.client.ClientRequest.writeRequestBody(ClientRequest.java:409)
at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor$ClientRequestEntity.<init>(ApacheHttpClientExecutor.java:117)
at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.loadHttpMethod(ApacheHttpClientExecutor.java:188)
at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.execute(ApacheHttpClientExecutor.java:56)
at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:378)
at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:590)
at org.jboss.resteasy.client.ClientRequest.post(ClientRequest.java:496)
at org.jboss.resteasy.client.ClientRequest.post(ClientRequest.java:501)
at org.tcs.TestJava.createUpdateALFPO(TestJava.java:52)
at org.tcs.TestJava.main(TestJava.java:31)

enter image description here

请查找依赖项列表

enter image description here

enter image description here

enter image description here

最佳答案

我唯一能看到的是您在发出发布请求后注册了适配器:

ClientResponse<CreatePOResp> clientResponse = client.post(CreatePOResp.class);
ResteasyProviderFactory.getInstance().addBuiltInMessageBodyReader(new JAXBXmlTypeProvider());

由于post调用出现异常,也许你应该尝试切换顺序。

我注意到您正在使用已弃用的 RestEasy 客户端 API。请注意,JAX-RS 2.0 客户端实现将自动加载所有可用的提供者类(通过服务加载器机制)。也许您应该考虑使用该 API。

关于java - RestEasy 客户端找不到内容类型应用程序/xml 类型的编写器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59620725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com