Lookup the response from the context.

@param request The context
@return The {@link NettyMutableHttpResponse}
425696
@Internal
    public static NettyMutableHttpResponse getOrCreate(NettyHttpRequest<?> request) {
        return getOr(request, io.micronaut.http.HttpResponse.ok());
    }
791087
public ListenableFuture<JsonRpcResponse> invoke(JsonRpcRequest request) {
    Service service = services.lookupByName(request.service());
    if (service == null) {
      JsonRpcError error = new JsonRpcError(HttpResponseStatus.BAD_REQUEST,
          "Unknown service: " + request.service());
      JsonRpcResponse response = JsonRpcResponse.error(error);
      return Futures.immediateFuture(response);
    }

    ServerMethod<? extends Message, ? extends Message> method = service.lookup(request.method());

    serverLogger.logMethodCall(service, method);

    if (method == null) {
      JsonRpcError error = new JsonRpcError(HttpResponseStatus.BAD_REQUEST,
          "Unknown method: " + request.service());
      JsonRpcResponse response = JsonRpcResponse.error(error);
      return Futures.immediateFuture(response);
    }

    return invoke(method, request.parameter(), request.id());
  }
685295
public static String getContextRequestUri(HttpServletRequest request) {
		String requestUri = request.getRequestURI();
		String contextPath = request.getContextPath();
		int cpLen = contextPath.length();
		if(cpLen > 0) {
			assert requestUri.startsWith(contextPath);
			return requestUri.substring(cpLen);
		} else {
			return requestUri;
		}
	}
131095
public static @Nullable GrailsWebRequest lookup(HttpServletRequest request) {
        GrailsWebRequest webRequest = (GrailsWebRequest) request.getAttribute(GrailsApplicationAttributes.WEB_REQUEST);
        return webRequest == null ? lookup() : webRequest;
    }
521171
protected Set<String> getParameters(HttpServletRequest request) {
        Set<String> parameters = new HashSet<String>();
        Enumeration<?> paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String parameter = (String) paramNames.nextElement();
            // Keep only first property.
            while (parameter.contains(".") || parameter.contains("[")) {
                if (parameter.contains(".")) {
                    parameter = parameter.substring(0, parameter.indexOf("."));
                }
                if (parameter.contains("[")) {
                    parameter = parameter.substring(0, parameter.indexOf("["));
                }
            }
            parameters.add(parameter);
        }
        return parameters;
    }
151631
public static HttpServletRequest getOuterRequest( HttpServletRequest request )
    {
        ScopedRequest scopedRequest = unwrapRequest( request );
        return scopedRequest != null ? scopedRequest.getOuterRequest() : request;
    }
817716
protected EvaluationContext getEvaluationContext(WebRequest request) {
        final HttpServletRequest httpRequest =
                this.portalRequestUtils.getOriginalPortalRequest(request);
        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpRequest);
        final IPerson person = userInstance.getPerson();

        final SpELEnvironmentRoot root = new SpELEnvironmentRoot(request, person);
        final StandardEvaluationContext context = new StandardEvaluationContext(root);
        context.setBeanResolver(this.beanResolver);
        return context;
    }
601368
public GetCacheQuotaResponse getCacheQuota(GetCacheQuotaRequest request) {
        InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET, CACHE, "quota");
        return this.invokeHttpClient(internalRequest, GetCacheQuotaResponse.class);
    }
1146645
public GetDomainCacheTTLResponse getDomainCacheTTL(GetDomainCacheTTLRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        InternalRequest internalRequest = createRequest(request, HttpMethodName.GET, DOMAIN, request.getDomain(), "config");
        internalRequest.addParameter("cacheTTL","");
        return invokeHttpClient(internalRequest, GetDomainCacheTTLResponse.class);
    }
833304
public GetWaterMarkResponse getWaterMark(GetWaterMarkRequest request) {
        checkStringNotEmpty(request.getWatermarkId(), "The parameter watermarkId should NOT be null or empty string.");
        InternalRequest internalRequest =
                createRequest(HttpMethodName.GET, request, WATER_MARK, request.getWatermarkId());
        
        return invokeHttpClient(internalRequest, GetWaterMarkResponse.class);
    }
633090
protected String getMethod(HttpServletRequest request) {
        String uri = request.getRequestURI();
        String q = uri.substring((request.getContextPath()+request.getServletPath()).length()+1);
        int i = q.indexOf(".");
        String method = null;
        if(i>0){
            method = q.substring(i+1);
        }
        return method;
    }
284878
protected Response executeRequest(Request request)
    {
        try
        {
            com.squareup.okhttp.Request httpRequest = buildHttpRequest(request);

            if(logger.isInfoEnabled())
                logger.info("Sending request: {} {}",httpRequest.method(),httpRequest.urlString());

            if(logger.isDebugEnabled() && request.getRequestMethod().isBodyRequest())
            {
                Buffer buffer = new Buffer();
                httpRequest.body().writeTo(buffer);
                if(maxLoggedBodySize == -1 || buffer.size() <= maxLoggedBodySize )
                    logger.debug("Request body: {}", buffer.readUtf8());
                else
                    logger.debug("Request body not captured: too large. ");
            }

            if(logger.isTraceEnabled())
                logger.trace("Request headers: {}",httpRequest.headers().toString());

            Response response = client.newCall(httpRequest).execute();

            if(response.code() == HttpURLConnection.HTTP_UNAUTHORIZED && authorizationFactory != null
                    && authorizationFactory.retryOnAuthenticationError())
            {
                if(authorizationFactory instanceof ResettableAuthorizationFactory)
                    ((ResettableAuthorizationFactory) authorizationFactory).reset();

                response = client.newCall(httpRequest).execute();
            }

            logger.info("Response code: {}",response.code());

            if(logger.isTraceEnabled())
                logger.trace("Response headers: {}",response.headers().toString());

            if(logger.isDebugEnabled())
            {
                ByteArrayOutputStream copy = new ByteArrayOutputStream();
                copy(response.body().byteStream(),copy);
                response = response.newBuilder().body(ResponseBody.create(response.body().contentType(),copy.toByteArray())).build();

                if(maxLoggedBodySize == -1 || copy.size() <= maxLoggedBodySize)
                    logger.debug("Response body: {}",copy.toString());
                else
                    logger.debug("Response body not captured: too large.");
            }
            if (response.code() >= HttpURLConnection.HTTP_BAD_REQUEST)
            {
                throw readException(response);
            }

            return response;
        }
        catch (IOException e)
        {
            throw new ClientConnectionException("Error calling service.",e);
        }

    }
293246
public GetStatHttpCodeResponse getStatHttpCode(GetStatHttpCodeRequest request) {
        InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET, STAT, "httpcode");
        
        if (request.getStartTime() != null) {
            internalRequest.addParameter("startTime", DateUtils.formatAlternateIso8601Date(request.getStartTime()));
        }
        
        if (request.getEndTime() != null) {
            internalRequest.addParameter("endTime", DateUtils.formatAlternateIso8601Date(request.getEndTime()));
        }
        
        if (request.getDomain() != null) {
            internalRequest.addParameter("domain", request.getDomain());
        }
        
        if (request.getPeriod() != null) {
            internalRequest.addParameter("period", String.valueOf(request.getPeriod()));
        }
        
        if (request.isWithRegion()) {
            internalRequest.addParameter("withRegion", "");
        }
        
        return this.invokeHttpClient(internalRequest, GetStatHttpCodeResponse.class);
    }
182645
public JobResult jobResult(HttpRequestBase request) {
        JobResult jobResult = new JobResult();
        try {
            HttpResponse response = httpClient.execute(request);
            if (response != null) {
                jobResult.responseCode = response.getStatusLine().getStatusCode();
                HttpEntity responseEntity = response.getEntity();
                long contentLength = responseEntity.getContentLength();
                if (contentLength < 0) {
                    contentLength = 0;
                }
                ByteArrayOutputStream bOut = new ByteArrayOutputStream((int) contentLength);
                InputStream in = responseEntity.getContent();
                int read;
                byte[] tmpBuf = new byte[8192];
                while ((read = in.read(tmpBuf)) != -1) {
                    bOut.write(tmpBuf, 0, read);
                }
                in.close();
                bOut.close();
                jobResult.response = bOut.toByteArray();
                switch (jobResult.responseCode) {
                case 200:
                    jobResult.parse(xmlValidator);
                    in = new ByteArrayInputStream(jobResult.response);
                    jobResult.job = Job.unmarshall(in);
                    in.close();
                    jobResult.status = ResultStatus.OK;
                    break;
                case 404:
                    jobResult.status = ResultStatus.NOT_FOUND;
                    break;
                case 500:
                    jobResult.status = ResultStatus.INTERNAL_ERROR;
                    break;
                default:
                    jobResult.status = ResultStatus.NO_RESPONSE;
                    break;
                }
            } else {
                jobResult.status = ResultStatus.NO_RESPONSE;
            }
        } catch (NoHttpResponseException e) {
            jobResult.status = ResultStatus.OFFLINE;
            jobResult.t = e;
        } catch (ClientProtocolException e) {
            jobResult.status = ResultStatus.RESPONSE_EXCEPTION;
            jobResult.t = e;
        } catch (IOException e) {
            jobResult.status = ResultStatus.RESPONSE_EXCEPTION;
            jobResult.t = e;
        } catch (JAXBException e) {
            jobResult.status = ResultStatus.JAXB_EXCEPTION;
            jobResult.t = e;
        } catch (XMLStreamException e) {
            jobResult.status = ResultStatus.XML_EXCEPTION;
            jobResult.t = e;
        }
        return jobResult;
    }
1338909
public GetStreamResponse getStream(GetStreamRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");

        checkStringNotEmpty(request.getPlayDomain(), "playDomain should NOT be empty.");
        checkStringNotEmpty(request.getApp(), "App should NOT be empty.");
        checkStringNotEmpty(request.getStream(), "Stream should NOT be empty.");

        InternalRequest internalRequest = createRequest(HttpMethodName.GET,
                request, LIVE_DOMAIN, request.getPlayDomain(),
                LIVE_APP, request.getApp(),
                LIVE_STREAM, request.getStream());
        return invokeHttpClient(internalRequest, GetStreamResponse.class);
    }
563430
public <T extends ApiObject> EntityResponse<T> query(Request<T> request)
    {
        return executeRequest(request, objectMapper.getTypeFactory()
                .constructParametrizedType(EntityResponse.class, EntityResponse.class, request.getEntityType()));
    }
239558
public static synchronized RequestBundle get(SlingHttpServletRequest request) {
        RequestBundle instance = (RequestBundle) request.getAttribute(ATTRIBUTE_KEY);
        if (instance == null) {
            instance = new RequestBundle(request);
            request.setAttribute(ATTRIBUTE_KEY, instance);
        }
        return instance;
    }