tags:

views:

11

answers:

1

Hi,

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,

A: 

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);
}

}

Sean Nguyen

related questions