/*
execute request coming from the servlet engine in a separate thread or not
347131
public boolean exeRequestAsync() {
	if (asyncReqHandle == null) asyncReqHandle = Caster.toBoolean(SystemUtil.getSystemPropOrEnvVar("lucee.async.request.handle", null), Boolean.FALSE);
	return asyncReqHandle;
    }
1122178
protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        // update counter
        numRequests++;

        try
        {
            // read request:
            LockManagerRemoteImpl.LockInfo info = (LockManagerRemoteImpl.LockInfo) buildObjectFromRequest(request);
            Object result = null;
            // now execute the command specified by the selector
            try
            {
                switch(info.methodName)
                {
                    case LockManagerRemoteImpl.METHOD_READ_LOCK:
                        {
                            result = new Boolean(lockmanager.readLock(info.key, info.resourceId, info.isolationLevel));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_RELEASE_SINGLE_LOCK:
                        {
                            result = new Boolean(lockmanager.releaseLock(info.key, info.resourceId));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_RELEASE_LOCKS:
                        {
                            lockmanager.releaseLocks(info.key);
                            result = Boolean.TRUE;
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_WRITE_LOCK:
                        {
                            result = new Boolean(lockmanager.writeLock(info.key, info.resourceId,
                                    info.isolationLevel));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_UPGRADE_LOCK:
                        {
                            result = new Boolean(lockmanager.upgradeLock(info.key, info.resourceId, info.isolationLevel));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_CHECK_READ:
                        {
                            result = new Boolean(lockmanager.hasRead(info.key, info.resourceId));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_CHECK_WRITE:
                        {
                            result = new Boolean(lockmanager.hasWrite(info.key, info.resourceId));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_CHECK_UPGRADE:
                        {
                            result = new Boolean(lockmanager.hasUpgrade(info.key, info.resourceId));
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_LOCK_INFO:
                        {
                            result = lockmanager.getLockInfo();
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_LOCK_TIMEOUT:
                        {
                            result = new Long(lockmanager.getLockTimeout());
                            break;
                        }
                    case LockManagerRemoteImpl.METHOD_BLOCK_TIMEOUT:
                        {
                            result = new Long(lockmanager.getBlockTimeout());
                            break;
                        }
//                    case LockManagerRemoteImpl.METHOD_LOCK_TIMEOUT_SET:
//                        {
//                            lockmanager.setLockTimeout(info.lockTimeout);
//                            break;
//                        }
//
//                    case LockManagerRemoteImpl.METHOD_BLOCK_TIMEOUT_SET:
//                        {
//                            lockmanager.setBlockTimeout(info.blockTimeout);
//                            break;
//                        }
                    default :
                        {
                            throw new LockRuntimeException("Unknown command:" + info.methodName);
                        }
                }
            }
            catch(RuntimeException e)
            {
                result = new LockRuntimeException("Error while invoke specified method in servlet.", e);
            }

            ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
            oos.writeObject(result);
            oos.flush();
            oos.close();
        }
        catch(Throwable t)
        {
            lastError = t;
            t.printStackTrace();
        }
    }
1085153
function execute(req, res) {
  var proxy = req.exec ? req.exec.proxy : this.proxy;
  res.send(null, proxy(req, res));
}
1357425
@Override
  protected boolean requestInvoke(FrameBuffer frameBuffer) {
    Runnable invocation = getRunnable(frameBuffer);
    if (invoker != null) {
      try {
        invoker.execute(invocation);
        return true;
      } catch (RejectedExecutionException rx) {
        LOGGER.warn("ExecutorService rejected execution!", rx);
        return false;
      }
    } else {
      // Invoke on the caller's thread
      invocation.run();
      return true;
    }
  }
906772
public boolean execute(Context context) throws Exception
   {
      GenericWebAppContext webCtx = (GenericWebAppContext)context;
      HttpServletResponse response = webCtx.getResponse();
      HttpServletRequest request = webCtx.getRequest();

      // standalone request?
      String servletPath = request.getPathInfo();
      boolean doClose = true;
      // or included?
      if (servletPath == null)
      {
         servletPath = (String)request.getAttribute("javax.servlet.include.path_info");
         if (servletPath != null)
            doClose = false;
      }

      Node file = (Node)webCtx.getSession().getItem((String)context.get(pathKey));
      file.refresh(false);

      Node content = null;

      try
      {
         content = JCRCommandHelper.getNtResourceRecursively(file);
      }
      catch (ItemNotFoundException e)
      {
         // Patch for ver 1.0 back compatibility
         // as exo:image was not primary item
         if (file.isNodeType("exo:article"))
         {
            try
            {
               content = file.getNode("exo:image");
            }
            catch (PathNotFoundException e1)
            {
               throw e; // new ItemNotFoundException("No nt:resource node found at
               // "+file.getPath()+" nor primary items of nt:resource type
               // ");
            }
         }
         else
         {
            throw e; // new ItemNotFoundException("No nt:resource node found at
            // "+file.getPath()+" nor primary items of nt:resource type
            // ");
         }

      }

      // if(file.isNodeType("nt:file")) {
      // content = file.getNode("jcr:content");
      // } else if(file.isNodeType("exo:article")) {
      // content = file.getNode("exo:image");
      // } else
      // throw new Exception("Invalid node type, expected nt:file or exo:article,
      // have "+file.getPrimaryNodeType().getName()+" at "+file.getPath());

      Property data;
      try
      {
         data = content.getProperty("jcr:data");
      }
      catch (PathNotFoundException e)
      {
         throw new PathNotFoundException("No jcr:data node found at " + content.getPath());
      }

      String mime = content.getProperty("jcr:mimeType").getString();
      String encoding =
         content.hasProperty("jcr:encoding") ? content.getProperty("jcr:encoding").getString() : DEFAULT_ENCODING;

      MimeTypeResolver resolver = new MimeTypeResolver();
      String fileName = file.getName();
      String fileExt = "";
      if (fileName.lastIndexOf(".") > -1)
      {
         fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
         fileName = fileName.substring(0, fileName.lastIndexOf("."));
      }
      String mimeExt = resolver.getExtension(mime);
      if (fileExt == null || fileExt.length() == 0)
      {
         fileExt = mimeExt;
      }
      response.setContentType(mime + "; charset=" + encoding);
      String parameter = (String)context.get("cache-control-max-age");
      String cacheControl = parameter == null ? "" : "public, max-age=" + parameter;
      response.setHeader("Cache-Control: ", cacheControl);
      response.setHeader("Pragma: ", ""); // leave blank to avoid IE errors
      response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "." + fileExt + "\"");

      if (mime.startsWith("text"))
      {
         PrintWriter out = response.getWriter();
         out.write(data.getString());
         out.flush();
         if (doClose)
            out.close();
      }
      else
      {
         InputStream is = data.getStream();
         byte[] buf = new byte[is.available()];
         is.read(buf);
         ServletOutputStream os = response.getOutputStream();
         os.write(buf);
         os.flush();
         if (doClose)
            os.close();
      }

      return true;
   }
1037429
private void executeGetOperation(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ClassNotFoundException {
        if (request.getContentLength() > 0) {
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(request.getInputStream()));
            CommandPayload paylod = (CommandPayload) input.readObject();
            events.put(currentCall, paylod);
        } else {
            if (events.containsKey(currentCall) && !events.get(currentCall).isExecuted()) {
                response.setStatus(HttpServletResponse.SC_OK);
                ObjectOutputStream output = new ObjectOutputStream(response.getOutputStream());
                output.writeObject(events.remove(currentCall));
                output.flush();
                output.close();
            } else {
                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            }
        }
    }
219757
function execute(req, res) {
  res.send(null, this.info.toString(req.args[0] ? '' + req.args[0] : null));
}
175971
public void invoke(HttpServletRequest req, HttpServletResponse rsp, Object root, String url) throws IOException, ServletException {
        RequestImpl sreq = new RequestImpl(this, req, new ArrayList<AncestorImpl>(), new TokenList(url));
        RequestImpl oreq = CURRENT_REQUEST.get();
        CURRENT_REQUEST.set(sreq);

        ResponseImpl srsp = new ResponseImpl(this, rsp);
        ResponseImpl orsp = CURRENT_RESPONSE.get();
        CURRENT_RESPONSE.set(srsp);

        try {
            invoke(sreq,srsp,root);
        } finally {
            CURRENT_REQUEST.set(oreq);
            CURRENT_RESPONSE.set(orsp);
        }
    }
449705
public void doProcess(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        ServletTask servletTask = new ServletTask(this, BasicServlet.SERVLET_TYPE.HTML);
        try {
            this.addBrowserProperties(req, servletTask);
            servletTask.doProcess(this, req, res, null);
        } catch (ServletException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        } finally {
            servletTask.free();
        }
    }
620643
public void processRequest(RequestContext context) throws Exception {
        if (processorIterator.hasNext()){
            RequestSecurityProcessor processor = processorIterator.next();

            logger.debug("Executing processor {}", processor);

            processor.processRequest(context, this);
        }
    }
284233
private <T> T execute(String url, Class<T> returnType, Object requestObject) throws Exception {
        URLConnection connection = new URL(url).openConnection();
        if (!(connection instanceof HttpURLConnection)) {
            throw new IllegalStateException("Not an http connection! " + connection);
        }
        HttpURLConnection httpConnection = (HttpURLConnection) connection;
        httpConnection.setUseCaches(false);
        httpConnection.setDefaultUseCaches(false);
        httpConnection.setDoInput(true);

        /*
         * With followRedirects enabled, simple URL redirects work as expected. But with port redirects (http->https)
         * followRedirects doesn't work and a HTTP 302 code is returned instead (ARQ-1365).
         *
         * In order to handle all redirects in one place, followRedirects is set to false and all HTTP 302 response codes are
         * treated accordingly within the execute method.
         */
        httpConnection.setInstanceFollowRedirects(false);

        try {

            if (requestObject != null) {
                httpConnection.setRequestMethod("POST");
                httpConnection.setDoOutput(true);
                httpConnection.setRequestProperty("Content-Type", "application/octet-stream");
            }

            if (requestObject != null) {
                ObjectOutputStream ous = new ObjectOutputStream(httpConnection.getOutputStream());
                try {
                    ous.writeObject(requestObject);
                } catch (Exception e) {
                    throw new RuntimeException("Error sending request Object, " + requestObject, e);
                } finally {
                    ous.flush();
                    ous.close();
                }
            }

            try {
                httpConnection.getResponseCode();
            } catch (ConnectException e) {
                return null; // Could not connect
            }
            if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                ObjectInputStream ois = new ObjectInputStream(httpConnection.getInputStream());
                Object o;
                try {
                    o = ois.readObject();
                } finally {
                    ois.close();
                }

                if (!returnType.isInstance(o)) {
                    throw new IllegalStateException(
                        "Error reading results, expected a " + returnType.getName() + " but got "
                            + o);
                }
                return returnType.cast(o);
            } else if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
                return null;
            } else if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) {
                String redirectUrl = httpConnection.getHeaderField("Location");
                return execute(redirectUrl, returnType, requestObject);
            } else if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) {
                throw new IllegalStateException("Error launching test at " + url + ". " + "Got "
                    + httpConnection.getResponseCode() + " (" + httpConnection.getResponseMessage() + ")");
            }
        } finally {
            httpConnection.disconnect();
        }
        return null;
    }
677002
public void execute() throws Exception {
        ActionRequest request = requestBuilder.request();

        //todo: maby change to instanceof multi?
        if(requestBuilder instanceof JoinRequestBuilder){
            executeJoinRequestAndSendResponse();
        }
		else if (request instanceof SearchRequest) {
			client.search((SearchRequest) request, new RestStatusToXContentListener<SearchResponse>(channel));
		} else if (requestBuilder instanceof SqlElasticDeleteByQueryRequestBuilder) {
            throw new UnsupportedOperationException("currently not support delete on elastic 2.0.0");
        }
        else if(request instanceof GetIndexRequest) {
            this.requestBuilder.getBuilder().execute( new GetIndexRequestRestListener(channel, (GetIndexRequest) request));
        }


		else {
			throw new Exception(String.format("Unsupported ActionRequest provided: %s", request.getClass().getName()));
		}
	}
269556
private HttpResponse execute(HttpClient client, HttpUriRequest request) throws IOException {
        if (localContext != null) {
            return client.execute(request, localContext);
        } else {
            return client.execute(request);
        }
    }
664082
public void doProcess(BasicServlet servlet, HttpServletRequest req, HttpServletResponse res, PrintWriter out) 
        throws ServletException, IOException
    {
        // Override this
    }
797175
public void handleRequest(ServletRequest req, ServletResponse res)
                    throws Exception
    {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)){
            logger.logp(Level.FINE, CLASS_NAME,"handleRequest", "should not enter invoker extension processor to handle request");
        }
        //even though we should have just called getServletWrapper, this time we pass true to do the error handling.
        //Before we passed it false in case the filters are invoked and give us a new url-pattern.
        IServletWrapper s = getServletWrapper(req,	res,true);
        if (s!=null){
            s.handleRequest(req,	res);
        } else if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)){
            logger.logp(Level.FINE, CLASS_NAME,"handleRequest", "unable to find servlet wrapper to handle request");
        }

        return;
    }
995190
@Override
   public void execute() {
       if(log.isDebugEnabled()) {
           log.debug("execute() starting for " + pages.size() + " pages.");
       }

       try {
           if (uriRoot == null) {
               if( pages.size() == 0 ) {
                   throw new JasperException(
                       Localizer.getMessage("jsp.error.jspc.missingTarget"));
               }
               String firstJsp = pages.get( 0 );
               File firstJspF = new File( firstJsp );
               if (!firstJspF.exists()) {
                   throw new JasperException(
                       Localizer.getMessage("jspc.error.fileDoesNotExist",
                                            firstJsp));
               }
               locateUriRoot( firstJspF );
           }

           if (uriRoot == null) {
               throw new JasperException(
                   Localizer.getMessage("jsp.error.jspc.no_uriroot"));
           }

           File uriRootF = new File(uriRoot);
           if (!uriRootF.isDirectory()) {
               throw new JasperException(
                   Localizer.getMessage("jsp.error.jspc.uriroot_not_dir"));
           }

           if(context == null) {
               initServletContext(initClassLoader());
           }

           // No explicit pages, we'll process all .jsp in the webapp
           if (pages.size() == 0) {
               scanFiles(uriRootF);
           }

           initWebXml();
           
           log.info("compiling with " + getThreads() + " threads");
           ExecutorService executor = Executors.newFixedThreadPool(getThreads());
           final List<JasperException> errorCollector = Collections.synchronizedList(new ArrayList<JasperException>());
           
           for (String nextjsp : pages) {            
               File fjsp = new File(nextjsp);
               if (!fjsp.isAbsolute()) {
                   fjsp = new File(uriRootF, nextjsp);
               }
               if (!fjsp.exists()) {
                   if (log.isWarnEnabled()) {
                       log.warn
                           (Localizer.getMessage
                            ("jspc.error.fileDoesNotExist", fjsp.toString()));
                   }
                   continue;
               }
               String s = fjsp.getAbsolutePath();
               if (s.startsWith(uriRoot)) {
                   nextjsp = s.substring(uriRoot.length());
               }
               if (nextjsp.startsWith("." + File.separatorChar)) {
                   nextjsp = nextjsp.substring(2);
               }
               
               final String jspToCompile = nextjsp;
               executor.execute(new Runnable() {
                public void run() {
                    try {
                        processFile(jspToCompile);
                    } catch (JasperException je) {
                        errorCollector.add(je);
                    }
                }
            });
           }
           
           executor.shutdown();
           executor.awaitTermination(compilationTimeoutMinutes, TimeUnit.MINUTES);
           
           if (errorCollector.size() > 0) {
               throwBuildException(errorCollector);
           }

           completeWebXml();

           if (addWebXmlMappings) {
               mergeIntoWebXml();
           }

       } catch (IOException ioe) {
           throw new BuildException(ioe);

       } catch (JasperException je) {
           throwBuildException(Arrays.asList(je));
       } catch (InterruptedException e) {
        throw new BuildException(e);
       } finally {
           if (loader != null) {
               LogFactory.release(loader);
           }
       }
   }
256800
@Override
	public void handleRequest(final Request request) {
		if (isDisabled()) {
			// Protect against client-side tampering of disabled/read-only fields.
			return;
		}

		if (isMenuPresent(request)) {
			String requestValue = request.getParameter(getId());

			if (requestValue != null) {
				// Only process on a POST
				if (!"POST".equals(request.getMethod())) {
					LOG.warn("Menu item on a request that is not a POST. Will be ignored.");
					return;
				}

				// Execute associated action, if set
				final Action action = getAction();

				if (action != null) {
					final ActionEvent event = new ActionEvent(this, this.getActionCommand(), this.
							getActionObject());

					Runnable later = new Runnable() {
						@Override
						public void run() {
							action.execute(event);
						}
					};

					invokeLater(later);
				}
			}
		}
	}