/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 * 
 * Created on Feb 17, 2004
 */
package org.jboss.net.sample.mail.client;

import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.soap.SOAPConstants;

import org.jboss.net.axis.transport.mail.client.MailTransport;

/**
 * <dl>
 * <dt><b>Title: </b><dd>Mail Client</dd>
 * <p>
 * <dt><b>Description: </b><dd>Sample client to demonstrate the email transport.</dd>
 * <p>
 * </dl>
 * @author <a href="mailto:jasone@greenrivercomputing.com">Jason Essington</a>
 * @version $Revision: 1.1.6.1 $
 */
public class MailClient
{

   public static final String MAIL_ENDPOINT = "@SERVER_EMAIL_ADDRESS@";

   public static final String METHOD = "echo";

   public static final String ACTION = "Echo";

   public static final String NAMESPACE = "@NAMESPACE@";

   public static void main(String[] args) throws Exception
   {
      try
      {
         Service service = new Service();
         Call call = (Call) service.createCall();

         call.setOperationName(new javax.xml.namespace.QName(NAMESPACE, METHOD));
         // We must use SOAP 1.2 or our message will be rejected.
         call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);
         call.addParameter("inStr", XMLType.XSD_STRING, ParameterMode.IN);
         call.setReturnType(XMLType.XSD_STRING);
         MailTransport mail = new MailTransport();
         mail.setRecipient(MAIL_ENDPOINT);
         mail.setAction(ACTION);
         call.setTransport(mail);
         String ret;
         if (args.length > 0)
            ret = (String) call.invoke(new Object[] {args[0]});
         else
            ret = (String) call.invoke(new Object[] {"oops forgot to add a parameter!"});
         System.out.println(ret);
      }
      catch (Exception e)
      {
         e.printStackTrace(System.out);
      }
   }
}
