You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ro...@apache.org on 2006/07/19 18:36:57 UTC
svn commit: r423520 - in /webservices/axis2/trunk/java/modules: integration/
integration/test/org/apache/axis2/spring/ spring/ spring/test-resources/
Author: robertlazarski
Date: Wed Jul 19 09:36:56 2006
New Revision: 423520
URL: http://svn.apache.org/viewvc?rev=423520&view=rev
Log:
Spring integration tests added
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBean.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBeanImpl.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringAwareService.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringServiceTest.java
webservices/axis2/trunk/java/modules/spring/test-resources/
webservices/axis2/trunk/java/modules/spring/test-resources/applicationContext.xml
Modified:
webservices/axis2/trunk/java/modules/integration/maven.xml
webservices/axis2/trunk/java/modules/integration/project.xml
webservices/axis2/trunk/java/modules/spring/project.xml
Modified: webservices/axis2/trunk/java/modules/integration/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/maven.xml?rev=423520&r1=423519&r2=423520&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/integration/maven.xml Wed Jul 19 09:36:56 2006
@@ -443,6 +443,11 @@
<copy file="../core/conf/axis2.xml"
tofile="target/groovyRepo/conf/axis2.xml"/>
+ <!-- Spring resources -->
+ <mkdir dir="target/test-resources/spring"/>
+ <copy file="../spring/test-resources/applicationContext.xml"
+ tofile="target/test-resources/spring/applicationContext.xml"/>
+
<!--Axis2 repositories for WS-Security interop tests -->
<!-- A default repository with security and addressing modules -->
Modified: webservices/axis2/trunk/java/modules/integration/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/project.xml?rev=423520&r1=423519&r2=423520&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/project.xml (original)
+++ webservices/axis2/trunk/java/modules/integration/project.xml Wed Jul 19 09:36:56 2006
@@ -53,6 +53,11 @@
<artifactId>axis2-samples</artifactId>
<version>${pom.currentVersion}</version>
</dependency>
+ <dependency>
+ <groupId>axis2</groupId>
+ <artifactId>axis2-spring</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
<dependency>
<groupId>ws-commons</groupId>
@@ -335,6 +340,38 @@
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
+ <dependency>
+ <groupId>springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
</dependencies>
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBean.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBean.java?rev=423520&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBean.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBean.java Wed Jul 19 09:36:56 2006
@@ -0,0 +1,6 @@
+package org.apache.axis2.spring;
+
+/** Interface for Spring aware Bean */
+public interface MyBean {
+ String emerge();
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBeanImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBeanImpl.java?rev=423520&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBeanImpl.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/MyBeanImpl.java Wed Jul 19 09:36:56 2006
@@ -0,0 +1,15 @@
+package org.apache.axis2.spring;
+
+/** Spring wired implementation */
+public class MyBeanImpl implements MyBean {
+
+ String str = null;
+ // spring 'injects' this value
+ public void setVal(String s) {
+ str = s;
+ }
+ // web service gets this value
+ public String emerge() {
+ return str;
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringAwareService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringAwareService.java?rev=423520&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringAwareService.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringAwareService.java Wed Jul 19 09:36:56 2006
@@ -0,0 +1,30 @@
+package org.apache.axis2.spring;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+
+public class SpringAwareService {
+
+ private MyBean myBean = null;
+
+ //spring 'injects' this implementation
+ public void setMyBean(MyBean myBean) {
+ this.myBean = myBean;
+ }
+
+ // The web service
+ public OMElement getValue(OMElement ignore) {
+ OMFactory factory=
+ OMAbstractFactory.getOMFactory();
+ OMNamespace payloadNs= factory.createOMNamespace(
+ "http://springExample.org/example1", "example1");
+ OMElement payload =
+ factory.createOMElement("string", payloadNs);
+ OMText response = factory.createOMText(this.myBean.emerge());
+ payload.addChild(response);
+ return payload;
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringServiceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringServiceTest.java?rev=423520&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringServiceTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/spring/SpringServiceTest.java Wed Jul 19 09:36:56 2006
@@ -0,0 +1,189 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* 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.apache.axis2.spring;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+import junit.framework.Assert;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.databinding.utils.BeanUtil;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.InOutAxisOperation;
+import org.apache.axis2.description.OutInAxisOperation;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+import org.apache.axis2.receivers.AbstractMessageReceiver;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import java.io.StringWriter;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringServiceTest extends UtilServerBasedTestCase {
+
+ protected QName transportName = new QName("http://springExample.org/example1",
+ "NullTransport");
+ EndpointReference targetEPR = new EndpointReference(
+ "http://127.0.0.1:" + (UtilServer.TESTING_PORT)
+// "http://127.0.0.1:" + 5556
+ // + "/axis2/services/EchoXMLService/echoOMElement");
+ + "/axis2/services/SpringExample/getValue");
+
+ protected AxisConfiguration engineRegistry;
+ protected MessageContext mc;
+ protected ServiceContext serviceContext;
+ protected AxisService service;
+ private QName springServiceName = new QName("SpringExample");
+
+ private QName springOperationName = new QName("getValue");
+
+ public static Test suite() {
+ return getTestSetup(new TestSuite(SpringServiceTest.class));
+ }
+
+ protected void setUp() throws Exception {
+
+ AxisService service =
+ createSpringService(springServiceName, new RawXMLINOutMessageReceiver(),
+ "org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier",
+ "springAwareService",
+ springOperationName);
+ createSpringAppCtx(service.getClassLoader());
+ UtilServer.deployService(service);
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(springServiceName);
+ UtilServer.unDeployClientService();
+ }
+
+ // Can't test SpringServletContextSupplier AFAIK cuz not sure how to get ServletContext
+ // with this test harness. The idea here then is to test the basic idea with the
+ // alternative method, SpringAppContextAwareObjectSupplier, whose purpose is to
+ // run in a non-servlet container environment
+ public void testSpringAppContextAwareObjectSupplier() throws Exception {
+
+ AxisService clientService =
+ createSpringServiceforClient(springServiceName, new RawXMLINOutMessageReceiver(),
+ "org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier",
+ "springAwareService",
+ springOperationName);
+ ConfigurationContext configcontext = UtilServer.createClientConfigurationContext();
+ ServiceClient sender = new ServiceClient(configcontext, clientService);
+
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = factory.createOMNamespace(
+ "http://springExample.org/example1", "example1");
+
+ OMElement method = factory.createOMElement("getValue", omNs);
+ OMElement value = factory.createOMElement("Text", omNs);
+ value.addChild(factory.createOMText(value, "Test String "));
+ method.addChild(value);
+
+ Options options = new Options();
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ options.setTo(targetEPR);
+ options.setAction(springOperationName.getLocalPart());
+ sender.setOptions(options);
+
+ OMElement result = sender.sendReceive(springOperationName, method);
+
+ StringWriter writer = new StringWriter();
+ result.serialize(XMLOutputFactory.newInstance()
+ .createXMLStreamWriter(writer));
+ writer.flush();
+ String testStr = writer.toString();
+ // write to report
+ System.out.println("\ntestSpringAppContextAwareObjectSupplier result: " + testStr);
+ assertNotSame(new Integer(testStr.indexOf("emerge thyself")), new Integer(-1));
+ }
+
+ private AxisService createSpringService(QName springServiceName,
+ MessageReceiver messageReceiver, String supplierName, String beanName, QName opName) throws AxisFault {
+
+ AxisService service = new AxisService(springServiceName.getLocalPart());
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new Parameter(AbstractMessageReceiver.SERVICE_OBJECT_SUPPLIER, supplierName));
+ service.addParameter(new Parameter(SpringAppContextAwareObjectSupplier.SERVICE_SPRING_BEANNAME, beanName));
+
+ AxisOperation axisOp = new InOutAxisOperation(opName);
+
+ axisOp.setMessageReceiver(messageReceiver);
+ axisOp.setStyle(WSDLConstants.STYLE_RPC);
+ service.addOperation(axisOp);
+ service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + opName.getLocalPart(), axisOp);
+
+ return service;
+ }
+
+ public AxisService createSpringServiceforClient(QName springServiceName,
+ MessageReceiver messageReceiver,
+ String supplierName,
+ String beanName,
+ QName opName)
+ throws AxisFault {
+ AxisService service = new AxisService(springServiceName.getLocalPart());
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new Parameter(AbstractMessageReceiver.SERVICE_OBJECT_SUPPLIER, supplierName));
+ service.addParameter(new Parameter(SpringAppContextAwareObjectSupplier.SERVICE_SPRING_BEANNAME, beanName));
+
+ AxisOperation axisOp = new OutInAxisOperation(opName);
+
+ axisOp.setMessageReceiver(messageReceiver);
+ axisOp.setStyle(WSDLConstants.STYLE_RPC);
+ service.addOperation(axisOp);
+
+ return service;
+ }
+
+ public void createSpringAppCtx(ClassLoader cl)
+ throws Exception {
+
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {Constants.TESTING_PATH + "spring/applicationContext.xml"}, false);
+ ctx.setClassLoader(cl);
+ ctx.refresh();
+ }
+}
Modified: webservices/axis2/trunk/java/modules/spring/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/spring/project.xml?rev=423520&r1=423519&r2=423520&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/spring/project.xml (original)
+++ webservices/axis2/trunk/java/modules/spring/project.xml Wed Jul 19 09:36:56 2006
@@ -83,7 +83,7 @@
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-core</artifactId>
- <version>1.2.6</version>
+ <version>${spring.version}</version>
<properties>
<module>true</module>
</properties>
Added: webservices/axis2/trunk/java/modules/spring/test-resources/applicationContext.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/spring/test-resources/applicationContext.xml?rev=423520&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/spring/test-resources/applicationContext.xml (added)
+++ webservices/axis2/trunk/java/modules/spring/test-resources/applicationContext.xml Wed Jul 19 09:36:56 2006
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+ <!-- Used to test a non-servlet container environment - gives spring to give a hook to axis2 -->
+ <bean id="applicationContext"
+ class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
+
+ <!-- Axis2 Web Service, but to Spring, its just another bean that has dependencies -->
+ <bean id="springAwareService" class="org.apache.axis2.spring.SpringAwareService">
+ <property name="myBean" ref="myBean"/>
+ </bean>
+
+ <!-- just another bean with a wired implementation, that's injected by Spring
+ into the Web Service -->
+ <bean id="myBean" class="org.apache.axis2.spring.MyBeanImpl">
+ <property name="val" value="Spring, emerge thyself" />
+ </bean>
+</beans>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org