Here is a simple console maintenance handler; it logs every request (not just POST) - both headers and payload:
package com.mycompany; import org.apache.http.*; import org.apache.http.entity.StringEntity; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.util.EntityUtils; import org.omg.CORBA.Request; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class LoggingHandler implements HttpRequestHandler { public void handle(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException { System.out.println("");
Registering the handler using org.apache.http.localserver.LocalTestServer (with ElementalHttpServer it looks like you also have the HttpRequestHandler implementation above):
public static void main(String[] args) throws Exception { LocalTestServer server = new LocalTestServer(null, null); try { server.start(); server.register("/*", new LoggingHandler()); server.awaitTermination(3600 * 1000); } catch (Exception e) { e.printStackTrace(); } finally { server.stop(); } }
Piotr de
source share