Клиент, созданный CXF, не включает заголовок SOAP - PullRequest
0 голосов
/ 28 мая 2020

Используя образец wsdl, развернутый в Apache CXF-дистрибутиве

https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/antbuild/wsdl/hello_world.wsdl

Я настроил небольшой проект Maven с этим (cxf-codegen- plugin) настройки генерации кода в pom. xml:

...
<plugins>
    <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>3.3.6</version>
        <executions>
            <execution>
                <id>generate-sources-x</id>
                <phase>generate-sources</phase>
                <configuration>
                    <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
                    <includes>
                        <include>hello_world.wsdl</include>
                    </includes>
                    <defaultOptions>
                        <extraargs>
                            <extraarg>-verbose</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>my.test.package</extraarg>
                            <extraarg>-exsh</extraarg>
                            <extraarg>true</extraarg>
                        </extraargs>
                    </defaultOptions>
                </configuration>
                <goals>
                    <goal>wsdl2java</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
...

Это мой модульный тест:

public class Test3 {
    public static void main(String[] args) throws JAXBException {
        System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
        System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
        System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
        System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");

        String url = "http://www.mmm.xxx/yyy/zzz";
        SOAPService service = new SOAPService();
        Greeter client = service.getSoapPort();
        BindingProvider bp = (BindingProvider) client;

        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

        List<Header> headers = new ArrayList<Header>();
        Header dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "decapitated", new JAXBDataBinding(String.class));
        headers.add(dummyHeader);

        bp.getRequestContext().put(Header.HEADER_LIST, headers);

        String response = client.greetMe("CIAO!");
    }
}

Теперь, запущен тестовый класс, это дамп HTTP-запроса:

---[HTTP request - http://www.mmm.xxx/yyy/zzz]---
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><greetMe xmlns="http://apache.org/hello_world_soap_http/types"><requestType>CIAO!</requestType></greetMe></S:Body></S:Envelope>--------------------

Нет раздела <S:Header>...</S:Header> в сообщении SOAP конверта. Я внимательно следил за этой настройкой в ​​документации CXF (http://cxf.apache.org/faq.html#FAQ -HowcanIaddsoapheaderstotherequest / response? ).

Что не так в моей реализации?

...