Introduced HttpCookieStore.Empty to disable cookies in HttpClient and in the websocket client.

This commit is contained in:
Simone Bordet 2012-12-13 18:04:27 +01:00
parent a386a46045
commit 127f4978a9
1 changed files with 18 additions and 41 deletions

View File

@ -25,7 +25,6 @@ import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@ -62,7 +61,7 @@ public class AsyncRestServlet extends AbstractRestServlet
public void init(ServletConfig servletConfig) throws ServletException
{
super.init(servletConfig);
_client = new HttpClient();
try
@ -79,19 +78,19 @@ public class AsyncRestServlet extends AbstractRestServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Long start=System.nanoTime();
// Do we have results yet?
Queue<Map<String, String>> results = (Queue<Map<String, String>>) request.getAttribute(RESULTS_ATTR);
// If no results, this must be the first dispatch, so send the REST request(s)
if (results==null)
{
// define results data structures
final Queue<Map<String, String>> resultsQueue = new ConcurrentLinkedQueue<Map<String,String>>();
final Queue<Map<String, String>> resultsQueue = new ConcurrentLinkedQueue<>();
request.setAttribute(RESULTS_ATTR, results=resultsQueue);
// suspend the request
// This is done before scheduling async handling to avoid race of
// This is done before scheduling async handling to avoid race of
// dispatch before startAsync!
final AsyncContext async = request.startAsync();
async.setTimeout(30000);
@ -99,7 +98,7 @@ public class AsyncRestServlet extends AbstractRestServlet
// extract keywords to search for
String[] keywords=request.getParameter(ITEMS_PARAM).split(",");
final AtomicInteger outstanding=new AtomicInteger(keywords.length);
// Send request each keyword
for (final String item:keywords)
{
@ -119,19 +118,19 @@ public class AsyncRestServlet extends AbstractRestServlet
}
});
}
// save timing info and return
request.setAttribute(START_ATTR, start);
request.setAttribute(DURATION_ATTR, new Long(System.nanoTime() - start));
request.setAttribute(DURATION_ATTR, System.nanoTime() - start);
return;
}
// We have results!
// Generate the response
String thumbs = generateThumbs(results);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head>");
@ -145,17 +144,17 @@ public class AsyncRestServlet extends AbstractRestServlet
long total=now-start0;
long generate=now-start;
long thread=initial+generate;
out.print("<b>Asynchronous: "+request.getParameter(ITEMS_PARAM)+"</b><br/>");
out.print("Total Time: "+ms(total)+"ms<br/>");
out.print("Thread held (<span class='red'>red</span>): "+ms(thread)+"ms (" + ms(initial) + " initial + " + ms(generate) + " generate )<br/>");
out.print("Async wait (<span class='green'>green</span>): "+ms(total-thread)+"ms<br/>");
out.println("<img border='0px' src='asyncrest/red.png' height='20px' width='"+width(initial)+"px'>"+
"<img border='0px' src='asyncrest/green.png' height='20px' width='"+width(total-thread)+"px'>"+
"<img border='0px' src='asyncrest/red.png' height='20px' width='"+width(generate)+"px'>");
out.println("<hr />");
out.println(thumbs);
out.println("</small>");
@ -163,21 +162,11 @@ public class AsyncRestServlet extends AbstractRestServlet
out.close();
}
private abstract class AsyncRestRequest implements Response.Listener
private abstract class AsyncRestRequest extends Response.Listener.Empty
{
final Utf8StringBuilder _content = new Utf8StringBuilder();
AsyncRestRequest()
{
}
@Override
public void onBegin(Response response)
{
}
@Override
public void onHeaders(Response response)
{
}
@ -188,19 +177,9 @@ public class AsyncRestServlet extends AbstractRestServlet
_content.append(bytes,0,bytes.length);
}
@Override
public void onSuccess(Response response)
{
}
@Override
public void onFailure(Response response, Throwable failure)
{
}
@Override
public void onComplete(Result result)
{
{
// extract auctions from the results
Map<String,?> query = (Map<String,?>) JSON.parse(_content.toString());
Object[] auctions = (Object[]) query.get("Item");
@ -215,14 +194,12 @@ public class AsyncRestServlet extends AbstractRestServlet
abstract void onAuctionFound(Map<String,String> details);
abstract void onComplete();
};
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request, response);
}
}