Java Code Examples for org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider#setMapper()

The following examples show how to use org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider#setMapper() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractStoresTest.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
/**
 * Configures and constructs a Resteasy client to use for calling the Alfresco Public ReST API in the dockerised deployment.
 *
 * @return the configured client
 */
protected static ResteasyClient setupResteasyClient()
{
    final SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new RestAPIBeanDeserializerModifier());

    final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_EMPTY);
    mapper.registerModule(module);
    resteasyJacksonProvider.setMapper(mapper);

    final LocalResteasyProviderFactory resteasyProviderFactory = new LocalResteasyProviderFactory(new ResteasyProviderFactoryImpl());
    resteasyProviderFactory.register(resteasyJacksonProvider);
    // will cause a warning regarding Jackson provider which is already registered
    RegisterBuiltin.register(resteasyProviderFactory);
    resteasyProviderFactory.register(new MultiValuedParamConverterProvider());

    final ResteasyClient client = new ResteasyClientBuilderImpl().providerFactory(resteasyProviderFactory).build();
    return client;
}
 
Example 2
Source File: HttpClient.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static Client createClient() {
    final ObjectMapper mapper = new ObjectMapper().registerModules(new Jdk8Module());
    final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();

    resteasyJacksonProvider.setMapper(mapper);

    final ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
    providerFactory.register(resteasyJacksonProvider);

    return ClientBuilder.newBuilder()
        .withConfig(providerFactory)
        .connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
        .readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
        .build();
}
 
Example 3
Source File: ExternalVerifierService.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    if (this.client == null) {
        final ObjectMapper mapper = new ObjectMapper().registerModules(new Jdk8Module());
        final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();

        resteasyJacksonProvider.setMapper(mapper);

        final ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
        providerFactory.register(resteasyJacksonProvider);

        this.client = ClientBuilder.newClient(providerFactory);
    }

}
 
Example 4
Source File: AdminClientUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static Keycloak createAdminClient(boolean ignoreUnknownProperties, String authServerContextRoot, String realmName, String username, String password, String clientId, String clientSecret) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException {
    ResteasyClientBuilder resteasyClientBuilder = new ResteasyClientBuilder();

    if ("true".equals(System.getProperty("auth.server.ssl.required"))) {
        File trustore = new File(PROJECT_BUILD_DIRECTORY, "dependency/keystore/keycloak.truststore");
        resteasyClientBuilder.sslContext(getSSLContextWithTrustore(trustore, "secret"));

        System.setProperty("javax.net.ssl.trustStore", trustore.getAbsolutePath());
    }

    // We need to ignore unknown JSON properties e.g. in the adapter configuration representation
    // during adapter backward compatibility testing
    if (ignoreUnknownProperties) {
        // We need to use anonymous class to avoid the following error from RESTEasy:
        // Provider class org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider is already registered.  2nd registration is being ignored.
        ResteasyJackson2Provider jacksonProvider = new ResteasyJackson2Provider() {};
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        jacksonProvider.setMapper(objectMapper);
        resteasyClientBuilder.register(jacksonProvider, 100);
    }

    resteasyClientBuilder
        .hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.WILDCARD)
        .connectionPoolSize(10)
        .httpEngine(getCustomClientHttpEngine(resteasyClientBuilder, 1));
    
    return KeycloakBuilder.builder()
            .serverUrl(authServerContextRoot + "/auth")
            .realm(realmName)
            .username(username)
            .password(password)
            .clientId(clientId)
            .clientSecret(clientSecret)
            .resteasyClient(resteasyClientBuilder.build()).build();
}