Axis2 выдает NonRepeatableRequestException: невозможно повторить запрос с неповторяемым объектом запроса
С помощью одного сгенерированного класса SOAP я получаю исключение NonRepeatableRequestException и понятия не имею, как его решить.
У меня есть один класс, созданный wsdl2java..\axis2-1.8.2\bin\wsdl2java.bat --output output.axis --test-case --package com.mycompany.axis --sync -uri zws_monthly_invoice.wsdl
Я использую эту службу для аутентификации пользователя (в противном случае я получаю ошибку 401: несанкционировано).
ZWS_MONTHLY_INVOICEStub stub = new ZWS_MONTHLY_INVOICEStub();
Options options = stub._getServiceClient().getOptions();
HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();
auth.setPreemptiveAuthentication(true);
auth.setPassword("myPassword");
auth.setUsername("myUser");
options.setProperty(HTTPConstants.AUTHENTICATE,auth);
ZWS_MONTHLY_INVOICEStub.Z_OMA_FAKT_AUFTRAG_CREATE payload = new ZWS_MONTHLY_INVOICEStub.Z_OMA_FAKT_AUFTRAG_CREATE();
ZWS_MONTHLY_INVOICEStub.ZAUF_FAKT_POS_IF_OMEGA_T items = new ZWS_MONTHLY_INVOICEStub.ZAUF_FAKT_POS_IF_OMEGA_T();
payload.setIT_INVOICE_ITEMS(items);
ZWS_MONTHLY_INVOICEStub.Z_OMA_FAKT_AUFTRAG_CREATEResponse x = stub.z_OMA_FAKT_AUFTRAG_CREATE(payload);
System.out.println("Z_OMA_FAKT_AUFTRAG_CREATEResponse=" + x.toString());
когда я запускаю его, я получаю следующие исключения:
[main] INFO org.apache.axis2.transport.http.HTTPSender -- Unable to send to url[http://mycompany.com:8050/sap/..../500/.../zws_monthly_invoice]
org.apache.http.client.ClientProtocolException: null
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.apache.axis2.transport.http.impl.httpclient4.RequestImpl.execute(RequestImpl.java:210)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:194)
at org.apache.axis2.transport.http.AbstractHTTPTransportSender.writeMessageWithCommons(AbstractHTTPTransportSender.java:386)
at org.apache.axis2.transport.http.AbstractHTTPTransportSender.invoke(AbstractHTTPTransportSender.java:214)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)
at com.mycompany.axis.ZWS_MONTHLY_INVOICEStub.z_OMA_FAKT_AUFTRAG_CREATE(ZWS_MONTHLY_INVOICEStub.java:181)
at com.mycompany.axis.SoapAxisStaticMainTest.testz_OMA_FAKT_AUFTRAG_CREATE(SoapAxisStaticMainTest.java:82)
at com.mycompany.axis.SoapAxisStaticMainTest.main(SoapAxisStaticMainTest.java:38)
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:225)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
... 13 common frames omitted
Exception in thread "main" org.apache.axis2.AxisFault
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:431)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:266)
at org.apache.axis2.transport.http.AbstractHTTPTransportSender.writeMessageWithCommons(AbstractHTTPTransportSender.java:386)
at org.apache.axis2.transport.http.AbstractHTTPTransportSender.invoke(AbstractHTTPTransportSender.java:214)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)
at com.mycompany.axis.ZWS_MONTHLY_INVOICEStub.z_OMA_FAKT_AUFTRAG_CREATE(ZWS_MONTHLY_INVOICEStub.java:181)
at com.mycompany.axis.SoapAxisStaticMainTest.testz_OMA_FAKT_AUFTRAG_CREATE(SoapAxisStaticMainTest.java:82)
at com.mycompany.axis.SoapAxisStaticMainTest.main(SoapAxisStaticMainTest.java:38)
Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.apache.axis2.transport.http.impl.httpclient4.RequestImpl.execute(RequestImpl.java:210)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:194)
... 9 more
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:225)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
... 13 more
Некоторые пишут, что это сломанная аутентификация, но я считаю, что проблема в другом.
Ребята, в NonRepeatableRequestException после добавления Basic Auth пишут одной строчкой, а куда эту строку вставить?post.setEntity(new BufferedHttpEntity(new InputStreamEntity(input)));
Спасибо за вашу помощь
1 ответ
Я мог бы решить свою проблему, заменив аутентификацию авторизацией следующим кодом:
String credentials = sapSoapUsername + ":" + sapSoapPassword;
String encodedCredentials = Base64.getEncoder()
.encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
String authorizationHeader = "Basic " + encodedCredentials;
Options options = stub._getServiceClient().getOptions();
Map<String, String> property = new HashMap<>();
property.put("Authorization", authorizationHeader);
options.setProperty(HTTPConstants.HTTP_HEADERS, property);