A RepraCustomClient Interface example.
package com.sybase.connector.repra; /** Configures the custom sender and custom property page */ public interface RepraCustomClient extends RepraClient, RepraCustomProps { }
import java.io.FileInputStream; import java.util.Date; import java.util.Properties;import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage;import com.sybase.connector.repra.RepraCustomClient; import com.sybase.connector.repra.logging.RaLogger;/*
* SampleClient2 * * Description: This is a sample of a customer sender * processor client that will load a custom property * page and then route the event to an email address * */ public class SampleClient2 implements RepraCustomClient { private Transport _transport = null; private MimeMessage _msg = null; private RaLogger _log = null;
protected static String _host;
protected String _from;
protected String _to;
protected String _cc;
protected String _subject,
protected String _username;
protected String _password; private String _propFile; /**
* sets the property file
*/ public void setConfigProps(String custPropsFile)
{
_propFile = custPropsFile; }
/**
* gets the property file
*/
public String getConfigProps()
{
return _propFile;
}
/**
* sets the default logger
*/
public void setLogger (RaLogger log)
{
if (_log == null)
{
_log = log;
}
}
/**
* gets the email information from the properties
* @throws Exception
*/
private void getHostInformation() throws Exception
{
String thePropFile = getConfigProps();
FileInputStream in = newFileInputStream(thePropFile);
_log.info ("SampleClient2.INFO", "** IN getHostInformation, loading prop file");
Properties prop = new Properties();
prop.load(in);
_host = prop.getProperty("MAIL_HOST","");
_from = prop.getProperty("MAIL_FROM","");
_to = prop.getProperty("MAIL_TO","");
_cc = prop.getProperty("MAIL_CC","");
_subject = prop.getProperty("MAIL_SUBJECT","");
_username = prop.getProperty("MAIL_USERNAME","");
_password = prop.getProperty("MAIL_PASSWORD","");
_log.info ("SampleClient2.INFO", "** HOST - " + _host + ", MAIL_TO - " +_to);
}
public void configureClient() throws Exception
{
try
{
_log.info ("SampleClient2.INFO", "** Starting ConfigureClient");
Properties prop =System.getProperties();
Session ses = Session.getDefaultInstance(prop,null);
getHostInformation();
_msg = new MimeMessage(ses);
_msg.setFrom(new InternetAddress(_from));
_msg.addRecipient(Message.RecipientType.TO, new InternetAddress(_to));
_msg.addRecipient(Message.RecipientType.CC, new InternetAddress(_cc));
_msg.setSubject(_subject);
_msg.setSentDate(new Date());
_msg.saveChanges();
_transport = ses.getTransport("smtp");
_transport.connect(_host, _username, _password);
log.info ("SampleClient2.INFO", "** Ending ConfigureClient");
}
catch (Exception ex)
{
throw ex;
}
}
/**
* sends out the repmsg as an email
*/
public boolean sendEvent(Object repmsg) throws Exception
{
try
{
_log.info ("SampleClient2.INFO", "** Starting SendEvent, repmsg is " + repmsg.toString()); _msg.setText(repmsg.toString());
_transport.sendMessage(_msg, _msg.getAllRecipients());
return true;
}
catch (Exception ex)
{
throw ex;
}
}
/**
* returns true if the connection is healthy
*/
public boolean isReady()
{
return _transport.isConnected();
}
/**
* closes the client connection
*/
public void close()
{
try
{
_transport.close();
}
catch (Exception ex)
{
// do nothing
}
}
}