Sample program source code:
1 | import java.io.BufferedOutputStream; |
Detailed explanation of source code:
main method
Line numbers 30 to 37
The following data is obtained from the arguments at runtime:
Argument | Variable | Use |
---|---|---|
1 | hostName | CEP Server host name |
2 | engineName | CEP engine name |
3 | dataType | Event data format |
4 | charSet | Character set |
5 | eventTypeId | Event type ID |
6 | data | Event data |
7 | lWait | Data transmission wait time |
8 | loop | Data transmission count |
Line number 39
Creates an HttpClient object.
Line number 40
Calls a method for sending event data.
Event data, character set, data transmission count, and data transmission wait time are passed as arguments.
HttpClient constructor
Line numbers 49 and 50
Creates an end point address from the arguments.
Line number 52
Creates a URL object.
open method
Line number 62
Creates a connection destination "HttpURLConnection" from the URL object.
Line number 64
Specifies POST as the HTTP method to send SOAP messages using the POST method.
Line number 65
Sets "TYPE" in request header.
Line number 66
Sets "EVENT-TYPE-ID" in request header.
Line numbers 68 to 75
Sets "content-type". Sets "text/plain" if the event data format is CSV and "text/xml" if it is XML. The event data character set should also be set.
Line number 77
Sets a flag to be output.
Line number 78
Connects to the data recipient.
sendMessage method
Line numbers 91 to 114
Loops the number of loop times specified in the argument.
Line number 92
Executes the open method, and connects to the data recipient.
Line number 93
Retrieves BufferedOutputStream.
Line number 95
Replaces %COUNTER% contained in the event data with the loop count.
This sends different event data every time.
This example assumes that the following event data is used:
"STR0001","CPN0001",%COUNTER%,"30"
Line number 96
Writes the data using the specified character set.
Line number 98
Flushes BufferedOutputStream.
Line number 99
Closes BufferedOutputStream.
Line numbers 101 and 102
Retrieves InputStream from HttpURLConnection, and creates BufferedReader.
Line number 106
Writes sent results from BufferedReader to the standard output.
Line numbers 109 and 110
Closes InputStream and BufferedReader.
Line number 112
Disconnects HttpURLConnection.
Line number 113
Waits until the next event data is sent.
An example of sample execution is shown below.
In this example, debug information is output to the engine log by using DebugLogListener.
Command execution result
# java -cp ./ HttpClient localhost CepEngine CSV UTF-8 CSVEvent HTTP,CSV,%COUNTER% 1 3 <ENTER>
Code=0 Message=Sending message completed normally.
Code=0 Message=Sending message completed normally.
Code=0 Message=Sending message completed normally.
Engine log output result
2012-07-29 13:05:02,954 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :0: String
ID :HTTP: String
2012-07-29 13:05:03,027 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :1: String
ID :HTTP: String
2012-07-29 13:05:03,108 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :2: String
ID :HTTP: String
An example of sample execution is shown below.
In this example, debug information is output to the engine log by using DebugLogListener.
Command execution result
# java -cp ./ HttpClient localhost CepEngine XML UTF-8 XMLEvent '<?xml version="1.0"\
encoding="UTF-8"?><XMLEvent><ID>HTTP</ID> <operation>XML</operation>\ <count>%COUNTER%</count></XMLEvent>' 1 3 <ENTER>
Code=0 Message=Sending message completed normally.
Code=0 Message=Sending message completed normally.
Code=0 Message=Sending message completed normally.
Note that in the command line example above, backslash ("\") and newlines have been added for readability only. The actual command line does not have backslash or newlines.
Engine log output result
2012-07-29 13:07:32,670 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :0: String
ID :HTTP: String
2012-07-29 13:07:32,685 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :1: String
ID :HTTP: String
2012-07-29 13:07:32,698 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :2: String
ID :HTTP: String