/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
/** * Sets the custom ConnectorProvider to use. Subclasses can override this to * be a no-op if they do not want to use the custom connector, or wish to * set their own. * * @param builder * The builder to set the provider on */ protected void setConnectorProvider(ClientBuilder builder) { LOG.info("Setting connector provider to HttpUrlConnectorProvider"); ClientConfig clientConfig = new ClientConfig(); // 1) enable workaround for 'patch' requests HttpUrlConnectorProvider provider = new HttpUrlConnectorProvider().useSetMethodWorkaround(); clientConfig.connectorProvider(provider); for (ClientConfigDecorator clientConfigDecorator : clientConfigDecorators) { clientConfigDecorator.customizeClientConfig(clientConfig); } builder.withConfig(clientConfig); }
private static void addProxy(ClientConfig cc, Config config) { if (config.getProxy() != null) { HttpUrlConnectorProvider cp = new HttpUrlConnectorProvider(); cc.connectorProvider(cp); final Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(config.getProxy().getRawHost(), config.getProxy().getPort())); cp.connectionFactory(new ConnectionFactory() { @Override public HttpURLConnection getConnection(URL url) throws IOException { return (HttpURLConnection) url.openConnection(proxy); }}); } }
/** * Default constructor. * @param accessKey app access key * @param secretKey app secret key */ public ParaClient(String accessKey, String secretKey) { this.accessKey = accessKey; this.secretKey = secretKey; if (StringUtils.length(secretKey) < 6) { logger.warn("Secret key appears to be invalid. Make sure you call 'signIn()' first."); } this.throwExceptionOnHTTPError = false; ObjectMapper mapper = ParaObjectUtils.getJsonMapper(); mapper.setSerializationInclusion(JsonInclude.Include.USE_DEFAULTS); ClientConfig clientConfig = new ClientConfig(); clientConfig.register(GenericExceptionMapper.class); clientConfig.register(new JacksonJsonProvider(mapper)); clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround()); SSLContext sslContext = SslConfigurator.newInstance().createSSLContext(); apiClient = ClientBuilder.newBuilder(). sslContext(sslContext). withConfig(clientConfig).build(); }
/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
/** * Default constructor. * @param accessKey app access key * @param secretKey app secret key */ public ParaClient(String accessKey, String secretKey) { this.accessKey = accessKey; this.secretKey = secretKey; if (StringUtils.length(secretKey) < 6) { logger.warn("Secret key appears to be invalid. Make sure you call 'signIn()' first."); } this.throwExceptionOnHTTPError = false; ObjectMapper mapper = ParaObjectUtils.getJsonMapper(); mapper.setSerializationInclusion(JsonInclude.Include.USE_DEFAULTS); ClientConfig clientConfig = new ClientConfig(); clientConfig.register(GenericExceptionMapper.class); clientConfig.register(new JacksonJsonProvider(mapper)); clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround()); SSLContext sslContext = SslConfigurator.newInstance().createSSLContext(); apiClient = ClientBuilder.newBuilder(). sslContext(sslContext). withConfig(clientConfig).build(); }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
private static HttpUrlConnectorProvider buildHttpUrlConnectorProvider(){ HttpUrlConnectorProvider.ConnectionFactory factory = new HttpUrlConnectorProvider.ConnectionFactory() { @Override public HttpURLConnection getConnection(URL url) throws IOException { HttpURLConnection result = (HttpURLConnection) url.openConnection(); result.setChunkedStreamingMode(1024); return result; } }; return new HttpUrlConnectorProvider().connectionFactory(factory); }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
@Override public Connector getConnector(final Client client, final Configuration config) { final Map<String, Object> properties = config.getProperties(); int computedChunkSize = ClientProperties.getValue(properties, ClientProperties.CHUNKED_ENCODING_SIZE, chunkSize, Integer.class); if (computedChunkSize < 0) { LOGGER.warning(LocalizationMessages.NEGATIVE_CHUNK_SIZE(computedChunkSize, chunkSize)); computedChunkSize = chunkSize; } final boolean computedUseFixedLengthStreaming = ClientProperties.getValue(properties, USE_FIXED_LENGTH_STREAMING, useFixedLengthStreaming, Boolean.class); final boolean computedUseSetMethodWorkaround = ClientProperties.getValue(properties, SET_METHOD_WORKAROUND, useSetMethodWorkaround, Boolean.class); return createHttpUrlConnector(client, connectionFactory, computedChunkSize, computedUseFixedLengthStreaming, computedUseSetMethodWorkaround); }
/** * Default configuration state constructor with {@link StateChangeStrategy "identity"} * state change strategy. * * @param client bound parent Jersey client. */ State(final JerseyClient client) { this.strategy = IDENTITY; this.commonConfig = new CommonConfig(RuntimeType.CLIENT, ComponentBag.EXCLUDE_EMPTY); this.client = client; final Iterator<ConnectorProvider> iterator = ServiceFinder.find(ConnectorProvider.class).iterator(); if (iterator.hasNext()) { this.connectorProvider = iterator.next(); } else { this.connectorProvider = new HttpUrlConnectorProvider(); } }
clientConfig.register(OrtbBidRequestBodyReader.class); clientConfig.register(OrtbBidRequestBodyWriter.class); clientConfig.connectorProvider(new CachingConnectorProvider(new HttpUrlConnectorProvider())); clientConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 3); client = ClientBuilder.newClient(clientConfig);