SWS-351 - Arbitrary parameter injection for @Endpoints

This commit is contained in:
Arjen Poutsma
2010-04-27 12:39:35 +00:00
parent e23d509e8c
commit 1e92d97aad
3 changed files with 97 additions and 2 deletions

View File

@@ -43,7 +43,7 @@ public class DomMethodArgumentProcessor extends AbstractPayloadMethodProcessor {
}
@Override
protected Object resolveRequestPayloadArgument(Source requestPayload, MethodParameter parameter) throws Exception {
protected Node resolveRequestPayloadArgument(Source requestPayload, MethodParameter parameter) throws Exception {
if (requestPayload instanceof DOMSource) {
return resolveArgumentDomSource(parameter, (DOMSource) requestPayload);
}
@@ -77,7 +77,7 @@ public class DomMethodArgumentProcessor extends AbstractPayloadMethodProcessor {
}
@Override
protected Source createResponsePayload(MethodParameter returnType, Object returnValue) {
protected DOMSource createResponsePayload(MethodParameter returnType, Object returnValue) {
Node returnedNode = (Node) returnValue;
return new DOMSource(returnedNode);
}

View File

@@ -0,0 +1,37 @@
/*
* 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 org.springframework.core.MethodParameter;
import org.springframework.ws.context.MessageContext;
/**
* Implementation of {@link MethodArgumentResolver} that supports {@link MessageContext} arguments.
*
* @author Arjen Poutsma
* @since 2.0
*/
public class MessageContextMethodArgumentResolver implements MethodArgumentResolver {
public boolean supportsParameter(MethodParameter parameter) {
return MessageContext.class.equals(parameter.getParameterType());
}
public MessageContext resolveArgument(MessageContext messageContext, MethodParameter parameter) throws Exception {
return messageContext;
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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 org.springframework.core.MethodParameter;
import org.springframework.ws.MockWebServiceMessageFactory;
import org.springframework.ws.context.DefaultMessageContext;
import org.springframework.ws.context.MessageContext;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class MessageContextMethodArgumentResolverTest {
private MessageContextMethodArgumentResolver resolver;
private MethodParameter supported;
@Before
public void setUp() throws NoSuchMethodException {
resolver = new MessageContextMethodArgumentResolver();
supported = new MethodParameter(getClass().getMethod("supported", MessageContext.class), 0);
}
@Test
public void supportsParameter() throws Exception {
assertTrue("resolver does not support MessageContext", resolver.supportsParameter(supported));
}
@Test
public void resolveArgument() throws Exception {
MessageContext messageContext = new DefaultMessageContext(new MockWebServiceMessageFactory());
MessageContext result = resolver.resolveArgument(messageContext, supported);
assertSame("Invalid message context returned", messageContext, result);
}
public void supported(MessageContext messageContext) {
}
}