Я реализовал soap класс веб-сервиса следующим образом
@WebService
@HandlerChain(file = "/handlers.xml")
public class TxnNotification {
public TxnNotification() {}
@WebMethod(operationName = "PaymentNotificationRequest")
@WebResult(name = "PaymentNotificationResult", partName = "PaymentNotificationResult")
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public NotificationResult receiveNotification(
@WebParam(name = "TransType") String transType,
@WebParam(name = "TransId") String transId,
@WebParam(name = "TransTime") String transTime,
@WebParam(name = "TransAmount") String transAmount) String status) {
NotificationResult notificationResult = new NotificationResult();
notificationResult.setResult(OkFail.OK);
return notificationResult;
}
}
Я могу получить успешный ответ с помощью soap пользовательского интерфейса, генерирующего следующий запрос:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soapws.common.fms.com/">
<soapenv:Header/>
<soapenv:Body>
<soap:PaymentNotificationRequest>
<TransType>?</TransType>
<TransId>?</TransId>
<TransTime>?</TransTime>
<TransAmount>?</TransAmount>
</soap:PaymentNotificationRequest>
</soapenv:Body>
</soapenv:Envelope>
, но клиент будет делать запрос в следующем формате
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soapws.common.fms.com/">
<soapenv:Header/>
<soapenv:Body>
<PaymentNotificationRequest>
<TransType>?</TransType>
<TransId>?</TransId>
<TransTime>?</TransTime>
<TransAmount>?</TransAmount>
</PaymentNotificationRequest>
</soapenv:Body>
</soapenv:Envelope>
Обратите внимание на разницу в префиксе soap в теге PaymentNotificationRequest
. Чтобы добавить ожидаемый префикс soap с помощью wildfly / cxf, я реализовал следующий обработчик
@Override
public boolean handleMessage(SOAPMessageContext context) {
......
if (!outbound)
SOAPElement element = (SOAPElement) childElementNode;
if (element.getNodeName() != null && element.getNodeName().equalsIgnoreCase("PaymentNotificationRequest")){
element.setPrefix("soap");
}
....
}
}
когда я регистрируюсь следующим образом:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
soapMsg.writeTo(baos);
log.info(baos);
Я получаю правильный запрос, но все равно получаю следующую ошибку
Interceptor for {http://soapws.common.fms.com/}TxnNotificationService has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: Message part PaymentNotificationResult was not recognized. (Does it exist in service WSDL?)
at org.apache.cxf.wsdl.interceptors.BareInInterceptor.handleMessage(BareInInterceptor.java:126)
at org.apache.cxf.binding.soap.interceptor.RPCInInterceptor.handleMessage(RPCInInterceptor.java:109)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
Как мне это исправить или как сделать так, чтобы конечная точка веб-службы могла использовать ожидаемый формат запроса?