SWS-351 - Arbitrary parameter injection for @Endpoints

This commit is contained in:
Arjen Poutsma
2010-04-27 13:00:59 +00:00
parent 1e92d97aad
commit caa22dfe36
6 changed files with 203 additions and 8 deletions

View File

@@ -44,7 +44,7 @@ public abstract class AbstractPayloadMethodProcessorTest extends TransformerObje
protected static final String LOCAL_NAME = "request";
private static final String REQUEST = "<" + LOCAL_NAME + " xmlns=\"" + NAMESPACE_URI + "\"/>";
protected static final String XML = "<" + LOCAL_NAME + " xmlns=\"" + NAMESPACE_URI + "\"/>";
protected AbstractPayloadMethodProcessor processor;
@@ -111,12 +111,15 @@ public abstract class AbstractPayloadMethodProcessorTest extends TransformerObje
for (MethodParameter supportedParameter : supportedParameters) {
Object argument = processor.resolveArgument(messageContext, supportedParameter);
assertTrue(argument + " is not an instance of " + supportedParameter.getParameterType(),
supportedParameter.getParameterType().isInstance(argument));
testArgument(argument, supportedParameter);
}
}
protected abstract void testArgument(Object argument, MethodParameter parameter);
protected void testArgument(Object argument, MethodParameter parameter) {
}
@Test
public void saajReturnValue() throws Exception {
@@ -157,14 +160,14 @@ public abstract class AbstractPayloadMethodProcessorTest extends TransformerObje
}
protected MessageContext createMockMessageContext() throws TransformerException {
MockWebServiceMessage request = new MockWebServiceMessage(new StringSource(REQUEST));
MockWebServiceMessage request = new MockWebServiceMessage(new StringSource(XML));
return new DefaultMessageContext(request, new MockWebServiceMessageFactory());
}
protected MessageContext createCachingAxiomMessageContext() throws Exception {
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory, true, false);
transform(new StringSource(REQUEST), request.getPayloadResult());
transform(new StringSource(XML), request.getPayloadResult());
AxiomSoapMessageFactory soapMessageFactory = new AxiomSoapMessageFactory();
soapMessageFactory.afterPropertiesSet();
return new DefaultMessageContext(request, soapMessageFactory);
@@ -173,7 +176,7 @@ public abstract class AbstractPayloadMethodProcessorTest extends TransformerObje
protected MessageContext createNonCachingAxiomMessageContext() throws Exception {
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory, false, false);
transform(new StringSource(REQUEST), request.getPayloadResult());
transform(new StringSource(XML), request.getPayloadResult());
AxiomSoapMessageFactory soapMessageFactory = new AxiomSoapMessageFactory();
soapMessageFactory.setPayloadCaching(false);
soapMessageFactory.afterPropertiesSet();

View File

@@ -31,11 +31,11 @@ import org.w3c.dom.Node;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class DomMethodArgumentProcessorTest extends AbstractPayloadMethodProcessorTest {
public class DomPayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTest {
@Override
protected AbstractPayloadMethodProcessor createProcessor() {
return new DomMethodArgumentProcessor();
return new DomPayloadMethodProcessor();
}
@Override

View File

@@ -0,0 +1,79 @@
/*
* Copyright 2005-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.ws.server.endpoint.adapter.method;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import org.springframework.core.MethodParameter;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.xml.transform.StringSource;
/** @author Arjen Poutsma */
public class SourcePayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTest {
@Override
protected AbstractPayloadMethodProcessor createProcessor() {
return new SourcePayloadMethodProcessor();
}
@Override
protected MethodParameter[] createSupportedParameters() throws NoSuchMethodException {
return new MethodParameter[] {
new MethodParameter(getClass().getMethod("source", Source.class), 0),
new MethodParameter(getClass().getMethod("dom", DOMSource.class), 0),
new MethodParameter(getClass().getMethod("sax", SAXSource.class), 0),
new MethodParameter(getClass().getMethod("stream", StreamSource.class), 0)};
}
@Override
protected MethodParameter[] createSupportedReturnTypes() throws NoSuchMethodException {
return new MethodParameter[] {
new MethodParameter(getClass().getMethod("source", Source.class), -1),
new MethodParameter(getClass().getMethod("dom", DOMSource.class), -1),
new MethodParameter(getClass().getMethod("sax", SAXSource.class), -1),
new MethodParameter(getClass().getMethod("stream", StreamSource.class), -1)};
}
@Override
protected Object getReturnValue(MethodParameter returnType) throws Exception {
return new StringSource(XML);
}
@ResponsePayload
public Source source(@RequestPayload Source source) {
return source;
}
@ResponsePayload
public DOMSource dom(@RequestPayload DOMSource source) {
return source;
}
@ResponsePayload
public SAXSource sax(@RequestPayload SAXSource source) {
return source;
}
@ResponsePayload
public StreamSource stream(@RequestPayload StreamSource source) {
return source;
}
}