Skip to content

Commit e7b73d7

Browse files
committed
SWS-249
1 parent a17d6fc commit e7b73d7

File tree

17 files changed

+474
-0
lines changed

17 files changed

+474
-0
lines changed

samples/pox/client/curl/client.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
curl --header "Content-type: application/xml" -v --data @contactsRequest.xml http://localhost:8080/pox/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Contacts xmlns="http://www.springframework.org/spring-ws/samples/pox">
3+
<Contact>
4+
<Name>John Doe</Name>
5+
<Phone>626-555-3456</Phone>
6+
</Contact>
7+
<Contact>
8+
<Name>Jane Doe</Name>
9+
<Phone>626-555-6543</Phone>
10+
</Contact>
11+
</Contacts>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0"?>
2+
3+
<project name="spring-ws-pox-sample-spring-ws-client" default="build" xmlns:artifact="urn:maven-artifact-ant">
4+
<property name="bin.dir" value="bin"/>
5+
<property name="src.dir" value="src"/>
6+
7+
<target name="init">
8+
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant">
9+
<classpath>
10+
<pathelement location="${basedir}/../../../maven-ant-tasks-2.0.7.jar"/>
11+
</classpath>
12+
</typedef>
13+
14+
<artifact:dependencies pathId="classpath">
15+
<dependency groupId="org.springframework.ws" artifactId="spring-ws-core" version="1.5.0-m2"/>
16+
<dependency groupId="log4j" artifactId="log4j" version="1.2.13"/>
17+
</artifact:dependencies>
18+
19+
</target>
20+
21+
<target name="build" depends="init">
22+
<mkdir dir="${bin.dir}"/>
23+
<javac srcdir="${src.dir}" destdir="${bin.dir}">
24+
<classpath refid="classpath"/>
25+
</javac>
26+
<copy todir="${bin.dir}">
27+
<fileset dir="${src.dir}">
28+
<exclude name="**/*.java"/>
29+
</fileset>
30+
</copy>
31+
</target>
32+
33+
<target name="clean">
34+
<delete dir="${bin.dir}"/>
35+
</target>
36+
37+
<target name="run" depends="contacts"/>
38+
39+
<target name="contacts" depends="build">
40+
<java classname="org.springframework.ws.samples.pox.client.sws.ContactsClient" fork="true" failonerror="true">
41+
<classpath refid="classpath"/>
42+
<classpath location="${bin.dir}"/>
43+
</java>
44+
</target>
45+
46+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootLogger=WARN, stdout
2+
log4j.logger.org.springframework.ws=DEBUG
3+
log4j.logger.org.springframework.xml=DEBUG
4+
5+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
6+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2007 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.samples.pox.client.sws;
18+
19+
import java.io.IOException;
20+
import javax.xml.transform.Source;
21+
import javax.xml.transform.dom.DOMResult;
22+
23+
import org.springframework.context.ApplicationContext;
24+
import org.springframework.context.support.ClassPathXmlApplicationContext;
25+
import org.springframework.core.io.Resource;
26+
import org.springframework.ws.WebServiceMessageFactory;
27+
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
28+
import org.springframework.xml.transform.ResourceSource;
29+
import org.springframework.xml.transform.StringResult;
30+
import org.springframework.xml.xpath.XPathExpression;
31+
32+
public class ContactsClient extends WebServiceGatewaySupport {
33+
34+
private Resource request;
35+
36+
private XPathExpression expression;
37+
38+
public ContactsClient(WebServiceMessageFactory messageFactory) {
39+
super(messageFactory);
40+
}
41+
42+
public void setRequest(Resource request) {
43+
this.request = request;
44+
}
45+
46+
public void setExpression(XPathExpression expression) {
47+
this.expression = expression;
48+
}
49+
50+
public void contacts() throws IOException {
51+
Source requestSource = new ResourceSource(request);
52+
DOMResult result = new DOMResult();
53+
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, result);
54+
int contactCount = (int) expression.evaluateAsNumber(result.getNode());
55+
System.out.println("contactCount = " + contactCount);
56+
}
57+
58+
public static void main(String[] args) throws IOException {
59+
ApplicationContext applicationContext =
60+
new ClassPathXmlApplicationContext("applicationContext.xml", ContactsClient.class);
61+
ContactsClient contactsClient = (ContactsClient) applicationContext.getBean("contactsClient");
62+
contactsClient.contacts();
63+
}
64+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
4+
5+
<bean id="contactsClient" class="org.springframework.ws.samples.pox.client.sws.ContactsClient">
6+
<constructor-arg ref="messageFactory"/>
7+
<property name="defaultUri" value="http://localhost:8080/pox/"/>
8+
<property name="request" value="classpath:org/springframework/ws/samples/pox/client/sws/contactsRequest.xml"/>
9+
<property name="expression" ref="expression"/>
10+
</bean>
11+
12+
<bean id="messageFactory" class="org.springframework.ws.pox.dom.DomPoxMessageFactory"/>
13+
14+
<bean id="expression" class="org.springframework.xml.xpath.XPathExpressionFactoryBean">
15+
<property name="namespaces">
16+
<props>
17+
<prop key="tns">http://www.springframework.org/spring-ws/samples/pox</prop>
18+
</props>
19+
</property>
20+
<property name="expression" value="/tns:ContactCount/text()"/>
21+
</bean>
22+
23+
</beans>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Contacts xmlns="http://www.springframework.org/spring-ws/samples/pox">
3+
<Contact>
4+
<Name>John Doe</Name>
5+
<Phone>626-555-3456</Phone>
6+
</Contact>
7+
<Contact>
8+
<Name>Jane Doe</Name>
9+
<Phone>626-555-6543</Phone>
10+
</Contact>
11+
</Contacts>

samples/pox/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<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">
2+
<parent>
3+
<artifactId>spring-ws-samples</artifactId>
4+
<groupId>org.springframework.ws</groupId>
5+
<version>1.5.0-rc1-SNAPSHOT</version>
6+
</parent>
7+
<modelVersion>4.0.0</modelVersion>
8+
<artifactId>pox</artifactId>
9+
<packaging>war</packaging>
10+
<name>Spring WS POX Sample</name>
11+
<description>A Spring-WS sample that uses Plain Old XML, rather than SOAP.</description>
12+
<profiles>
13+
<profile>
14+
<id>jdk14-jdk15</id>
15+
<activation>
16+
<jdk>!1.6</jdk>
17+
</activation>
18+
<dependencies>
19+
<dependency>
20+
<groupId>stax</groupId>
21+
<artifactId>stax-api</artifactId>
22+
</dependency>
23+
</dependencies>
24+
</profile>
25+
</profiles>
26+
<reporting>
27+
<plugins>
28+
<plugin>
29+
<artifactId>maven-javadoc-plugin</artifactId>
30+
<configuration>
31+
<stylesheetfile>${basedir}/../../src/main/javadoc/javadoc.css</stylesheetfile>
32+
</configuration>
33+
</plugin>
34+
</plugins>
35+
</reporting>
36+
<dependencies>
37+
<!-- Spring-WS dependencies -->
38+
<dependency>
39+
<groupId>org.springframework.ws</groupId>
40+
<artifactId>spring-ws-core</artifactId>
41+
</dependency>
42+
<!-- Test dependencies -->
43+
<dependency>
44+
<groupId>easymock</groupId>
45+
<artifactId>easymock</artifactId>
46+
<version>1.2_Java1.3</version>
47+
<scope>test</scope>
48+
</dependency>
49+
</dependencies>
50+
</project>

samples/pox/readme.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=========================================================
2+
== Spring Web Service Plain Old XML sample application ==
3+
=========================================================
4+
5+
6+
1. INTRODUCTION
7+
8+
This sample shows a service that uses Plain Old XML rather than SOAP. Incoming
9+
messages are handled via SAX, and a response is created using DOM.
10+
11+
2. INSTALLATION
12+
13+
Simply run "mvn package" and deploy the war file generated in target
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2008 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.samples.pox.ws;
18+
19+
import javax.xml.parsers.DocumentBuilder;
20+
import javax.xml.parsers.DocumentBuilderFactory;
21+
import javax.xml.transform.Source;
22+
import javax.xml.transform.dom.DOMSource;
23+
24+
import org.w3c.dom.Document;
25+
import org.w3c.dom.Element;
26+
import org.xml.sax.Attributes;
27+
import org.xml.sax.ContentHandler;
28+
import org.xml.sax.SAXException;
29+
import org.xml.sax.helpers.DefaultHandler;
30+
31+
import org.springframework.ws.server.endpoint.AbstractSaxPayloadEndpoint;
32+
33+
public class ContactCountEndpoint extends AbstractSaxPayloadEndpoint {
34+
35+
private static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/pox";
36+
37+
private static final String CONTANT_NAME = "Contact";
38+
39+
private static final String CONTANT_COUNT_NAME = "ContactCount";
40+
41+
private DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
42+
43+
public ContactCountEndpoint() {
44+
documentBuilderFactory.setNamespaceAware(true);
45+
}
46+
47+
protected ContentHandler createContentHandler() throws Exception {
48+
return new ContactCounter();
49+
}
50+
51+
protected Source getResponse(ContentHandler contentHandler) throws Exception {
52+
ContactCounter counter = (ContactCounter) contentHandler;
53+
54+
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
55+
Document response = documentBuilder.newDocument();
56+
Element contactCountElement = response.createElementNS(NAMESPACE_URI, CONTANT_COUNT_NAME);
57+
response.appendChild(contactCountElement);
58+
contactCountElement.setTextContent(Integer.toString(counter.contactCount));
59+
60+
return new DOMSource(response);
61+
}
62+
63+
private static class ContactCounter extends DefaultHandler {
64+
65+
private int contactCount = 0;
66+
67+
public void startElement(String uri, String localName, String qName, Attributes attributes)
68+
throws SAXException {
69+
if (NAMESPACE_URI.equals(uri) && CONTANT_NAME.equals(localName)) {
70+
contactCount++;
71+
}
72+
}
73+
74+
75+
}
76+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootLogger=WARN, stdout
2+
log4j.logger.org.springframework.ws=DEBUG
3+
log4j.logger.org.springframework.xml=DEBUG
4+
5+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
6+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
3+
targetNamespace="http://www.springframework.org/spring-ws/samples/pox">
4+
5+
<xsd:element name="Contacts">
6+
<xsd:annotation>
7+
<xsd:documentation>
8+
Defines a contact-list, with names and phone numbers.
9+
</xsd:documentation>
10+
</xsd:annotation>
11+
<xsd:complexType>
12+
<xsd:sequence>
13+
<xsd:element name="Contact" minOccurs="0" maxOccurs="unbounded">
14+
<xsd:complexType>
15+
<xsd:all>
16+
<xsd:element name="Name" type="xsd:string"/>
17+
<xsd:element name="Phone" type="xsd:string"/>
18+
</xsd:all>
19+
</xsd:complexType>
20+
</xsd:element>
21+
</xsd:sequence>
22+
</xsd:complexType>
23+
</xsd:element>
24+
25+
<xsd:element name="ContactCount" type="xsd:integer"/>
26+
27+
28+
</xsd:schema>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
4+
5+
<description>
6+
This web application context contains Spring-WS beans. The beans defined in this context are automatically
7+
detected by Spring-WS, similar to the way Controllers are picked up in Spring Web MVC.
8+
</description>
9+
10+
<bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
11+
<description>
12+
This endpoint mapping uses the qualified name of the payload (body contents) to determine the endpoint for
13+
an incoming message. Every message is passed to the default endpoint. Additionally, messages are logged
14+
using the logging interceptor.
15+
</description>
16+
<property name="defaultEndpoint" ref="contactCountEndpoint"/>
17+
<property name="interceptors" ref="validatingInterceptor"/>
18+
</bean>
19+
20+
<bean id="validatingInterceptor"
21+
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
22+
<description>
23+
This interceptor validates both incoming and outgoing message contents according to the 'contacts.xsd' XML
24+
Schema file.
25+
</description>
26+
<property name="schema" value="/WEB-INF/contacts.xsd"/>
27+
<property name="validateRequest" value="true"/>
28+
<property name="validateResponse" value="true"/>
29+
</bean>
30+
31+
<bean id="contactCountEndpoint" class="org.springframework.ws.samples.pox.ws.ContactCountEndpoint"/>
32+
33+
<bean id="messageFactory" class="org.springframework.ws.pox.dom.DomPoxMessageFactory"/>
34+
35+
</beans>

0 commit comments

Comments
 (0)