Updated MTOM sample to use maven
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.samples.mtom.service;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
public interface ImageRepository {
|
||||
|
||||
Image readImage(String name) throws IOException;
|
||||
|
||||
void storeImage(String name, Image image) throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.samples.mtom.service;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
public class StubImageRepository implements ImageRepository {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(StubImageRepository.class);
|
||||
|
||||
private Map<String, Image> images = new HashMap<String, Image>();
|
||||
|
||||
public Image readImage(String name) throws IOException {
|
||||
logger.info("Loading image " + name);
|
||||
return images.get(name);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.samples.mtom.ws;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.samples.mtom.schema.Image;
|
||||
import org.springframework.ws.samples.mtom.schema.ObjectFactory;
|
||||
import org.springframework.ws.samples.mtom.service.ImageRepository;
|
||||
import org.springframework.ws.server.endpoint.annotation.Endpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
@Endpoint
|
||||
public class ImageRepositoryEndpoint {
|
||||
|
||||
private ImageRepository imageRepository;
|
||||
|
||||
private ObjectFactory objectFactory;
|
||||
|
||||
public ImageRepositoryEndpoint(ImageRepository imageRepository) {
|
||||
Assert.notNull(imageRepository, "'imageRepository' must not be null");
|
||||
this.imageRepository = imageRepository;
|
||||
this.objectFactory = new ObjectFactory();
|
||||
}
|
||||
|
||||
@PayloadRoot(localPart = "StoreImageRequest", namespace = "http://www.springframework.org/spring-ws/samples/mtom")
|
||||
public void store(JAXBElement<Image> requestElement) throws IOException {
|
||||
Image request = requestElement.getValue();
|
||||
imageRepository.storeImage(request.getName(), request.getImage());
|
||||
}
|
||||
|
||||
@PayloadRoot(localPart = "LoadImageRequest", namespace = "http://www.springframework.org/spring-ws/samples/mtom")
|
||||
public JAXBElement<Image> load(JAXBElement<String> requestElement) throws IOException {
|
||||
String name = requestElement.getValue();
|
||||
Image response = new Image();
|
||||
response.setName(name);
|
||||
response.setImage(imageRepository.readImage(name));
|
||||
return objectFactory.createLoadImageResponse(response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
8
samples/mtom/server/src/main/resources/log4j.properties
Normal file
8
samples/mtom/server/src/main/resources/log4j.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
log4j.rootLogger=WARN, stdout
|
||||
log4j.logger.org.springframework.ws=DEBUG
|
||||
log4j.logger.org.springframework.xml=DEBUG
|
||||
log4j.logger.org.springframework.ws.samples=INFO
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
|
||||
19
samples/mtom/server/src/main/webapp/WEB-INF/schema.xsd
Normal file
19
samples/mtom/server/src/main/webapp/WEB-INF/schema.xsd
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/mtom"
|
||||
xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified">
|
||||
|
||||
<element name="StoreImageRequest" type="tns:Image"/>
|
||||
|
||||
<element name="LoadImageRequest" type="string"/>
|
||||
|
||||
<element name="LoadImageResponse" type="tns:Image"/>
|
||||
|
||||
<complexType name="Image">
|
||||
<sequence>
|
||||
<element name="name" type="string"/>
|
||||
<element name="image" type="base64Binary" xmime:expectedContentTypes="image/png"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
</schema>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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="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.GenericMarshallingMethodEndpointAdapter">
|
||||
<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>
|
||||
34
samples/mtom/server/src/main/webapp/WEB-INF/web.xml
Normal file
34
samples/mtom/server/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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">
|
||||
|
||||
<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>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user