tomcat and apache problem

749 views
Skip to first unread message

Fran

unread,
Feb 15, 2010, 4:47:29 PM2/15/10
to Google Web Toolkit
Hello,

I need your help about GWT integration in apache and tomcat.

I have a GWT aplication that has server side. This server side is
listening in 8081 port at tomcat.
I need that the client side be in apache that is listening in port 80,
so I need call server side at port 8081 of tomcat.
How can I do?

If I run the aplication int tomcat, its works fine. But If I run the
aplication in apache, the server side dont work.

Help me please
Thanks

Fran

unread,
Feb 16, 2010, 1:54:37 PM2/16/10
to Google Web Toolkit
I am using now Proxypass for apache. The config is:

<VirtualHost *:80>
ServerName california.####.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/####
ProxyRequests On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /app/com.app http://california.####.com:8081/app/com.app
ProxyPassReverse /app/com.app http://california.####.com:8081/app/com.app

DirectoryIndex index.php
AccessFileName .htaccess
</VirtualHost>

The aplication is a Comet chat.
With this configuration, the aplication executed from apache works but
some message lost.
The error log shows:

[error] [client ########] proxy: error reading status line from remote
server california.####.com, referer:
http://california.####.com/app/com.app/2179BCD97ED1043BAEE2BAA974B2E73A.cache.html
[error] [client ########] ] proxy: Error reading from remote server
returned by /app/com.app/messenger, referer:
http://california.####.com/app/com.app/2179BCD97ED1043BAEE2BAA974B2E73A.cache.html


I read in some forum that is needed the lines in Location directive of
apache:

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

If I put this, the aplications is beeing more and more slowly.


Someone can tell me a solutions please :(

Fran

unread,
Feb 16, 2010, 6:53:18 PM2/16/10
to Google Web Toolkit
help me please

On 16 feb, 19:54, Fran <fra...@gmail.com> wrote:
> I am using now Proxypass for apache. The config is:
>
> <VirtualHost *:80>
>         ServerName california.####.com
>         ServerAdmin webmaster@localhost
>         DocumentRoot /var/www/####
>         ProxyRequests On
>         <Proxy *>
>                 Order deny,allow
>                 Allow from all
>         </Proxy>
>         ProxyPass /app/com.apphttp://california.####.com:8081/app/com.app

>         ProxyPassReverse /app/com.apphttp://california.####.com:8081/app/com.app


>
>         DirectoryIndex index.php
>         AccessFileName .htaccess
> </VirtualHost>
>
> The aplication is a Comet chat.
> With this configuration, the aplication executed from apache works but
> some message lost.
> The error log shows:
>
> [error] [client ########] proxy: error reading status line from remote

> server california.####.com, referer:http://california.####.com/app/com.app/2179BCD97ED1043BAEE2BAA974B2E7...


> [error] [client ########] ] proxy: Error reading from remote server

> returned by /app/com.app/messenger, referer:http://california.####.com/app/com.app/2179BCD97ED1043BAEE2BAA974B2E7...

Fran

unread,
Feb 17, 2010, 2:56:58 PM2/17/10
to Google Web Toolkit
anyone can help me please?

Chris Lercher

unread,
Feb 17, 2010, 5:46:46 PM2/17/10
to Google Web Toolkit
Hi,

I don't have an Apache+Tomcat setup, so I can only guess what may be
happening: There are two basic ways to do Comet.

- Streaming (for one request, the server sends a few bytes, then later
some more etc.)
- Long polling (for one request, the server sends zero bytes
initially, and just waits until it can send anything. When the client
receives that response, it creates a new request.)

Streaming is known not to work reliably, especially with proxies
(unfortunately). Long polling also only works reliably, if you don't
wait too long with your response.

Even if you manage to set up your apache in a way that it works, you
probably can't control how additional proxies etc (and also the
browser) between your server and the client behave.

Maybe this helps a little bit.
Chris

Fran

unread,
Feb 17, 2010, 6:41:36 PM2/17/10
to Google Web Toolkit
I use Comet that its Long polling.
I think that the problem is a timeout that is applied by tomcat when
apache conect the proxy to the tomcat.

If I execute the aplication directly in tomcat. Its works fine.
If I execute the aplication in apache and a proxypass to servlet, the
aplication has a timeout between comet events that I dont understand.

You can test it:

Aplication in tomcat directly: http://california.lirondo.com:8081/msn/Messenger.html
---> It works very good (is needed to use diferents navegators for
conect diferent users)
Aplication in apache: http://california.lirondo.com/msn/Messenger.html
--> If you are patient, you can test that works fine but is soooo slow


Help please, thanks!

Fran

unread,
Feb 18, 2010, 8:04:50 PM2/18/10
to Google Web Toolkit
anyone know the problem? please

Fran

unread,
Feb 19, 2010, 9:17:50 AM2/19/10
to Google Web Toolkit
After some tests I can to confirm that the delay between Comet events
are constant.

Seems that Apache apply a timeout when conects to tomcat by Proxypass

Anyone know it?

Chris Lercher

unread,
Feb 19, 2010, 9:29:04 AM2/19/10
to Google Web Toolkit

Fran

unread,
Feb 19, 2010, 7:29:04 PM2/19/10
to Google Web Toolkit
Thanks Chris,

I put the ProxyTimeout directive to 1 and now seems that the
aplications have timeout 1.
Now the problem is that the aplication close the conection and dont is
hearing the future comet events

:(

On 19 feb, 15:29, Chris Lercher <cl_for_mail...@gmx.net> wrote:
> I'd take a look at this:http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxytimeout
>

> Or you add parameters to your ProxyPass directivehttp://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass

Chris Lercher

unread,
Feb 19, 2010, 7:39:00 PM2/19/10
to Google Web Toolkit
The timeout for your connections should be _shorter_ than the
ProxyTimeout, so setting it to 1 second may not be an ideal choice...

Chris Lercher

unread,
Feb 19, 2010, 7:57:07 PM2/19/10
to Google Web Toolkit

Fran

unread,
Feb 19, 2010, 8:08:36 PM2/19/10
to Google Web Toolkit
If I dont put a short timeout, the aplication isnt good.
Do you imagine that the MSN Messenger delay 15 seconds to show you the
contact list?

I need that the solution works as the aplication in tomcat. If I
execute the aplication on tomcat, it work without timeout. So I need
when the aplication works in apache, seems that is working in tomcat.

Im going to show the url that you tell me. Thanks!

Fran

unread,
Feb 19, 2010, 8:24:53 PM2/19/10
to Google Web Toolkit
I finally read it but seems that they cant help me. They arent use my
technical that is a Comet long polling technique.

I am reading the apache log and I find a curious error:

[error] [client 127.0.0.1] (OS 10060)A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond. : proxy: error reading response

It could be the cause of the conection close last the reception of the
first comet event.

dablack

unread,
Feb 19, 2010, 9:20:17 PM2/19/10
to Google Web Toolkit
Fran,

I use an Apache/Tomcat configuration and am very satisfied with its
performance; however, I use the mod_jk module rather than the
mod_proxy module. Have you looked into using the mod_jk module? With
it the communication between Apache and Tomcat are instantaneous. The
link http://tomcat.apache.org/connectors-doc/ can help you get more
information on this module and how to get it and use it. If you are
interested, I would be happy to share excerpts from my configuration
files to show how I've configured the connection.

Chris Lercher

unread,
Feb 19, 2010, 9:46:48 PM2/19/10
to Google Web Toolkit
The timeout is for the max time the app server gets to respond. If it
closes the connection earlier (which it should do, once it sends its
response), then the delay is shorter. This is what long polling is all
about. So if you set the delay to 15 seconds, it doesn't mean you have
to wait for 15 seconds every time. That's only, when the server
doesn't send the response within 15 seconds.

But as dablack says, probably mod_jk is the better solution anyway.
However, like I said earlier, there may be additional proxies between
your server and the client. So if it doesn't work correctly with
mod_proxy, this could indicate, that there is some problem in the way
the app server and the client interact. I have the feeling, that the
server maybe doesn't close its connection, so the proxy won't (always)
flush its contents. This triggers a timeout on the proxy or on the
client (depending on which is shorter).

Fran

unread,
Feb 20, 2010, 10:04:22 AM2/20/10
to Google Web Toolkit
Ok, thanks.

I will test mod_jk. I tested jk but i couldnt to run it in tomcat 6.
Im going to test jk one more time.

Thanks a lot!

Fran

unread,
Feb 20, 2010, 12:49:24 PM2/20/10
to Google Web Toolkit
I am configuring mod_jk

For tomat, in server.xml :

<Connector
connectionTimeout="20000"
port="8081"
protocol="AJP/1.3"
maxThreads="5"
acceptorThreadCount="2"
redirectPort="8443"
socket.directBuffer="false" />

For apache, in httpd.conf :

<IfModule mod_jk.c>
JkWorkersFile "/etc/httpd/conf/workers.properties"
JkLogFile "/etc/httpd/logs/mod_jk.log"
JkLogLevel warn
JkMount /msn/* worker1
</IfModule>


The result is that the url: http://localhost/msn/Messenger.html works,
but this html conects to servelet that not work.
The mod_jk runs html in apache that fisically are in tomcat, but cant
run the servlet.

¿Is necesary some special configure?

Thanks!

Fran

unread,
Feb 20, 2010, 1:04:14 PM2/20/10
to Google Web Toolkit
Should be due to protocol.
My messenger seems that need NIO protocol but if I put the NIO
protocol MOD_JK cant conect apache with tomcat

If I use this tomcat config, mod_jk cant conect apache with tomcat.

<Connector
connectionTimeout="20000"
port="8081"

protocol="org.apache.coyote.http11.Http11NioProtocol"


maxThreads="5"
acceptorThreadCount="2"
redirectPort="8443"
socket.directBuffer="false" />

If I use the last tomcat config, tomcat cant execute the servlet.
This is the error log:

GRAVE: Error, processing connection
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(Unknown Source)
at org.apache.jk.common.ChannelSocket.read(ChannelSocket.java:620)
at org.apache.jk.common.ChannelSocket.receive(ChannelSocket.java:577)
at
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:
685)
at org.apache.jk.common.ChannelSocket
$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Unknown Source)

Fran

unread,
Feb 20, 2010, 1:13:24 PM2/20/10
to Google Web Toolkit
Here the error when I change the protocol of
protocol="org.apache.coyote.http11.Http11NioProtocol" to protocol="AJP/
1.3"

[error] jk_ajp_common.c (1962): (worker1) Tomcat is down or refused
connection. No response has been sent to the client (yet)
[error] jk_ajp_common.c (2466): (worker1) connecting to tomcat failed.

Fran

unread,
Feb 20, 2010, 1:51:36 PM2/20/10
to Google Web Toolkit
Bad notices.

This dude has same problem that me and he was answered that mod_jk
dont support NIO

http://www.mail-archive.com/us...@tomcat.apache.org/msg67701.html

:(

dablack

unread,
Feb 20, 2010, 5:18:09 PM2/20/10
to Google Web Toolkit
Fran,

I'm really not an expert on setting up the connection between Apache
and Tomcat but I believe that the connections only operate in two
protocols: http or ajp. NIO is a Tomcat connector that can communicate
in either http or ajp. Because of that, I don't see any reason that
the Apache mod_jk connector module couldn't communicate with the NIO
connector. Since I don't use an NIO connector I could be wrong, but
that is the way I see it. As a starting point, try these
configurations:

server.xml

<Connector protocol="AJP/1.3" port="0" channelNioSocket.port="8009"
channelNioSocket.maxThreads="150"
channelNioSocket.maxSpareThreads="50"
channelNioSocket.minSpareThreads="25"
channelNioSocket.bufferSize="16384" />

(You seem to want to use port 8081 which should be fine, but the
standard ajp port is 8009. However, I wouldn't put it on port 8081 if
you are already using that port for another protocol such as http.)

httpd.conf

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /*.svc ajp13

(For the JkMount I use *.svc because I use the svc extension for my
GWT service target to differentiate service points from other files.)

(For example, in my web.xml file I will map my service something like
this to use the svc extension:
<servlet>
<servlet-name>MyService</servlet-name>
<servlet-class>com.mysite.server.MyServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyService</servlet-name>
<url-pattern>/MyService.svc</usr-pattern>
</servlet-mapping>

And in my GWT code I create my service target like this:

target.setServiceEntryPoint( GWT.getModuleBaseURL() +
"MyService.svc" );

I did this because I had troubles with the 'JkMount /* ajp13' entry,
but when I used /*.svc the problems cleared up.)

workers.properties

workers.tomcat_home=/usr/tomcat/apache-tomcat-6.0.16
workers.java_home=/usr/java/jdk1.6.0_06
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13

(Of course, match the ajp port in the workers.property file to the
port you define in the server.xml file. Also, if your Tomcat is not on
the same server as your Apache you will need to change the localhost
host entry to the correct host URL.)

I hope this helps.

Fran

unread,
Feb 20, 2010, 5:36:40 PM2/20/10
to google-we...@googlegroups.com
I cant undestand why this config:


<Connector protocol="AJP/1.3" port="0" channelNioSocket.port="8009"
channelNioSocket.maxThreads="
150"
  channelNioSocket.maxSpareThreads="50"
channelNioSocket.minSpareThreads="25"
  channelNioSocket.bufferSize="16384" />


Why port 0 ?


2010/2/20 dablack <david.blackwell.sr@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Fran

unread,
Feb 20, 2010, 5:45:02 PM2/20/10
to Google Web Toolkit
I test your config, dablack, but I cant connect to the servlet.
With this config I cant access not even to: http://localhost:8009/servlet
that is tomcat directly without apache


On 20 feb, 23:36, Fran <fra...@gmail.com> wrote:
> I cant undestand why this config:
>
> <Connector protocol="AJP/1.3" port="0" channelNioSocket.port="8009"
> channelNioSocket.maxThreads="
> 150"
>   channelNioSocket.maxSpareThreads="50"
> channelNioSocket.minSpareThreads="25"
>   channelNioSocket.bufferSize="16384" />
>
> Why port 0 ?
>

> 2010/2/20 dablack <david.blackwell...@gmail.com>

> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>

Paul S

unread,
Feb 20, 2010, 7:00:45 PM2/20/10
to Google Web Toolkit
So basically you are trying to serve up 2 things. An app from Tomcat
and some other web content from Apache server? Firstly, can't the
other content be served from Tomcat too? That way you could just stop
your Apache server from running, then configure Tomcat to load up on
port 80 (default for http) and that way no one will every know they're
hitting a Tomcat server. Or, there is an Apache server module, I
forgot the name, but is allows you to specify that any normal request
goes to the http server and then any request at /j/* gets pushed along
to the Tomcat server. I'm hazy on the details but have seen it working
before and I don't think it's using a proxy in the way you are.

Could work?

Fran

unread,
Feb 20, 2010, 7:11:33 PM2/20/10
to google-we...@googlegroups.com
The module that you are telling is mod_jk and I cant use it because dont support NIO or I cant to do work.
I cant implement all aplication without apache because I am implementing a comet chat that will be included in a web aplication that already exists and I cant import to tomcat.

Thanks for your help

2010/2/21 Paul S <paulss...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

dablack

unread,
Feb 20, 2010, 8:10:22 PM2/20/10
to Google Web Toolkit
I borrowed that connector configuration from a website I came across.
I'm not sure why port=0 either. If I put more research into the NIO
connector I could probably find out. Why don't you try adding the
lines,

enableLookups="false"
scheme="http"

to the NIO connector configuration in the server.xml file that I gave
you earlier.

As far as accessing the ajp service using http://localhost:8009/servlet,
that will not work. Your browser uses the http protocol and the 8009
port is being serviced by the ajp protocol. You should still have your
connector using the http protocol configured to listen on port 8081.

Hopefully the scheme line above will help the NIO connector
communicate back to Apache.

Fran

unread,
Feb 20, 2010, 8:21:55 PM2/20/10
to google-we...@googlegroups.com
The problem persist with the news changes.
Seems that apache cant connect to tomcat :( 
The error log of apache and mod_jk dont show nothing. Not ever nio conection stablished

2010/2/21 dablack <david.blackwell.sr@gmail.com>
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

dablack

unread,
Feb 20, 2010, 9:21:59 PM2/20/10
to Google Web Toolkit
Sorry to lead you on a wild goose chase. I guess you will have to use
the Apache mod_proxy_http module with the Tomcat NIO connector using
the http protocol after all. I don't have any experience with the
mod_proxy_http module at all so not really anything I can help you
with.

Good luck.


On Feb 20, 7:21 pm, Fran <fra...@gmail.com> wrote:
> The problem persist with the news changes.
> Seems that apache cant connect to tomcat :(
> The error log of apache and mod_jk dont show nothing. Not ever nio conection
> stablished
>

> 2010/2/21 dablack <david.blackwell...@gmail.com>


>
> > I borrowed that connector configuration from a website I came across.
> > I'm not sure why port=0 either. If I put more research into the NIO
> > connector I could probably find out. Why don't you try adding the
> > lines,
>
> > enableLookups="false"
> > scheme="http"
>
> > to the NIO connector configuration in the server.xml file that I gave
> > you earlier.
>

> > As far as accessing the ajp service usinghttp://localhost:8009/servlet,

> ...
>
> read more »

Martin D'Aloia

unread,
Feb 20, 2010, 10:06:07 PM2/20/10
to google-we...@googlegroups.com
have you looked mod_rewrite ( http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html ) ? doesn't it help you?

Why you need that the client side runs on apache httpd and not in a tomcat? do you have shared resources? if not, maybe you can let tomcat serve the client side also and, if you need performance, look at APR for tomcat ( http://tomcat.apache.org/tomcat-6.0-doc/apr.html )



--

Fran

unread,
Feb 21, 2010, 7:11:05 AM2/21/10
to Google Web Toolkit
I tested the mod_proxy_http, in the last post you can see the config
that I used.
But in Comet HTTP streaming, I found mod_proxy blocked the response
until server close the
stream (after timeout), then send the whole response to client at
once.

In the first time I was wrong because I thought that if I put
timeout=1 I found the solution but Its not real because the server
close the conection after timeout

In the five post of mine is an example of the problem.

This dude has a similar problem: http://forums.java.net/jive/thread.jspa?threadID=41377

I am hopeless :(

> ...
>
> leer más »

Fran

unread,
Feb 21, 2010, 7:13:25 AM2/21/10
to Google Web Toolkit
The mod_rewrite cant help me because I need that the server sends me
the response. Modrewrite only redirect.
I need that the client be in apache because my aplication is an
extended module of a webpage that is wrote in php/mysql and has a
special configuration in apache

Thanks for help

On 21 feb, 04:06, "Martin D'Aloia" <martindal...@gmail.com> wrote:
> have you looked mod_rewrite (http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html) ? doesn't it help


> you?
>
> Why you need that the client side runs on apache httpd and not in a tomcat?
> do you have shared resources? if not, maybe you can let tomcat serve the
> client side also and, if you need performance, look at APR for tomcat (http://tomcat.apache.org/tomcat-6.0-doc/apr.html)
>

> ...
>
> leer más »

Chris Lercher

unread,
Feb 21, 2010, 8:39:34 AM2/21/10
to Google Web Toolkit
Here are some things you can check - maybe one of these helps (?)

- In your servlet: Do you expect that anything gets flushed
(reliably), before you call the close() method on CometEvent? If yes,
then what you're actually trying to do is _streaming_ (which doesn't
work). Calling writer.flush() is certainly not enough, since mod_proxy
has no way to know that writer.flush() has been called.

- Did you try to set "no-cache" headers etc.?

> ...
>
> read more »

Fran

unread,
Feb 21, 2010, 9:18:11 AM2/21/10
to google-we...@googlegroups.com
Here the source code of my servlet. This code is part of aplication code of the book "Google Web Toolkit Applications"

public class MessengerServiceCometImpl extends HttpServlet implements CometProcessor {
   
    class CometMessengerService extends AbstractMessengerService{

        final ThreadLocal perThreadRequest = new ThreadLocal();
        public String getCurrentId() {
            return ((HttpServletRequest)perThreadRequest.get()).getSession(true).getId();
        }
       
        public void onEvents(String id) {
            synchronized(pendingRequests){
                PendingRequest pr = (PendingRequest)pendingRequests.get( id );
                if( pr != null ){
                    pendingRequests.remove(id);
                    sendResponse( pr.event, pr.rpcRequest );
                }
            }
        }
    }
   
    class PendingRequest{
        RPCRequest rpcRequest;
        CometEvent event;
        public PendingRequest(RPCRequest rpcRequest, CometEvent event) {
            this.rpcRequest = rpcRequest;
            this.event = event;
        }
    }
   
    Map pendingRequests = new HashMap();
    CometMessengerService messengerService =  new CometMessengerService();
   
    public void event(CometEvent event) throws IOException, ServletException {
        if (event.getEventType() == CometEvent.EventType.READ) {
            //get the RPC request
            RPCRequest rpcRequest = RPC.decodeRequest( readRequest( event ) );
            Method targetMethod = rpcRequest.getMethod();

            //if its the event request then wait for events
            synchronized(pendingRequests){
            messengerService.perThreadRequest.set( event.getHttpServletRequest() );
                if( targetMethod.getName().equals("getEvents") && !messengerService.hasEvents() ){
                    //save this request for processing later.
                    pendingRequests.put( messengerService.getCurrentId(), new PendingRequest( rpcRequest, event ) );
                }
                else{
                    //otherwise process the RPC call as usual
                    sendResponse( event, rpcRequest );
                }
            }
        }
    }

    public void sendResponse( CometEvent event, RPCRequest rpcRequest ) {
        try{
            try{
                messengerService.perThreadRequest.set( event.getHttpServletRequest() );
                String result = RPC.invokeAndEncodeResponse(messengerService, rpcRequest.getMethod(), rpcRequest.getParameters());
                writeResponse(event.getHttpServletResponse(), result);
                event.close();

            } catch (IncompatibleRemoteServiceException e) {
                writeResponse( event.getHttpServletResponse(), RPC.encodeResponseForFailure(null, e) );
            }
        }catch (Throwable e) {
            writeResponse( event.getHttpServletResponse(), "Server Error" );
        }
    }
   
    public String readRequest( CometEvent event ) throws IOException, ServletException{
        int contentLength = event.getHttpServletRequest().getContentLength();
        if (contentLength == -1) {
            // Content length must be known.
            throw new ServletException("Content-Length must be specified");
        }
        InputStream in = event.getHttpServletRequest().getInputStream();
        byte[] payload = new byte[contentLength];
        int offset = 0;
        int len = contentLength;
        int byteCount;
        while (offset < contentLength) {
            byteCount = in.read(payload, offset, len);
            if (byteCount == -1) {
                throw new ServletException("Client did not send " + contentLength
                        + " bytes as expected");
            }
            offset += byteCount;
            len -= byteCount;
        }
        return new String(payload, "UTF-8");
    }
   
    public void writeResponse( HttpServletResponse response, String body ){
        try {
            // this line is added by me
            response.addHeader("Transfer-Encoding", "Chunked");
            PrintWriter writer = response.getWriter();
            writer.print(body);
            writer.flush();
        } catch (IOException e) {
            log("IOExeption sending response", e);
        }
    }

}

2010/2/21 Chris Lercher <cl_for_...@gmx.net>

--

Fran

unread,
Feb 21, 2010, 9:28:45 AM2/21/10
to Google Web Toolkit
Yes Chris, I use writer.flush()
I cant use it at mod_proxy? What can I do?

Thanks

> ...
>
> leer más »

Chris Lercher

unread,
Feb 21, 2010, 9:38:07 AM2/21/10
to Google Web Toolkit
Using writer.flush() is absolutely ok, it's just not enough. Taking a
quick look at the code you posted, it looks ok, because after calling
writer.flush(), it always calls event.close(). So, no problem here.
But: I don't see any timeout in the code. The server must also call
event.close() after some timeout - which must be shorter than your
proxy's and your browser's timeout. (Some people say, it should in any
case be less than a minute.)

So either you can configure the timeout somewhere in tomcat (please
refer to the tomcat documentation), or you'll have to send something
back manually after some time.
When the client receives such a dummy response, it must open a new
request (that's the long polling principle).

> ...
>
> read more »

Fran

unread,
Feb 21, 2010, 9:50:32 AM2/21/10
to Google Web Toolkit
I based the code in a GWT book.
Please take a look at http://217.13.89.62/messenger%20nonblocking%20calls.pdf
next the phrase at the first page: "Using Server-Side Advanced IO"

Thanks for your time

> ...
>
> leer más »

Fran

unread,
Feb 21, 2010, 9:54:19 AM2/21/10
to Google Web Toolkit
Chris, the big problem is that the aplication works fully in tomcat
but I use apache to run it with the servlet in tomcat, it cant work.
I only need to emulate that the execution in apache is the same that
in tomcat

On 21 feb, 15:50, Fran <fra...@gmail.com> wrote:
> I based the code in a GWT book.

> Please take a look athttp://217.13.89.62/messenger%20nonblocking%20calls.pdf

> ...
>
> leer más »

Chris Lercher

unread,
Feb 21, 2010, 10:29:48 AM2/21/10
to Google Web Toolkit
I expect that your application works, if you use tomcat only, because
many browsers will wait for the response for a very long time. In that
case, you don't need a timeout on your server.

But when there's any proxy between your client and the server (and
that's also the case when the client connects to the Internet via a
proxy), then it often fails. Also expected behaviour.

I'd take a look at this: http://tomcat.apache.org/tomcat-6.0-doc/aio.html

It says you can set a timeout like this:
event.setTimeout(30*1000)

I'd do this for EventType.BEGIN.

Then you can test for EventType.TIMEOUT (the documentation says, that
you may need the
org.apache.catalina.valves.CometConnectionManagerValve for this).

On timeout, send some dummy response. The client should recognize the
response as a timeout message, and retry.

So, in effect I imagine it could look something like this (I can't try
it here, so there may be some mistakes):

public void event(CometEvent event) throws IOException,
ServletException {

if (event.getEventType() == CometEvent.EventType.BEGIN) {
event.setTimeout(30*1000);
}
if (event.getEventType() == CometEvent.EventType.READ) { ...}
if (event.getEventType() == CometEvent.EventType.TIMEOUT) {
writeResponse(response, "timeout");
event.close();
}
}

> ...
>
> read more »

Fran

unread,
Feb 21, 2010, 10:49:20 AM2/21/10
to Google Web Toolkit
it dont work, apache cant conect to tomcat with this changes. The
login msn is loading indefinitely... And error logs dont show nothing,
except tomcat that says:

org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read


Here the changes...
Added this lines in event method:

if (event.getEventType() == CometEvent.EventType.BEGIN) {
event.setTimeout(30*1000);
}

if (event.getEventSubType() == CometEvent.EventSubType.TIMEOUT) {
writeResponse(event.getHttpServletResponse(), "timeout");
event.close();
}

server.xml (tomcat):

<Connector
connectionTimeout="20000"
port="8081"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="5"
acceptorThreadCount="2"
redirectPort="8443"
socket.directBuffer="false" />

httpd.conf (apache):

keepalive Off
ProxyRequests Off
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass /msn/com.msn/messenger http://localhost:8081/msn/com.msn/messenger
ProxyPassReverse /msn/com.msn/messenger http://localhost:8081/msn/com.msn/messenger

> ...
>
> leer más »

Fran

unread,
Feb 22, 2010, 1:19:38 PM2/22/10
to Google Web Toolkit
I think that I will need a iframe that loads tomcat page. But this
solution isnt good

On 21 feb, 16:49, Fran <fra...@gmail.com> wrote:
> it dont work, apache cant conect totomcatwith this changes. The


> login msn is loading indefinitely... And error logs dont show nothing,

>         ProxyPassReverse /msn/com.msn/messengerhttp://localhost:8081/msn/com.msn/messenger


>
> On 21 feb, 16:29, Chris Lercher <cl_for_mail...@gmx.net> wrote:
>

> > I expect that your application works, if you usetomcatonly, because

> > > but I use apache to run it with the servlet intomcat, it cant work.


> > > I only need to emulate that the execution in apache is the same that
> > > intomcat
>
> > > On 21 feb, 15:50, Fran <fra...@gmail.com> wrote:
>
> > > > I based the code in a GWT book.
> > > > Please take a look athttp://217.13.89.62/messenger%20nonblocking%20calls.pdf
> > > > next the phrase at the first page: "Using Server-Side Advanced IO"
>
> > > > Thanks for your time
>
> > > > On 21 feb, 15:38, Chris Lercher <cl_for_mail...@gmx.net> wrote:
>
> > > > > Using writer.flush() is absolutely ok, it's just not enough. Taking a
> > > > > quick look at the code you posted, it looks ok, because after calling
> > > > > writer.flush(), it always calls event.close(). So, no problem here.
> > > > > But: I don't see any timeout in the code. The server must also call
> > > > > event.close() after some timeout - which must be shorter than your
> > > > > proxy's and your browser's timeout. (Some people say, it should in any
> > > > > case be less than a minute.)
>
> > > > > So either you can configure the timeout somewhere intomcat(please

> > > > > refer to thetomcatdocumentation), or you'll have to send something

> > > > > > > > > the Apache mod_proxy_http module with theTomcatNIO connector using


> > > > > > > > > the http protocol after all. I don't have any experience with the
> > > > > > > > > mod_proxy_http module at all so not really anything I can help you
> > > > > > > > > with.
>
> > > > > > > > > Good luck.
>
> > > > > > > > > On Feb 20, 7:21 pm, Fran <fra...@gmail.com> wrote:
>
> > > > > > > > > > The problem persist with the news changes.

> > > > > > > > > > Seems that apache cant connect totomcat:(


> > > > > > > > > > The error log of apache and mod_jk dont show nothing. Not ever nio conection
> > > > > > > > > > stablished
>
> > > > > > > > > > 2010/2/21 dablack <david.blackwell...@gmail.com>
>
> > > > > > > > > > > I borrowed that connector configuration from a website I came across.
> > > > > > > > > > > I'm not sure why port=0 either. If I put more research into the NIO
> > > > > > > > > > > connector I could probably find out. Why don't you try adding the
> > > > > > > > > > > lines,
>
> > > > > > > > > > > enableLookups="false"
> > > > > > > > > > > scheme="http"
>
> > > > > > > > > > > to the NIO connector configuration in the server.xml file that I gave
> > > > > > > > > > > you earlier.
>
> > > > > > > > > > > As far as accessing the ajp service usinghttp://localhost:8009/servlet,
> > > > > > > > > > > that will not work. Your browser uses the http protocol and the 8009
> > > > > > > > > > > port is being serviced by the ajp protocol. You should still have your
> > > > > > > > > > > connector using the http protocol configured to listen on port 8081.
>
> > > > > > > > > > > Hopefully the scheme line above will help the NIO connector
> > > > > > > > > > > communicate back to Apache.
>
> > > > > > > > > > > On Feb 20, 4:45 pm, Fran <fra...@gmail.com> wrote:
> > > > > > > > > > > > I test your config, dablack, but I cant connect to the servlet.
> > > > > > > > > > > > With this config I cant access not even to:http://localhost:8009/servlet

> > > > > > > > > > > > that istomcatdirectly without apache


>
> > > > > > > > > > > > On 20 feb, 23:36, Fran <fra...@gmail.com> wrote:
>
> > > > > > > > > > > > > I cant undestand why this config:
>
> > > > > > > > > > > > > <Connector protocol="AJP/1.3" port="0" channelNioSocket.port="8009"
> > > > > > > > > > > > > channelNioSocket.maxThreads="
> > > > > > > > > > > > > 150"
> > > > > > > > > > > > >   channelNioSocket.maxSpareThreads="50"
> > > > > > > > > > > > > channelNioSocket.minSpareThreads="25"
> > > > > > > > > > > > >   channelNioSocket.bufferSize="16384" />
>
> > > > > > > > > > > > > Why port 0 ?
>
> > > > > > > > > > > > > 2010/2/20 dablack <david.blackwell...@gmail.com>
>
> > > > > > > > > > > > > > Fran,
>
> > > > > > > > > > > > > > I'm really not an expert on setting up the connection between Apache

> > > > > > > > > > > > > > andTomcatbut I believe that the connections only operate in two
> > > > > > > > > > > > > > protocols: http or ajp. NIO is aTomcatconnector that can


> > > > > > > > > > > communicate
> > > > > > > > > > > > > > in either http or ajp. Because of that, I don't see any reason that
> > > > > > > > > > > > > > the Apache mod_jk connector module couldn't communicate with the NIO
> > > > > > > > > > > > > > connector. Since I don't use an NIO connector I could be wrong, but
> > > > > > > > > > > > > > that is the way I see it. As a starting point, try these
> > > > > > > > > > > > > > configurations:
>
> > > > > > > > > > > > > > server.xml
>
> > > > > > > > > > > > > > <Connector protocol="AJP/1.3" port="0" channelNioSocket.port="8009"
> > > > > > > > > > > > > > channelNioSocket.maxThreads="150"
> > > > > > > > > > > > > >   channelNioSocket.maxSpareThreads="50"
> > > > > > > > > > > > > > channelNioSocket.minSpareThreads="25"
> > > > > > > > > > > > > >   channelNioSocket.bufferSize="16384" />
>
> > > > > > > > > > > > > > (You seem to want to use port 8081 which should be fine, but the
> > > > > > > > > > > > > > standard ajp port is 8009. However, I wouldn't put it on port 8081 if
> > > > > > > > > > > > > > you are already using that port for another protocol such as http.)
>
> > > > > > > > > > > > > > httpd.conf
>
> > > > > > > > > > > > > > LoadModule jk_module
>

> ...
>
> leer más »

Chris Lercher

unread,
Feb 22, 2010, 1:48:19 PM2/22/10
to Google Web Toolkit
I believe, that people in a specialized Tomcat forum may be able to
help you a lot better.

As a last hint, if all else fails, you can still experiment with a
timeout on the client. See this thread:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/11960c28e1a2d9eb?pli=1
Or set something like a content aware load balancer in front, to
balance between your Apache and Tomcat without acting like a proxy, if
that's possible at all, and if it works with your special PHP setup.

Sorry I couldn't help you with more specifics, but it's been some
years since I last used a Tomcat+Apache setup...

Chris

> ...
>
> read more »

Ashar Lohmar

unread,
Feb 23, 2010, 8:52:11 AM2/23/10
to Google Web Toolkit
i use appache(httpd)+Tomcat with AJP, these are my confs:

httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
ServerAdmin ad...@example.com
DocumentRoot "<dummy_path_ussualy_the_default_httpd's_htdocs>"
ErrorLog "logs/app_error_log"
CustomLog "logs/app-access_log" common
<Location />
ProxyPass ajp://127.0.0.1:8009/
ProxyPassReverse ajp://127.0.0.1:8009/
</Location>
</VirtualHost>

in httpd/conf/httpd.conf i've uncommented a include line as below
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

in my tomcat/conf/server.xml the ajp connector is defined as below
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
address="127.0.0.1" />
i also added the address="127.0.0.1" attribute to the others
<connector> tags as i want my app to be reached from "outside" only
through httpd.
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="18443" address="127.0.0.1" />


one more thing that you should have in mind is that i've compiled my
httpd with the following params "--enable-proxy --enable-proxy-ajp --
enable-proxy-balancer --enable-ssl --with-included-apr" and of course
de --prefix param
also i've "installed" the tomcat-native with "--with-apr=$HOME/httpd/
bin/apr-1-config --with-java-home=$HOME/java --with-ssl=yes" and
followed their instruction and added the lib in the LD_LIBRARY_PATH


hope these will help you
good luck

Chris Lercher

unread,
Feb 23, 2010, 11:11:52 AM2/23/10
to Google Web Toolkit
Hi Ashar,

the Tomcat documentation says, that AJP doesn't work with Comet/AIO:
http://tomcat.apache.org/tomcat-6.0-doc/aio.html
Are you using Comet?

Fran

unread,
Feb 23, 2010, 11:58:18 AM2/23/10
to google-we...@googlegroups.com
good question Chris

2010/2/23 Chris Lercher <cl_for_...@gmx.net>

Ashar Lohmar

unread,
Feb 24, 2010, 3:20:23 AM2/24/10
to Google Web Toolkit
sorry i haven't read all the topic, the first question didn't said
anything about comet, from what I've understood by reading a few of
the answers I thought that the comet was given as an solution/
alternative.

i have no experience in working with comet, so i didn't use it.

On Feb 23, 6:58 pm, Fran <fra...@gmail.com> wrote:
> good question Chris
>

> 2010/2/23 Chris Lercher <cl_for_mail...@gmx.net>

> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>

ani

unread,
Mar 23, 2010, 7:05:32 AM3/23/10
to Google Web Toolkit
Hi,

Go through this post http://blog.findasolution.in/2010/03/apache-tomcat-connectorintegrate-apache-with-tomcat/
hope this will help you.

On Feb 21, 6:10 am, dablack <david.blackwell...@gmail.com> wrote:
> I borrowed that connector configuration from a website I came across.
> I'm not sure why port=0 either. If I put more research into the NIO
> connector I could probably find out. Why don't you try adding the
> lines,
>
> enableLookups="false"
> scheme="http"
>
> to the NIO connector configuration in the server.xml file that I gave
> you earlier.
>

> As far as accessing the ajp service usinghttp://localhost:8009/servlet,

Fran

unread,
Mar 23, 2010, 12:57:47 PM3/23/10
to google-we...@googlegroups.com
Hi ani,

I read it but its the same problem. It dont work with comet.
I you read all the post, you can see that mod_jk dont work.

Thanks

2010/3/23 ani <anees...@gmail.com>
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages