org.apache.muse.core.routing
Class ReflectionMessageHandler
java.lang.Object
org.apache.muse.core.routing.AbstractMessageHandler
org.apache.muse.core.routing.ReflectionMessageHandler
- All Implemented Interfaces:
- MessageHandler
public class ReflectionMessageHandler
- extends AbstractMessageHandler
ReflectionMessageHandler is a generic implementation of
MessageHandler
that can be applied to any Java method. It uses reflection to determine
what types are being used by a method signature and then invokes the
Serializers that have been registered with Muse
to do the XML/POJO transformations. If a method references a type that is
not included in Muse's set of built-in Serializers, you must register a
Serializer for that type in order to take advantage of this class.
Muse uses this class by default if no MessageHandler is specified for
a user-defined operation. Application initialization will fail if this
default is specified but no Serializer is provided for a user-defined type.
You can add custom MessageHandlers to your own capabilities programmatically
using the Capability.setMessageHandlers() method.
- Author:
- Dan Jemiolo (danj)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReflectionMessageHandler
public ReflectionMessageHandler(String actionURI,
QName requestQName,
QName returnValueName)
fromXML
public Object[] fromXML(Element xml)
throws SoapFault
- Deserializes the given DOM Element into a set of POJOs that can be
used when invoking a Java method. Implementations should use Muse's
registered Serializers in order to deserialize the XML into objects of
the proper types.
This implementation uses the MessageHandler's java.lang.reflect.Method
to discover what parameter types can be expected in the given Element.
It then looks up the Serializers and uses them to deserialize the child
Elements in order.
If the Element has no child elements but has text content, and
the method has one parameter, the given Element is parsed as though it
were the parameter.
- Parameters:
xml
- The contents of a SOAP Body, where the root element contains
all of the method parameters. For simple parameters, this
element may contain the actual parameter data.
- Returns:
- An array with the method parameters in the correct order for
invocation. This array can be passed to the invoke() method in
java.lang.reflect.Method. If the method takes no parameters,
an empty array is returned.
- Throws:
SoapFault
-
- If the number of parameters does not match the number of
child Elements.
- If no serialization mechanism exists for the object's type.
- If any child elements could not be deserialized into an object.
- See Also:
Serializer.fromXML(Element)
getReturnValueName
protected QName getReturnValueName()
toXML
public Element toXML(Object result)
throws SoapFault
- Serializes the given object into a DOM Element. Implementations should
use Muse's registered Serializers in order to serialize the objects
into the proper formats.
This implementation uses the MessageHandler's java.lang.reflect.Method
to discover what return type can be expected in the given Element. It
then looks up the Serializer and uses it to serialize the object.
- Parameters:
result
- The response value from the operation, which must be serialized
into XML.
- Returns:
- The XML equivalent of the given object, wrapped in an element
whose QName is the value of getResponseName().
- Throws:
SoapFault
-
- If no serialization mechanism exists for the object's type.
- If the object could not be serialized into XML.
- See Also:
MessageHandler.getResponseName()
,
Serializer.toXML(Object, QName)
Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.