package com.mycompany; import com.sybase.connector.repra.RepraClient; import com.sybase.connector.repra.logging.RaLogger; import java.io.*; public class SampleClient implements RepraClient { BufferedWriter _fout; String _filename = "myCustomOut.dat" // This method creates an instance of the BufferedWriter object public void configureClient() throws Exception { _fout = new BufferedWriter(new FileWriter(_filename, true)); } // You can do whatever you want in this method. // This sample appends the String value of the message to the file. public boolean sendEvent(Object repmsg) throws Exception { _fout.write(repmsg.toString(), 0, repmsg.toString().length()); _fout.newLine(); _fout.flush(); return true; } //It returns true if the client channel is ready. //Otherwise, it returns false. public boolean isReady() { if (_fout != null) { return true; } return false; } // This method closes the client channel. public void close() { if (isReady()) { try { _fout.close(); } catch (Exception ex) { ex.printStackTrace(); } } } // This method sets the default logger. In this sample, it // does nothing. public void setLogger(RaLogger log) { } }
Compiling the customized sender processor
To compile your sender processor:
Change to the directory of your sender processor.
Use the Java compiler by defining the -classpath parameter with the required libraries to compile the customized class.
For Windows:
cd C:\work\custom md customclasses c:\jdk141\bin\javac -classpath .;C:\sybase\EAServer\repra\ lib\repraconn.jar \ -d customclasses com\mycompany\SampleClient.java
For UNIX:
cd /work/custom mkdir customclasses /usr/jdk141/bin/javac -classpath .:/opt/sybase/EAServer/repra/ lib/repraconn.jar \ -d customclasses com/mycompany/SampleClient.java
Verify the compilation.
When the compilation finishes without any error messages, go to the customclasses directory to see if SampleClient.class is under com\mycompany (Windows) or com/mycompany (UNIX).
Building the runtime environment for the customized sender
processor
To use a jar file that includes the customized sender processor, go to the customclasses directory and use the jar command to build a jar file from the com directory. Otherwise, you can use the directory path to set up your environment.
Sybase recommends that you use jar file format for the customization.
Build a jar file.
For Windows:
cd C:\work\custom\customclasses C:\jdk141\bin\jar -cf mycustom.jar com
For UNIX:
cd /work/custom/customclasses /usr/jdk141/bin/jar -cf mycustom.jar com
For EAServer:
Copy the jar file or the directory structure containing the Java classes created from the previous step to the EAServer java/classes (Windows) or java/classes (UNIX) directory.
If you are using the jar file, start EAServer and connect to it from EAServer Manager.
Then, go to the Servers/<your server> directory and select the Server Properties menu. From the pop-up, select the Java Classes tab and click Add to add the name of the jar file, such as mycustom.jar. Click OK.
Add repra.con.jar to the Server Properties.
For WebLogic:
Shut down the application server if it is running.
Modify the %BEA_HOME%\repra\bin\repra_env.bat (Windows) or $BEA_HOME/repra/bin/repra_env.sh ( UNIX) file to add the full path of mycustom.jar or the customclasses directory to CLASSPATH at the ending part of the CLASSPATH definition.
For Windows:
set CLASSPATH=C:\work\custom\customclasses;%CLASSPATH% or set CLASSPATH=C:\work\custom\customclasses\mycustom.jar;%CLASSPATH%
For UNIX:
set CLASSPATH=/work/custom/customclasses:$CLASSPATH or set CLASSPATH=/work/custom/customclasses/mycustom.jar;$CLASSPATH
Start the WebLogic Server to activate the new environment change.
For information on creating new custom sender and formatter
classes, see “Creating new custom sender and custom formatter classes”.