Runs the {@code beforeMarshalling} method of any
{@code RequestHandler2}s associated with this client.

@param request the request passed in from the user
@return the (possibly different) request to marshal
336447
@SuppressWarnings("unchecked")
    protected final <T extends AmazonWebServiceRequest> T beforeMarshalling(
            T request) {

        T local = request;
        for (RequestHandler2 handler : requestHandler2s) {
            local = (T) handler.beforeMarshalling(local);
        }
        return local;
    }
928472
@Override
	public void handleRequest(final Request request) {
		if (!isInitialised()) {
			getOrCreateComponentModel().delegate = new SafetyContainerDelegate(UIContextHolder.
					getCurrent());
			setInitialised(true);
		}

		try {
			UIContext delegate = getComponentModel().delegate;
			UIContextHolder.pushContext(delegate);

			try {
				for (int i = 0; i < shim.getChildCount(); i++) {
					shim.getChildAt(i).serviceRequest(request);
				}

				delegate.doInvokeLaters();
			} finally {
				UIContextHolder.popContext();
			}
		} catch (final ActionEscape e) {
			// We don't want to catch ActionEscapes (e.g. ForwardExceptions)
			throw e;
		} catch (final Exception e) {
			if (isAjaxOrTargetedRequest(request)) {
				throw new SystemException(e.getMessage(), e);
			} else {
				setAttribute(ERROR_KEY, e);
			}
		}
	}
1027194
public static void bind(HttpServletRequest request) {
        if (request != null && threadLocal.get() != null) {
            throw new IllegalStateException("HttpServletRequestHolder.bind() called for a "
                    + "thread that already has a request associated with it. It's likely that the request "
                    + "was not correctly removed from the thread before it is put back into the thread pool.");
        }
        threadLocal.set(request);
    }
1233991
@Override
    public Request<DeleteRouteRequest> getDryRunRequest() {
        Request<DeleteRouteRequest> request = new DeleteRouteRequestMarshaller().marshall(this);
        request.addParameter("DryRun", Boolean.toString(true));
        return request;
    }
146375
public static ScopedRequest unwrapRequest( ServletRequest request )
    {
        // Unwrap the multipart request, if there is one.
        if ( request instanceof MultipartRequestWrapper )
        {
            request = ( ( MultipartRequestWrapper ) request ).getRequest();
        }

        while ( request instanceof ServletRequestWrapper )
        {
            if ( request instanceof ScopedRequest )
            {
                return ( ScopedRequest ) request;
            }
            else
            {
                request = ( ( ServletRequestWrapper ) request ).getRequest();
            }
        }
        
        return null;
    }
677813
@Override
    public Request<ModifySnapshotAttributeRequest> getDryRunRequest() {
        Request<ModifySnapshotAttributeRequest> request = new ModifySnapshotAttributeRequestMarshaller().marshall(this);
        request.addParameter("DryRun", Boolean.toString(true));
        return request;
    }
1292341
protected <T> Response<T> dispatchByMethod(Request<T> request) {
		HttpMethod method = HttpMethodUtil.retrieveMethod(request);

		switch (method) {
			case GET:
				return doGet(request);
			case POST:
				return doPost(request);
			case PUT:
				return doPut(request);
			case DELETE:
				return doDelete(request);
			default:
				throw new CommunicationErrorException(HttpStatus.Not_Implemented);
		}
	}
853030
@Override
	public void serviceRequest(final Request request) {
		// Get the expected session token
		UIContext uic = UIContextHolder.getCurrent();
		String expected = uic.getEnvironment().getSessionToken();

		// Get the session token from the request
		String got = request.getParameter(Environment.SESSION_TOKEN_VARIABLE);

		// Check tokens match (Both null if new session)
		// or processing a GET and no token
		if (Util.equals(expected, got) || (got == null && "GET".equals(request.getMethod()))) {
			// Process request
			getBackingComponent().serviceRequest(request);
		} else {  // Invalid token
			String msg;
			if (expected == null && got != null) {
				msg = "Session for token [" + got + "] is no longer valid or timed out.";
			} else {
				msg = "Wrong session token detected for servlet request. Expected token [" + expected
						+ "] but got token [" + got + "].";
			}
			LOG.error(msg);
			String message = I18nUtilities.format(uic.getLocale(),
					InternalMessages.DEFAULT_SESSION_TOKEN_ERROR);
			throw new SystemException(message);
		}

	}
10773
static void preHandleMultipartRequest(HttpServletRequest request)
        throws ServletException
    {
        MultipartRequestHandler multipartHandler = getCachedMultipartHandler(request);
        
        if (multipartHandler == null)
        {
            multipartHandler = getMultipartHandler(request);
            
            if (multipartHandler != null)
            {
                //
                // Run the request through the handler, and cache the handler in the outer request.
                //
                multipartHandler.handleRequest(request);
                HttpServletRequest outerRequest = ScopedServletUtils.getOuterRequest(request);
                outerRequest.setAttribute(PREHANDLED_MULTIPART_REQUEST_ATTR, multipartHandler);
            }
        }
    }
317394
public static void before(Object request, Object response) {
        /*
         * Use reflection to access the HttpServletRequest/Response as using the
         * true method signature caused ClassLoader issues.
         */
        Class<?> reqClass = request.getClass();
        try {
            /*
             * Retrieve the tracker from the request and increment nesting level
             */
            HttpRequestTracker tracker;
            Method getAttribute = reqClass.getMethod(GET_ATTRIBUTE, String.class);
            tracker = (HttpRequestTracker) (getAttribute.invoke(request, TRACKER_ATTRIBUTE));
            if (tracker == null) {
                tracker = new HttpRequestTracker();
            }
            tracker.increment();
            Method setAttribute = reqClass.getMethod(SET_ATTRIBUTE, String.class, Object.class);
            setAttribute.invoke(request, TRACKER_ATTRIBUTE, tracker);
        } catch (Exception e) {
            // Log any exception caused by our injected code
            System.err.println("Javametrics: Servlet callback exception: " + e.toString());
            e.printStackTrace();
        }
    }
309875
@Override
    public Request<DescribeSnapshotsRequest> getDryRunRequest() {
        Request<DescribeSnapshotsRequest> request = new DescribeSnapshotsRequestMarshaller().marshall(this);
        request.addParameter("DryRun", Boolean.toString(true));
        return request;
    }
535434
public static WrappedRequest wrap(final HttpServletRequest request) throws IOException {
        if (request instanceof WrappedRequest) {
            return (WrappedRequest) request;
        }

        return new WrappedRequest(request);
    }
877872
@Override
	public void serviceRequest(final Request request) {

		// Get expected step count
		UIContext uic = UIContextHolder.getCurrent();
		int expected = uic.getEnvironment().getStep();

		// Get step count from the request
		int got = StepCountUtil.getRequestStep(request);

		// Match (first time, both are zero)
		// or no Step count and processing a GET
		if (expected == got || (!StepCountUtil.isStepOnRequest(request) && "GET".equals(request.
				getMethod()))) {
			// Process Service Request
			getBackingComponent().serviceRequest(request);
		} else { // Invalid step
			LOG.warn(
					"SERVER: Wrong step detected. Expected step " + expected + " but got step " + got);

			// Redirect to error page
			if (StepCountUtil.isErrorRedirect()) {
				String url = StepCountUtil.getErrorUrl();
				LOG.warn("User will be redirected to an error page. URL: " + url);
				try {
					getResponse().sendRedirect(url);
				} catch (IOException e) {
					LOG.warn("Error trying to redirect for wrong step indicator.");
				}

				// Make sure the render phase is not processed
				throw new ActionEscape();
			} else {  // Warp to the future
				// Call handle step error
				WComponent application = getUI();
				if (application instanceof WApplication) {
					LOG.warn("The handleStepError method will be called on WApplication.");
					((WApplication) application).handleStepError();
				}

				LOG.warn("The render phase will warp the user back to the future.");
			}
		}
	}
588430
protected JsonRpcResponse execute(JsonRpcRequest request) {
        if (request == null) {
            return new JsonRpcResponse(null, JsonRpcError.parseError(null));
        }

        String serviceName = null;
        String methodName = request.getMethod();
        int lastIndex = methodName.lastIndexOf('.');
        if (lastIndex >= 0) {
            serviceName = methodName.substring(0, lastIndex);
            methodName = methodName.substring(lastIndex + 1);
        }

        ServiceEntry<?> serviceEntry = serviceRegistry.getService(serviceName);
        if (serviceEntry == null) {
            return new JsonRpcResponse(null, JsonRpcError.methodNotFoundError(null));
        }
        Set<Method> methods = serviceEntry.getMethods(methodName);
        if (methods == null || methods.isEmpty()) {
            return new JsonRpcResponse(null, JsonRpcError.methodNotFoundError(null));
        }

        String id = request.getId();
        Node[] params = request.getParams();
        Method method = findExecutableMethod(methods, params);
        if (method == null) {
            return new JsonRpcResponse(null, JsonRpcError.invalidParamsError(null));
        }

        Object service = serviceEntry.getService();
        Object[] args = getParameters(method, params);
        try {
            Object invokeValue = method.invoke(service, args);

            if (id == null) {
                return null;
            }

            Node result = jsonImpl.convert(invokeValue);
            return new JsonRpcResponse(id, result);
        } catch (Throwable t) {
            if (t instanceof InvocationTargetException) {
                t = ((InvocationTargetException) t).getTargetException();
            }
            LOG.debug("executing error : " + method, t);
            return new JsonRpcResponse(id, JsonRpcError.serverError(2, "Server error", t));
        }
    }
1213450
@Override
	public void handleRequest(final Request request) {
		if (!isDisabled()) {
			final SelectToggleModel model = getComponentModel();
			String requestParam = request.getParameter(getId());

			final State newValue;
			if ("all".equals(requestParam)) {
				newValue = State.ALL;
			} else if ("none".equals(requestParam)) {
				newValue = State.NONE;
			} else if ("some".equals(requestParam)) {
				newValue = State.SOME;
			} else {
				newValue = model.state;
			}

			if (!newValue.equals(model.state)) {
				setState(newValue);
			}
			if (!model.clientSide && model.target != null && !State.SOME.equals(newValue)) {
				// We need to change the selections *after* all components
				// Have updated themselves from the request, as they may change
				// their values when their handleRequest methods are called.
				invokeLater(new Runnable() {
					@Override
					public void run() {
						setSelections(model.target, State.ALL.equals(newValue));
					}
				});
			}
		}
	}
423469
@Override
    public Request<DescribeReservedInstancesModificationsRequest> getDryRunRequest() {
        Request<DescribeReservedInstancesModificationsRequest> request = new DescribeReservedInstancesModificationsRequestMarshaller().marshall(this);
        request.addParameter("DryRun", Boolean.toString(true));
        return request;
    }
511291
@Override
	public void serviceRequest(final Request request) {

		// Get trigger id
		String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
		if (triggerId == null) {
			throw new SystemException("No AJAX trigger id to on request");
		}

		// Find the Component for this trigger
		ComponentWithContext trigger = WebUtilities.getComponentById(triggerId,
				true);
		if (trigger == null) {
			throw new SystemException("No component found for AJAX trigger " + triggerId + ".");
		}
		WComponent triggerComponent = trigger.getComponent();

		// Check for an internal AJAX request (if client has flagged it as internal)
		boolean internal = request.getParameter(WServlet.AJAX_TRIGGER_INTERNAL_PARAM_NAME) != null;

		AjaxOperation ajaxOperation = null;
		if (internal) {
			if (!(triggerComponent instanceof AjaxInternalTrigger)) {
				throw new SystemException("AJAX trigger [" + triggerId + "] does not support internal actions.");
			}
			// Create internal operation
			ajaxOperation = new AjaxOperation(triggerId);
		} else {
			// Check for a registered AJAX operation
			ajaxOperation = AjaxHelper.getAjaxOperation(triggerId);

			// Override registered operation if it is a GET and trigger supports Internal AJAX
			// TODO This is only required until all components start using the Internal param flag
			if (ajaxOperation != null && "GET".equals(request.getMethod()) && triggerComponent instanceof AjaxInternalTrigger) {
				// Create internal operation
				ajaxOperation = new AjaxOperation(triggerId);
			}
		}

		// If no operation registered, check if the trigger supports internal AJAX then assume it is an Internal Action
		if (ajaxOperation == null && trigger.getComponent() instanceof AjaxInternalTrigger) {
			// Create internal operation
			ajaxOperation = new AjaxOperation(triggerId);
		}

		// No Valid operation
		if (ajaxOperation == null) {
			throw new SystemException("No AJAX operation has been registered for trigger " + triggerId + ".");
		}

		// Set current operation
		AjaxHelper.setCurrentOperationDetails(ajaxOperation, trigger);

		// Process Service Request
		super.serviceRequest(request);
	}