Top
Interstage Big Data Complex Event Processing Server V1.0.0 Developer's Reference
Interstage

3.5.1 SOAP Adapter

Sample program source code:

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
140

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;

}

}

The following data are 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
%COUNTER% included in event data needs to be substituted with loop count so that different event data shall be sent at each loop.

7

lWait

Data transmission wait time

8

loop

Data transmission count

3.5.1.1 Example of Sample Execution(Sends a CSV data)

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 ./ 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/env
elope/"><S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><re
turn>Code=0 Message=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/env
elope/"><S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><re
turn>Code=0 Message=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/env
elope/"><S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><re
turn>Code=0 Message=Sending message completed normally.</return></ns2:notifyResponse></S:Body>
</S:Envelope>

Please note that we added newlines in the example above (lines 2 to 4, 6 to 8, and 10 to 12) for readability only - the actual output does not have a newline.

Engine log output result

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 Example of Sample Execution(Sends an XML data)

An example of sample execution is shown below.

In this example, debug information is output to the engine log by using DebugLogListener.

Note

In case XML data is sent through SOAP adapter, enclose the data with CDATA as described in the command execution result below.

Command execution result

# 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/env
elope/"><S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><re
turn>Code=0 Message=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/env
elope/"><S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><re
turn>Code=0 Message=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/env
elope/"><S:Body><ns2:notifyResponse xmlns:ns2="http://adapter.front.cep.cspf.fujitsu.com/"><re
turn>Code=0 Message=Sending message completed normally.</return></ns2:notifyResponse></S:Body>
</S:Envelope>

Please note that we added backslash ("\") and newline characters in the command line example above for readability only - the actual command line does not have a backslash and newline.

Please note that we added newlines in the output example above (lines 4 to 6, 8 to 10, and 12 to 14) for readability only - the actual output does not have a newline.

Engine log output result

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