Невозможно установить обратное действие мыла в клиенте веб-службы с помощью Spring Boot WS - PullRequest
1 голос
/ 12 мая 2019

У меня проблема с вызовом .Net Webservice из Java-клиента с использованием Spring Boot.

Журналы ошибок:

org.springframework.ws.soap.client.SoapFaultClientException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://staging.dayross.ca/public/shipmentservices.asmx.

Я добавил действие SOAP в свой код клиента:

    @Component
    public class SOAPConnector extends WebServiceGatewaySupport {

        public Object callWebService(String url, Object request) {
            return getWebServiceTemplate().marshalSendAndReceive(url, request, new SoapActionCallback("http://staging.dayross.ca/public/shipmentservices.asmx"));
        }



    }

    //Client code:

    CreatePickup2Response result = (CreatePickup2Response) soapConnector
                    .callWebService("http://staging.dayross.ca/public/shipmentservices.asmx", pickupReq);

//Bean configuration:

@Bean
     public SOAPConnector soapConnector(Jaxb2Marshaller marshaller) {
            SOAPConnector client = new SOAPConnector();
            client.setDefaultUri("http://staging.dayross.ca/public/shipmentservices.asmx");
            client.setMarshaller(marshaller);
            client.setUnmarshaller(marshaller);
            return client;
        }

Я почти уверен, что мне не хватает какой-то базовой конфигурации, но я не могу понять. Может кто-нибудь помочь мне решить эту проблему?

Полная трассировка:

2019-05-11 22:21:06.685 DEBUG 21052 --- [  restartedMain] o.s.ws.client.core.WebServiceTemplate    : Opening [org.springframework.ws.transport.http.HttpUrlConnection@4c12c5cb] to [http://staging.dayross.ca/public/shipmentservices.asmx]
2019-05-11 22:21:06.719 TRACE 21052 --- [  restartedMain] o.s.ws.client.MessageTracing.sent        : Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:CreatePickup2 xmlns:ns2="http://dayrossgroup.com/web/public/webservices/shipmentServices" xmlns:ns3="http://www.dayrossgroup.com/web/common/webServices/OnlineShipping"><ns2:division>GeneralFreight</ns2:division><ns2:emailAddress>staging@dr.com</ns2:emailAddress><ns2:password>test</ns2:password><ns2:shipment><ns2:ShipperAddress><ns2:Address1>8345 WHITE OAK AVENUE</ns2:Address1><ns2:City>Saint-Augustin-De-Desmaures</ns2:City><ns2:Country>CA</ns2:Country><ns2:Name>SHIPPER CONTACT NAME</ns2:Name><ns2:PostalCode>G3A0G2</ns2:PostalCode><ns2:Province>QC</ns2:Province><ns2:CompanyName>ADVANTAGE</ns2:CompanyName><ns2:EmailAddress>SHIPPEREMAIL@EMAIL.COM</ns2:EmailAddress><ns2:PhoneNumber>9092044990</ns2:PhoneNumber></ns2:ShipperAddress><ns2:ConsigneeAddress><ns2:Address1>5622 BURLEIGH CRESCENT SE</ns2:Address1><ns2:City>CALGARY</ns2:City><ns2:Country>CA</ns2:Country><ns2:Name>CONSIGNEE CONTACT NAME</ns2:Name><ns2:PostalCode>T2H1Z8</ns2:PostalCode><ns2:Province>AB</ns2:Province><ns2:CompanyName>LOWRY</ns2:CompanyName><ns2:PhoneNumber>8964567412</ns2:PhoneNumber></ns2:ConsigneeAddress><ns2:BillToAccount>56896</ns2:BillToAccount><ns2:Items><ns2:ShipmentItem><ns2:Description>SKID OF TAPE</ns2:Description><ns2:Height>24</ns2:Height><ns2:Length>30</ns2:Length><ns2:LengthUnit>Inches</ns2:LengthUnit><ns2:Pieces>2</ns2:Pieces><ns2:Weight>50</ns2:Weight><ns2:WeightUnit>Pounds</ns2:WeightUnit><ns2:Width>30</ns2:Width></ns2:ShipmentItem></ns2:Items><ns2:ServiceLevel>GL</ns2:ServiceLevel><ns2:ShipmentType>Regular</ns2:ShipmentType><ns2:ReadyTime>2019-05-19 15:19:27</ns2:ReadyTime><ns2:ClosingTime>2019-05-19 17:19:27</ns2:ClosingTime><ns2:ShipmentStatus><ns2:Id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/><ns2:RowVersion>0</ns2:RowVersion><ns2:InternalStatus>false</ns2:InternalStatus><ns2:OrderEntryState>ReadyForPickup</ns2:OrderEntryState></ns2:ShipmentStatus><ns2:MeasurementSystem>Imperial</ns2:MeasurementSystem><ns2:ExpiryDate>2029-01-07T22:21:06.659-06:00</ns2:ExpiryDate><ns2:Division>GeneralFreight</ns2:Division><ns2:ReferenceNumbers><ns2:string>RA89653</ns2:string></ns2:ReferenceNumbers></ns2:shipment><ns2:language>EN</ns2:language></ns2:CreatePickup2></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2019-05-11 22:21:06.970 TRACE 21052 --- [  restartedMain] o.s.ws.client.MessageTracing.received    : Received response [<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://staging.dayross.ca/public/shipmentservices.asmx.
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)</faultstring><detail/></soap:Fault></soap:Body></soap:Envelope>] for request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:CreatePickup2 xmlns:ns2="http://dayrossgroup.com/web/public/webservices/shipmentServices" xmlns:ns3="http://www.dayrossgroup.com/web/common/webServices/OnlineShipping"><ns2:division>GeneralFreight</ns2:division><ns2:emailAddress>staging@dr.com</ns2:emailAddress><ns2:password>test</ns2:password><ns2:shipment><ns2:ShipperAddress><ns2:Address1>8345 WHITE OAK AVENUE</ns2:Address1><ns2:City>Saint-Augustin-De-Desmaures</ns2:City><ns2:Country>CA</ns2:Country><ns2:Name>SHIPPER CONTACT NAME</ns2:Name><ns2:PostalCode>G3A0G2</ns2:PostalCode><ns2:Province>QC</ns2:Province><ns2:CompanyName>ADVANTAGE</ns2:CompanyName><ns2:EmailAddress>SHIPPEREMAIL@EMAIL.COM</ns2:EmailAddress><ns2:PhoneNumber>9092044990</ns2:PhoneNumber></ns2:ShipperAddress><ns2:ConsigneeAddress><ns2:Address1>5622 BURLEIGH CRESCENT SE</ns2:Address1><ns2:City>CALGARY</ns2:City><ns2:Country>CA</ns2:Country><ns2:Name>CONSIGNEE CONTACT NAME</ns2:Name><ns2:PostalCode>T2H1Z8</ns2:PostalCode><ns2:Province>AB</ns2:Province><ns2:CompanyName>LOWRY</ns2:CompanyName><ns2:PhoneNumber>8964567412</ns2:PhoneNumber></ns2:ConsigneeAddress><ns2:BillToAccount>56896</ns2:BillToAccount><ns2:Items><ns2:ShipmentItem><ns2:Description>SKID OF TAPE</ns2:Description><ns2:Height>24</ns2:Height><ns2:Length>30</ns2:Length><ns2:LengthUnit>Inches</ns2:LengthUnit><ns2:Pieces>2</ns2:Pieces><ns2:Weight>50</ns2:Weight><ns2:WeightUnit>Pounds</ns2:WeightUnit><ns2:Width>30</ns2:Width></ns2:ShipmentItem></ns2:Items><ns2:ServiceLevel>GL</ns2:ServiceLevel><ns2:ShipmentType>Regular</ns2:ShipmentType><ns2:ReadyTime>2019-05-19 15:19:27</ns2:ReadyTime><ns2:ClosingTime>2019-05-19 17:19:27</ns2:ClosingTime><ns2:ShipmentStatus><ns2:Id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/><ns2:RowVersion>0</ns2:RowVersion><ns2:InternalStatus>false</ns2:InternalStatus><ns2:OrderEntryState>ReadyForPickup</ns2:OrderEntryState></ns2:ShipmentStatus><ns2:MeasurementSystem>Imperial</ns2:MeasurementSystem><ns2:ExpiryDate>2029-01-07T22:21:06.659-06:00</ns2:ExpiryDate><ns2:Division>GeneralFreight</ns2:Division><ns2:ReferenceNumbers><ns2:string>RA89653</ns2:string></ns2:ReferenceNumbers></ns2:shipment><ns2:language>EN</ns2:language></ns2:CreatePickup2></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2019-05-11 22:21:06.971 DEBUG 21052 --- [  restartedMain] o.s.ws.client.core.WebServiceTemplate    : Received Fault message for request [SaajSoapMessage {http://dayrossgroup.com/web/public/webservices/shipmentServices}CreatePickup2]

1 Ответ

0 голосов
/ 12 мая 2019

Ваша проблема в том, что сервер, на котором вы пытаетесь выполнить операцию, не распознает заголовок SOAPAction и поэтому не может направить ваши запросы в соответствующую конечную точку.Если вы посмотрите на WSDL службы , к которой вы пытаетесь подключиться, вы можете выполнить множество различных операций.

Для вашего конкретного примера, CreatePickup2, операция указана как

<wsdl:operation name="CreatePickup2">
    <soap:operation soapAction="http://dayrossgroup.com/web/public/webservices/shipmentServices/CreatePickup2" style="document"/>
    <wsdl:input>
        <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
        <soap:body use="literal"/>
    </wsdl:output>
</wsdl:operation>

Поскольку вы уже указали defaultUri в своем бобе, вам не нужно указыватьURL в вашем getWebServiceTemplate().marshalSendAndReceive(...) методе.

Это даст вам компонент, похожий на этот

@Component
public class SOAPConnector extends WebServiceGatewaySupport {

    public Object callWebService(Object request, String soapAction) {
        return getWebServiceTemplate().marshalSendAndReceive(request, new SoapActionCallback(soapAction));
    }
}

И клиентский код примерно такой

CreatePickup2Response result = (CreatePickup2Response) soapConnector
        .callWebService(pickupReq, "http://dayrossgroup.com/web/public/webservices/shipmentServices/CreatePickup2");

Если вымы будем использовать более одной операции, которая понадобится вам, чтобы сделать предложенное решение более общим.

...