Calling a Profile with Input Agent HTTP(S)

Profiles with an HTTP(S) Input Agent are called by HTTP request.

Calling with a Java Program

The following listing shows the source code for a Java program that calls a profile with an HTTP(S) Input Agent. The data sent is in CSV format.

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
//Simple example to trigger profile with an HTTP(S) Input Agent
public class TestHttpAgent {
//Connect to Lobster_data HTTP(S) server and trigger profile
public static void main (String[] args) {
try {
//Parameters to match correct profile.
String params = "?param1=value1&param2=value2&param3=value3&param4=value4";
//Create Connection to Lobster_data HTTP server
URL url = new URL("http", "localhost", 80,"/dw/Request/example" + params);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestProperty("Content-Type", "");
//Use POST method
con.setDoOutput(true);
con.connect();
//Input data for profile
DataOutputStream out = new DataOutputStream(con.getOutputStream());
out.writeBytes("value11 , value12 , value13\n"
+ "value21, value22, value23\n"
+ "value31, value32, value33");
//Read and print response
InputStream in = con.getInputStream();
BufferedInputStream bufIn = new BufferedInputStream(in);
int len = 0;
byte[] response = new byte[100];
while (len >= 0) {
len = bufIn.read(response);
if (len > 0)
System.out.print(new String(response, 0,len));
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
//Cleanup
in.close();
out.close();
}
}
}

Calling with a Browser

Another way to call the Input Agent is a file upload via a browser. The user will be provided with an HTML form through which he can send his data to Lobster_data. The following screenshot shows how such a form can look like.

images/download/thumbnails/36575307/HTTP_2_EN-version-1-modificationdate-1561364337000-api-v2.png

The following listing shows the HTML source code for the form.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html401/loose.dtd">
<html>
<head>
<title>Example HTML</title>
</head>
<body>
<p align="center"><font size="8">Example to call a profile</font></p>
<p>&nbsp;</p>
<form name="formular" action="http://localhost/dw/Request/example" enctype="multipart/form-data" method=post>
<p align="center">
<input type="submit" value="send">
<input type="file" name="upload">
<input type="hidden" name="param1" value="value1">
<input type="hidden" name="param2" value="value2">
<input type="hidden" name="param3" value="value3">
<input type="hidden" name="param4" value="value4">
<p>
</form>
</body>
</html>