The HTTP delivery option (see Selecting an Output Destination) is especially useful when you need to process data as soon as the Collector has sent it. It can also be helpful if you need to transfer the output to a machine that does not have an FTP server.
To use the Data Collector's HTTP POST output, you must use a Servlet, CGI program, or other server-side Web technology. Each of these technologies has its advantages and disadvantages; a complete discussion is beyond the scope of this document. Almost all, however, support the processing of large amounts of data sent with POST.
If you have dealt with POST on the server side before, you were probably involved with processing data from an HTML form with the ACTION property set to POST. POSTing from a form typically yields a set of name/value pairs corresponding to the form's input elements. The Collector sends its data in a slightly different format: the entire Output is sent as the message-body of the HTTP request.
If you have dealt with the low levels of the HTTP protocol, you are familiar with the request format used by the Collector:
POST /yoursite/yoururl
<mcudata>
... the rest of the output
Obtaining and processing this data depends strongly upon your application environment.
The Data Collector will interpret any response from the web server with a status of 400 or more (such as 404, File Not Found or 500, Internal Server Error) as a delivery failure. If an error is encountered and the delivery was scheduled to run automatically (as opposed to On Demand), the Data Collector will try to send the output again.
This short example shows how to override javax.servlet.http.HttpServlet's doPost() method in order to process the data sent by the Data Collector:
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
ServletInputStream is = req.getInputStream();
byte[] ba = new byte[1024];
int len = 0;
int bytesRead = 0;
while (-1!=(len=is.read(ba)))
{
String outString = new String(ba,0,len);
bytesRead += len;
// Do something with the data read into outString here:
// write to the database, create a file, etc.
}
out.println("<HTML>");
out.println("<HEAD><TITLE>UploadTest</TITLE></HEAD>");
out.println("<BODY></BODY></HTML>");
}
catch (Exception e) {
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
For information on the HTTP 1.1 specification, visit http://www.w3.org/Protocols/rfc2616/rfc2616.html.