/** * Create a new {@link TransportClient} with the specified properties, {@link SSLContext} and * {@link SSLParameters} * * @param properties map of properties for the {@link TransportClient} * @param sslContext {@link SSLContext} to be used for requests over SSL/TLS. * @param sslParameters {@link SSLParameters} to configure secure connections. * @return an appropriate {@link TransportClient} instance, as specified by the properties. */ private TransportClient getClient( Map<String, ? extends Object> properties, SSLContext sslContext, SSLParameters sslParameters) { LOG.info("Getting a client with configuration {} and SSLContext {}", properties, sslContext); TransportClient client = getRawClient(properties, sslContext, sslParameters); List<String> httpResponseCompressionOperations = ConfigValueExtractor.buildList( properties.remove(HTTP_RESPONSE_COMPRESSION_OPERATIONS), LIST_SEPARATOR); List<String> httpRequestServerSupportedEncodings = ConfigValueExtractor.buildList( properties.remove(HTTP_REQUEST_CONTENT_ENCODINGS), LIST_SEPARATOR); FilterChain filters; if (_useClientCompression) { String httpServiceName = (String) properties.get(HTTP_SERVICE_NAME); String requestContentEncodingName = getRequestContentEncodingName(httpRequestServerSupportedEncodings); CompressionConfig compressionConfig = getCompressionConfig(httpServiceName, requestContentEncodingName); String responseCompressionSchemaName = httpResponseCompressionOperations.isEmpty() ? "" : buildAcceptEncodingSchemaNames(); filters = _filters.addLast( new ClientCompressionFilter( requestContentEncodingName, compressionConfig, responseCompressionSchemaName, httpResponseCompressionOperations)); } else { filters = _filters; } Integer queryPostThreshold = chooseNewOverDefault(getIntValue(properties, HTTP_QUERY_POST_THRESHOLD), Integer.MAX_VALUE); filters = filters.addLast(new ClientQueryTunnelFilter(queryPostThreshold)); client = new FilterChainClient(client, filters); client = new FactoryClient(client); synchronized (_mutex) { if (!_running) { throw new IllegalStateException("Factory is shutting down"); } _clientsOutstanding++; return client; } }
/** * Construct a new instance by composing the specified {@link TransportClient} and {@link * FilterChain}. * * @param client the {@link TransportClient} to be composed. * @param filters the {@link FilterChain} to be composed. */ public FilterChainClient(TransportClient client, FilterChain filters) { _client = client; final ResponseFilter responseFilter = new ResponseFilter(); final ClientRequestFilter requestFilter = new ClientRequestFilter(_client); _filters = filters.addFirst(responseFilter).addLast(requestFilter); }
@Override public void restRequest( RestRequest request, RequestContext requestContext, Map<String, String> wireAttrs, TransportCallback<RestResponse> callback) { ResponseFilter.registerCallback(callback, requestContext); _filters.onRestRequest(request, requestContext, wireAttrs); }
@Override @Deprecated @SuppressWarnings("deprecation") public void rpcRequest( RpcRequest request, RequestContext requestContext, Map<String, String> wireAttrs, TransportCallback<RpcResponse> callback) { ResponseFilter.registerCallback(callback, requestContext); _filters.onRpcRequest(request, requestContext, wireAttrs); }