public void forceQueRequest(Request request) { synchronized (lock) { if (blockingRequest == null) { requestQueue.add(request); channel.writeAndFlush(request.getRequest()); if (request.isBlocking()) { blockingRequest = new BlockingRequestInProgress(request); request .getToComplete() .addListener( new DbListener<Object>() { @Override public void onCompletion(DbFuture<Object> future) { blockingRequest.continueWithRequests(); } }); } } else { if (blockingRequest.unblockBy(request)) { requestQueue.add(request); channel.writeAndFlush(request.getRequest()); } else { blockingRequest.add(request); } } } }
private void forceCloseOnPendingRequests() { for (Request request : requestQueue) { if (request.getRequest().tryCancel()) { request .getToComplete() .trySetException(new DbSessionClosedException("Connection is closed")); } } if (null != blockingRequest) { for (Request waitingRequest : blockingRequest.waitingRequests) { if (waitingRequest.getRequest().tryCancel()) { waitingRequest .getToComplete() .trySetException(new DbSessionClosedException("Connection is closed")); } } } }
public Request dequeRequest() { synchronized (lock) { final Request request = requestQueue.poll(); if (logger.isDebugEnabled()) { logger.debug("Dequeued request: {}", request); } if (request.getRequest().wasCancelled()) { if (logger.isDebugEnabled()) { logger.debug("Request has been cancelled: {}", request); } return dequeRequest(); } return request; } }
public static void main(String[] args) throws Exception { LogFactory.getFactory() .setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); WebClient client = new WebClient(); client.getOptions().setCssEnabled(false); client.getOptions().setJavaScriptEnabled(false); client.getOptions().setThrowExceptionOnFailingStatusCode(false); client.getOptions().setThrowExceptionOnScriptError(false); // HtmlPage page = client.getPage(url); // String source = page.getWebResponse().getContentAsString(); // p(source); Request r = new Request(); r.getRequest(client); while (true) ; }
public void invoke(Request request, Response response, ValveContext valveContext) throws IOException, ServletException { SimpleWrapper wrapper = (SimpleWrapper) getContainer(); ServletRequest sreq = request.getRequest(); ServletResponse sres = response.getResponse(); Servlet servlet = null; HttpServletRequest hreq = null; if (sreq instanceof HttpServletRequest) hreq = (HttpServletRequest) sreq; HttpServletResponse hres = null; if (sres instanceof HttpServletResponse) hres = (HttpServletResponse) sres; // Allocate a servlet instance to process this request try { servlet = wrapper.allocate(); if (hres != null && hreq != null) { servlet.service(hreq, hres); } else { servlet.service(sreq, sres); } } catch (ServletException e) { } }
public RequestExecutor execute(Request r) throws ClientProtocolException, IOException { clear(); r.customizeIfNeeded(); request = r.getRequest(); // Optionally setup for basic authentication if (r.getUsername() != null) { httpClient .getCredentialsProvider() .setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(r.getUsername(), r.getPassword())); // And add request interceptor to have preemptive authentication httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); } else { // Make sure existing credentials are not reused - but looks like we // cannot set null as credentials httpClient .getCredentialsProvider() .setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(getClass().getName(), getClass().getSimpleName())); httpClient.removeRequestInterceptorByClass(PreemptiveAuthInterceptor.class); } // Setup redirects httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, r.getRedirects()); // Execute request response = httpClient.execute(request); entity = response.getEntity(); if (entity != null) { consumeEntity(); } return this; }
private void request() { Socket soc = sm.openSocket(); Request rqnrs = new Request(); rqnrs.getRequest(soc, header); bis = rqnrs.getBufferedInputStream(soc); }