package ora.jwsnut.chapter3.echoservice;
import java.io.ByteArrayOutputStream;
import javax.xml.soap.SOAPMessage;
import ora.jwsnut.saaj.SAAJServlet;
/**
* A servlet that recieves a SOAP messages and
* returns it to its sender.
*/
public class EchoServlet extends SAAJServlet {
/**
* Output stream used to save a SOAP message
* for logging.
*/
private ByteArrayOutputStream os = new ByteArrayOutputStream();
/**
* Handles a received SOAP message by simply
* returning it.
*/
public SOAPMessage onMessage(SOAPMessage message) {
// Convert the message to string representation
// and log it.
try {
message.writeTo(os);
log("Received SOAP message:\n" + os.toString());
os.reset();
} catch (Exception ex) {
log("Exception", ex);
}
// Return the received message to the caller.
return message;
}
} |