Java 类io.dropwizard.jersey.jackson.JacksonMessageBodyProvider 实例源码

项目:geoplatform-oauth2-extensions    文件:CoreServiceApp.java   
@Override
public void run(CoreServiceConfig t, Environment e) throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(CoreOAuth2ServiceLoader.class);
    ctx.registerShutdownHook();
    ctx.start();

    e.jersey().register(new JacksonMessageBodyProvider(new GPJacksonSupport().getDefaultMapper()));
    e.jersey().register(new OAuth2ExceptionProvider());

    e.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<GPAuthenticatedPrincipal>()
                    .setAuthenticator(new CoreOAuthAuthenticator(t))
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    e.jersey().register(RolesAllowedDynamicFeature.class);
    e.jersey().register(new AuthValueFactoryProvider.Binder<>(Principal.class));

    e.healthChecks().register("service-health-check",
            new CoreServiceHealthCheck());

    Map<String, Object> resources = ctx.getBeansWithAnnotation(Path.class);

    for (Map.Entry<String, Object> entry : resources.entrySet()) {
        e.jersey().register(entry.getValue());
    }
}
项目:monasca-common    文件:AbstractResourceTest.java   
@BeforeMethod
protected void beforeTestCase() throws Exception {
  singletons.clear();
  providers.clear();
  features.clear();
  properties.clear();
  setupResources();

  test = new JerseyTest() {
    @Override
    protected AppDescriptor configure() {
      final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(metricRegistry);
      for (Class<?> provider : providers)
        config.getClasses().add(provider);
      for (Map.Entry<String, Boolean> feature : features.entrySet())
        config.getFeatures().put(feature.getKey(), feature.getValue());
      for (Map.Entry<String, Object> property : properties.entrySet())
        config.getProperties().put(property.getKey(), property.getValue());
      config.getSingletons().add(new JacksonMessageBodyProvider(objectMapper, validator));
      config.getSingletons().addAll(singletons);
      return new LowLevelAppDescriptor.Builder(config).build();
    }
  };

  test.setUp();
}
项目:btc1k    文件:RestClient.java   
public RestClient (URI baseURI)
{
    ObjectMapper mapper = Jackson.newObjectMapper ()
                                 .registerModule (new SupernodeModule ());

    Validator validator = Validation.buildDefaultValidatorFactory ().getValidator ();

    ClientConfig cc = new DefaultClientConfig (JsonProcessingExceptionMapper.class);
    cc.getProperties ().put (ClientConfig.PROPERTY_CONNECT_TIMEOUT, 5000);
    cc.getProperties ().put (ClientConfig.PROPERTY_READ_TIMEOUT, 5000);
    cc.getSingletons ().add (new JacksonMessageBodyProvider (mapper, validator));

    Client client = Client.create (cc);
    client.addFilter (new LoggingFilter ());

    this.client = client;
    this.baseURI = baseURI;
}
项目:emodb    文件:BlobStoreClientFactory.java   
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:emodb    文件:PurgeDatabusEventsCommand.java   
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:emodb    文件:UserAccessControlClientFactory.java   
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:emodb    文件:DataStoreClientFactory.java   
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:emodb    文件:QueueClientFactory.java   
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:emodb    文件:DedupQueueClientFactory.java   
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:emodb    文件:DatabusClientFactory.java   
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
项目:soabase    文件:SoaBundle.java   
private void initJerseyAdmin(SoaConfiguration configuration, SoaFeaturesImpl features, Ports ports, final Environment environment, AbstractBinder binder)
{
    if ( (configuration.getAdminJerseyPath() == null) || !ports.adminPort.hasPort() )
    {
        return;
    }

    String jerseyRootPath = configuration.getAdminJerseyPath();
    if ( !jerseyRootPath.endsWith("/*") )
    {
        if ( jerseyRootPath.endsWith("/") )
        {
            jerseyRootPath += "*";
        }
        else
        {
            jerseyRootPath += "/*";
        }
    }

    DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics());
    jerseyConfig.setUrlPattern(jerseyRootPath);

    JerseyContainerHolder jerseyServletContainer = new JerseyContainerHolder(new ServletContainer(jerseyConfig));
    environment.admin().addServlet("soa-admin-jersey", jerseyServletContainer.getContainer()).addMapping(jerseyRootPath);

    JerseyEnvironment jerseyEnvironment = new JerseyEnvironment(jerseyServletContainer, jerseyConfig);
    features.putNamed(jerseyEnvironment, JerseyEnvironment.class, SoaFeatures.ADMIN_NAME);
    jerseyEnvironment.register(SoaApis.class);
    jerseyEnvironment.register(DiscoveryApis.class);
    jerseyEnvironment.register(DynamicAttributeApis.class);
    jerseyEnvironment.register(LoggingApis.class);
    jerseyEnvironment.register(binder);
    jerseyEnvironment.setUrlPattern(jerseyConfig.getUrlPattern());
    jerseyEnvironment.register(new JacksonMessageBodyProvider(environment.getObjectMapper()));

    checkCorsFilter(configuration, environment.admin());
    checkAdminGuiceFeature(environment, jerseyEnvironment);
}
项目:CredentialStorageService-dw-hibernate    文件:JerseyIntegrationTest.java   
@Override
protected void configureClient(final ClientConfig config) {
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validators.newValidator()));
}
项目:dropwizard-jooq    文件:ExampleResourceTest.java   
@Override
protected void configureClient(ClientConfig config) {
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validation.buildDefaultValidatorFactory().getValidator()));
}
项目:dropwizard-jooq    文件:ExampleResourceTest.java   
@Override
protected Application configure() {
    final MetricRegistry metricRegistry = new MetricRegistry();
    final DataSourceFactory dbConfig = new DataSourceFactory();
    final Environment environment = mock(Environment.class);
    final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
    when(environment.metrics()).thenReturn(metricRegistry);

    String url = "jdbc:hsqldb:mem:dwtest" + System.nanoTime();

    Map<String, String> props = new HashMap<String, String>();
    props.put("username", "sa");
    props.put("password", "");
    props.put("url", url);

    try {
        HSQLDBInit.initPublic(props);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    dbConfig.setUrl(props.get("url"));
    dbConfig.setUser(props.get("user"));
    dbConfig.setDriverClass("org.hsqldb.jdbcDriver");
    dbConfig.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");

    final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(new MetricRegistry());

    DataSource dataSource = dbConfig.build(metricRegistry, "jooq");
    config.register(JooqTransactionalApplicationListener.class);

    Configuration configuration = new DefaultConfiguration().set(SQLDialect.HSQLDB);
    configuration.set(new DataSourceConnectionProvider(dataSource));

    config.register(new ConfigurationFactoryProvider.Binder(configuration, dataSource,
            new TestTenantConnectionProvider(dbConfig, metricRegistry, url)));
    config.register(ExampleResource.class);
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validation.buildDefaultValidatorFactory().getValidator()));
    return config;
}