/** * Build the Client used to make HTTP requests with the latest settings, * i.e. objectMapper and debugging. * TODO: better to use the Builder Pattern? * @return API client */ public ApiClient rebuildHttpClient() { // Add the JSON serialization support to Jersey JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper); DefaultClientConfig conf = new DefaultClientConfig(); conf.getSingletons().add(jsonProvider); Client client = Client.create(conf); client.addFilter(new GZIPContentEncodingFilter(false)); if (debugging) { client.addFilter(new LoggingFilter()); } this.httpClient = client; return this; }
DefaultClientConfig clientConfig = new DefaultClientConfig(); JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider(). configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); clientConfig.getSingletons().add(jacksonJsonProvider);
@Override public Client loadDefaultClient() { DefaultClientConfig config = new DefaultClientConfig(); Class<?>[] extensionClasses = new Class[]{ FamilySearchPlatform.class, ArtifactMetadata.class, ChangeInfo.class, ChildAndParentsRelationship.class, Discussion.class, DiscussionReference.class, MessageThread.class, Error.class, FeedbackInfo.class, MatchInfo.class, NameSearchInfo.class, PersonInfo.class, SearchInfo.class, Merge.class, MergeAnalysis.class, MergeConflict.class, Tag.class, User.class, Ordinance.class }; config.getSingletons().add( new FamilySearchPlatformJsonProvider(extensionClasses) ); config.getSingletons().add( new GedcomxAtomJsonProvider(extensionClasses) ); config.getSingletons().add( new JacksonJsonProvider() ); Client client = new Client(new URLConnectionClientHandler(), config); //how to add an experiment: //client.addFilter(new ExperimentsFilter("experiment-name", "experiment-name")); if (Boolean.valueOf(System.getProperty(ENABLE_JERSEY_LOGGING_ENV_NAME))) { // handles null client.addFilter(new com.sun.jersey.api.client.filter.LoggingFilter()); } return client; }
public HttpReporter(final URI snampLocation, final Map<String, ?> properties) { final DefaultClientConfig clientConfig = new SnampClientConfig(properties); clientConfig.getSingletons().add(new JacksonJsonProvider()); httpClient = Client.create(clientConfig); if (clientConfig.getPropertyAsFeature(GZIP_COMPRESSION_FEATURE)) httpClient.addFilter(new GZIPContentEncodingFilter()); final ExecutorService customExecutorService = (ExecutorService) clientConfig.getProperty(EXECUTOR_SERVICE_PROPERTY); if(customExecutorService != null) httpClient.setExecutorService(customExecutorService); batchResource = httpClient.resource(UriBuilder.fromUri(snampLocation).path(BATCH_PATH).build()); nonBatchResource = httpClient.resource(UriBuilder.fromUri(snampLocation).path(NON_BATCH_PATH).build()); final MeasurementBuffer buffer = (MeasurementBuffer) clientConfig.getProperty(BUFFER_PROPERTY); this.buffer = buffer == null ? new SoftMeasurementBuffer() : buffer; resending = new AtomicBoolean(false); asynchronous = true; }
conf.getSingletons().add(jsonProvider);
public static Client newClient(JerseyClientFactory clientFactory, OClientBehavior[] behaviors) { DefaultClientConfig cc = new DefaultClientConfig(); cc.getSingletons().add(new StringProvider2()); if (behaviors != null) { for (OClientBehavior behavior : behaviors) { if (behavior instanceof JerseyClientBehavior) { ((JerseyClientBehavior) behavior).modify(cc); } } } Client client = clientFactory.createClient(cc); if (behaviors != null) { for (OClientBehavior behavior : behaviors) { if (behavior instanceof JerseyClientBehavior) { ((JerseyClientBehavior) behavior).modifyClientFilters(client); } } } return client; }
/** * Build the Client used to make HTTP requests with the latest settings, * i.e. objectMapper and debugging. * TODO: better to use the Builder Pattern? * @return API client */ public ApiClient rebuildHttpClient() { // Add the JSON serialization support to Jersey JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper); DefaultClientConfig conf = new DefaultClientConfig(); conf.getSingletons().add(jsonProvider); Client client = Client.create(conf); client.addFilter(new GZIPContentEncodingFilter(false)); if (debugging) { client.addFilter(new LoggingFilter()); } this.httpClient = client; return this; }