ich einen SOAP-Client erzeugt mit Apache CXF haben, und es gibt ein Problem mit der Handhabung MTOM attachment:Apache CXF SOAP - Umgang mit MTOM Befestigung: Reaktion war unerwartet text/html Content
WARNING: Interceptor for {http://someaddress.com.au/soap2/}
SomeAddressPortTypeService#{http://someaddress.com.au/soap2/}
SomeFunction has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.
Incoming portion of HTML stream: <?xml version="1.0" encoding="UTF-8"?>
....etc
Unten ist mein pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.someid</groupId>
<artifactId>SomeSOAPClient</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>SomeSOAPClient</name>
<url>http://maven.apache.org</url>
<properties>
<junit.version>4.12</junit.version>
<cxf.version>3.0.4</cxf.version>
<spring.version>4.1.7.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<version>3.5.1</version>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>src/main/java-generated</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>http://localhost:4001/someAddress.WSDL</wsdl>
<extraargs>
<extraarg>-autoNameResolution</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Unten ist mein beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<context:property-placeholder/>
<context:annotation-config/>
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"/>
<jaxws:client id="soapClientBean"
address="http://localhost:4001"
serviceClass="some.package.SomePortType">
</jaxws:client>
<context:component-scan base-package="some.package,
another.package"/>
ähnlich
@Component
public class SOAPClient {
@Autowired
private SomePortType soapClientBean;
public String doStuff(String arg, ...){ ... }
und schließlich ist der Test auf unter:
Die Client-Klasse wird wie definiert
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:beans.xml"})
public class SOAPClientTest {
@Autowired
SOAPClient soapClient;
@Test
public void testDoStuff(){
assertNotNull(soapClient.doStuff("blah"));
}
Mein Verständnis, dass es möglich sein sollte, eine Interceptor auf dem CXF-Client, würde hinzufügen Setzen Sie die Message.CONTENT_TYPE-Eigenschaft zurück, aber ich weiß nicht, wie das geht. Oder
ist es eine andere Möglichkeit?
Könnte jemand bitte helfen? Vielen Dank!
UPDATE:
ich auch MTOM versucht haben, wie unten ermöglicht, aber das war nicht bewirken:
Binding binding = ((BindingProvider) soapClientBean).getBinding();
((SOAPBinding)binding).setMTOMEnabled(true);
UPDATE2:
Auch nach http://cxf.apache.org/docs/simple-frontend-configuration.html, unter Konfiguration sollte auch MTOM aktivieren, aber es hat auch keine Wirkung (Namespaces & hinzugefügt und die Client-Bean wie folgt neu definiert):
xmlns:simple="http://cxf.apache.org/simple"
xmlns:soap="http://cxf.apache.org/bindings/soap"
<simple:client id="soapClientBean"
address="http://localhost:4001"
serviceClass="some.package.SomePortType">
<simple:binding>
<soap:soapBinding mtomEnabled="true" version="1.2"/>
</simple:binding>
</simple:client>