This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Java HttpServer from PHP;

 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have created an httpserver using 'com.sun.net.httpserver'. Everything works fine except one thing.

When i make this simple call from PHP (http://localhost:8081/something outputs an XML file):-


Nothing appears and it times out after sometime.

However, while the browser is 'trying' to get the result (from PHP file) if i 'stop' my HttpServer (Java) the result suddenly appears. I am very sure i close all the streams i opened. Does anyone have any idea?

Thanks
Neville
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put breakpoint on doGet() method and go over your lines in both scenarious - if you request your servlet from web browser and if you request your servlet from php simplexml_load_file() method. See the difference.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the content length known?
 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Content length is known and set in headers;
 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So on doing some debugging i realized that the http thread that started executing may have not exited correctly. That may explain the fact that when i shut the java server down explicitly while the 'php' code waits for some response, the response suddenly appears.

While creating the server i am using:-


In ThreadPoolExecutor.class




Using the debugger tool took me to the class ThreadPoolExecutor.class which seems to be the bottleneck; This condition is true (poolSize > corePoolSize || allowCoreThreadTimeOut(=false)) and it starts polling. I think maybe this is causing the problem and if it exited maybe the result would appear. Even if the corePoolSize is more than poolsize it seems to be getting stuck in .

I dont know how it works ok with a browser but hangs when PHP request comes into the picture. Strange...

Thanks
Neville
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a red herring. What it is telling you is that all your request threads have completed the requests they are working on, and are looking for the next request to come in.

So you know your requests complete. But the data doesn't show. This happens for a number of reasons:
1) You aren't closing the connections you think you are, or are not flushing data as you should be
2) You are sending incomplete data - perhaps missing some close tags in your output.
3) You have some other mis-handled exception which causes your request to end in-appropriately.

p.s. You have a duplicate thread on the Sun Java Forums. That is kind-of rude, please let everyone know when you crosspost to other forums. It prevents a lot of wasted time caused by repeating what you have alreadt been told.
 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was not trying to divert attention on purpose; i just thought this maybe the issue. Also, had no idea we needed to mention the we have cross-posted, will do that next time. Thanks for the help.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nev Mehta wrote:Was not trying to divert attention on purpose; i just thought this maybe the issue. Also, had no idea we needed to mention the we have cross-posted, will do that next time. Thanks for the help.


Nono, I didn't mean you were trying to divert our attention, sorry if you misunderstood. I meant the part of the code you picked up on was diverting your attention from the real issue.
 
John Meilak
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've coded a hack in order to close down the connection initiated by the PHP script.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic