Re: Comet explicit event close

2010-02-09 Thread Stephen Byrne
On Tuesday 09 February 2010 07:11:40 you wrote:
> Hi,
> I  am Using a Socket client to send a http request to sever and then waits
> to read response from the socket inputstream..
> 
> 1. I have a comet servlet. On its read event it starts a new thread passing
> the request and response object.
> 
> 2.The read event code block then returns.
> 3. The thread started in the read event starts writing the responses in the
> response stream.
> PrintWriter writer =response.getWriter();
> writer.write("asynresponse");
> 
> 4. after writing say 5 responses i want to just close the request and
> response (not the socket which sent the request)
> Sending header Connection:close closes the Socket
> 
> How do i do this?
> 
> Since i cannot trigger the Comet servlet END event explicitly, where/how
> can I call event.close();
> 
> I tried passing the event object from the read event to the thread and
> called event.close in the thread. But an exception was
> thrown saying event object is no longer  associated with the request and
> response.
> 
> Thanks,
> Animesh

Why are you starting a new thread instead of writing the response and calling 
event.close() from the thread in which event(CometEvent) is called?
 
> P.S: BTW Kudos to the forum. Is is so alive. have been sending queries
>  since some days and got replies.
> Also just to let u know i have a business problem where a http request and
> response are to be served using comet asyncronously on the same socket
> connection.
> 
> So i have a single socket client which wants to send http request again and
> again (pipeline) and waits for a asyn response from the comet server.
>  trying a POC for the same.
> Any ideas for concrete pipelining clients would be greatly appreciated.
> 
> Thanks,
> Animesh
> 

-- 
Stephen Byrne
step...@lincware.com
(585) 286-5817

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Comet Client Example

2010-02-08 Thread Stephen Byrne
On 2/8/2010 5:36 AM, Animesh Sonkar wrote:
> Looked around all the forums for a well working example for Comet Client.

Here is some code I wrote to test a CometProcessor:

Using HttpURLConnection:

URL url = new URL( "http://"; );
HttpURLConnection connection = (HttpURLConnection)
  url.openConnection();
connection.setChunkedStreamingMode( 1 );
connection.setDoOutput( true );
connection.setDoInput( true );
connection.connect();
OutputStream os = connection.getOutputStream();

while ( true ) {
  os.write( 1 );
  os.flush();
  Thread.sleep( 1000 );
}

os.write( 0 );
os.flush();

os.close();

connection.disconnect();

Using sockets:

try {
  Socket socket;
  try {
socket = new Socket( "1.2.3.4", 8911 );
  } catch ( Exception e ) {
log.error( e.getMessage(), e );
return;
  }

  OutputStream out = null;
  PrintWriter pw = null;
  BufferedReader in = null;
  try {
out = socket.getOutputStream();
pw = new PrintWriter( out, true );
in = new BufferedReader(
new InputStreamReader(
  socket.getInputStream() ) );

pw.print( "POST /cometProcessor HTTP/1.1" );
pw.print( CRLF );
pw.print( "Host: example.com" );
pw.print( CRLF );
pw.print( "Accept: image/png,image/*;q=0.8,*/*;q=0.5" ); // fixme
pw.print( CRLF );
pw.print( "Accept-Language: en-us,en;q=0.5" );
pw.print( CRLF );
pw.print( "Accept-Encoding: gzip,deflate" ); // fixme
pw.print( CRLF );
pw.print( "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" );
pw.print( CRLF );
pw.print( "Connection: keep-alive" );
pw.print( CRLF );

pw.print( "Content-Type: text/plain" );
pw.print( CRLF );

pw.print( "Transfer-Encoding: chunked" );
pw.print( CRLF );

pw.print( CRLF );

pw.flush();
out.flush();

// send a byte every second.
log.debug( "Send a byte every second. . ." );
while ( true ) {
  pw.print( "01" ); // chunk size
  pw.print( CRLF );
  pw.print( "A" );
  pw.print( CRLF );
  pw.flush();
  Thread.sleep( 1000 );
}

pw.print( "0" ); // end of chunks
pw.print( CRLF );

pw.print( CRLF ); // end of request.
pw.flush();

Thread.sleep( 1000 );
  } finally {
if ( in != null ) {
  try {
String s;
log.debug( "RESPONSE" );
while ( ( s = in.readLine() ) != null ) {
  log.debug( s );
}
log.debug( "END" );
in.close();
  } catch ( Exception e ) {
log.warn( e.getMessage(), e );
  }
}

if ( out != null ) {
  try {
out.close();
  } catch ( IOException e ) {
  }
}

if ( socket != null ) {
  try {
socket.close();
  } catch ( IOException e ) {
  }
}
  }

}


-- 
Stephen Byrne
step...@lincware.com
(585) 286-5817

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Configuring two connectors and COMET Read event

2010-02-04 Thread Stephen Byrne
Animesh Sonkar wrote:
*snip*
> 2. I am not able to invoke the READ event.  How do i do that?

You need to send the HTTP request as chunked data. If you happen to be
using an HttpURLConnection, call setChunkedStreamingMode( 1 ). If you
are taking a lower level approach, (i.e. using sockets), send a header
"Transfer-Encoding: chunked", and send CRLF and flush your stream
between chunks.

*snip*
> Thanks,
> Animesh.


-- 
Stephen Byrne
step...@lincware.com
(585) 286-5817

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: CometProcessor proxied through Apache httpd

2010-01-27 Thread Stephen Byrne

Robin Wilson wrote:

Where are you putting the ProxyPass (which file, where in the file)?

Also, did you have this in the file somewhere before the ProxyPass:

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

AND... In your Apache "modules" directory, is there a 'mod_proxy_ajp.so' file?

Lastly, this is what our connector looks like in the 'server.xml' file for the 
tomcat instance:



So I'm not sure if the 'address' is causing the problem or not.

Keep in mind, 'proxy' (and AJP) don't work the same as HTTP exactly. The 
rewrites will just re-point your browser to use the new URL (so rewriting to an 
'ajp://' protocol will break the browser - since it doesn't speak 'ajp' 
protocol). The proxy actually passes the request _through_ the Apache HTTP 
process - to the Tomcat's AJP process - so the browser only talks 'http' to the 
Apache service, while Apache talks 'ajp' to the Tomcat service. It's the 
difference of:

Browser --HTTP request--> Apache
Browser <--HTTP (redirect to Tomcat path)-- Apache
Browser --HTTP request--> Tomcat
Browser <--HTTP response-- Tomcat

vs.

Browser --HTTP request--> Apache --AJP (proxied request)--> Tomcat
Browser <--HTTP response-- Apache <--AJP (proxied response)-- Tomcat

(I'll admit, I could be wrong on this - but that's how I think it works...)


I do have proxy_ajp_module loaded.
I have the ProxyPass (or RewriteRule) in a 
The [P] at the end of the RewriteRule causes Apache to pass the request 
through the proxy - not to send a redirect to the browser.


Have you successfully used a CometProcessor behind an AJP proxy?

-Stephen



--
Robin D. Wilson
Director of Web Development
KingsIsle Entertainment, Inc.
CELL: 512-426-3929
DESK: 512-623-5913
www.KingsIsle.com


-Original Message-
From: Stephen Byrne [mailto:step...@lincware.com] 
Sent: Wednesday, January 27, 2010 9:54 AM

To: Tomcat Users List
Subject: Re: CometProcessor proxied through Apache httpd

Robin Wilson wrote:

Have you tried using mod_proxy_ajp?

ProxyPass /some/path ajp://tomcat.host.domain:8009/some/other/path


Yes, I did try this, and got the same results as using RewriteRule - a 
405 error.



--
Robin D. Wilson
Director of Web Development
KingsIsle Entertainment, Inc.
CELL: 512-426-3929
DESK: 512-623-5913
www.KingsIsle.com

-Original Message-
From: Stephen Byrne [mailto:step...@lincware.com] 
Sent: Wednesday, January 27, 2010 9:27 AM

To: users@tomcat.apache.org
Subject: CometProcessor proxied through Apache httpd

Is there a way to get CometProcessor to work when proxying through 
Apache httpd? Here is what I have tried:


I have an HttpServlet implementing CometProcessor.

When I have a Tomcat connector like this:



and I connect to it directly, everything works wonderfully - I get 
CometEvent.EventType.READ events as I send data from the client.



When I have a Tomcat connector like this:



and have Apache httpd proxy requests like this:

RewriteRule ^/path/to/servlet http://localhost:8911/path/to/servlet [P]

I get exactly one CometEvent.EventType.READ event with all of the data 
after I finish sending data from the client.



When I have a Tomcat connector like this:


and have Apache httpd proxy requests like this:

RewriteRule ^/path/to/servlet ajp://localhost:8909/path/to/servlet [P]

I get zero CometEvents and the client gets an HTTP error 405 (Method Not 
Allowed). I was hoping that AJP would work so I could try using 
ProxyPass with flushpackets=on, but the Apache documentation says that 
only works with AJP.



If I use Http11NioConnector instead of HTTP/1.1 and try to proxy with 
Apache, I get the same results as if I were using the HTTP/1.1 connector.


My client code (Java) is:

// Direct to Tomcat (HTTP)
//URL url = new URL( "http://server:8912/path/to/servlet"; );
// Apache proxies to Tomcat
URL url = new URL( "http://server/path/to/servlet"; );
HttpURLConnection connection = (HttpURLConnection)
   url.openConnection();
connection.setChunkedStreamingMode( 1 );
connection.setDoOutput( true );
connection.setDoInput( true );
connection.connect();
OutputStream os = connection.getOutputStream();
for ( int i = 0; i < 10; i++ ) {
   os.write( 1 );
   os.flush();
   Thread.sleep( 1000 );
}
os.close();
log.debug( "response:" + connection.getResponseCode() );
log.debug( "response:" + connection.getResponseMessage() );
connection.disconnect();

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org




Re: CometProcessor proxied through Apache httpd

2010-01-27 Thread Stephen Byrne

Robin Wilson wrote:

Have you tried using mod_proxy_ajp?

ProxyPass /some/path ajp://tomcat.host.domain:8009/some/other/path


Yes, I did try this, and got the same results as using RewriteRule - a 
405 error.



--
Robin D. Wilson
Director of Web Development
KingsIsle Entertainment, Inc.
CELL: 512-426-3929
DESK: 512-623-5913
www.KingsIsle.com

-Original Message-
From: Stephen Byrne [mailto:step...@lincware.com] 
Sent: Wednesday, January 27, 2010 9:27 AM

To: users@tomcat.apache.org
Subject: CometProcessor proxied through Apache httpd

Is there a way to get CometProcessor to work when proxying through 
Apache httpd? Here is what I have tried:


I have an HttpServlet implementing CometProcessor.

When I have a Tomcat connector like this:



and I connect to it directly, everything works wonderfully - I get 
CometEvent.EventType.READ events as I send data from the client.



When I have a Tomcat connector like this:



and have Apache httpd proxy requests like this:

RewriteRule ^/path/to/servlet http://localhost:8911/path/to/servlet [P]

I get exactly one CometEvent.EventType.READ event with all of the data 
after I finish sending data from the client.



When I have a Tomcat connector like this:


and have Apache httpd proxy requests like this:

RewriteRule ^/path/to/servlet ajp://localhost:8909/path/to/servlet [P]

I get zero CometEvents and the client gets an HTTP error 405 (Method Not 
Allowed). I was hoping that AJP would work so I could try using 
ProxyPass with flushpackets=on, but the Apache documentation says that 
only works with AJP.



If I use Http11NioConnector instead of HTTP/1.1 and try to proxy with 
Apache, I get the same results as if I were using the HTTP/1.1 connector.


My client code (Java) is:

// Direct to Tomcat (HTTP)
//URL url = new URL( "http://server:8912/path/to/servlet"; );
// Apache proxies to Tomcat
URL url = new URL( "http://server/path/to/servlet"; );
HttpURLConnection connection = (HttpURLConnection)
   url.openConnection();
connection.setChunkedStreamingMode( 1 );
connection.setDoOutput( true );
connection.setDoInput( true );
connection.connect();
OutputStream os = connection.getOutputStream();
for ( int i = 0; i < 10; i++ ) {
   os.write( 1 );
   os.flush();
   Thread.sleep( 1000 );
}
os.close();
log.debug( "response:" + connection.getResponseCode() );
log.debug( "response:" + connection.getResponseMessage() );
connection.disconnect();

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



CometProcessor proxied through Apache httpd

2010-01-27 Thread Stephen Byrne
Is there a way to get CometProcessor to work when proxying through 
Apache httpd? Here is what I have tried:


I have an HttpServlet implementing CometProcessor.

When I have a Tomcat connector like this:



and I connect to it directly, everything works wonderfully - I get 
CometEvent.EventType.READ events as I send data from the client.



When I have a Tomcat connector like this:



and have Apache httpd proxy requests like this:

RewriteRule ^/path/to/servlet http://localhost:8911/path/to/servlet [P]

I get exactly one CometEvent.EventType.READ event with all of the data 
after I finish sending data from the client.



When I have a Tomcat connector like this:


and have Apache httpd proxy requests like this:

RewriteRule ^/path/to/servlet ajp://localhost:8909/path/to/servlet [P]

I get zero CometEvents and the client gets an HTTP error 405 (Method Not 
Allowed). I was hoping that AJP would work so I could try using 
ProxyPass with flushpackets=on, but the Apache documentation says that 
only works with AJP.



If I use Http11NioConnector instead of HTTP/1.1 and try to proxy with 
Apache, I get the same results as if I were using the HTTP/1.1 connector.


My client code (Java) is:

// Direct to Tomcat (HTTP)
//URL url = new URL( "http://server:8912/path/to/servlet"; );
// Apache proxies to Tomcat
URL url = new URL( "http://server/path/to/servlet"; );
HttpURLConnection connection = (HttpURLConnection)
  url.openConnection();
connection.setChunkedStreamingMode( 1 );
connection.setDoOutput( true );
connection.setDoInput( true );
connection.connect();
OutputStream os = connection.getOutputStream();
for ( int i = 0; i < 10; i++ ) {
  os.write( 1 );
  os.flush();
  Thread.sleep( 1000 );
}
os.close();
log.debug( "response:" + connection.getResponseCode() );
log.debug( "response:" + connection.getResponseMessage() );
connection.disconnect();

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org