I'm moving from java 8 to java 11. I have integration with old style SOAP 1.2 service. Because of cutting of JEE web services stuff from java 11 extending from javax.xml.ws.Service
and call super.getPort(new QName(...), SomeWebService.class, someFeatures);
from generated sources is not working for me any more.
So I decided to use for this SOAP call OpenFeign https://github.com/OpenFeign/feign#soap , https://github.com/OpenFeign/feign/tree/master/soap
Service I would like to call is:
- SOAP 1.2 based
- charset is utf-8
- Content-Type request: application/soap+xml
- Content-Type response: application/xop+xml
The call I would like to do looks like this in plain xml:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc</wsa:To>
<wsa:Action>http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj</wsa:Action>
</soap:Header>
<soap:Body>
<ns:Zaloguj>
<ns:pKluczUzytkownika>theUsersKey</ns:pKluczUzytkownika>
</ns:Zaloguj>
</soap:Body>
</soap:Envelope>
What I did using OpenFeign was interface for connecting:
import my.domain.schema.cis.bir.publ._2014._07.Zaloguj;
import feign.Headers;
import feign.RequestLine;
public interface MyWebServiceCallInterface {
@RequestLine("POST /")
@Headers({
"SOAPAction: http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj",
"Content-Type: application/soap+xml"
})
String zaloguj(Zaloguj zaloguj);
}
Zaloguj class looks like this:
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"pKluczUzytkownika"
})
@XmlRootElement(name = "Zaloguj")
public class Zaloguj {
@XmlElementRef(name = "pKluczUzytkownika", namespace = "http://CIS/BIR/PUBL/2014/07", type = JAXBElement.class, required = false)
protected JAXBElement<String> pKluczUzytkownika;
public JAXBElement<String> getPKluczUzytkownika() {
return pKluczUzytkownika;
}
public void setPKluczUzytkownika(JAXBElement<String> value) {
this.pKluczUzytkownika = value;
}
}
and I have implemented service with SOAP calling:
public ResponseEntity callSOAPService() {
JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder()
.withMarshallerJAXBEncoding("UTF-8") .withMarshallerSchemaLocation("https://wyszukiwarkaregon.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-prod.wsdl")
.build();
MyWebServiceCallInterface myWebServiceCallInterface = Feign.builder()
.encoder(new SOAPEncoder(jaxbFactory))
.decoder(new SOAPDecoder(jaxbFactory))
.target(MyWebServiceCallInterface.class, "https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc");
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> userKeyElement =objectFactory.createZalogujPKluczUzytkownika("topSecretUserKey");
Zaloguj zaloguj = new Zaloguj();
zaloguj1.setPKluczUzytkownika(userKeyElement);
String result = myWebServiceCallInterface.zaloguj(zaloguj);
}
But for this call I've received:
feign.FeignException$BadRequest: [400 Bad Request] during [POST] to [https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/] [MyWebServiceCallInterface#zaloguj(Zaloguj)]: []
I was trying to debug and in Feign SynchronousMethodHandler method executeAndDecode has a template field with value:
POST / HTTP/1.1
Content-Length: 511
Content-Type: application/soap+xml
SOAPAction: http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj
<?xml version="1.0" encoding="UTF-8" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><Zaloguj xmlns="http://CIS/BIR/PUBL/2014/07" xmlns:ns2="http://CIS/BIR/PUBL/2014/07/DataContract" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://wyszukiwarkaregon.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-prod.wsdl"><pKluczUzytkownika>b7e7df92129b4e25aeab</pKluczUzytkownika></Zaloguj></SOAP-ENV:Body></SOAP-ENV:Envelope>
and in Feign ErrorDecoder method decode has request field with value:
POST https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ HTTP/1.1
Content-Length: 511
Content-Type: application/soap+xml
SOAPAction: http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj
<?xml version="1.0" encoding="UTF-8" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><Zaloguj xmlns="http://CIS/BIR/PUBL/2014/07" xmlns:ns2="http://CIS/BIR/PUBL/2014/07/DataContract" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://wyszukiwarkaregon.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-prod.wsdl"><pKluczUzytkownika>b7e7df92129b4e25aeab</pKluczUzytkownika></Zaloguj></SOAP-ENV:Body></SOAP-ENV:Envelope>
Maybe some on of You know how to fix it?
Did I make something wrong in my MyWebServiceCallInterface implementation?
I'm looking forward for Your advises!