/*
 * Created by Ray Plante for the US National Virtual Observatory
 * c. 2006
 */
package net.ivoa.registry.search;

import net.ivoa.registry.RegistryServiceException;

import java.net.URL;
import java.io.PrintWriter;

import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPException;
import org.w3c.dom.Element;

/**
 * a ServiceCaller that will print the SOAP messages to a PrintWriter.  This
 * is useful for debugging service communication.
 */
public MessagePrintingServiceCaller extends DefaultServiceCaller {
    PrintWriter out = new PrintWriter(System.err);

    /**
     * create a default ServiceCaller object
     * @param connection   the SOAPConnection object to use to connect to the 
     *                        service.  If null, a default connection will be 
     *                        created.
     * @param endpoint     the service's endpoint URL.  
     */
    public DefaultServiceCaller(SOAPConnection connection, URL endpoint) {
        super(connection, endpoint);
    }

    /**
     * create a default ServiceCaller object
     * @param endpoint     the service's endpoint URL
     */
    public DefaultServiceCaller(URL endpoint) {
        super(endpoint);
    }

    /**
     * create a default ServiceCaller object
     * @param connection   the SOAPConnection object to use to connect to the 
     *                        service  If null, a default connection will be 
     *                        created.
     */
    public DefaultServiceCaller(SOAPConnection connection) {
        super(connection);
    }

    /**
     * create a default ServiceCaller object
     */
    public DefaultServiceCaller() {
        super();
    }

    /**
     * set the stream to send the messages to.
     * @param strm   the destination PrintWriter; if null, System.err is set.
     */
    public void setMessageDestination(PrintWriter strm) {
        if (strm == null) strm = new PrintWriter(System.err);
        out = strm;
    }

    /**
     * return the stream that messages are being sent to
     */
    public PrintWriter getMessageDestination() { return out; }

    /**
     * call the SOAP service and return the content of the body the 
     * SOAP response.  This assumes a <em>wrapped document<em> message
     * style in which the body contains a single child element.  
     * @param msg     the input SOAP message to send
     * @param action  the SOAP action URI to use
     * @exception SOAPException  if an error occurs while handling the SOAP.
     * @exception RegistryServiceException   if any errors occurs while 
     *                communicating with the service.
     */
    public Element call(SOAPMessage msg, String actionURI)
         throws RegistryServiceException, SOAPException
    {


    }
}
