Trying to reproduce SWS-396
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<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">
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>spring-ws-parent</artifactId>
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
@@ -89,6 +90,15 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- JEE dependencies -->
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
@@ -101,5 +111,23 @@
|
||||
<scope>test</scope>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>2.1_3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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()");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
|
||||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<bean id="mapping"
|
||||
class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
|
||||
|
||||
<bean id="endpoint" class="org.springframework.ws.server.endpoint.mapping.PayloadRootEndpoint">
|
||||
</bean>
|
||||
|
||||
<bean id="other" class="org.springframework.ws.server.endpoint.mapping.OtherBean"/>
|
||||
|
||||
<bean id="logAspect" class="org.springframework.ws.server.endpoint.mapping.LogAspect"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user