Reworked mtom sample to code config

This commit is contained in:
Arjen Poutsma
2014-04-28 15:37:22 +02:00
parent bdcf6e608d
commit 3e7e422ba8
12 changed files with 158 additions and 94 deletions

View File

@@ -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",

View File

@@ -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"));
}
}

View File

@@ -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);

View File

@@ -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>

View File

@@ -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>