Example usage for com.fasterxml.jackson.jaxrs.json JacksonJaxbJsonProvider JacksonJaxbJsonProvider

List of usage examples for com.fasterxml.jackson.jaxrs.json JacksonJaxbJsonProvider JacksonJaxbJsonProvider

Introduction

In this page you can find the example usage for com.fasterxml.jackson.jaxrs.json JacksonJaxbJsonProvider JacksonJaxbJsonProvider.

Prototype

public JacksonJaxbJsonProvider() 

Source Link

Document

Default constructor, usually used when provider is automatically configured to be used with JAX-RS implementation.

Usage

From source file:com.alliander.osgp.shared.usermanagement.OrganisationManagementClient.java

/**
 * Construct a UserManagementClient instance.
 *
 * @param keystoreLocation//from ww w  .  jav a2s  . c o m
 *            The location of the key store.
 * @param keystorePassword
 *            The password for the key store.
 * @param keystoreType
 *            The type of the key store.
 * @param baseAddress
 *            The base address or URL for the UserManagementClient.
 *
 * @throws OrganisationManagementClientException
 *             In case the construction fails, a
 *             OrganisationManagementClientException will be thrown.
 */
public OrganisationManagementClient(final String keystoreLocation, final String keystorePassword,
        final String keystoreType, final String baseAddress) throws OrganisationManagementClientException {

    InputStream stream = null;
    boolean isClosed = false;
    Exception exception = null;

    try {
        // Create the KeyStore.
        final KeyStore keystore = KeyStore.getInstance(keystoreType.toUpperCase());

        stream = new FileInputStream(keystoreLocation);
        keystore.load(stream, keystorePassword.toCharArray());

        // Create TrustManagerFactory and initialize it using the KeyStore.
        final TrustManagerFactory tmf = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(keystore);

        // Create Apache CXF WebClient with JSON provider.
        final List<Object> providers = new ArrayList<Object>();
        providers.add(new JacksonJaxbJsonProvider());

        this.webClient = WebClient.create(baseAddress, providers);
        if (this.webClient == null) {
            throw new UserManagementClientException("webclient is null");
        }

        // Set up the HTTP Conduit to use the TrustManagers.
        final ClientConfiguration config = WebClient.getConfig(this.webClient);
        final HTTPConduit conduit = config.getHttpConduit();

        conduit.setTlsClientParameters(new TLSClientParameters());
        conduit.getTlsClientParameters().setTrustManagers(tmf.getTrustManagers());
    } catch (final Exception e) {
        LOGGER.error(CONSTRUCTION_FAILED, e);
        throw new OrganisationManagementClientException(CONSTRUCTION_FAILED, e);
    } finally {
        try {
            stream.close();
            isClosed = true;
        } catch (final Exception streamCloseException) {
            LOGGER.error(CONSTRUCTION_FAILED, streamCloseException);
            exception = streamCloseException;
        }
    }

    if (!isClosed) {
        throw new OrganisationManagementClientException(CONSTRUCTION_FAILED, exception);
    }
}

From source file:com.alliander.osgp.shared.usermanagement.UserManagementClient.java

/**
 * Construct a UserManagementClient instance.
 *
 * @param keystoreLocation//from   www . ja  va  2 s  .co m
 *            The location of the key store.
 * @param keystorePassword
 *            The password for the key store.
 * @param keystoreType
 *            The type of the key store.
 * @param baseAddress
 *            The base address or URL for the UserManagementClient.
 *
 * @throws UserManagementClientException
 *             In case the construction fails, a
 *             UserManagmentClientException will be thrown.
 */
public UserManagementClient(final String keystoreLocation, final String keystorePassword,
        final String keystoreType, final String baseAddress) throws UserManagementClientException {

    InputStream stream = null;
    boolean isClosed = false;
    Exception exception = null;

    try {
        // Create the KeyStore.
        final KeyStore keystore = KeyStore.getInstance(keystoreType.toUpperCase());

        stream = new FileInputStream(keystoreLocation);
        keystore.load(stream, keystorePassword.toCharArray());

        // Create TrustManagerFactory and initialize it using the KeyStore.
        final TrustManagerFactory tmf = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(keystore);

        // Create Apache CXF WebClient with JSON provider.
        final List<Object> providers = new ArrayList<Object>();
        providers.add(new JacksonJaxbJsonProvider());

        this.webClient = WebClient.create(baseAddress, providers);
        if (this.webClient == null) {
            throw new UserManagementClientException("webclient is null");
        }

        // Set up the HTTP Conduit to use the TrustManagers.
        final ClientConfiguration config = WebClient.getConfig(this.webClient);
        final HTTPConduit conduit = config.getHttpConduit();

        conduit.setTlsClientParameters(new TLSClientParameters());
        conduit.getTlsClientParameters().setTrustManagers(tmf.getTrustManagers());
    } catch (final Exception e) {
        LOGGER.error(CONSTRUCTION_FAILED, e);
        throw new UserManagementClientException(CONSTRUCTION_FAILED, e);
    } finally {
        try {
            stream.close();
            isClosed = true;
        } catch (final Exception streamCloseException) {
            LOGGER.error(CONSTRUCTION_FAILED, streamCloseException);
            exception = streamCloseException;
        }
    }

    if (!isClosed) {
        throw new UserManagementClientException(CONSTRUCTION_FAILED, exception);
    }
}

From source file:org.keycloak.admin.client.Keycloak.java

/**
 * Create a secure proxy based on an absolute URI.
 * All set up with appropriate token/* w  ww  .java 2s .  co  m*/
 *
 * @param proxyClass
 * @param absoluteURI
 * @param <T>
 * @return
 */
public <T> T proxy(Class<T> proxyClass, URI absoluteURI) {
    List providers = new ArrayList();
    providers.add(new BearerAuthFilter(tokenManager));
    providers.add(new JacksonJaxbJsonProvider());
    WebClient.create(absoluteURI.toString(), providers);
    return JAXRSClientFactory.fromClient(client, proxyClass);
    //return client.target(absoluteURI).register(new BearerAuthFilter(tokenManager)).proxy(proxyClass);
}

From source file:com.alliander.osgp.shared.usermanagement.AuthenticationClient.java

/**
 * Construct an AuthenticationClient instance.
 *
 * @param keystoreLocation//from  www. j  ava  2  s  .  co  m
 *            The location of the key store.
 * @param keystorePassword
 *            The password for the key store.
 * @param keystoreType
 *            The type of the key store.
 * @param baseAddress
 *            The base address or URL for the AuthenticationClient.
 *
 * @throws AuthenticationClientException
 *             In case the construction fails, an
 *             AuthenticationClientException will be thrown.
 */
public AuthenticationClient(final String keystoreLocation, final String keystorePassword,
        final String keystoreType, final String baseAddress) throws AuthenticationClientException {

    InputStream stream = null;
    boolean isClosed = false;
    Exception exception = null;

    try {
        // Create the KeyStore.
        final KeyStore keystore = KeyStore.getInstance(keystoreType.toUpperCase());

        stream = new FileInputStream(keystoreLocation);
        keystore.load(stream, keystorePassword.toCharArray());

        // Create TrustManagerFactory and initialize it using the KeyStore.
        final TrustManagerFactory tmf = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(keystore);

        // Create Apache CXF WebClient with JSON provider.
        final List<Object> providers = new ArrayList<Object>();
        providers.add(new JacksonJaxbJsonProvider());

        this.webClient = WebClient.create(baseAddress, providers, true);
        if (this.webClient == null) {
            throw new AuthenticationClientException("webclient is null");
        }

        // Set up the HTTP Conduit to use the TrustManagers.
        final ClientConfiguration config = WebClient.getConfig(this.webClient);
        final HTTPConduit conduit = config.getHttpConduit();

        conduit.setTlsClientParameters(new TLSClientParameters());
        conduit.getTlsClientParameters().setTrustManagers(tmf.getTrustManagers());

        this.jacksonObjectMapper = new ObjectMapper();
    } catch (final Exception e) {
        LOGGER.error(CONSTRUCTION_FAILED, e);
        throw new AuthenticationClientException(CONSTRUCTION_FAILED, e);
    } finally {
        try {
            stream.close();
            isClosed = true;
        } catch (final Exception streamCloseException) {
            LOGGER.error(CONSTRUCTION_FAILED, streamCloseException);
            exception = streamCloseException;
        }
    }

    if (!isClosed) {
        throw new AuthenticationClientException(CONSTRUCTION_FAILED, exception);
    }
}

From source file:com.thinkbiganalytics.rest.JerseyConfig.java

public JerseyConfig() {

    //Register Swagger
    Set<Class<?>> resources = new HashSet();
    resources.add(io.swagger.jaxrs.listing.ApiListingResource.class);
    resources.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
    registerClasses(resources);//  w  w  w. j  av  a2s .c o m

    packages("com.thinkbiganalytics.ui.rest.controller", "com.thinkbiganalytics.config.rest.controller",
            "com.thinkbiganalytics.servicemonitor.rest.controller",
            "com.thinkbiganalytics.scheduler.rest.controller", "com.thinkbiganalytics.jobrepo.rest.controller",
            "com.thinkbiganalytics.hive.rest.controller", "com.thinkbiganalytics.feedmgr.rest.controller",
            "com.thinkbiganalytics.policy.rest.controller", "com.thinkbiganalytics.security.rest.controller",
            "com.thinkbiganalytics.metadata.rest.api",
            "com.thinkbiganalytics.metadata.migration.rest.controller",
            "com.thinkbiganalytics.spark.rest.controller", "com.thinkbiganalytics.rest.exception",
            "com.thinkbiganalytics.discovery.rest.controller", "com.thinkbiganalytics.audit.rest.controller",
            "com.thinkbiganalytics.alerts.rest.controller", "com.thinkbiganalytics.rest.controller");

    register(JacksonFeature.class);
    register(MultiPartFeature.class);
    register(WadlResource.class);

    ObjectMapper om = new ObjectMapper();
    om.registerModule(new JodaModule());
    //        om.registerModule(new JavaTimeModule());
    om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(om);
    register(provider);

}

From source file:org.waastad.enumjparest.service.RatingServiceIT.java

@Test
public void test_04_correct_insert_webclient() throws Exception {
    System.out.println("test_04_correct_insert_webclient");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJaxbJsonProvider());
    WebClient client = WebClient.create("http://127.0.0.1:4204/TomeeEnumRest/rest", providers);
    ClientConfiguration config = WebClient.getConfig(client);
    config.getOutInterceptors().add(new LoggingOutInterceptor());
    config.getInInterceptors().add(new LoggingInInterceptor());
    Movie movie = new Movie("flaaklypa", Rating.G);
    client.accept(MediaType.APPLICATION_JSON);
    client.type(MediaType.APPLICATION_JSON);
    Collection<? extends Movie> postObjectGetCollection = client.postObjectGetCollection(movie, Movie.class);

    Query q = em.createQuery("SELECT t FROM Movie t");
    List resultList = q.getResultList();
    Assert.assertEquals(2, resultList.size());
    q = em.createQuery("SELECT t FROM Movie t WHERE t.rating=:rating").setParameter("rating", Rating.G);
    List resultList1 = q.getResultList();
    Assert.assertEquals(1, resultList1.size());
}

From source file:org.apache.archiva.redback.rest.services.UserServiceTest.java

@Test
public void register() throws Exception {
    try {//from www  .  j  av a  2  s .co  m
        UserService service = getUserService();
        User u = new User();
        u.setFullName("the toto");
        u.setUsername("toto");
        u.setEmail("toto@toto.fr");
        u.setPassword("toto123");
        u.setConfirmPassword("toto123");
        String key = service.registerUser(new UserRegistrationRequest(u, "http://wine.fr/bordeaux")).getKey();

        assertFalse(key.equals("-1"));

        ServicesAssert assertService = JAXRSClientFactory.create(
                "http://localhost:" + port + "/" + getRestServicesPath() + "/testsService/",
                ServicesAssert.class, Collections.singletonList(new JacksonJaxbJsonProvider()));

        List<EmailMessage> emailMessages = assertService.getEmailMessageSended();
        assertEquals(1, emailMessages.size());
        assertEquals("toto@toto.fr", emailMessages.get(0).getTos().get(0));

        assertEquals("Welcome", emailMessages.get(0).getSubject());
        String messageContent = emailMessages.get(0).getText();

        log.info("messageContent: {}", messageContent);

        assertThat(messageContent).contains("Use the following URL to validate your account.")
                .contains("http://wine.fr/bordeaux").containsIgnoringCase("toto");

        assertTrue(service.validateUserFromKey(key));

        service = getUserService(authorizationHeader);

        u = service.getUser("toto");

        assertNotNull(u);
        assertTrue(u.isValidated());
        assertTrue(u.isPasswordChangeRequired());

        assertTrue(service.validateUserFromKey(key));

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        deleteUserQuietly("toto");
    }

}

From source file:de.metas.procurement.webui.sync.SyncConfiguration.java

/**
 * Creates the {@link IServerSync} client endpoint which this application can use to talk to the metasfresh server.
 *
 * @return/*from w w  w. j  a  v a2 s. c o m*/
 */
@Bean
public IServerSync clientEndPoint() {
    if (useMockedServer) {
        logger.warn("Using mocked implementation for {}", IServerSync.class);
        return new MockedServerSync();
    }

    //
    // Get server's URL
    logger.info("mfprocurement.sync.url: {}", serverUrl);
    if (Strings.isNullOrEmpty(serverUrl)) {
        logger.warn("Using null implementation for {}", IServerSync.class);
        return new NullServerSync();
    }

    //
    // Get MediaType
    final MediaType mediaType = getMediaType();

    //
    // Create the server binding.
    final JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider();

    final IServerSync serverSync = JAXRSClientFactory.create(serverUrl.trim(), IServerSync.class,
            Collections.singletonList(jacksonJaxbJsonProvider),
            Collections.singletonList((Feature) loggingFeature), null); // not providing a particular configLocation
    WebClient.client(serverSync).type(mediaType).accept(mediaType);
    return serverSync;
}

From source file:com.test.app.CXFApplication.java

@Bean
@ConditionalOnMissingBean//from  w  w  w. ja va  2  s  .  co m
public JacksonJsonProvider jsonProvider(ObjectMapper objectMapper) {
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(objectMapper);
    return provider;
}