private boolean hasRequestContextTimeout(RequestContext requestContext) { Object requestTimeout = requestContext.getLocalAttr(R2Constants.REQUEST_TIMEOUT); return (requestTimeout instanceof Number) && (((Number)requestTimeout).intValue() > 0); }
private void verifyRequestContextTimeout(Request<?> request, int timeout, Boolean ignoreIfHigher) { assertTrue(_capturingRestClient.getCapturedRequestContexts().containsKey(request)); RequestContext context = _capturingRestClient.getCapturedRequestContexts().get(request); Number contextTimeout = (Number)context.getLocalAttr(R2Constants.REQUEST_TIMEOUT); assertNotNull(contextTimeout); assertEquals(contextTimeout.intValue(), timeout); if (ignoreIfHigher == null) { assertNull(context.getLocalAttr(R2Constants.REQUEST_TIMEOUT_IGNORE_IF_HIGHER_THAN_DEFAULT)); } else { assertEquals(context.getLocalAttr(R2Constants.REQUEST_TIMEOUT_IGNORE_IF_HIGHER_THAN_DEFAULT), ignoreIfHigher); } } }
public static String getRealClientIpAddr(final ResourceContext context) { // If some upstream device added an X-Forwarded-For header // use it for the client ip // This will support scenarios where load balancers or gateways // front the Azkaban web server and a changing Ip address invalidates // the session final Map<String, String> headers = context.getRequestHeaders(); final WebUtils utils = new WebUtils(); return utils.getRealClientIpAddr(headers, (String) context.getRawRequestContext().getLocalAttr("REMOTE_ADDR")); } }
private void verifyRequestContext(Request<?> request) { assertTrue(_capturingRestClient.getCapturedRequestContexts().containsKey(request)); assertNotNull(_capturingRestClient.getCapturedRequestContexts().get(request).getLocalAttr("method")); assertEquals(_capturingRestClient.getCapturedRequestContexts().get(request).getLocalAttr("method"), request.getMethod()); }
String operation = (String) requestContext.getLocalAttr(R2Constants.OPERATION); if (!_acceptEncodingHeader.isEmpty() && _helper.shouldCompressResponseForOperation(operation)) (CompressionOption) requestContext.getLocalAttr(R2Constants.RESPONSE_COMPRESSION_OVERRIDE); req = addResponseCompressionHeaders(responseCompressionOverride, req); CompressionOption option = (CompressionOption) requestContext.getLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE); if (option == null || option != CompressionOption.FORCE_OFF)
NextFilter<StreamRequest, StreamResponse> nextFilter) Boolean decompressionOff = (Boolean) requestContext.getLocalAttr(R2Constants.RESPONSE_DECOMPRESSION_OFF); if (decompressionOff == null || !decompressionOff)
(CompressionOption) requestContext.getLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE) )) String operation = (String) requestContext.getLocalAttr(R2Constants.OPERATION); if (!_acceptEncodingHeader.isEmpty() && _helper.shouldCompressResponseForOperation(operation)) (CompressionOption) requestContext.getLocalAttr(R2Constants.RESPONSE_COMPRESSION_OVERRIDE); req = addResponseCompressionHeaders(responseCompressionOverride, req);
NextFilter<RestRequest, RestResponse> nextFilter) Boolean decompressionOff = (Boolean) requestContext.getLocalAttr(R2Constants.RESPONSE_DECOMPRESSION_OFF); if (decompressionOff == null || !decompressionOff)
Boolean decompressionOff = (Boolean) requestContext.getLocalAttr(R2Constants.RESPONSE_DECOMPRESSION_OFF); if (decompressionOff == null || !decompressionOff)
try String responseCompression = (String) requestContext.getLocalAttr(HttpConstants.ACCEPT_ENCODING); if (responseCompression == null) final int threshold = (Integer) requestContext.getLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD); final StreamingCompressor compressor = selectedEncoding.getCompressor(_executor); PartialReader reader = new PartialReader(threshold, new Callback<EntityStream[]>()
@Test public void testBatchableRequestBatched() { try { setInboundRequestContext(new InboundRequestContextBuilder() .setName("withBatching") .build()); GetRequest<Greeting> request1 = new GreetingsBuilders().get().id(1L).build(); GetRequest<Greeting> request2 = new GreetingsBuilders().get().id(2L).build(); Task<?> task = Task.par(_parseqClient.createTask(request1), _parseqClient.createTask(request2)); runAndWait(getTestClassName() + ".testBatchableRequestBatched", task); Collection<RequestContext> contexts = _capturingRestClient.getCapturedRequestContexts().values(); assertEquals(contexts.size(), 1); RequestContext context = contexts.iterator().next(); assertNotNull(context.getLocalAttr("method")); assertEquals(context.getLocalAttr("method"), ResourceMethod.BATCH_GET); } finally { _capturingRestClient.clearCapturedRequestContexts(); } }
String responseAcceptedEncodings = (String) requestContext.getLocalAttr(HttpConstants.ACCEPT_ENCODING); if (responseAcceptedEncodings == null) res.getEntity().length() > (Integer) requestContext.getLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD))
private static boolean isFullRequest(RequestContext requestContext) { Object isFull = requestContext.getLocalAttr(R2Constants.IS_FULL_REQUEST); return isFull != null && (Boolean)isFull; } }
/** * Evaluates if the disrupt source is already set in the {@link RequestContext} * * @param requestContext Context associated with the request * @return {@code true} if disrupt source is already set, {@code false} otherse; */ private boolean isDisruptSourceAlreadySet(RequestContext requestContext) { return requestContext.getLocalAttr(DisruptContext.DISRUPT_SOURCE_KEY) != null; } }
/** * Looks for a target host hint in the RequestContext, returning it if found, or null if no * hint is present. * @param context RequestContext for the request * @return URI for target host hint, or null if no hint is present in the RequestContext */ public static URI getRequestContextTargetHost(RequestContext context) { return (URI)context.getLocalAttr(TARGET_HOST_KEY_NAME); } }
/** * Retrieve the excluded hosts hint in the RequestContext, returning it if found, or null if no * hint is present. * @param context RequestContext for the request * @return Set of excluded hosts */ @SuppressWarnings("unchecked") public static Set<URI> getRequestContextExcludedHosts(RequestContext context) { return (Set<URI>)context.getLocalAttr(EXCLUDED_HOST_KEY_NAME); }
/** * Looks for a target service hint in the RequestContext, returning it if found, or null if no * hint is present. * @param context RequestContext for the request * @return URI for target service hint, or null if no hint is present in the RequestContext */ public static URI getRequestContextTargetService(RequestContext context) { return (URI)context.getLocalAttr(TARGET_SERVICE_KEY_NAME); } }
@SuppressWarnings("unchecked") private <T> TransportCallback<T> getCallback(RequestContext context) { TransportCallback<T> callback = (TransportCallback<T>) context.getLocalAttr(CALLBACK_ATTR); if (callback == null) { _log.error("No callback registered in local attributes. Caller will not get response. Attributes: " + context); callback = new NullTransportCallback<T>(); } return callback; } }
private void trace(final String method, final RestResponse response, final Map<String, String> wireAttrs, final RequestContext requestContext) { final URI requestUri = (URI)requestContext.getLocalAttr(REQUEST_URI); final String requestMethod = (String)requestContext.getLocalAttr(REQUEST_METHOD); _log.debug(buildLogMessage(method, "response", formatResponse(response, response.getEntity().length(), requestUri, requestMethod), wireAttrs, requestContext)); }
private <T> ScatterGatherStrategy getScatterGatherStrategy(final RequestContext requestContext) { return requestContext.getLocalAttr(SCATTER_GATHER_STRATEGY) != null ? (ScatterGatherStrategy)requestContext.removeLocalAttr(SCATTER_GATHER_STRATEGY) : _restLiClientConfig.getScatterGatherStrategy(); }