This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Accessing Java HttpServer from PHP; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing Java HttpServer from PHP;" Watch "Accessing Java HttpServer from PHP;" New topic
Author

Accessing Java HttpServer from PHP;

Nev Mehta
Greenhorn

Joined: Jan 09, 2007
Posts: 26
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

Joined: Aug 18, 2009
Posts: 174

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

Joined: Oct 27, 2005
Posts: 19651
    
  18

Is the content length known?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nev Mehta
Greenhorn

Joined: Jan 09, 2007
Posts: 26
Content length is known and set in headers;
Nev Mehta
Greenhorn

Joined: Jan 09, 2007
Posts: 26
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

Joined: Jan 28, 2003
Posts: 4165
    
  21

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.


Steve
Nev Mehta
Greenhorn

Joined: Jan 09, 2007
Posts: 26
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

Joined: Jan 28, 2003
Posts: 4165
    
  21

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

Joined: Oct 16, 2012
Posts: 1
Hi all,

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

 
Don't get me started about those stupid light bulbs.
 
subject: Accessing Java HttpServer from PHP;
 
Similar Threads
forward() in servlets.
Java Standard Edition & Web service security
Apache Tomcat 6.0 for Windows error
JSF faces-redirect not working
Can't Get Tomcat 4.1.18 running