ページの先頭行へ戻る
Interstage Big DataComplex Event Processing Server V1.1.0 開発リファレンス
FUJITSU Software

3.5.1 SOAPアダプター

サンプルプログラムのソースコード:

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
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class SoapClient {
URL soapAdapterUrl = null;
String url = "http://%HOSTNAME%/%ENGINE%FrontServerService/SoapReceiverService";
HttpURLConnection con = null;

public static void main(String[] args) {
String hostName = "";
String engineName = "";
String dataType = "";
String charSet = "";
String eventTypeId = "";
String data = "";
long lWait = 10;

try {
int loop = 0;
if (args.length != 8) {
System.out.println("param is Abnormal");
return;
}

hostName = String.valueOf(args[0]);
engineName = String.valueOf(args[1]);
dataType = String.valueOf(args[2]);
charSet = String.valueOf(args[3]);
eventTypeId = String.valueOf(args[4]);
data = String.valueOf(args[5]);
lWait = Long.valueOf(args[6]);
loop = Integer.valueOf(args[7]);

SoapClient sc = new SoapClient(hostName, engineName);
sc.sendMessage(data, dataType, eventTypeId,charSet, loop, lWait);
} catch (Exception e) {
e.printStackTrace();
}
}

public SoapClient(String hostName, String engineName) throws IOException {

try {
String wkUrl = url.replaceAll("%ENGINE%", engineName);
wkUrl = wkUrl.replaceAll("%HOSTNAME%", hostName);

soapAdapterUrl = new URL(wkUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

private HttpURLConnection open(String charSet) throws IOException {

HttpURLConnection con = null;
con = (HttpURLConnection) soapAdapterUrl.openConnection();

con.setRequestMethod("POST");
con.setRequestProperty("content-type", "text/xml;charset=" + charSet);
con.setDoOutput(true);
con.connect();

return con;
}

private void sendMessage(String baseData, String dataType, String eventTypeId,
String charSet, int loop, long lWait) throws Exception {

BufferedOutputStream bos = null;
InputStreamReader ir1 = null;
BufferedReader br1 = null;

try {
for (int i = 0; i < loop; i++) {
con = this.open(charSet);
bos = new BufferedOutputStream(con.getOutputStream());

String data = baseData.replaceAll("%COUNTER%", String.valueOf(i));
String MSG = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<S:Header />"
+ "<S:Body>"
+ "<a:notify xmlns:a=\"http://adapter.front.cep.cspf.fujitsu.com/\">"
+ "<type>" + dataType + "</type>"
+ "<eventTypeId>" + eventTypeId + "</eventTypeId>"
+ "<data>" + data + "</data>"
+ "</a:notify>"
+ "</S:Body>"
+ "</S:Envelope>";
bos.write(MSG.getBytes(charSet));

bos.flush();
bos.close();

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

String line;
while ((line = br1.readLine()) != null) {
System.out.println(line);
}

br1.close();
ir1.close();

con.disconnect();
Thread.sleep(lWait);
}

} catch (MalformedURLException e) {
e.printStackTrace();
throw e;
} catch (IOException e) {
e.printStackTrace();
throw e;
} catch (InterruptedException e) {
e.printStackTrace();
throw e;
} finally {
try {
if (br1 != null) {
br1.close();
}
if (ir1 != null) {
ir1.close();
}
} catch (IOException e) {
e.printStackTrace();
return;
}
}

return;
}
}

ソースコードについて解説します。

3.5.1.1 サンプル実行例(CSVデータを送信する場合)

サンプルの実行例を以下に記述します。

なお、例ではDebugLogListenerを使用し、エンジンログにデバッグ情報を出力しています。

コマンド実行結果

# java -cp ./ SoapClient localhost CepEngine CSV UTF-8 CSVEvent SOAP,CSV,%COUNTER% 1 3 <ENTER>
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><return>Code=0 Mess
age=Sending message completed normally.</return></ns2:notifyResponse></S:Body></S:Envelope>
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><return>Code=0 Mess
age=Sending message completed normally.</return></ns2:notifyResponse></S:Body></S:Envelope>
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><return>Code=0 Mess
age=Sending message completed normally.</return></ns2:notifyResponse></S:Body></S:Envelope>

(注) 見やすさのため、上記の例では出力の途中に改行を入れています(2-3行目、5-6行目、8-9行目)。実際には一行で続けて表示されます。

エンジンログ出力結果

2012-07-29 13:01:20,693 [DEBUG] abc:length=1
abc[0]
        operation       :CSV: String
        count   :0: String
        ID      :SOAP: String

2012-07-29 13:01:20,730 [DEBUG] abc:length=1
abc[0]
        operation       :CSV: String
        count   :1: String
        ID      :SOAP: String

2012-07-29 13:01:20,768 [DEBUG] abc:length=1
abc[0]
        operation       :CSV: String
        count   :2: String
        ID      :SOAP: String

3.5.1.2 サンプル実行例(XMLデータを送信する場合)

サンプルの実行例を以下に記述します。

なお、例ではDebugLogListenerを使用し、エンジンログにデバッグ情報を出力しています。

注意

SOAPアダプターを使用し、XMLデータを送信する場合はコマンド実行結果に記載されているようにデータをCDATAで囲んでください。

コマンド実行結果

# java -cp ./ SoapClient localhost CepEngine XML UTF-8 XMLEvent '<![CDATA[<?xml version="1.0"\
encoding="UTF-8"?><XMLEvent><ID>SOAP</ID> <operation>XML</operation> <count>%COUNTER%</count>\
</XMLEvent>]]>' 1 3 <ENTER>
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><return>Code=0 Mess
age=Sending message completed normally.</return></ns2:notifyResponse></S:Body></S:Envelope>
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><return>Code=0 Mess
age=Sending message completed normally.</return></ns2:notifyResponse></S:Body></S:Envelope>
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><return>Code=0 Mess
age=Sending message completed normally.</return></ns2:notifyResponse></S:Body></S:Envelope>

(注1) 見やすさのため、上記の例では入力コマンドの途中で「\」で改行しています。実際には「\」は入力せず、次の行の内容を続けて入力します。

(注2) 見やすさのため、上記の例では出力の途中に改行を入れています(4-5行目、7-8行目、10-11行目)。実際には一行で続けて表示されます。

エンジンログ出力結果

2012-07-29 13:02:21,860 [DEBUG] abc--0:length=1
abc--0[0]
        operation       :XML: String
        count   :0: String
        ID      :SOAP: String

2012-07-29 13:02:21,900 [DEBUG] abc--0:length=1
abc--0[0]
        operation       :XML: String
        count   :1: String
        ID      :SOAP: String

2012-07-29 13:02:21,935 [DEBUG] abc--0:length=1
abc--0[0]
        operation       :XML: String
        count   :2: String
        ID      :SOAP: String