What happens when several Java servlet apps running on the same port ?

Posted by Frank on Stack Overflow See other posts from Stack Overflow or by Frank
Published on 2010-04-01T16:02:06Z Indexed on 2010/04/01 16:23 UTC
Read the original article Hit count: 330

Filed under:
|
|

Something strange happened to my servlets and I think I've figured out why, yet I'm more confused. I used Netbean6.7 to develop a Paypal IPN (Instant Payment Notification) message servlet, it listens on port 8080 by default for Paypal IPN messages. I used some sample Java code from it's web site, but when it ran, only about 1 in 10 messages came through, and they looked correct, but why 1 in 10 ? Not 100% or none ? So I asked some questions here and got some advices, one in particular points me to Google's App Engine, so I downloaded it and ran the demo guestbook while my IPN servlet is still running on Netbeans, the strange thing happened, after I entered "appengine-java-sdk-1.3.2\bin\dev_appserver.cmd appengine-java-sdk-1.3.2\demos\guestbook\war" from the command prompt, I went to the following url on my browser "http://localhost:8080/", I thought I would see the Google demo guestbook page, NO, what I saw was another servlet I developed 2 years ago : "Web Academy", online course registration app. How can that happen ? I never started it, and I haven't touch that project for years. I guess because it's also listening on port 8080, so now I understand why the IPN messages only came through 1 in 10 times, because another servlet was also listening on that port and could have got the messages intended for IPN, or some how those two servlets' processes mixed up and therefore couldn't respond to Paypal properly, and failed. In order to verify some of my guesses, I turn off Netbeans, and ran the Google guestbook again at the prompt, this time on my browser http://localhost:8080/ points to the demo guestbook page.

My Urls look like this :
[A] Paypal IPN  : http://localhost:8080/PayPal_App/PayPal_Servlet
[B] Web Academy : http://localhost:8080/

So now, my questions are :
<1> Why the "Web Academy" servlet was auto started when I ran the Paypal servlet ?
<2> If I change the IPN listening port to 8083, would that mean I can run both of them on my PC at the same time without affecting each other ?
<3> But I still don't understand, [A] and [B] look different, if a page for [A] is refreshed, it should show the Paypal content, and another page looking at [B] should show the Web Academy content, and that's exactly what happens when I started Netbeans to run the Paypal servlet, both pages show their respective content correctly side by side without interfering with each other, how come the IPN messages couldn't get through 100% of the time ?
<4> In Netbeans how to assign 8080 to servlet [A] and assign port 8083 to servlet [B] ?
<5> How to turn off auto start of Web Academy by Netbeans ?

© Stack Overflow or respective owner

Related posts about java

Related posts about java-ee