Reworked mtom sample to code config
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
ext.springWsVersion = '2.2.0.BUILD-SNAPSHOT'
|
||||
ext.springVersion = '4.0.3.RELEASE'
|
||||
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
@@ -5,6 +9,7 @@ subprojects {
|
||||
|
||||
repositories {
|
||||
maven { url 'http://repo.spring.io/libs-release' }
|
||||
maven { url 'http://repo.spring.io/libs-snapshot' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -2,12 +2,10 @@ configurations {
|
||||
jaxb
|
||||
}
|
||||
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
|
||||
task genJaxb {
|
||||
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
|
||||
ext.classesDir = "${buildDir}/classes/jaxb"
|
||||
ext.schema = "${projectDir}/../../server/src/main/webapp/WEB-INF/schema.xsd"
|
||||
ext.schema = "${projectDir}/../../server/src/main/resources/schema.xsd"
|
||||
|
||||
inputs.files schema
|
||||
outputs.dir classesDir
|
||||
@@ -43,6 +41,7 @@ task genJaxb {
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
compile("org.springframework:spring-context:$springVersion")
|
||||
compile("org.apache.ws.commons.axiom:axiom-api:1.2.14")
|
||||
compile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.ws.samples.mtom.client.sws;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class Driver {
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Driver {
|
||||
fileName = args[0];
|
||||
}
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("applicationContext.xml", Driver.class);
|
||||
new AnnotationConfigApplicationContext(MtomClientConfig.class);
|
||||
|
||||
SaajMtomClient saajClient = applicationContext.getBean("saajClient", SaajMtomClient.class);
|
||||
saajClient.doIt(fileName);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.springframework.ws.samples.mtom.client.sws;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Configuration
|
||||
public class MtomClientConfig {
|
||||
|
||||
@Bean
|
||||
public SaajMtomClient saajClient() {
|
||||
SaajMtomClient client = new SaajMtomClient(saajSoapMessageFactory());
|
||||
client.setDefaultUri("http://localhost:8080/mtom-server/services");
|
||||
client.setMarshaller(marshaller());
|
||||
client.setUnmarshaller(marshaller());
|
||||
return client;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SaajSoapMessageFactory saajSoapMessageFactory() {
|
||||
return new SaajSoapMessageFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AxiomMtomClient axiomClient() {
|
||||
AxiomMtomClient client = new AxiomMtomClient(axiomSoapMessageFactory());
|
||||
client.setDefaultUri("http://localhost:8080/mtom-server/services");
|
||||
return client;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AxiomSoapMessageFactory axiomSoapMessageFactory() {
|
||||
return new AxiomSoapMessageFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jaxb2Marshaller marshaller() {
|
||||
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setContextPath("org.springframework.ws.samples.mtom.client.sws");
|
||||
marshaller.setMtomEnabled(true);
|
||||
return marshaller;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import org.springframework.ws.soap.client.SoapFaultClientException;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
/**
|
||||
* Simple client that demonstartes MTOM by invoking <code>StoreImage</code> and <code>LoadImage</code> using a
|
||||
* Simple client that demonstrates MTOM by invoking {@code StoreImage} and {@code LoadImage} using a
|
||||
* WebServiceTemplate and SAAJ.
|
||||
*
|
||||
* @author Tareq Abed Rabbo
|
||||
@@ -66,6 +66,7 @@ public class SaajMtomClient extends WebServiceGatewaySupport {
|
||||
stopWatch.stop();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void load(String path) {
|
||||
JAXBElement<String> loadImageRequest = objectFactory.createLoadImageRequest(StringUtils.getFilename(path));
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="client" abstract="true">
|
||||
<property name="defaultUri" value="http://localhost:8080/mtom-server/services"/>
|
||||
</bean>
|
||||
|
||||
<bean id="saajClient" class="org.springframework.ws.samples.mtom.client.sws.SaajMtomClient" parent="client">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
|
||||
</constructor-arg>
|
||||
<property name="marshaller" ref="marshaller"/>
|
||||
<property name="unmarshaller" ref="marshaller"/>
|
||||
</bean>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||
<property name="contextPath" value="org.springframework.ws.samples.mtom.client.sws"/>
|
||||
<property name="mtomEnabled" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="axiomClient" class="org.springframework.ws.samples.mtom.client.sws.AxiomMtomClient" parent="client">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -12,8 +12,6 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
ext.springVersion = '3.2.4.RELEASE'
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
ext.tomcatVersion = '7.0.42'
|
||||
|
||||
|
||||
@@ -64,10 +62,12 @@ tomcatRun {
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
compile("org.springframework:spring-context:$springVersion")
|
||||
compile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
|
||||
runtime("log4j:log4j:1.2.16")
|
||||
|
||||
runtime("wsdl4j:wsdl4j:1.6.1")
|
||||
|
||||
jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
|
||||
|
||||
tomcat("org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion",
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.springframework.ws.samples.mtom.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
import org.springframework.ws.config.annotation.EnableWs;
|
||||
import org.springframework.ws.config.annotation.WsConfigurationSupport;
|
||||
import org.springframework.ws.samples.mtom.service.ImageRepository;
|
||||
import org.springframework.ws.samples.mtom.service.StubImageRepository;
|
||||
import org.springframework.ws.samples.mtom.ws.ImageRepositoryEndpoint;
|
||||
import org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler;
|
||||
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@EnableWs
|
||||
@Configuration
|
||||
public class MtomServerConfiguration extends WsConfigurationSupport {
|
||||
|
||||
@Bean
|
||||
public ImageRepository imageRepository() {
|
||||
return new StubImageRepository();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ImageRepositoryEndpoint imageRepositoryEndpoint() {
|
||||
return new ImageRepositoryEndpoint(imageRepository());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public DefaultMethodEndpointAdapter defaultMethodEndpointAdapter() {
|
||||
List<MethodArgumentResolver> argumentResolvers =
|
||||
new ArrayList<MethodArgumentResolver>();
|
||||
argumentResolvers.add(methodProcessor());
|
||||
|
||||
List<MethodReturnValueHandler> returnValueHandlers =
|
||||
new ArrayList<MethodReturnValueHandler>();
|
||||
returnValueHandlers.add(methodProcessor());
|
||||
|
||||
DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
|
||||
adapter.setMethodArgumentResolvers(argumentResolvers);
|
||||
adapter.setMethodReturnValueHandlers(returnValueHandlers);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MarshallingPayloadMethodProcessor methodProcessor() {
|
||||
return new MarshallingPayloadMethodProcessor(marshaller());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jaxb2Marshaller marshaller() {
|
||||
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setContextPath("org.springframework.ws.samples.mtom.schema");
|
||||
marshaller.setMtomEnabled(true);
|
||||
return marshaller;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultWsdl11Definition mtom() {
|
||||
DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
|
||||
definition.setSchema(schema());
|
||||
definition.setPortTypeName("ImageRepository");
|
||||
definition.setLocationUri("http://localhost:8080/mtom-server/");
|
||||
return definition;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SimpleXsdSchema schema() {
|
||||
return new SimpleXsdSchema(new ClassPathResource("/schema.xsd"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,11 +31,13 @@ public class StubImageRepository implements ImageRepository {
|
||||
|
||||
private Map<String, Image> images = new HashMap<String, Image>();
|
||||
|
||||
@Override
|
||||
public Image readImage(String name) throws IOException {
|
||||
logger.info("Loading image " + name);
|
||||
return images.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeImage(String name, Image image) throws IOException {
|
||||
logger.info("Storing image " + name + " [" + image.getWidth(null) + "x" + image.getHeight(null) + "]");
|
||||
images.put(name, image);
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<bean id="imageRepository" class="org.springframework.ws.samples.mtom.service.StubImageRepository"/>
|
||||
|
||||
<bean class="org.springframework.ws.samples.mtom.ws.ImageRepositoryEndpoint">
|
||||
<constructor-arg ref="imageRepository"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
|
||||
|
||||
<bean class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
|
||||
<property name="methodArgumentResolvers" ref="methodProcessor"/>
|
||||
<property name="methodReturnValueHandlers" ref="methodProcessor"/>
|
||||
</bean>
|
||||
|
||||
<bean id="methodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
|
||||
<constructor-arg ref="marshaller"/>
|
||||
</bean>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||
<property name="contextPath" value="org.springframework.ws.samples.mtom.schema"/>
|
||||
<property name="mtomEnabled" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mtom" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
|
||||
<property name="schema" ref="schema"/>
|
||||
<property name="portTypeName" value="ImageRepository"/>
|
||||
<property name="locationUri" value="http://localhost:8080/mtom-server/"/>
|
||||
</bean>
|
||||
|
||||
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
|
||||
<property name="xsd" value="/WEB-INF/schema.xsd"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,29 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2007 the original author or authors.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
|
||||
version="2.4">
|
||||
|
||||
<web-app>
|
||||
<display-name>MyCompany HR Holiday Service</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextClass</param-name>
|
||||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>org.springframework.ws.samples.mtom.config.MtomServerConfiguration</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
|
||||
Reference in New Issue
Block a user