开发者

Deserialization with Axis 2

开发者 https://www.devze.com 2023-02-07 04:24 出处:网络
I have some Java code that takes an XML (SOAP) message and returns the deserialized object: public s开发者_开发技巧tatic <T> T deserializeObject(String xml, Class<T> clazz) throws AxisFau

I have some Java code that takes an XML (SOAP) message and returns the deserialized object:

public s开发者_开发技巧tatic <T> T deserializeObject(String xml, Class<T> clazz) throws AxisFault, Exception {
    assert xml != null : "xml != null";
    assert clazz != null : "clazz != null";

    T result = null;
    try {
        Message message = new Message(SOAP_START + xml + SOAP_END);
        result = (T)message.getSOAPEnvelope().getFirstBody().getObjectValue(clazz);
    } catch (Exception e) {
        // most likely namespace error due to removed namespaces
        Message message = new Message(SOAP_START_XSI + xml + SOAP_END);
        result = (T)message.getSOAPEnvelope().getFirstBody().getObjectValue(clazz);
    }
       return result;
    }

However this code only works with Axis 1.4 :-( Could someone Help me have that code work with Axis 2?

In fact, I might just need to know what to replace the import org.apache.axis.Message with? Thanks in advance.


Every message within the Axis2 engine is wrapped inside a MessageContext object. When a SOAP message arrives into the system or is prepared to be sent out, we create an AXIOM object model of the SOAP message.

(Please read the AXIOM article series for more information on AXIOM). This AXIOM model is then included inside the message context object. Let's see how to access this SOAP message inside Axis2.

// if you are within a handler, reference to the message context 
MessageContext messageContext; 

object will be passed to you through Handler.invoke(MessageContext) method.

SOAPEnvelope soapEnvelope = messageContext.getEnvelope();

please see : javax.xml.soap Interface SOAPEnvelope

Processing Axis2 message

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号