From 53f044193292ccf97331f9b949db373bbde9a2df Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 15 Jul 2008 10:48:25 +0000 Subject: [PATCH] Trying to reproduce SWS-396 --- core-tiger/pom.xml | 30 +++++++++- .../ws/server/endpoint/mapping/Log.java | 21 +++++++ .../ws/server/endpoint/mapping/LogAspect.java | 54 ++++++++++++++++++ ...otAnnotationMethodEndpointMappingTest.java | 57 ++++++++++++++----- .../endpoint/mapping/PayloadRootEndpoint.java | 21 ++++++- .../endpoint/mapping/applicationContext.xml | 20 +++++++ 6 files changed, 186 insertions(+), 17 deletions(-) create mode 100644 core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/Log.java create mode 100644 core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/LogAspect.java create mode 100644 core-tiger/src/test/resources/org/springframework/ws/server/endpoint/mapping/applicationContext.xml diff --git a/core-tiger/pom.xml b/core-tiger/pom.xml index fa6abe10..e46b983c 100644 --- a/core-tiger/pom.xml +++ b/core-tiger/pom.xml @@ -1,4 +1,5 @@ - + spring-ws-parent org.springframework.ws @@ -89,6 +90,15 @@ org.springframework spring-context + + org.springframework + spring-aop + + + org.springframework + spring-test + test + javax.activation @@ -101,5 +111,23 @@ test 2.2 + + org.aspectj + aspectjrt + 1.5.4 + test + + + org.aspectj + aspectjweaver + 1.5.4 + test + + + cglib + cglib-nodep + 2.1_3 + test + diff --git a/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/Log.java b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/Log.java new file mode 100644 index 00000000..acd1c5bb --- /dev/null +++ b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/Log.java @@ -0,0 +1,21 @@ +/* + * Copyright 2008 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.server.endpoint.mapping; + +public @interface Log { + +} diff --git a/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/LogAspect.java b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/LogAspect.java new file mode 100644 index 00000000..bc2dceb2 --- /dev/null +++ b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/LogAspect.java @@ -0,0 +1,54 @@ +/* + * Copyright 2008 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.server.endpoint.mapping; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; + +@Aspect +public class LogAspect { + + private static final Log logger = LogFactory.getLog(LogAspect.class); + + private boolean logInvoked = false; + + public boolean isLogInvoked() { + return logInvoked; + } + + @Pointcut("@annotation(org.springframework.ws.server.endpoint.mapping.Log)") + private void loggedMethod() { + + } + + @Around("loggedMethod()") + public void log(ProceedingJoinPoint joinPoint) throws Throwable { + logInvoked = true; + logger.info("Before: " + joinPoint.getSignature()); + try { + joinPoint.proceed(); + } + finally { + logger.info("After: " + joinPoint.getSignature()); + } + } + +} diff --git a/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootAnnotationMethodEndpointMappingTest.java b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootAnnotationMethodEndpointMappingTest.java index ac6b635b..dec14f10 100644 --- a/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootAnnotationMethodEndpointMappingTest.java +++ b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootAnnotationMethodEndpointMappingTest.java @@ -17,31 +17,39 @@ package org.springframework.ws.server.endpoint.mapping; import java.lang.reflect.Method; +import java.util.Collections; +import javax.xml.namespace.QName; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; +import javax.xml.transform.Source; -import junit.framework.TestCase; - -import org.springframework.context.support.StaticApplicationContext; +import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.springframework.ws.context.DefaultMessageContext; +import org.springframework.ws.context.MessageContext; +import org.springframework.ws.server.EndpointAdapter; +import org.springframework.ws.server.MessageDispatcher; import org.springframework.ws.server.endpoint.MethodEndpoint; +import org.springframework.ws.server.endpoint.adapter.PayloadMethodEndpointAdapter; +import org.springframework.ws.soap.saaj.SaajSoapMessage; +import org.springframework.ws.soap.saaj.SaajSoapMessageFactory; +import org.springframework.ws.soap.server.SoapMessageDispatcher; -public class PayloadRootAnnotationMethodEndpointMappingTest extends TestCase { +public class PayloadRootAnnotationMethodEndpointMappingTest extends AbstractDependencyInjectionSpringContextTests { private PayloadRootAnnotationMethodEndpointMapping mapping; - private StaticApplicationContext applicationContext; + protected String getConfigPath() { + return "applicationContext.xml"; + } - protected void setUp() throws Exception { - applicationContext = new StaticApplicationContext(); - applicationContext.registerSingleton("mapping", PayloadRootAnnotationMethodEndpointMapping.class); - applicationContext.registerSingleton("endpoint", PayloadRootEndpoint.class); - applicationContext.registerSingleton("other", OtherBean.class); - applicationContext.refresh(); - mapping = (PayloadRootAnnotationMethodEndpointMapping) applicationContext.getBean("mapping"); + public void setMapping(PayloadRootAnnotationMethodEndpointMapping mapping) { + this.mapping = mapping; } public void testRegistration() throws NoSuchMethodException { MethodEndpoint endpoint = mapping.lookupEndpoint("{http://springframework.org/spring-ws}Request"); assertNotNull("MethodEndpoint not registered", endpoint); - Method doIt = PayloadRootEndpoint.class.getMethod("doIt", new Class[0]); + Method doIt = PayloadRootEndpoint.class.getMethod("doIt", Source.class); MethodEndpoint expected = new MethodEndpoint("endpoint", applicationContext, doIt); assertEquals("Invalid endpoint registered", expected, endpoint); @@ -49,4 +57,27 @@ public class PayloadRootAnnotationMethodEndpointMappingTest extends TestCase { mapping.lookupEndpoint("{http://springframework.org/spring-ws}Request2")); } + public void testInvoke() throws Exception { + + MessageFactory messageFactory = MessageFactory.newInstance(); + SOAPMessage request = messageFactory.createMessage(); + request.getSOAPBody().addBodyElement(QName.valueOf("{http://springframework.org/spring-ws}Request")); + MessageContext messageContext = + new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory)); + EndpointAdapter adapter = new PayloadMethodEndpointAdapter(); + + MessageDispatcher messageDispatcher = new SoapMessageDispatcher(); + messageDispatcher.setApplicationContext(applicationContext); + messageDispatcher.setEndpointMappings(Collections.singletonList(mapping)); + messageDispatcher.setEndpointAdapters(Collections.singletonList(adapter)); + + messageDispatcher.receive(messageContext); + + PayloadRootEndpoint endpoint = (PayloadRootEndpoint) applicationContext.getBean("endpoint"); + assertTrue("doIt() not invoked on endpoint", endpoint.isDoItInvoked()); + + LogAspect aspect = (LogAspect) applicationContext.getBean("logAspect"); + assertTrue("log() not invoked on aspect", aspect.isLogInvoked()); + } + } \ No newline at end of file diff --git a/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootEndpoint.java b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootEndpoint.java index 1299219d..e33f3d40 100644 --- a/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootEndpoint.java +++ b/core-tiger/src/test/java/org/springframework/ws/server/endpoint/mapping/PayloadRootEndpoint.java @@ -16,15 +16,30 @@ package org.springframework.ws.server.endpoint.mapping; +import javax.xml.transform.Source; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.ws.server.endpoint.annotation.Endpoint; import org.springframework.ws.server.endpoint.annotation.PayloadRoot; @Endpoint -class PayloadRootEndpoint { +public class PayloadRootEndpoint { + + private static final Log logger = LogFactory.getLog(PayloadRootEndpoint.class); + + private boolean doItInvoked = false; + + public boolean isDoItInvoked() { + return doItInvoked; + } @PayloadRoot(localPart = "Request", namespace = "http://springframework.org/spring-ws") - public void doIt() { - + @org.springframework.ws.server.endpoint.mapping.Log + public void doIt(Source payload) { + doItInvoked = true; + logger.info("In doIt()"); } } diff --git a/core-tiger/src/test/resources/org/springframework/ws/server/endpoint/mapping/applicationContext.xml b/core-tiger/src/test/resources/org/springframework/ws/server/endpoint/mapping/applicationContext.xml new file mode 100644 index 00000000..0cfc9da7 --- /dev/null +++ b/core-tiger/src/test/resources/org/springframework/ws/server/endpoint/mapping/applicationContext.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + +