libajp13 is a fully featured open source library implementing the Apache JServ Protocol version 1.3 (ajp13), based on the Apache Protocol Reference.
The library has been developed from Espen Wiborg's ajp_client, licensed under the Apache License 2.0. At this point, most of the code has been refactored and improved to support all AJP13 packet types.
As of 04/02/2015, the JaCoCoverage analysis of project "libajp13" reports: ![Test Code Coverage](http://i.imgur.com/hTqSSZR.png"Test Code Coverage")
This implementation is derived from Dan Milstein's reversing work, based on Tomcat 3.x AJP code. If you've discovered a bug, please open an issue in Github.
The following code examples show how to use libajp13.
For more details, please refer to the official JavaDoc.
CPing and CPong
//Create a CPing message
AjpMessage msg = new CPingMessage();
//Send the content of the packet - msg.getBytes()
[...]
AjpMessage reply = AjpReader.parseMessage(gotBytes);
if (reply instanceof CPongMessage) {
System.out.println("[OK] Valid CPong");
}
Shutdown
AjpMessage msg = new ShutdownMessage();
EndResponse with session reuse set to 'true'
AjpMessage msg = new EndResponseMessage(true);
SendBodyChunkMessage
AjpMessage msg = new SendBodyChunkMessage("ABCD".getBytes());
SendHeadersMessage
List<Pair<String, String>> headers = new LinkedList<>();
headers.add(Pair.make("Content-Type","text/html; charset=utf-8"));
AjpMessage msg = new SendHeadersMessage(200,"OK",headers);
GetBodyChunkMessage
AjpMessage msg = new GetBodyChunkMessage(10);
BodyMessage
AjpMessage msg = new BodyMessage("MyStringSentAsBytes".getBytes());
ForwardRequestMessage to build a simple GET request
List<Pair<String, String>> headers = new LinkedList<>();
headers.add(Pair.make("Content-Type","text/html; charset=utf-8"));
AjpMessage msg = new ForwardRequestMessage(2, new URL("http://127.0.0.1/"), headers, null);
ForwardRequestMessage using ForwardRequestMessageGetBuilder
AjpMessage msg = ForwardRequestMessage.ForwardRequestMessageGetBuilder(new URL("http://192.168.1.1/log/"));
ForwardRequestMessage to build a PUT request with custom headers and attributes
List<Pair<String, String>> headers = new LinkedList<>();
headers.add(Pair.make("Content-Type","text/html; charset=utf-8"));
headers.add(Pair.make("CustomHeaderName","CustomHeaderValue"));
List<Pair<String, String>> attributes = new LinkedList<>();
attributes.add(Pair.make("jvm_route","3131212"));
attributes.add(Pair.make("custom_attribute","custom_value"));
AjpMessage msg = new ForwardRequestMessage(5, "HTTP/1.0", "/api/", "127.0.0.1", "localhost", "127.0.0.1", 8009, true, headers, attributes);
Passing SSL configuration and client certificate
String cert= "-----BEGIN CERTIFICATE-----\n" +
"BASE64TADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADATADATADATADATADATADATADATADATADATADATA\n" +
"DATADATADATADATADATADATADA==\n" +
"-----END CERTIFICATE-----\n";
attributes.add(Pair.make("ssl_cert", cert));
attributes.add(Pair.make("ssl_cipher","ECDH-ECDSA-AES128-SHA"));
attributes.add(Pair.make("ssl_key_size","128"));
- https://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html
- https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/coyote/ajp/Constants.html
- https://github.com/kohsuke/ajp-client
- http://isu.ifmo.ru/docs/IAS904/web.904/q20202/protocol/AJPv21.html
- http://en.wikipedia.org/wiki/Apache_JServ_Protocol
- https://tomcat.apache.org/tomcat-7.0-doc/config/ajp.html