ページの先頭行へ戻る
Interstage Big DataComplex Event Processing Server V1.1.0 ユーザーズガイド
FUJITSU Software

5.11.6 イベント送信サンプルプログラム

CSV形式のテスト用イベントデータをHTTPアダプターに送信する、イベント送信アプリケーションです。

実行形式

プログラムの実行形式は以下の通りです。

/opt/FJSVcep/sample/sample1/bin/sendevent.sh イベントタイプ  データファイルのパス [ 送信先URL ]
引数
イベントタイプ

データをどのイベントタイプとして送信するかを指定します。

対象となるイベントタイプの開発資産IDを指定します。

データファイル

イベントデータを含むCSV形式のファイルのパスを指定します。

送信先URL

HTTPアダプターのエンドポイントアドレスを指定します。

省略時は、http://localhost/CepEngineFrontServerService/HttpReceiverとなります。

参考

CEPエンジンのエンドポイントアドレス

CEPエンジンの送信先URLは以下の通りです。

http://CEPエンジンのアドレス/CEPエンジン名FrontServerService/HttpReceiver

CEPサーバ cephost.example.com の、CEPエンジンCepEngineの送信先URLは以下の通りです。

http://cephost.example.com/CepEngineFrontServerService/HttpReceiver

ソースコード

イベント送信サンプルプログラムのソースコードです。

/opt/FJSVcep/sample/sample1/src/HttpClient.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package sample;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpClient {

static String DEFAULT_URL = "http://localhost/CepEngineFrontServerService/HttpReceiver";

public static void main(String[] args) {
if (args.length != 2 && args.length != 3) {
System.err.println("Requires two or three arguments: event-type, file name, [URL]");
System.exit(1);
}
String eventType = args[0];
String fileName = args[1];
String url = DEFAULT_URL;
if (args.length == 3) {
url = args[2];
}

try {
BufferedReader br0 =
new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));

String str;
while ((str = br0.readLine()) != null) {
URL TestURL = new URL(url);
HttpURLConnection con = (HttpURLConnection) TestURL.openConnection();

con.setRequestMethod("POST");
con.setRequestProperty("TYPE", "CSV");
con.setRequestProperty("EVENT-TYPE-ID", eventType);
con.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
con.setDoOutput(true);

BufferedOutputStream bos = new BufferedOutputStream(con.getOutputStream());
bos.write(str.getBytes("utf-8"));
bos.flush();
bos.close();

BufferedReader br1 = new BufferedReader(new InputStreamReader(con.getInputStream()));

String line;
while ((line = br1.readLine()) != null) {
System.out.println(line);
}
br1.close();
con.disconnect();
}
br0.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}