开发者

parse soap xml using axis 1.2

开发者 https://www.devze.com 2023-01-20 23:37 出处:网络
I am using axis 1.2 for my soap client. I need to write a unit test that takes a开发者_运维技巧 soap message response and parse it to java objects that generated by axis. I couldn\'t figure out a way

I am using axis 1.2 for my soap client. I need to write a unit test that takes a开发者_运维技巧 soap message response and parse it to java objects that generated by axis. I couldn't figure out a way to do that. Can anybody help me on this?

Thanks,


I finally found a way to do it. You can do it by create a mock soap engine that return the xml that you wants. Then axis will do all the parsing and going through all the logic as if it got it from an http source. Here is an example:

public class SimulatorHandler extends BasicHandler
{


    /**
     * System property to that hold soap response message in xml.
     */
    private static final String responseMsg = "soapResponse";

    /**
     * @return the responseMsg
     */
    public static String getResponseMsgSystemProperty()
    {
        return responseMsg;
    }

    public void invoke(MessageContext context) throws AxisFault
    {

                // i haven't figure out a way to do a setter on this msg
                // so I have to get it from system properties
        String msg = System.getProperty(responseMsg);
        ByteArrayInputStream is = new ByteArrayInputStream(msg.getBytes());
        Message response = new Message(is);
        response.setMessageType(Message.RESPONSE);
        context.setResponseMessage(response);
    }
}
0

精彩评论

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