I am facing an issue in calling .Net Webservice from Java client using Spring Boot.
Error logs:
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.
I added SOAP action in my client code:
@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;
}
I am pretty sure I am missing some basic configuration here but not able to figure out. Can someone help me troubleshoot this issue?
Complete Trace:
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>[email protected]</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>[email protected]</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& 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>[email protected]</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>[email protected]</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]
Your problem is that the server you're trying to perform an operation on does not recognize the SOAPAction
header and is therefore unable to route your requests to the appropriate endpoint. If you take a look at the WSDL of the service you're trying to connect to there are many different operations you can perform.
For your specific example, CreatePickup2
, the operation is specified as
<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>
Since you've already specified the defaultUri
in your bean you don't need to specify the URL in your getWebServiceTemplate().marshalSendAndReceive(...)
method.
That will give you a component looking like this
@Component
public class SOAPConnector extends WebServiceGatewaySupport {
public Object callWebService(Object request, String soapAction) {
return getWebServiceTemplate().marshalSendAndReceive(request, new SoapActionCallback(soapAction));
}
}
And a client code something like this
CreatePickup2Response result = (CreatePickup2Response) soapConnector
.callWebService(pickupReq, "http://dayrossgroup.com/web/public/webservices/shipmentServices/CreatePickup2");
If you're gonna use more than one of the operations you'll need to make my proposed solution more generic.