INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.integration.samples.ws;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.springframework.integration.xml.source.DomSourceFactory;
|
||||
/**
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SimpleEchoResponder {
|
||||
|
||||
public Source issueResponseFor(DOMSource request) {
|
||||
return new DomSourceFactory().createSource(
|
||||
"<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">" +
|
||||
request.getNode().getTextContent() + "</echoResponse>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<int:channel id="input"/>
|
||||
|
||||
<int-ws:inbound-gateway id="ws-inbound-gateway" request-channel="input"/>
|
||||
|
||||
<int:service-activator input-channel="input">
|
||||
<bean class="org.springframework.integration.samples.ws.SimpleEchoResponder"/>
|
||||
</int:service-activator>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?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.0.xsd">
|
||||
|
||||
<import resource="classpath:/org/springframework/integration/samples/ws/inbound-gateway-config.xml"/>
|
||||
|
||||
<!-- Ensures that all incoming requests will be routed to the ws:inbound-gateway -->
|
||||
<bean class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
|
||||
<property name="defaultEndpoint" ref="ws-inbound-gateway"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
24
basic/ws-inbound-gateway/src/main/webapp/WEB-INF/web.xml
Normal file
24
basic/ws-inbound-gateway/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
<description>ws:inbound-gateway sample</description>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>WEB-INF/spring-ws-config.xml</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<url-pattern>/echoservice</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.html</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
</web-app>
|
||||
1
basic/ws-inbound-gateway/src/main/webapp/index.html
Normal file
1
basic/ws-inbound-gateway/src/main/webapp/index.html
Normal file
@@ -0,0 +1 @@
|
||||
The web service has been successfully deployed. You may now issue SOAP requests. See included JUnit tests for examples.
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.integration.samples.ws;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
/**
|
||||
* System tests ensuring the Spring WS MessageDispatcherServlet is correctly
|
||||
* set up and configured to delegate incoming requests to our ws:inbound-gateway.
|
||||
*
|
||||
* Use 'mvn package' to create a war file for this project, then deploy before
|
||||
* attempting to run this test.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class InContainerTests {
|
||||
|
||||
private static Logger logger = Logger.getLogger(InContainerTests.class);
|
||||
private static final String WS_URI = "http://localhost:8080/ws-inbound-gateway/echoservice";
|
||||
private final WebServiceTemplate template = new WebServiceTemplate();
|
||||
|
||||
@Test
|
||||
public void testWebServiceRequestAndResponse() {
|
||||
StringResult result = new StringResult();
|
||||
Source payload = new StringSource(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>");
|
||||
|
||||
template.sendSourceAndReceiveToResult(WS_URI, payload, result);
|
||||
logger.info("RESULT: " + result.toString());
|
||||
assertThat(result.toString(), equalTo(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.integration.samples.ws;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.ws.SimpleWebServiceInboundGateway;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.pox.dom.DomPoxMessage;
|
||||
import org.springframework.ws.pox.dom.DomPoxMessageFactory;
|
||||
|
||||
/**
|
||||
* Out-of-container tests for ws:inbound-gateway message processing.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@ContextConfiguration("/META-INF/spring/integration/inbound-gateway-config.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class InboundGatewayTests {
|
||||
|
||||
@Autowired
|
||||
private SimpleWebServiceInboundGateway gateway;
|
||||
|
||||
/**
|
||||
* Emulate the Spring WS MessageDispatcherServlet by calling the gateway
|
||||
* with a DOMSource object representing the payload of the original SOAP
|
||||
* 'echoRequest' message. Expect an 'echoResponse' DOMSource object
|
||||
* to be returned in synchronous fashion, which the MessageDispatcherServlet
|
||||
* would in turn wrap in a SOAP envelope and return to the client.
|
||||
*/
|
||||
@Test
|
||||
public void testSendAndReceive() throws Exception {
|
||||
String xml = "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>";
|
||||
DomPoxMessageFactory messageFactory = new DomPoxMessageFactory();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(new InputSource(new StringReader(xml)));
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
DomPoxMessage request = new DomPoxMessage(document, transformer, "text/xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(request, messageFactory);
|
||||
gateway.invoke(messageContext);
|
||||
Object reply = messageContext.getResponse().getPayloadSource();
|
||||
assertThat(reply, is(DOMSource.class));
|
||||
DOMSource replySource = (DOMSource) reply;
|
||||
Element element = (Element) replySource.getNode().getFirstChild();
|
||||
assertThat(element.getTagName(), equalTo("echoResponse"));
|
||||
}
|
||||
}
|
||||
28
basic/ws-inbound-gateway/src/test/resources/log4j.xml
Normal file
28
basic/ws-inbound-gateway/src/test/resources/log4j.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user