/** * Convenience method for specifying plain-text as the transmission media type. * * <p> * Identical to calling <code>serializer(PlainTextSerializer.<jk>class</jk>).parser(PlainTextParser.<jk>class</jk>)</code>. * * @return This object (for method chaining). */ public RestClientBuilder plainText() { return serializer(PlainTextSerializer.class).parser(PlainTextParser.class); }
/** * Sets the client version by setting the value for the <js>"X-Client-Version"</js> header. * * @param version The version string (e.g. <js>"1.2.3"</js>) * @return This object (for method chaining). */ public RestClientBuilder clientVersion(String version) { return header("X-Client-Version", version); }
/** * Instantiates a new clean-slate {@link RestClientBuilder} object. * * @return A new {@link RestClientBuilder} object. */ public static RestClientBuilder create() { return new RestClientBuilder(PropertyStore.DEFAULT, null); }
private FullContact(FullContactConfiguration configuration) throws InstantiationException { this.configuration = configuration; this.parser = JsonParser.DEFAULT.builder() .ignoreUnknownBeanProperties(true) .build(); this.serializer = JsonSerializer.DEFAULT.builder() .trimEmptyCollections(true) .trimEmptyMaps(true) .build(); this.restClientBuilder = RestClient.create() .accept("application/json") .contentType("application/json") .disableAutomaticRetries() .disableCookieManagement() .disableRedirectHandling() .header("Authorization", "Bearer "+configuration.getToken()) .parser(parser) .serializer(serializer) .rootUrl(baseUrl()); this.restClient = restClientBuilder.build(); }
.build(); this.restClient = RestClient.create() .rootUrl(rootUrl) .accept(APPLICATION_JSON.getMimeType()) .httpClient(httpclient, true) .pooled() .parser( JsonParser.DEFAULT.builder() .ignoreUnknownBeanProperties(true) .pojoSwaps(JodaDateSwap.class) .build()) .serializer( JsonSerializer.DEFAULT.builder() .pojoSwaps(JodaDateSwap.class) .build()) .retryable( configuration.getRetryMax().intValue(), configuration.getRetrySleepMs().intValue(), new InstagramRetryHandler()) .build(); this.mapper = StreamsJacksonMapper.getInstance();
/** * Sets a mock connection used to construct a connection manager for working against mocked REST interfaces. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='link'>{@doc juneau-rest-client.UnitTesting} * </ul> * * @param c The mock connection. * @return This object (for method chaining). */ public RestClientBuilder mockHttpConnection(MockHttpConnection c) { rootUrl("http://localhost"); return httpClientConnectionManager(new MockHttpClientConnectionManager(c)); }
/** * Configuration property: Request headers. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link RestClient#RESTCLIENT_headers} * </ul> * * @param key The header name. * @param value The header value. * @return This object (for method chaining). */ public RestClientBuilder header(String key, Object value) { return addTo(RESTCLIENT_headers, key, value); }
@SuppressWarnings("resource") @Override /* ContextBuilder */ public RestClient build() { try { CloseableHttpClient c = httpClient != null ? httpClient : createHttpClient(); PropertyStore ps = psb.build(); return new RestClient(ps, httpClientBuilder, c); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Creates an instance of an {@link HttpClient} to be used to handle all HTTP communications with the target server. * * <p> * This HTTP client is used when the HTTP client is not specified through one of the constructors or the * {@link #httpClient(CloseableHttpClient, boolean)} method. * * <p> * Subclasses can override this method to provide specially-configured HTTP clients to handle stuff such as * SSL/TLS certificate handling, authentication, etc. * * <p> * The default implementation returns an instance of {@link HttpClient} using the client builder returned by * {@link #createHttpClientBuilder()}. * * @return The HTTP client to use. * @throws Exception */ protected CloseableHttpClient createHttpClient() throws Exception { // Don't call createConnectionManager() if RestClient.setConnectionManager() was called. if (httpClientConnectionManager == null) httpClientBuilder.setConnectionManager(createConnectionManager()); else httpClientBuilder.setConnectionManager(httpClientConnectionManager); return httpClientBuilder.build(); }
/** * Sets a mock connection used to construct a connection manager for working against mocked REST interfaces. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='link'>{@doc juneau-rest-client.UnitTesting} * </ul> * * @param c The mock connection. * @return This object (for method chaining). */ public RestClientBuilder mockHttpConnection(MockHttpConnection c) { rootUrl("http://localhost"); return httpClientConnectionManager(new MockHttpClientConnectionManager(c)); }
/** * Configuration property: Request query parameters. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link RestClient#RESTCLIENT_query} * </ul> * * @param key The query parameter name. * @param value The query parameter value value. * @return This object (for method chaining). */ public RestClientBuilder query(String key, Object value) { return addTo(RESTCLIENT_query, key, value); }
@SuppressWarnings("resource") @Override /* ContextBuilder */ public RestClient build() { try { CloseableHttpClient c = httpClient != null ? httpClient : createHttpClient(); PropertyStore ps = psb.build(); return new RestClient(ps, httpClientBuilder, c); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Creates an instance of an {@link HttpClient} to be used to handle all HTTP communications with the target server. * * <p> * This HTTP client is used when the HTTP client is not specified through one of the constructors or the * {@link #httpClient(CloseableHttpClient, boolean)} method. * * <p> * Subclasses can override this method to provide specially-configured HTTP clients to handle stuff such as * SSL/TLS certificate handling, authentication, etc. * * <p> * The default implementation returns an instance of {@link HttpClient} using the client builder returned by * {@link #createHttpClientBuilder()}. * * @return The HTTP client to use. * @throws Exception */ protected CloseableHttpClient createHttpClient() throws Exception { // Don't call createConnectionManager() if RestClient.setConnectionManager() was called. if (httpClientConnectionManager == null) httpClientBuilder.setConnectionManager(createConnectionManager()); else httpClientBuilder.setConnectionManager(httpClientConnectionManager); return httpClientBuilder.build(); }
/** * Convenience method for specifying UON as the transmission media type. * * <p> * Identical to calling <code>serializer(UonSerializer.<jk>class</jk>).parser(UonParser.<jk>class</jk>)</code>. * * @return This object (for method chaining). */ public RestClientBuilder uon() { return serializer(UonSerializer.class).parser(UonParser.class); }
/** * Sets the value for the <code>Accept-Encoding</code> request header. * * <p> * This is a shortcut for calling <code>header(<js>"Accept-Encoding"</js>, value);</code> * * @param value The new header value. * @return This object (for method chaining). */ public RestClientBuilder acceptEncoding(Object value) { return header("Accept-Encoding", value); }
/** * Sets a mock connection used to construct a connection manager for working against mocked REST interfaces. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='link'>{@doc juneau-rest-client.UnitTesting} * </ul> * * @param c The mock connection. * @return This object (for method chaining). */ public RestClientBuilder mockHttpConnection(MockHttpConnection c) { rootUrl("http://localhost"); return httpClientConnectionManager(new MockHttpClientConnectionManager(c)); }
/** * Configuration property: Request query parameters. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link RestClient#RESTCLIENT_query} * </ul> * * @param key The query parameter name. * @param value The query parameter value value. * @return This object (for method chaining). */ public RestClientBuilder query(String key, Object value) { return addTo(RESTCLIENT_query, key, value); }
/** * Instantiates a new clean-slate {@link RestClientBuilder} object. * * @return A new {@link RestClientBuilder} object. */ public static RestClientBuilder create() { return new RestClientBuilder(PropertyStore.DEFAULT, null); }