This commit is contained in:
Arjen Poutsma
2007-11-05 22:56:26 +00:00
parent 47760ade38
commit 02541be5ff
12 changed files with 535 additions and 77 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.ws.server.endpoint;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.springframework.core.JdkVersion;
import org.springframework.util.Assert;
/**
@@ -120,6 +121,19 @@ public final class MethodEndpoint {
}
public String toString() {
return this.method.toString();
if (JdkVersion.getMajorJavaVersion() <= JdkVersion.JAVA_14) {
return this.method.toString();
}
else {
return GenericToStringProvider.toString(method);
}
}
/** Inner class to avoid a static JDK 1.5 dependency for generic string generation. */
private static class GenericToStringProvider {
public static String toString(Method method) {
return method.toGenericString();
}
}
}

View File

@@ -56,14 +56,6 @@ public class MarshallingMethodEndpointAdapter extends AbstractMethodEndpointAdap
private Unmarshaller unmarshaller;
public void setMarshaller(Marshaller marshaller) {
this.marshaller = marshaller;
}
public void setUnmarshaller(Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}
/**
* Creates a new <code>MarshallingMethodEndpointAdapter</code>. The {@link Marshaller} and {@link Unmarshaller} must
* be injected using properties.
@@ -94,8 +86,8 @@ public class MarshallingMethodEndpointAdapter extends AbstractMethodEndpointAdap
"MarshallingMethodEndpointAdapter(Marshaller, Unmarshaller) constructor.");
}
else {
this.marshaller = marshaller;
this.unmarshaller = (Unmarshaller) marshaller;
this.setMarshaller(marshaller);
this.setUnmarshaller((Unmarshaller) marshaller);
}
}
@@ -108,13 +100,58 @@ public class MarshallingMethodEndpointAdapter extends AbstractMethodEndpointAdap
public MarshallingMethodEndpointAdapter(Marshaller marshaller, Unmarshaller unmarshaller) {
Assert.notNull(marshaller, "marshaller must not be null");
Assert.notNull(unmarshaller, "unmarshaller must not be null");
this.setMarshaller(marshaller);
this.setUnmarshaller(unmarshaller);
}
/** Returns the marshaller used for transforming objects into XML. */
public Marshaller getMarshaller() {
return marshaller;
}
/** Sets the marshaller used for transforming objects into XML. */
public final void setMarshaller(Marshaller marshaller) {
this.marshaller = marshaller;
}
/** Returns the unmarshaller used for transforming XML into objects. */
public Unmarshaller getUnmarshaller() {
return unmarshaller;
}
/** Sets the unmarshaller used for transforming XML into objects. */
public final void setUnmarshaller(Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(marshaller, "marshaller is required");
Assert.notNull(unmarshaller, "unmarshaller is required");
Assert.notNull(getMarshaller(), "marshaller is required");
Assert.notNull(getUnmarshaller(), "unmarshaller is required");
}
protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
WebServiceMessage request = messageContext.getRequest();
Object requestObject = unmarshalRequest(request);
Object responseObject = methodEndpoint.invoke(new Object[]{requestObject});
if (responseObject != null) {
WebServiceMessage response = messageContext.getResponse();
marshalResponse(responseObject, response);
}
}
private Object unmarshalRequest(WebServiceMessage request) throws IOException {
Object requestObject = MarshallingUtils.unmarshal(getUnmarshaller(), request);
if (logger.isDebugEnabled()) {
logger.debug("Unmarshalled payload request to [" + requestObject + "]");
}
return requestObject;
}
private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Marshalling [" + responseObject + "] to response payload");
}
MarshallingUtils.marshal(getMarshaller(), responseObject, response);
}
/**
@@ -126,34 +163,19 @@ public class MarshallingMethodEndpointAdapter extends AbstractMethodEndpointAdap
*/
protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
Method method = methodEndpoint.getMethod();
return (Void.TYPE.isAssignableFrom(method.getReturnType()) || marshaller.supports(method.getReturnType())) &&
method.getParameterTypes().length == 1 && unmarshaller.supports(method.getParameterTypes()[0]);
return supportsReturnType(method) && supportsParameters(method);
}
protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
WebServiceMessage request = messageContext.getRequest();
Object requestObject = unmarshalRequest(request);
Object responseObject = methodEndpoint.invoke(new Object[]{requestObject});
if (responseObject != null) {
WebServiceMessage response = messageContext.getResponse();
marshalResponse(responseObject, response);
private boolean supportsReturnType(Method method) {
return (Void.TYPE.equals(method.getReturnType()) || getMarshaller().supports(method.getReturnType()));
}
private boolean supportsParameters(Method method) {
if (method.getParameterTypes().length != 1) {
return false;
}
}
private Object unmarshalRequest(WebServiceMessage request) throws IOException {
Object requestObject = MarshallingUtils.unmarshal(unmarshaller, request);
if (logger.isDebugEnabled()) {
logger.debug("Unmarshalled payload request to [" + requestObject + "]");
else {
return getUnmarshaller().supports(method.getParameterTypes()[0]);
}
return requestObject;
}
private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Marshalling [" + responseObject + "] to response payload");
}
MarshallingUtils.marshal(marshaller, responseObject, response);
}
}

View File

@@ -160,7 +160,8 @@ public class MarshallingMethodEndpointAdapterTest extends TestCase {
return s;
}
public static class MyType {
private static class MyType {
}
}

View File

@@ -17,6 +17,8 @@
package org.springframework.ws.server.endpoint.adapter;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
import org.springframework.ws.MockWebServiceMessage;
@@ -42,12 +44,12 @@ public class PayloadMethodEndpointAdapterTest extends TestCase {
}
public void testSupportedNoResponse() throws NoSuchMethodException {
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", new Class[]{Source.class});
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", new Class[]{DOMSource.class});
assertTrue("Method unsupported", adapter.supportsInternal(methodEndpoint));
}
public void testSupportedResponse() throws NoSuchMethodException {
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", new Class[]{Source.class});
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", new Class[]{StreamSource.class});
assertTrue("Method unsupported", adapter.supportsInternal(methodEndpoint));
}
@@ -67,7 +69,7 @@ public class PayloadMethodEndpointAdapterTest extends TestCase {
}
public void testNoResponse() throws Exception {
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", new Class[]{Source.class});
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", new Class[]{DOMSource.class});
assertFalse("Method invoked", noResponseInvoked);
adapter.invoke(messageContext, methodEndpoint);
assertTrue("Method not invoked", noResponseInvoked);
@@ -76,17 +78,17 @@ public class PayloadMethodEndpointAdapterTest extends TestCase {
public void testResponse() throws Exception {
WebServiceMessage request = new MockWebServiceMessage("<request/>");
messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", new Class[]{Source.class});
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", new Class[]{StreamSource.class});
assertFalse("Method invoked", responseInvoked);
adapter.invoke(messageContext, methodEndpoint);
assertTrue("Method not invoked", responseInvoked);
}
public void noResponse(Source request) {
public void noResponse(DOMSource request) {
noResponseInvoked = true;
}
public Source response(Source request) {
public Source response(StreamSource request) {
responseInvoked = true;
return request;
}