INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
@@ -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