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

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

Introduction

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

Prototype

public JacksonJsonProvider(ObjectMapper mapper) 

Source Link

Usage

From source file:com.erudika.para.client.ParaClient.java

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.");
    }//ww  w.  jav  a 2  s  .  c  o m
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(GenericExceptionMapper.class);
    clientConfig.register(new JacksonJsonProvider(ParaObjectUtils.getJsonMapper()));
    clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
    SSLContext sslContext = SslConfigurator.newInstance().securityProtocol("TLSv1.2").createSSLContext();
    apiClient = ClientBuilder.newBuilder().sslContext(sslContext).withConfig(clientConfig).build();
}

From source file:io.nflow.jetty.config.NflowJettyConfiguration.java

@Bean
public JacksonJsonProvider jsonProvider(@Named(REST_OBJECT_MAPPER) ObjectMapper nflowRestObjectMapper) {
    return new JacksonJsonProvider(nflowRestObjectMapper);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * {@inheritDoc}/*w  ww. j a  va 2s. c  o  m*/
 */
@Override
protected Application configure() {
    ResourceConfig config = new ResourceConfig();
    // Exception Mappers
    config.register(ScimExceptionMapper.class);
    config.register(RuntimeExceptionMapper.class);
    config.register(JsonProcessingExceptionMapper.class);

    JacksonJsonProvider provider = new JacksonJsonProvider(JsonUtils.createObjectMapper());
    provider.configure(JaxRSFeature.ALLOW_EMPTY_INPUT, false);
    config.register(provider);

    // Filters
    config.register(DotSearchFilter.class);
    config.register(TestAuthenticatedSubjectAliasFilter.class);
    config.register(DefaultContentTypeFilter.class);
    requestFilter = new TestRequestFilter();
    config.register(requestFilter);

    // Standard endpoints
    config.register(ResourceTypesEndpoint.class);
    config.register(CustomContentEndpoint.class);
    config.register(SchemasEndpoint.class);
    config.register(TestServiceProviderConfigEndpoint.class);

    config.register(TestResourceEndpoint.class);
    config.register(new TestSingletonResourceEndpoint());

    return config;
}

From source file:com.cloudera.api.ClouderaManagerClientBuilder.java

protected <T> T build(Class<T> proxyType) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();

    String address = generateAddress();
    boolean isTlsEnabled = address.startsWith("https://");
    bean.setAddress(address);/*  w w w.j a va 2 s . com*/
    if (username != null) {
        bean.setUsername(username);
        bean.setPassword(password);
    }
    if (enableLogging) {
        bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
    }
    bean.setResourceClass(proxyType);
    bean.setProvider(new JacksonJsonProvider(new ApiObjectMapper()));

    T rootResource = bean.create(proxyType);
    ClientConfiguration config = WebClient.getConfig(rootResource);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    if (isTlsEnabled) {
        TLSClientParameters tlsParams = new TLSClientParameters();
        if (!validateCerts) {
            tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
        } else if (trustManagers != null) {
            tlsParams.setTrustManagers(trustManagers);
        }
        tlsParams.setDisableCNCheck(!validateCn);
        conduit.setTlsClientParameters(tlsParams);
    }

    HTTPClientPolicy policy = conduit.getClient();
    policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
    policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
    return rootResource;
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test that retrieving an invalid endpoint results in 404.
 */// w  w w.j  av a2s .com
@Test
public void testInvalidEndpoint() {
    try {
        new ScimService(target()).retrieve("badPath", "id", UserResource.class);
        fail();
    } catch (ScimException e) {
        assertTrue(e instanceof ResourceNotFoundException);
    }

    // Now with application/json
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path("badPath").path("id").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).get();
    assertEquals(response.getStatus(), 404);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test all schemas can be retrieved./* ww w  .j  a  v  a 2 s  .  c  o m*/
 *
 * @throws ScimException if an error occurs.
 */
@Test
public void testGetSchemas() throws ScimException {
    final ListResponse<SchemaResource> returnedSchemas = new ScimService(target()).getSchemas();

    assertEquals(returnedSchemas.getTotalResults(), 2);
    assertTrue(contains(returnedSchemas, userSchema));
    assertTrue(contains(returnedSchemas, enterpriseSchema));

    // Now with application/json
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path(ApiConstants.SCHEMAS_ENDPOINT).request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).get();
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test an individual schema can be retrieved.
 *
 * @throws ScimException if an error occurs.
 *///  www .  j a v a2 s. c om
@Test
public void testGetSchema() throws ScimException {
    SchemaResource returnedSchema = new ScimService(target()).getSchema(userSchema.getId());

    assertEquals(returnedSchema, userSchema);

    returnedSchema = new ScimService(target()).getSchema(enterpriseSchema.getId());

    assertEquals(returnedSchema, enterpriseSchema);

    // Now with application/json
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path(ApiConstants.SCHEMAS_ENDPOINT).path(userSchema.getId()).request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).get();
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test all resource types can be retrieved.
 *
 * @throws ScimException if an error occurs.
 *//*from  ww  w . ja v  a2s  .c om*/
@Test
public void testGetResourceTypes() throws ScimException {
    final ListResponse<ResourceTypeResource> returnedResourceTypes = new ScimService(target())
            .getResourceTypes();

    assertEquals(returnedResourceTypes.getTotalResults(), 3);
    assertTrue(contains(returnedResourceTypes, resourceType));
    assertTrue(contains(returnedResourceTypes, singletonResourceType));

    // Now with application/json
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path(ApiConstants.RESOURCE_TYPES_ENDPOINT).request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).get();
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test an individual resource type can be retrieved.
 *
 * @throws ScimException if an error occurs.
 *///from  w w  w .  j  a v a 2 s.c  o  m
@Test
public void testGetResourceType() throws ScimException {
    final ResourceTypeResource returnedResourceTypeById = new ScimService(target())
            .getResourceType(resourceType.getId());

    assertEquals(returnedResourceTypeById, resourceType);

    final ResourceTypeResource returnedResourceTypeByName = new ScimService(target())
            .getResourceType(singletonResourceType.getId());

    assertEquals(returnedResourceTypeByName, singletonResourceType);

    final SchemaResource returnedSchema = new ScimService(target())
            .getSchema(returnedResourceTypeById.getSchema().toString());

    assertEquals(returnedSchema, userSchema);

    // Now with application/json
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path(ApiConstants.RESOURCE_TYPES_ENDPOINT).path(resourceType.getId()).request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).get();
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test an resource endpoint implementation registered as a class.
 *
 * @throws ScimException if an error occurs.
 *//*from   w  w  w  .  j a  v  a 2 s.c  o  m*/
@Test
public void testGetUsersUsingPost() throws ScimException {
    final ListResponse<UserResource> returnedUsers = new ScimService(target()).searchRequest("Users")
            .filter("meta.resourceType eq \"User\"").page(1, 10).sort("id", SortOrder.DESCENDING)
            .excludedAttributes("addresses", "phoneNumbers").invokePost(UserResource.class);

    assertEquals(returnedUsers.getTotalResults(), 1);
    assertEquals(returnedUsers.getStartIndex(), new Integer(1));
    assertEquals(returnedUsers.getItemsPerPage(), new Integer(1));

    // Now with application/json
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Set<String> excludedAttributes = new HashSet<String>();
    excludedAttributes.add("addresses");
    excludedAttributes.add("phoneNumbers");
    SearchRequest searchRequest = new SearchRequest(null, excludedAttributes, "meta.resourceType eq \"User\"",
            "id", SortOrder.DESCENDING, 1, 10);

    Response response = target.path("Users").path(".search").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE)
            .post(Entity.json(searchRequest));
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
    response.close();

    // Now with application/json; charset=UTF-8
    response = target.path("Users").path(".search").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE)
            .post(Entity.entity(searchRequest, "application/json; charset=UTF-8"));
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
    response.close();

    // Now with invalid MIME type
    response = target.path("Users").path(".search").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).post(Entity.text("bad"));
    assertEquals(response.getStatus(), 415);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
    response.close();

    // Now with invalid empty body
    response = target.path("Users").path(".search").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE).post(Entity.json(null));
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
    response.close();
}