• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Accessing Java HttpServer from PHP;

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 174
Java ME Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22682
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the content length known?
 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Content length is known and set in headers;
 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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

 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic