com.sun.jersey.api.json.JSONConfiguration Java Examples
The following examples show how to use
com.sun.jersey.api.json.JSONConfiguration.
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 |
/** * @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: RepositoryCleanupUtil.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Use REST API to authenticate provided credentials * * @throws Exception */ @VisibleForTesting void authenticateLoginCredentials() throws Exception { KettleClientEnvironment.init(); if ( client == null ) { ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) ); } WebResource resource = client.resource( url + AUTHENTICATION + AdministerSecurityAction.NAME ); String response = resource.get( String.class ); if ( !response.equals( "true" ) ) { throw new Exception( Messages.getInstance().getString( "REPOSITORY_CLEANUP_UTIL.ERROR_0012.ACCESS_DENIED" ) ); } }
Example #3
Source File: AppServletModule.java From appstart with Apache License 2.0 | 6 votes |
@Override protected void configureServlets() { // filters // Objectify filter filter("/*").through(ObjectifyFilter.class); // servlets serve("/home").with(HomeServlet.class); // Jersey restful servlet HashMap<String, String> params = new HashMap<String, String>(); params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "uk.co.inetria.appstart.frontend.rest"); params.put(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); // speed up jersey startup under appengine params.put(ResourceConfig.FEATURE_DISABLE_WADL, "true"); serve("/api/*").with(GuiceContainer.class, params); }
Example #4
Source File: JAXBContextResolver.java From big-c with Apache License 2.0 | 5 votes |
public JAXBContextResolver() throws Exception { this.types = new HashSet<Class>(Arrays.asList(cTypes)); // sets the json configuration so that the json output looks like // the xml output this.context = new JSONJAXBContext(JSONConfiguration.natural(). rootUnwrapping(false).build(), cTypes); }
Example #5
Source File: HopServer.java From hop with Apache License 2.0 | 5 votes |
/** * Checks that HopServer is running and if so, shuts down the HopServer server * * @param hostname * @param port * @param username * @param password * @throws ParseException * @throws HopServerCommandException */ @VisibleForTesting static void callStopHopServerRestService( String hostname, String port, String username, String password ) throws ParseException, HopServerCommandException { // get information about the remote connection try { HopClientEnvironment.init(); ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); Client client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) ); // check if the user can access the hop server. Don't really need this call but may want to check it's output at // some point String contextURL = "http://" + hostname + ":" + port + "/hop"; WebResource resource = client.resource( contextURL + "/status/?xml=Y" ); String response = resource.get( String.class ); if ( response == null || !response.contains( "<serverstatus>" ) ) { throw new HopServerCommandException( BaseMessages.getString( PKG, "HopServer.Error.NoServerFound", hostname, "" + port ) ); } // This is the call that matters resource = client.resource( contextURL + "/stopHopServer" ); response = resource.get( String.class ); if ( response == null || !response.contains( "Shutting Down" ) ) { throw new HopServerCommandException( BaseMessages.getString( PKG, "HopServer.Error.NoShutdown", hostname, "" + port ) ); } } catch ( Exception e ) { throw new HopServerCommandException( BaseMessages.getString( PKG, "HopServer.Error.NoServerFound", hostname, "" + port ), e ); } }
Example #6
Source File: NaturalNotationContextResolver.java From exhibitor with Apache License 2.0 | 5 votes |
NaturalNotationContextResolver() { try { this.context = new JSONJAXBContext ( JSONConfiguration.natural().build(), Index.class, Result.class, SearchId.class, SearchRequest.class, SearchResult.class, UITabSpec.class, NameAndModifiedDate.class, PathAnalysis.class, PathAnalysisNode.class, PathAnalysisRequest.class, IdList.class, UsageListingRequest.class, FieldValue.class, ServerStatus.class ); } catch ( JAXBException e ) { throw new RuntimeException(e); } }
Example #7
Source File: NexusConnector.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
private Client buildClient() { DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig(); config.getState().setCredentials(null, null, -1, username, password); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); Client restClient = ApacheHttpClient.create(config); restClient.setFollowRedirects(true); return restClient; }
Example #8
Source File: ArtifactoryConnector.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
private Client buildClient() { DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig(); config.getState().setCredentials(null, null, -1, username, password); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); Client restClient = ApacheHttpClient.create(config); restClient.setFollowRedirects(true); return restClient; }
Example #9
Source File: RestfulApplication.java From maven-framework-project with MIT License | 5 votes |
public RestfulApplication() { // This Java package will be automatically scanned for JAX-RS services to register. super("com.packtpub.hibernatesearch.rest"); // Jersey is the JAX-RS implementation being used in this application. The Jersey feature // below makes the Jackson parser available for converting objects to JSON format. getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); }
Example #10
Source File: RestfulApplication.java From maven-framework-project with MIT License | 5 votes |
public RestfulApplication() { // This Java package will be automatically scanned for JAX-RS services to register. super("com.packtpub.hibernatesearch.rest"); // Jersey is the JAX-RS implementation being used in this application. The Jersey feature // below makes the Jackson parser available for converting objects to JSON format. getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); }
Example #11
Source File: RestfulApplication.java From maven-framework-project with MIT License | 5 votes |
public RestfulApplication() { // This Java package will be automatically scanned for JAX-RS services to register. super("com.packtpub.hibernatesearch.rest"); // Jersey is the JAX-RS implementation being used in this application. The Jersey feature // below makes the Jackson parser available for converting objects to JSON format. getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); }
Example #12
Source File: PublishRestUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Used for REST Jersey calls */ private void initRestService() { ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getClasses().add( MultiPartWriter.class ); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, password ) ); }
Example #13
Source File: PublishRestUtilTestIT.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected AppDescriptor configure() { ClientConfig config = new DefaultClientConfig(); config.getClasses().add( MultiPartWriter.class ); config.getClasses().add( TestRepositoryPublishResource.class ); config.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); return new WebAppDescriptor.Builder( "org.pentaho.reporting.libraries.pensol.resources" ) .contextPath( "api" ) .clientConfig( config ) .build(); }
Example #14
Source File: RestServer.java From hraven with Apache License 2.0 | 5 votes |
@Override protected void startUp() throws Exception { // setup the jetty config ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest"); sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(this.port); connector.setHost(address); server.addConnector(connector); // TODO: in the future we may want to provide settings for the min and max threads // Jetty sets the default max thread number to 250, if we don't set it. // QueuedThreadPool threadPool = new QueuedThreadPool(); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); // start server server.start(); }
Example #15
Source File: Carte.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Checks that Carte is running and if so, shuts down the Carte server * * @param hostname * @param port * @param username * @param password * @throws ParseException * @throws CarteCommandException */ @VisibleForTesting static void callStopCarteRestService( String hostname, String port, String username, String password ) throws ParseException, CarteCommandException { // get information about the remote connection try { KettleClientEnvironment.init(); ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); Client client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) ); // check if the user can access the carte server. Don't really need this call but may want to check it's output at // some point String contextURL = "http://" + hostname + ":" + port + "/kettle"; WebResource resource = client.resource( contextURL + "/status/?xml=Y" ); String response = resource.get( String.class ); if ( response == null || !response.contains( "<serverstatus>" ) ) { throw new Carte.CarteCommandException( BaseMessages.getString( PKG, "Carte.Error.NoServerFound", hostname, "" + port ) ); } // This is the call that matters resource = client.resource( contextURL + "/stopCarte" ); response = resource.get( String.class ); if ( response == null || !response.contains( "Shutting Down" ) ) { throw new Carte.CarteCommandException( BaseMessages.getString( PKG, "Carte.Error.NoShutdown", hostname, "" + port ) ); } } catch ( Exception e ) { throw new Carte.CarteCommandException( BaseMessages.getString( PKG, "Carte.Error.NoServerFound", hostname, "" + port ), e ); } }
Example #16
Source File: AbstractWebIT.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void createClient(String ctxPath) throws Exception { testProperties = new TestProperties(); APP_BASE_PATH = testProperties.getApplicationPath("/" + ctxPath); LOGGER.info("Connecting to application "+APP_BASE_PATH); ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = ApacheHttpClient4.create(clientConfig); defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient(); HttpParams params = defaultHttpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000); HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000); }
Example #17
Source File: AbstractWebIntegrationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void createClient(String ctxPath) throws Exception { testProperties = new TestProperties(); APP_BASE_PATH = testProperties.getApplicationPath("/" + ctxPath); LOGGER.info("Connecting to application "+APP_BASE_PATH); ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = ApacheHttpClient4.create(clientConfig); defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient(); HttpParams params = defaultHttpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000); HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000); }
Example #18
Source File: TestUtil.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public TestUtil(TestProperties testProperties) { this.testProperties = testProperties; // create admin user: ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = ApacheHttpClient4.create(clientConfig); defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient(); }
Example #19
Source File: RegistryClientUtil.java From occurrence with Apache License 2.0 | 5 votes |
/** * 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 #20
Source File: WebUtils.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * A helper method for creating clients. The client will be created using * the given configuration and security context. Additionally, the client * will be automatically configured for JSON serialization/deserialization. * * @param config client configuration * @param ctx security context, which may be null for non-secure client * creation * * @return a Client instance */ private static Client createClientHelper(final ClientConfig config, final SSLContext ctx) { final ClientConfig finalConfig = (config == null) ? new DefaultClientConfig() : config; if (ctx != null && StringUtils.isBlank((String) finalConfig.getProperty(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES))) { // custom hostname verifier that checks subject alternative names against the hostname of the URI final HostnameVerifier hostnameVerifier = new HostnameVerifier() { @Override public boolean verify(final String hostname, final SSLSession ssls) { try { for (final Certificate peerCertificate : ssls.getPeerCertificates()) { if (peerCertificate instanceof X509Certificate) { final X509Certificate x509Cert = (X509Certificate) peerCertificate; final List<String> subjectAltNames = CertificateUtils.getSubjectAlternativeNames(x509Cert); if (subjectAltNames.contains(hostname.toLowerCase())) { return true; } } } } catch (final SSLPeerUnverifiedException | CertificateParsingException ex) { logger.warn("Hostname Verification encountered exception verifying hostname due to: " + ex, ex); } return false; } }; finalConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx)); } finalConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); finalConfig.getClasses().add(ObjectMapperResolver.class); // web client for restful request return Client.create(finalConfig); }
Example #21
Source File: JAXBContextResolver.java From hadoop with Apache License 2.0 | 5 votes |
public JAXBContextResolver() throws Exception { this.types = new HashSet<Class>(Arrays.asList(cTypes)); // sets the json configuration so that the json output looks like // the xml output this.context = new JSONJAXBContext(JSONConfiguration.natural(). rootUnwrapping(false).build(), cTypes); }
Example #22
Source File: YandexTranslate.java From localization_nifi with Apache License 2.0 | 5 votes |
@OnScheduled public void onScheduled(final ProcessContext context) { final ClientConfig config = new DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); config.getClasses().add(ObjectMapperResolver.class); client = Client.create(config); }
Example #23
Source File: HmacClientFilterTest.java From jersey-hmac-auth with Apache License 2.0 | 4 votes |
private Client createClient() { ClientConfig config = new DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); return Client.create(config); }
Example #24
Source File: StramWebApp.java From Bats with Apache License 2.0 | 4 votes |
/** * @throws Exception */ public JAXBContextResolver() throws Exception { this.types = new HashSet<>(Arrays.asList(cTypes)); this.context = new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false).build(), cTypes); }
Example #25
Source File: JAXBContextResolver.java From ambari-metrics with Apache License 2.0 | 4 votes |
public JAXBContextResolver() throws Exception { this.types = new HashSet<Class>(Arrays.asList(cTypes)); this.context = new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false) .build(), cTypes); }
Example #26
Source File: LiveSalesViewClient.java From marathonv5 with Apache License 2.0 | 4 votes |
public LiveSalesViewClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(config); webResource = client.resource(DataApplication.SERVER_URI).path("com.javafx.experiments.dataapp.model.livesaleslist"); }
Example #27
Source File: RegionClient.java From marathonv5 with Apache License 2.0 | 4 votes |
public RegionClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(config); webResource = client.resource(DataApplication.SERVER_URI).path("com.javafx.experiments.dataapp.model.region"); }
Example #28
Source File: ProductTypeClient.java From marathonv5 with Apache License 2.0 | 4 votes |
public ProductTypeClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(config); webResource = client.resource(DataApplication.SERVER_URI).path("com.javafx.experiments.dataapp.model.producttype"); }
Example #29
Source File: CumulativeLiveSalesClient.java From marathonv5 with Apache License 2.0 | 4 votes |
public CumulativeLiveSalesClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(config); webResource = client.resource(DataApplication.SERVER_URI).path("com.javafx.experiments.dataapp.model.cumulativelivesales"); }
Example #30
Source File: HeatMapClient.java From marathonv5 with Apache License 2.0 | 4 votes |
public HeatMapClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(config); webResource = client.resource(DataApplication.SERVER_URI).path("com.javafx.experiments.dataapp.model.heatmap"); }