Клиенту RestEasy не удалось найти средство записи для приложения с типом содержимого / xml type - PullRequest
0 голосов
/ 07 января 2020

Я пишу тестовый клиент для моей конечной точки, но он не может выполнить соединение, давая

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);

От Почтальона конечная точка возвращая результат в порядке. Я попытался добавить все фляги RestEasy в свой проект, но он по-прежнему выдает ту же ошибку, пока

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

1 Ответ

0 голосов
/ 07 января 2020

Единственное, что я вижу, это то, что вы регистрируете адаптер после отправки запроса:

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

Поскольку исключение происходит при пост-вызове, возможно, вам следует попробовать изменить порядок.

Я заметил, что вы используете устаревший клиентский API RestEasy. Обратите внимание, что клиентская реализация JAX-RS 2.0 автоматически загрузит все доступные классы провайдеров (через механизм загрузчика служб). Возможно, вам следует рассмотреть возможность использования этого API вместо этого.

...