Bug 47242 - request for AJP command line client
request for AJP command line client
Status: NEW
Product: Tomcat 6
Classification: Unclassified
Component: Connectors
unspecified
All Linux
: P3 enhancement (vote)
: default
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2009-05-22 07:13 UTC by Ken Van Camp
Modified: 2012-10-11 16:34 UTC (History)
2 users (show)



Attachments
AJP command line client (34.45 KB, application/zip)
2010-02-25 03:23 UTC, chamith buddhika
Details
AJP Client Bug Fix Version (20.04 KB, application/java-archive)
2010-03-09 03:01 UTC, chamith buddhika
Details
AJPClient sources (13.60 KB, application/zip)
2010-03-12 02:36 UTC, chamith buddhika
Details
AJPClient patch (44.32 KB, patch)
2010-04-02 10:01 UTC, chamith buddhika
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ken Van Camp 2009-05-22 07:13:27 UTC
In a recent post on the Tomcat user forum, I discussed with Rainer Jung the need for a simple command line utility like wget that would allow me to make requests to the AJP connector in Tomcat.  This can be very useful when trying to troubleshoot a problem with the AJP connector, or could even be used to do some simple stress testing.  Rainer suggested I open an enhancement request here, so this is it.

Rainer's comment:
Coud you please open an enhancement request in Bugzilla for this? There
is some code floating around, which we might be able to bundle with the
mod_jk source release. Not sure, how soon we would provide a windows
binary, but at least we should offer what we already have lying around.

It would definitely make sense to have an AJP commandline client to test
connectivity. 

Full text of the issue that led to this discussion can be found here:
http://www.nabble.com/AJP-connections-just-stop-working-td1118618.html#a23669763

Thank you.
Ken Van Camp
Comment 1 Sebb 2009-05-22 07:31:20 UTC
Apache JMeter has an AJP/1.3 Sampler which uses the Tomcat mod_jk protocol, see:

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#HTTP_Request

That might perhaps be usable here?

JMeter is obviously trickier to set up than a command-line utility, but it does offer stress tesing, and tests can be run without the GUI once set up.
Comment 2 Ken Van Camp 2009-05-26 06:51:14 UTC
I think JMeter is definitely worth using for stress testing, but is overkill for what I need.  If, as Rainer suggests, there is already some code floating around that does what I need, I'd appreciate someone pointing me to it.  And it does seem like it's worth bundling into some future release (but obviously not a high priority).
Comment 3 chamith buddhika 2010-02-18 15:36:16 UTC
Any updates on this? I would like to have a look at this if this is required. But I would need some advice on AJP and the the use case requirements since I am relatively new to the project.
Comment 4 Ken Van Camp 2010-02-18 21:37:38 UTC
I have not heard any updates, but I'll give you a little more detail on my use case: It is frequently useful to be able to test the health of a web server by making individual requests to it, for instance if receiving reports of server being unreachable.  We may also wish to institute automated health checks from a script or third-party software, and it is easy to do both over an HTTP connection because many tools exist.  Over AJP, however, this is not generally feasible.

My Tomcat web server is not on the Internet - it sits behind an IIS proxy server.  Users connect to the IIS proxy over HTTPS, and the proxy communicates to my Tomcat server over AJP.  When I get reports that my web server is unreachable via the proxy over HTTPS, my next step is to hit my Tomcat server over HTTP and verify that's working.  If Tomcat is working properly over HTTP, but the proxy is not responding over HTTPS, there are still a number of possible causes, including the proxy server itself, network connectivity between the proxy and Tomcat, and the AJP connections on Tomcat.  I currently have no way to directly test Tomcat over AJP - no simple tools exist that I know of.

There are many possible ways to fill this need - one way I've found useful, and fairly reusable, in the HTTP world is a simple command line tool like wget, which is a standard command-line utility in Linux.  It allows me to issue a simple GET request from the command line, or a script, which may be used to check the health of my web server, and may be automated.

Wget has a large number of command line options, but all of my use cases could be satisfied with probably just one of them: a timeout option so the request doesn't hang there forever if the server is unresponsive.  The only other parameter I need to give this wget-like AJP utility is the URL I'd like to hit on Tomcat.

Please let me know if you need any further clarification.  Thanks.
Ken
Comment 5 Bill Barker 2010-02-19 04:56:29 UTC
(In reply to comment #3)
> Any updates on this? I would like to have a look at this if this is required.
> But I would need some advice on AJP and the the use case requirements since I
> am relatively new to the project.

As the initial contributor to the JMeter AJP/1.3 Sampler (mentioned by Sebb), I would look there for a starting point.  That contains all of the Java code to create an AJP/1.3 client.

Personally, I prefer working with JMeter for this type of low-level connection analysis, but if you want to create a stand-alone version, knock yourself out.
Comment 6 chamith buddhika 2010-02-19 09:34:41 UTC
(In reply to comment #5)

> As the initial contributor to the JMeter AJP/1.3 Sampler (mentioned by Sebb), I
> would look there for a starting point.  That contains all of the Java code to
> create an AJP/1.3 client.
> 
> Personally, I prefer working with JMeter for this type of low-level connection
> analysis, but if you want to create a stand-alone version, knock yourself out.

If there is already some code lying around for this I also think it would be best to come up with some sort of a client with that as per this requirement rather than reinventing the wheel.I will keep in touch with any updates on Bill's findings. I am currently going through AJP protocol documentation to see how it works. Btw I just wanted to have an entry point for making some contributions for Tomcat project since I am new to the project. :-)
Comment 7 Rainer Jung 2010-02-20 15:32:26 UTC
Go with the JMeter AJP client if you want to implement in Java. If you need or want to implement in C, there is also:

http://svn.apache.org/viewvc/tomcat/archive/connectors/trunk/ajp/ajplib/

Regards,

Rainer
Comment 8 chamith buddhika 2010-02-21 12:31:36 UTC
(In reply to comment #7)
> Go with the JMeter AJP client if you want to implement in Java.

I will look in that. Thanks for pointing that out.

Regards
Comment 9 chamith buddhika 2010-02-25 03:23:26 UTC
Created attachment 25056 [details]
AJP command line client

Hi all,

I am attaching the initial version of the client that I have been working on. It is capable of fetching URLs specified on the command line and also is capable of reading a configuration file to get the URL details. But it's not very comprehensive and may have bugs. I would appreciate your suggestions on this.
Comment 10 Ken Van Camp 2010-03-04 18:53:04 UTC
Hi Chamith, I downloaded your AJP client to give it a try.  It's not clear to me how to specify the URL for an AJP request.  As you can see below, I tried a few alternatives (even tried telling it to use HTTP just to get past the malformed URL exception) to no avail.  Can you provide a command-line example?  Thanks!
Ken

$ java -jar ajpc.jar abeitmts1:9009/itm/
Exception in thread "main" java.net.MalformedURLException: unknown protocol: abe
itmts1
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at org.apache.coyote.ajp.client.ClientContext.init(ClientContext.java:98
)
        at org.apache.coyote.ajp.client.AJPClient.init(AJPClient.java:200)
        at org.apache.coyote.ajp.client.AJPClient.main(AJPClient.java:53)
$ java -jar ajpc.jar ajp://abeitmts1:9009/itm/
Exception in thread "main" java.net.MalformedURLException: unknown protocol: ajp

        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at org.apache.coyote.ajp.client.ClientContext.init(ClientContext.java:98
)
        at org.apache.coyote.ajp.client.AJPClient.init(AJPClient.java:200)
        at org.apache.coyote.ajp.client.AJPClient.main(AJPClient.java:53)
$ java -jar ajpc.jar http://abeitmts1:9009/itm/
Exception in thread "Thread-0" java.lang.StringIndexOutOfBoundsException: String
 index out of range: 41082
        at java.lang.String.checkBounds(Unknown Source)
        at java.lang.String.<init>(Unknown Source)
        at org.apache.coyote.ajp.client.AjpProcessor.getString(AjpProcessor.java
:546)
        at org.apache.coyote.ajp.client.AjpProcessor.parseHeaders(AjpProcessor.j
ava:482)
        at org.apache.coyote.ajp.client.AjpProcessor.handshake(AjpProcessor.java
:434)
        at org.apache.coyote.ajp.client.AjpProcessor.execute(AjpProcessor.java:4
21)
        at org.apache.coyote.ajp.client.AjpProcessor.process(AjpProcessor.java:1
04)
        at org.apache.coyote.ajp.client.AjpProcessor.run(AjpProcessor.java:95)
        at java.lang.Thread.run(Unknown Source)

$
Comment 11 chamith buddhika 2010-03-05 02:08:14 UTC
(In reply to comment #10)

Hi Ken,

The basic syntax currently is as follows.

java -jar ajpc.jar -o=- http://localhost:8009/axis2
 
-o switch with - tells to output to the console. 
8009 is the port Tomcat is listening for AJP connections.

Output should be some thing like this

Run: 10/03/05 07:17:06

|Connection     |StartTime           |TimedOut  |TimeElapsed(ms)|ReplyCode |URL                                                                        

|0              |10/03/05 07:17:06   |false     |2              |302       |http://localhost:8009/axis2          


I think first two exceptions you encountered are due to the fact that specifying URL differently. Currently you have to give the URL in full with the protocol (http) to make it work. Last one is bit strange because it seems to be a problem with protocol handling logic. I also came up with this error once during half way implementing the client. But it was random and only occured once and disappeared once I completed client in full. But anyway I will see in to that if you come across it again.

Btw I guess 9009 is the port tomcat is listening for AJP connections. It has to be like that and not the normal http port for correct functioning for now. 

Let me know if you come across any issues again. Also you can get a some description of the switches by using -h switch on the command line.

Regards,
Chamith
Comment 12 chamith buddhika 2010-03-09 03:01:22 UTC
Created attachment 25106 [details]
AJP Client Bug Fix Version

After some debugging I was able to fix the issue above mentioned by Ken. I am attaching new version with this. Any suggestions are welcome.
Comment 13 Ken Van Camp 2010-03-10 18:14:47 UTC
Thanks Chamith for your prompt fixes!  Could you please attach your updated source code too?  Looks like your latest attachment is just the jar file.
Ken
Comment 14 chamith buddhika 2010-03-12 02:36:23 UTC
Created attachment 25118 [details]
AJPClient sources

Hi Ken,

Attached you will find modified sources. I have been doing some changes lately but has not been incorporated to this as yet since I couldn't test the additions. Btw now no need to use -o switch explicitly since the by default it will output to the console.
Comment 15 chamith buddhika 2010-04-02 10:01:00 UTC
Created attachment 25223 [details]
AJPClient patch

I have attached the related patch file. If possible some committer please have a look at it and make a comment. Anyway I am not sure where this should belong to in the code base if this is to be incorporated in to trunk subsequently.
Comment 16 Rebeccah 2011-03-23 20:42:30 UTC
Rainer, Chamith, any update on when this patch will be incorporated into JMeter?  As of JMeter 2.4, the header parsing exception mentioned in comment 6 is occurring in the AjpSampler, preventing me from doing the testing I want to do.  I logged Bug 50963 before I realized it was the same exception.

Thanks,

Rebeccah
Comment 17 Bill Barker 2011-03-23 21:22:05 UTC
(In reply to comment #16)
> Rainer, Chamith, any update on when this patch will be incorporated into
> JMeter?  As of JMeter 2.4, the header parsing exception mentioned in comment 6
> is occurring in the AjpSampler, preventing me from doing the testing I want to
> do.  I logged Bug 50963 before I realized it was the same exception.
> 
> Thanks,
> 
> Rebeccah

Of the people that have replied here, I believe that only Sebb has karma to fix JMeter.  So you are better off posting to Bug 50963 to get JMeter fixed.
Comment 18 Sebb 2011-03-23 21:54:49 UTC
Bug 50963 has just been fixed.

What I would like to see is an AJP client jar which includes methods for generating requests and parsing responses. Then JMeter and other applications can make use of the same code.

Does that sound reasonable? Any takers to define an API?