Ok, assuming that i am testing suspend/resume (probably you get it
since this is my only argument in this days)
let's report a strange
issue.
Using "grizzly-http-webserver-1.9.16-20090512.183249-3.jar"
(test code at the bottom of the mail)
Description :)
I have make a
simple test case that, basically, read the cookie of a request (print
it to stdout)
and then overwrite with a setcookie the req to "PIZZA"
(yeah we like italian stile, and the cliquet pasta pizza mandolino!)
Anyway :)
let's take a look to output, before with
boolean USERESUME =
false;
Note that i delete the cookie before each try! (and you should
also do it)
RESUMING -->PIZZA
COOKIE SID -- PIZZA
RESUMING -->PIZZA
COOKIE SID -- PIZZA
RESUMING -->PIZZA
COOKIE SID -- PIZZA
RESUMING --
>PIZZA
So far so good, now, set USERESUME=true (please delete cookie
before do a new try, if not, you will get COOKIE-SID as a first
request)
RESUMING -->PIZZA
COOKIE SID -- PIZZA
RESUMING -->PIZZA
RESUMING -->PIZZA
COOKIE SID -- PIZZAA ---> HO MY GOOD WHAT'S HAPPEN!!
A long pizzaaa :D
RESUMING -->PIZZA
Also, please notice, if we use
MACCARONI we will get MACCARONII as output :)
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)
------------------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,"PIZZA");
} else {
if (!grizzlyResponse.isSuspended()) {
grizzlyResponse.suspend(100000,this,new
CompletionHandler<SuspendTest>() {
public void
resumed(SuspendTest attachment) {
try {
attachment.resume(grizzlyResponse,"
PIZZA");
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.
}
}
}
}
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/