org.codehaus.jackson.jaxrs.JacksonJsonProvider Java Examples

The following examples show how to use org.codehaus.jackson.jaxrs.JacksonJsonProvider. 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: ApiClientConfiguration.java    From occurrence with Apache License 2.0 6 votes vote down vote up
/**
 * @return a new jersey client using a multithreaded http client
 */
public WebResource newApiClient() {
  ClientConfig cc = new DefaultClientConfig();
  cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
  cc.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, timeout);
  cc.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, timeout);
  cc.getClasses().add(JacksonJsonProvider.class);
  // use custom configured object mapper ignoring unknown properties
  cc.getClasses().add(ObjectMapperContextResolver.class);

  HttpClient http = HttpUtil.newMultithreadedClient(timeout, maxConnections, maxConnections);
  ApacheHttpClient4Handler hch = new ApacheHttpClient4Handler(http, null, false);
  Client client = new ApacheHttpClient4(hch, cc);

  LOG.info("Connecting to GBIF API: {}", url);
  return client.resource(url);
}
 
Example #2
Source File: ServerProvider.java    From angulardemorestful with MIT License 6 votes vote down vote up
public void createServer() throws IOException {
    System.out.println("Starting grizzly...");

    Injector injector = Guice.createInjector(new ServletModule() {
        @Override
        protected void configureServlets() {
            bind(UserService.class).to(UserServiceImpl.class);
            bind(UserRepository.class).to(UserMockRepositoryImpl.class);
            bind(DummyService.class).to(DummyServiceImpl.class);
            bind(DummyRepository.class).to(DummyMockRepositoryImpl.class);

            // hook Jackson into Jersey as the POJO <-> JSON mapper
            bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);
        }
    });

    ResourceConfig rc = new PackagesResourceConfig("ngdemo.web");
    IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory(rc, injector);
    server = GrizzlyServerFactory.createHttpServer(BASE_URI + "web/", rc, ioc);

    System.out.println(String.format("Jersey app started with WADL available at "
            + "%srest/application.wadl\nTry out %sngdemo\nHit enter to stop it...",
            BASE_URI, BASE_URI));
}
 
Example #3
Source File: NgDemoApplicationSetup.java    From angulardemorestful with MIT License 6 votes vote down vote up
@Override
protected Injector getInjector() {
    return Guice.createInjector(new ServletModule() {

        @Override
        protected void configureServlets() {

            super.configureServlets();

            // Configuring Jersey via Guice:
            ResourceConfig resourceConfig = new PackagesResourceConfig("ngdemo/web");
            for (Class<?> resource : resourceConfig.getClasses()) {
                bind(resource);
            }

            // hook Jackson into Jersey as the POJO <-> JSON mapper
            bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);

            serve("/web/*").with(GuiceContainer.class);

            filter("/web/*").through(ResponseCorsFilter.class);
        }
    }, new UserModule());
}
 
Example #4
Source File: EagleServiceBaseClient.java    From Eagle with Apache License 2.0 6 votes vote down vote up
public EagleServiceBaseClient(String host, int port, String basePath, String username, String password) {
    this.host = host;
    this.port = port;
    this.basePath = basePath;
    this.baseEndpoint = buildBathPath().toString();
    this.username = username;
    this.password = password;

    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
    cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
    cc.getClasses().add(JacksonJsonProvider.class);
    cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    this.client = Client.create(cc);
    client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
    //        Runtime.getRuntime().addShutdownHook(new EagleServiceClientShutdownHook(this));
}
 
Example #5
Source File: RegistryClientUtil.java    From occurrence with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an HTTP client.
 */
private static ApacheHttpClient createHttpClient() {
  ClientConfig cc = new DefaultClientConfig();
  cc.getClasses().add(JacksonJsonContextResolver.class);
  cc.getClasses().add(JacksonJsonProvider.class);
  cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
  cc.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, REGISTRY_CLIENT_TO);
  cc.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, REGISTRY_CLIENT_TO);
  JacksonJsonContextResolver.addMixIns(Mixins.getPredefinedMixins());
  return ApacheHttpClient.create(cc);
}
 
Example #6
Source File: MetricsResourceTest.java    From metrics with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {
    FastJsonAutoDiscoverable.autoDiscover = false;
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    ResourceConfig config = new ResourceConfig(MetricsResource.class);
    config.register(new JacksonJsonProvider(mapper));
    return config;
}
 
Example #7
Source File: RangerUgSyncRESTClient.java    From ranger with Apache License 2.0 5 votes vote down vote up
public RangerUgSyncRESTClient(String policyMgrBaseUrls, String ugKeyStoreFile, String ugKeyStoreFilepwd,
		String ugKeyStoreType, String ugTrustStoreFile, String ugTrustStoreFilepwd, String ugTrustStoreType,
		String authenticationType, String principal, String keytab, String polMgrUsername, String polMgrPassword) {

	super(policyMgrBaseUrls, "", UserGroupSyncConfig.getInstance().getConfig());
	if (!(authenticationType != null && AUTH_KERBEROS.equalsIgnoreCase(authenticationType)
			&& SecureClientLogin.isKerberosCredentialExists(principal, keytab))) {
		setBasicAuthInfo(polMgrUsername, polMgrPassword);
	}

	if (isSSL()) {
		setKeyStoreType(ugKeyStoreType);
		setTrustStoreType(ugTrustStoreType);
		KeyManager[] kmList = getKeyManagers(ugKeyStoreFile, ugKeyStoreFilepwd);
		TrustManager[] tmList = getTrustManagers(ugTrustStoreFile, ugTrustStoreFilepwd);
		SSLContext sslContext = getSSLContext(kmList, tmList);
		ClientConfig config = new DefaultClientConfig();

		config.getClasses().add(JacksonJsonProvider.class); // to handle List<> unmarshalling
		HostnameVerifier hv = new HostnameVerifier() {
			public boolean verify(String urlHostName, SSLSession session) {
				return session.getPeerHost().equals(urlHostName);
			}
		};
		config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hv, sslContext));

		setClient(Client.create(config));
		if (StringUtils.isNotEmpty(getUsername()) && StringUtils.isNotEmpty(getPassword())) {
			getClient().addFilter(new HTTPBasicAuthFilter(getUsername(), getPassword()));
		}
	}
}
 
Example #8
Source File: JiraRestAccess.java    From rtc2jira with GNU General Public License v2.0 5 votes vote down vote up
public JiraRestAccess(String url, String user, String password) {
  this.restHome = url + JIRA_REST_API_SUFFIX;
  String userAndPassword = user + ':' + password;
  this.authentification = new String(Base64.getEncoder().encode(userAndPassword.getBytes()));

  JacksonJsonProvider jacksonJsonProvider =
      new JacksonJaxbJsonProvider().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  objectMapper = jacksonJsonProvider.locateMapper(Object.class, MediaType.APPLICATION_JSON_TYPE);

  ClientConfig cfg = new DefaultClientConfig();
  cfg.getSingletons().add(jacksonJsonProvider);
  this.client = Client.create(cfg);
  // this.client.addFilter(new LoggingFilter(System.out));
}
 
Example #9
Source File: RESTServiceModule.java    From guacamole-client with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureServlets() {

    // Bind session map
    bind(TokenSessionMap.class).toInstance(tokenSessionMap);

    // Bind low-level services
    bind(ListenerService.class);
    bind(AuthenticationService.class);
    bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class);
    bind(DecorationService.class);

    // Automatically translate GuacamoleExceptions for REST methods
    bind(RESTExceptionMapper.class);

    // Set up the API endpoints
    bind(ExtensionRESTService.class);
    bind(LanguageRESTService.class);
    bind(PatchRESTService.class);
    bind(TokenRESTService.class);

    // Root-level resources
    bind(SessionRESTService.class);
    install(new FactoryModuleBuilder().build(SessionResourceFactory.class));
    install(new FactoryModuleBuilder().build(TunnelCollectionResourceFactory.class));
    install(new FactoryModuleBuilder().build(TunnelResourceFactory.class));
    install(new FactoryModuleBuilder().build(UserContextResourceFactory.class));

    // Resources below root
    install(new ActiveConnectionModule());
    install(new ConnectionModule());
    install(new ConnectionGroupModule());
    install(new SharingProfileModule());
    install(new UserModule());
    install(new UserGroupModule());

    // Set up the servlet and JSON mappings
    bind(GuiceContainer.class);
    bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);
    serve("/api/*").with(GuiceContainer.class);

    // Serve Webjar JavaScript dependencies
    bind(WebjarsServlet.class).in(Scopes.SINGLETON);
    serve("/webjars/*").with(WebjarsServlet.class);

}
 
Example #10
Source File: DatastoreClient.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
public void init() {
    clientConfig = new DefaultClientConfig();
    clientConfig.getClasses().add(JacksonJsonProvider.class);
    client = Client.create(clientConfig);
}
 
Example #11
Source File: RESTServiceModule.java    From guacamole-client with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureServlets() {

    // Bind session map
    bind(TokenSessionMap.class).toInstance(tokenSessionMap);

    // Bind low-level services
    bind(ListenerService.class);
    bind(AuthenticationService.class);
    bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class);
    bind(DecorationService.class);

    // Automatically translate GuacamoleExceptions for REST methods
    bind(RESTExceptionMapper.class);

    // Set up the API endpoints
    bind(ExtensionRESTService.class);
    bind(LanguageRESTService.class);
    bind(PatchRESTService.class);
    bind(TokenRESTService.class);

    // Root-level resources
    bind(SessionRESTService.class);
    install(new FactoryModuleBuilder().build(SessionResourceFactory.class));
    install(new FactoryModuleBuilder().build(TunnelCollectionResourceFactory.class));
    install(new FactoryModuleBuilder().build(TunnelResourceFactory.class));
    install(new FactoryModuleBuilder().build(UserContextResourceFactory.class));

    // Resources below root
    install(new ActiveConnectionModule());
    install(new ConnectionModule());
    install(new ConnectionGroupModule());
    install(new SharingProfileModule());
    install(new UserModule());
    install(new UserGroupModule());

    // Set up the servlet and JSON mappings
    bind(GuiceContainer.class);
    bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);
    serve("/api/*").with(GuiceContainer.class);

    // Serve Webjar JavaScript dependencies
    bind(WebjarsServlet.class).in(Scopes.SINGLETON);
    serve("/webjars/*").with(WebjarsServlet.class);

}
 
Example #12
Source File: RDFServerExtensionTest.java    From neo4j-sparql-extension with GNU General Public License v3.0 4 votes vote down vote up
protected Client request() {
	DefaultClientConfig defaultClientConfig = new DefaultClientConfig();
	defaultClientConfig.getClasses().add(JacksonJsonProvider.class);
	return Client.create(defaultClientConfig);
}
 
Example #13
Source File: SamzaRestApplication.java    From samza with Apache License 2.0 4 votes vote down vote up
public SamzaRestApplication(SamzaRestConfig config) {
  register(JacksonJsonProvider.class);
  registerConfiguredResources(config);
}
 
Example #14
Source File: CoffeeConfig.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #15
Source File: CustomerConfig.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #16
Source File: MusicConfig.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #17
Source File: AppConfig.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #18
Source File: CoffeeConfig.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #19
Source File: WebServiceConfig.java    From jwala with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider getJacksonJsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #20
Source File: AemWebServiceConfiguration.java    From jwala with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider getV1JsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #21
Source File: MetricsResourceTest.java    From metrics with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureClient(ClientConfig config) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    config.register(new JacksonJsonProvider(mapper));
}
 
Example #22
Source File: CustomerConfig.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #23
Source File: MusicConfig.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}
 
Example #24
Source File: AppConfig.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@Bean
public JacksonJsonProvider jsonProvider() {
    return new JacksonJsonProvider();
}