Skip to main content

(Comet) Running GlassFish with mod_proxy

5 replies [Last post]
kzri
Offline
Joined: 2008-05-20

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kzri
Offline
Joined: 2008-05-20

Hi.
By Jeanfrancois's help, I can find out the reason.
#thanks a lot Jeanfrancois!

The cause will be mod_proxy.
The mod_proxy don't release the connection between glassfish and apache.
So, The glassfish cannot detect the browser's exit.

For example, I did the below command.
#netstat -an | grep <> | wc -l
the result is:
Direct access ---------------------------
- before aceess:4
- access glassfish:5
- exit browser:4
mod_proxy access ------------------------
- before aceess:4
- access mod_proxy:5
- exit browser:5
------------------------------------------
the number was same in spite of close the connection.
it means mod_proxy hasn't closed the connection
and we need to find how to configure mod_proxy in a way that
when the client close the connection, mod-proxy also close the
connection between Apache and GlassFish.

the mod_proxy's options are here.
http://httpd.apache.org/docs/2.2/en/mod/mod_proxy.html
I had try "keepalive", "timeout", "max", "smax"...but result is same.

My test servlet is here:
-----------------------------------------------
package sample;

import com.sun.enterprise.web.connector.grizzly.comet.*;
import java.io.*;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.*;

public class CometServlet extends HttpServlet {

private String contextPath;
private Logger logger = Logger.getLogger("servlet");

@Override
public void init(ServletConfig config) throws ServletException {
contextPath = config.getServletContext().getContextPath() + "/CometServlet";
CometContext context = CometEngine.getEngine().register(contextPath);
context.setExpirationDelay(12 * 60 * 60 * 1000);
logger.info("init");
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

CometHandler handler = new CometHandler() {
PrintWriter writer;
public void attach(PrintWriter writer) {
this.writer = writer;
}
public void onEvent(CometEvent arg0) throws IOException {}
public void onInitialize(CometEvent arg0) throws IOException {}
public void onTerminate(CometEvent arg0) throws IOException {
onInterrupt(arg0);
}
public void onInterrupt(CometEvent event) throws IOException {
this.writer.close();
event.getCometContext().removeCometHandler(this);
logger.info("onInterrupt!");
}
};
handler.attach(response.getWriter());
CometContext context = CometEngine.getEngine().getCometContext(contextPath);
context.addCometHandler(handler);
logger.info("connect!");
}
}
-----------------------------------------------

If anyone know the setting, please tell me.
Thanks!

Jeanfrancois Arcand

Salut,

(adding Comet to the title so it will makes easier for peoples to search).

glassfish@javadesktop.org wrote:
> Hi,
> I am writing a WebChat system using HTTP streaming by reference to
> http://docs.sun.com/app/docs/doc/820-4496/ggrgy
>
> The application have to close the XMPP connection when the browser reloaded or exit.
> So, I had created the CometHandler like below.
>
> MyCometHandler:
> public void onTerminate(CometEvent event) throws IOException {
> onInterrupt(event);
> }
> public void onInterrupt(CometEvent event) throws IOException {
> logger.info("close");
> writer.close();
> event.getCometContext().removeCometHandler(this);
> // XMPP Connection close
> ....
> }
>
> I accessed the glassfish directly, it worked fine,
> and the onInterrupt method is called immediately.
>
> So, I try to access the glassfish through the apache mod_proxy.
> that followed the instruction in
> http://forums.java.net/jive/thread.jspa?messageID=276500
>
> The application works fine.
> but I realize the onInterrupt method isn't called in spite of the browser exit.
> It called after timeout. I want to call it immediately.
>
> My test environment is:
> ・GlassFish v3 TP2
> ・Apach httpd(mod_proxy) 2.2.9
> ・Windows XP
>
> My mod_proxy configuration in httpd.conf is:
>
>
> ProxyPass http://localhost:8080/webchat/
> ProxyPassReverse http://localhost:8080/webchat/
>

>

>
> If anyone resolved this problem, please tell me the solution.
> Thanks!

Hum...no simple to debug :-)

[1] I suspect mod_proxy isn't closing the connection immediately ( I
could be completely wrong) and might delay it.

[2] Can I send you a Grizzly patch that contains debugging information?
Inside that patch I will add extra logging to see if the connection is
really closed. If the connection is closed, I suspect there is somes
bytes that are sen by mod_proxy, and Grizzly thinks this is a pipelined
http requests. In that case, and since Grizzly Comet supports
asynchronous I/O (read and write), the Comet engine might think this is
an event for your CometHandler, but since you haven't registed to get
notified, the event goes nowhere.

I unfortunalty don't have time today to install your config, but if you
cannot patch GlassFish I will try next week.

Thanks

-- Jeanfrancois

> [Message sent by forum member 'kzri' (kzri)]
>
> http://forums.java.net/jive/thread.jspa?messageID=282916
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

kzri
Offline
Joined: 2008-05-20

Hi Jeanfrancois.
Thanks for the advice!

> Can I send you a Grizzly patch that contains debugging information?
Great!! Please send me the patch !
myaddress is kzri@dev.java.net, or taken.kz@gmail.com

I can't check mail-box this weekend,
but I'll try it at next Monday, and report the output here.

Thanks!

Kristian Rink

Hi there;

glassfish@javadesktop.org schrieb:
[...]
> My mod_proxy configuration in httpd.conf is:
>
>
> ProxyPass http://localhost:8080/webchat/
> ProxyPassReverse http://localhost:8080/webchat/
>

>

Just to make sure, have you already read through

http://forums.java.net/jive/thread.jspa?messageID=276500

and tested whether this addresses your problem? We're not (yet) using
any comet functionality in our apache2/glassfish2 environment but
reading through the solution it sounds logical...

Cheers,
Kristian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

kzri
Offline
Joined: 2008-05-20

Hi.
Thank you for your response.

> Just to make sure, have you already read through and tested whether this addresses your problem?

Yes. and I think this post will indicate how to connect between client and glassfish with mod_proxy.
I can hold a long HTTP connection by reference to the post.
It works fine.(Thanks Xu Erdong!)

My problem is the glassfish-comet cannot detect the client's exit.

If I access GlassFish directly, the connection close fine (onInterrupt method called).
And if I access mod_proxy, the long HTTP connection works fine,
I can receive streaming data.
But onInterrupt method isn't called when I close browser.

Thanks.