PRE: sorry i hate webmail, the previous msg was partially sended...
ridicoulous :) (missing part was in the middle..how is possible
hhehehe, stupid webmail)
Hello :)
I am here to report a issue in
Suspend/Resume cookie.
GWS version: grizzly-http-webserver-1.9.16-
20090512.183249-3.jar
test code is added to the mail, as a small
portion of my test, to better explain the problem
What's happen?
If
you set USERESUME= false (as the example)
you will see on output
----
RESUMING -->123
COOKIE SID -- 123
RESUMING -->123
COOKIE SID -- 123
RESUMING -->123
---
That is correct, since the RESUME request will set
the cookie to 123 :)
if you set USERESUME=true and you delete the
cookie you get
----
COOKIE SID -- 123
RESUMING -->123
COOKIE SID -- 123
RESUMING -->123
COOKIE SID -- 1233 ----> HOLY CRAP :)
RESUMING -->123
---
and after a while
15-mag-2009 12.11.08 com.sun.grizzly.http.
ProcessorTask invokeAdapter
GRAVE: HTTP Processing error
java.lang.
NullPointerException
at com.sun.grizzly.tcp.StaticResourcesAdapter.
service(StaticResourcesAdapter.java:126)
at com.sun.grizzly.tcp.http11.
GrizzlyAdapter.service(GrizzlyAdapter.java:123)
at com.sun.grizzly.
http.ProcessorTask.invokeAdapter(ProcessorTask.java:746)
at com.sun.
grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:655)
at com.
sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:905)
at com.
sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.
java:161)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter
(DefaultProtocolChain.java:135)
at com.sun.grizzly.
DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.
grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:
76)
at com.sun.grizzly.ProtocolChainContextTask.doCall
(ProtocolChainContextTask.java:53)
at com.sun.grizzly.
SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.
sun.grizzly.NIOContext.execute(NIOContext.java:510)
at com.sun.grizzly.
SelectorHandlerRunner.handleSelectedKey(SelectorHandlerRunner.java:357)
at com.sun.grizzly.SelectorHandlerRunner.handleSelectedKeys
(SelectorHandlerRunner.java:257)
at com.sun.grizzly.
SelectorHandlerRunner.doSelect(SelectorHandlerRunner.java:194)
at com.
sun.grizzly.SelectorHandlerRunner.run(SelectorHandlerRunner.java:129)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:886)
at java.util.concurrent.
ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.
lang.Thread.run(Thread.java:619)
Also notice, if you set PIZZA on the
code, you will see PIZZAA on the output (yeah, we like italian style,
and cliquet pizza pasta mandolino)
:)
----------TEST CASE---------
import com.sun.grizzly.http.embed.GrizzlyWebServer;
import com.sun.
grizzly.tcp.CompletionHandler;
import com.sun.grizzly.tcp.http11.
GrizzlyAdapter;
import com.sun.grizzly.tcp.http11.GrizzlyRequest;
import com.sun.grizzly.tcp.http11.GrizzlyResponse;
import com.sun.
grizzly.util.http.Cookie;
import com.eg.euler.ipc.http.SID;
import
java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* Created by IntelliJ IDEA.
* User: rama
* Date: 11-mag-2009
* Time: 13.33.19
* To change this
template use File | Settings | File Templates.
*/
public class Suspend
{
public Suspend() {
GrizzlyWebServer gws = new
GrizzlyWebServer();
gws.addGrizzlyAdapter(new SuspendTest(),new
String[]{"/"});
gws.getSelectorThread().setDisplayConfiguration
(true);
try {
gws.start();
} catch
(IOException e) {
e.printStackTrace(); //To change body of
catch statement use File | Settings | File Templates.
}
}
static LinkedBlockingQueue<GrizzlyResponse> queue = new
LinkedBlockingQueue<GrizzlyResponse>();
static {
new
Thread() {
public void run() {
while (true)
{
try {
GrizzlyResponse s =
queue.poll(1, TimeUnit.HOURS);
Thread.sleep
(1000);
s.resume();
} catch
(Exception e) {
}
}
}
}.start();
}
boolean USERESUME = true;
public
static void main(String args[]) {
new Suspend();
}
class SuspendTest extends GrizzlyAdapter {
public void service
(final GrizzlyRequest grizzlyRequest, final GrizzlyResponse
grizzlyResponse) {
//read the cookie!
Cookie[]
s = grizzlyRequest.getCookies();
if (s != null) {
for (Cookie value : s) {
System.
out.println("COOKIE "+value.getName()+" -- "+value.getValue());
}
}
if (!USERESUME) {
resume(grizzlyResponse,"123");
} else {
if (!grizzlyResponse.isSuspended()) {
grizzlyResponse.suspend(100000,this,new
CompletionHandler<SuspendTest>() {
public void
resumed(SuspendTest attachment) {
try {
attachment.resume(grizzlyResponse,"
123");
attachment.afterService
(grizzlyRequest,grizzlyResponse);
} catch
(Exception e) {
}
}
public void
cancelled(SuspendTest attachment) {
throw
new Error("Request cancelled?!?");
}
});
queue.add(grizzlyResponse);
return;
}
}
}
private void resume(GrizzlyResponse grizzlyResponse,String
SID) {
System.out.println("RESUMING -->"+SID);
grizzlyResponse.setHeader("Set-Cookie", "SID="+SID);
grizzlyResponse.setCharacterEncoding("UTF-8");
grizzlyResponse.setStatus(200);
grizzlyResponse.
setContentType("text/xml");
try {
grizzlyResponse.getWriter().print("<bla>hi</bla>");
} catch
(IOException e) {
e.printStackTrace(); //To change
body of catch statement use File | Settings | File Templates.
}
}
}
}
----------TEST CASE---------
E' arrivato Tiscali Mobile! Acquista la tua SIM Tiscali a soli €5 e scopri la semplicità e la convenienza del nuovo servizio per il tuo cellulare. Passa a Tiscali Mobile http://abbonati.tiscali.it/promo/tiscalimobile/