org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider Java Examples
The following examples show how to use
org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider.
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: RESTClient.java From TeaStore with Apache License 2.0 | 5 votes |
/** * Creates a new REST Client for an entity of Type T. The client interacts with a Server providing * CRUD functionalities * @param hostURL The url of the host. Common Pattern: "http://[hostname]:[port]/servicename/" * @param application The name of the rest application, usually {@link #DEFAULT_REST_APPLICATION} "rest" (no "/"!) * @param endpoint The name of the rest endpoint, typically the all lower case name of the entity in a plural form. * E.g., "products" for the entity "Product" (no "/"!) * @param entityClass Classtype of the Entitiy to send/receive. Note that the use of this Class type is * open for interpretation by the inheriting REST clients. */ public RESTClient(String hostURL, String application, String endpoint, final Class<T> entityClass) { if (!hostURL.endsWith("/")) { hostURL += "/"; } if (!hostURL.contains("://")) { hostURL = "http://" + hostURL; } ClientConfig config = new ClientConfig(); config.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout); config.property(ClientProperties.READ_TIMEOUT, readTimeout); //PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); //connectionManager.setMaxTotal(MAX_POOL_SIZE); //connectionManager.setDefaultMaxPerRoute(DEFAULT_POOL_SIZE); //config.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager); config.connectorProvider(new GrizzlyConnectorProvider()); client = ClientBuilder.newClient(config); service = client.target(UriBuilder.fromUri(hostURL).build()); applicationURI = application; endpointURI = endpoint; this.entityClass = entityClass; parameterizedGenericType = new ParameterizedType() { public Type[] getActualTypeArguments() { return new Type[] { entityClass }; } public Type getRawType() { return List.class; } public Type getOwnerType() { return List.class; } }; genericListType = new GenericType<List<T>>(parameterizedGenericType) { }; }
Example #2
Source File: RxJerseyClientFeature.java From rx-jersey with MIT License | 5 votes |
private Client createClient() { int cores = Runtime.getRuntime().availableProcessors(); ClientConfig config = new ClientConfig(); config.connectorProvider(new GrizzlyConnectorProvider()); config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, cores); config.register(RxObservableInvokerProvider.class); return ClientBuilder.newClient(config); }
Example #3
Source File: RxJerseyClientFeature.java From rx-jersey with MIT License | 5 votes |
private Client defaultClient() { int cores = Runtime.getRuntime().availableProcessors(); ClientConfig config = new ClientConfig(); config.connectorProvider(new GrizzlyConnectorProvider()); config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, cores); config.register(RxFlowableInvokerProvider.class); return ClientBuilder.newClient(config); }
Example #4
Source File: RxJerseyBundle.java From rx-jersey with MIT License | 4 votes |
private Client getClient(Environment environment, JerseyClientConfiguration jerseyClientConfiguration) { return new JerseyClientBuilder(environment) .using(jerseyClientConfiguration) .using(new GrizzlyConnectorProvider()) .buildRx("rxJerseyClient", RxFlowableInvokerProvider.class); }
Example #5
Source File: HttpClientCommon.java From datacollector with Apache License 2.0 | 4 votes |
public List<Stage.ConfigIssue> init(List<Stage.ConfigIssue> issues, Stage.Context context) { this.context = context; if (jerseyClientConfig.tlsConfig.isEnabled()) { jerseyClientConfig.tlsConfig.init( context, Groups.TLS.name(), SSL_CONFIG_PREFIX, issues ); } resourceVars = context.createELVars(); resourceEval = context.createELEval(RESOURCE_CONFIG_NAME); methodVars = context.createELVars(); methodEval = context.createELEval(HTTP_METHOD_CONFIG_NAME); headerVars = context.createELVars(); headerEval = context.createELEval(HEADER_CONFIG_NAME); String proxyUsername = null; String proxyPassword = null; if(jerseyClientConfig.useProxy) { proxyUsername = jerseyClientConfig.proxy.resolveUsername(context, Groups.PROXY.name(), "conf.client.proxy.", issues); proxyPassword = jerseyClientConfig.proxy.resolvePassword(context, Groups.PROXY.name(), "conf.client.proxy.", issues); } jerseyClientConfig.init(context, Groups.PROXY.name(), "conf.client.", issues); // Validation succeeded so configure the client. if (issues.isEmpty()) { ClientConfig clientConfig = new ClientConfig() .property(ClientProperties.CONNECT_TIMEOUT, jerseyClientConfig.connectTimeoutMillis) .property(ClientProperties.READ_TIMEOUT, jerseyClientConfig.readTimeoutMillis) .property(ClientProperties.ASYNC_THREADPOOL_SIZE, jerseyClientConfig.numThreads); if(jerseyClientConfig.useProxy) { clientConfig = clientConfig.connectorProvider(new GrizzlyConnectorProvider(new GrizzlyClientCustomizer( jerseyClientConfig.useProxy, proxyUsername, proxyPassword ))); } clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig); if (jerseyClientConfig.requestLoggingConfig.enableRequestLogging) { Feature feature = new LoggingFeature( REQUEST_LOGGER, Level.parse(jerseyClientConfig.requestLoggingConfig.logLevel), jerseyClientConfig.requestLoggingConfig.verbosity, jerseyClientConfig.requestLoggingConfig.maxEntitySize ); clientBuilder = clientBuilder.register(feature); } configureCompression(clientBuilder); if (jerseyClientConfig.useProxy) { JerseyClientUtil.configureProxy( jerseyClientConfig.proxy.uri, proxyUsername, proxyPassword, clientBuilder ); } JerseyClientUtil.configureSslContext(jerseyClientConfig.tlsConfig, clientBuilder); configureAuthAndBuildClient(clientBuilder, issues); } return issues; }
Example #6
Source File: HttpClientCommon.java From datacollector with Apache License 2.0 | 4 votes |
public List<Stage.ConfigIssue> init(List<Stage.ConfigIssue> issues, Stage.Context context) { this.context = context; if (jerseyClientConfig.tlsConfig.isEnabled()) { jerseyClientConfig.tlsConfig.init( context, Groups.TLS.name(), SSL_CONFIG_PREFIX, issues ); } resourceVars = context.createELVars(); resourceEval = context.createELEval(RESOURCE_CONFIG_NAME); methodVars = context.createELVars(); methodEval = context.createELEval(HTTP_METHOD_CONFIG_NAME); headerVars = context.createELVars(); headerEval = context.createELEval(HEADER_CONFIG_NAME); String proxyUsername = null; String proxyPassword = null; if(jerseyClientConfig.useProxy) { proxyUsername = jerseyClientConfig.proxy.resolveUsername(context, Groups.PROXY.name(), "conf.client.proxy.", issues); proxyPassword = jerseyClientConfig.proxy.resolvePassword(context, Groups.PROXY.name(), "conf.client.proxy.", issues); } jerseyClientConfig.init(context, Groups.PROXY.name(), "conf.client.", issues); // Validation succeeded so configure the client. if (issues.isEmpty()) { ClientConfig clientConfig = new ClientConfig() .property(ClientProperties.CONNECT_TIMEOUT, jerseyClientConfig.connectTimeoutMillis) .property(ClientProperties.READ_TIMEOUT, jerseyClientConfig.readTimeoutMillis) .property(ClientProperties.ASYNC_THREADPOOL_SIZE, jerseyClientConfig.numThreads) .property(ClientProperties.REQUEST_ENTITY_PROCESSING, jerseyClientConfig.transferEncoding) .property(ClientProperties.USE_ENCODING, jerseyClientConfig.httpCompression.getValue()); if(jerseyClientConfig.useProxy) { clientConfig = clientConfig.connectorProvider(new GrizzlyConnectorProvider(new GrizzlyClientCustomizer( jerseyClientConfig.useProxy, proxyUsername, proxyPassword ))); } clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig); if (jerseyClientConfig.requestLoggingConfig.enableRequestLogging) { Feature feature = new LoggingFeature( REQUEST_LOGGER, Level.parse(jerseyClientConfig.requestLoggingConfig.logLevel), jerseyClientConfig.requestLoggingConfig.verbosity, jerseyClientConfig.requestLoggingConfig.maxEntitySize ); clientBuilder = clientBuilder.register(feature); } configureCompression(clientBuilder); if (jerseyClientConfig.useProxy) { JerseyClientUtil.configureProxy( jerseyClientConfig.proxy.uri, proxyUsername, proxyPassword, clientBuilder ); } JerseyClientUtil.configureSslContext(jerseyClientConfig.tlsConfig, clientBuilder); configureAuthAndBuildClient(clientBuilder, issues); if(jerseyClientConfig.authType.equals(AuthenticationType.KERBEROS_SPNEGO)) { String principal = jerseyClientConfig.spnegoPrincipal; String keytab = jerseyClientConfig.spnegoKeytabFile; CredentialValue princPass = jerseyClientConfig.spnegoPrincipalPassword; String pathnameSpnegoConf = context.getResourcesDirectory() + "/spnego.conf"; File f = new File(pathnameSpnegoConf); try { PrintWriter pw = new PrintWriter(f); pw.println(String.format(SPNEGO_CLIENT_LOGIN, principal, keytab)); pw.close(); } catch (IOException e) { throw new StageException(HTTP_36,e); } System.setProperty(JAVAX_SECURITY_AUTH_USE_SUBJECT_CREDS_ONLY, "false"); System.setProperty(JAVA_SECURITY_AUTH_LOGIN_CONFIG, pathnameSpnegoConf); Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { String kuser = principal; String kpass = princPass.get(); return (new PasswordAuthentication(kuser, kpass.toCharArray())); } }); } } return issues; }
Example #7
Source File: DatabricksJobExecutor.java From datacollector with Apache License 2.0 | 4 votes |
@Override public List<Stage.ConfigIssue> init() { List<Stage.ConfigIssue> issues = new ArrayList<>(); Optional .ofNullable(databricksConfigBean.init(getContext(), PREFIX)) .ifPresent(issues::addAll); baseUrl = databricksConfigBean.baseUrl.endsWith("/") ? databricksConfigBean.baseUrl.substring(0, databricksConfigBean.baseUrl.length() - 1) : databricksConfigBean.baseUrl; HttpProxyConfigBean proxyConf = databricksConfigBean.proxyConfigBean; String proxyUsername = null; String proxyPassword = null; if(databricksConfigBean.useProxy) { proxyUsername = proxyConf.resolveUsername(getContext(), "PROXY", "conf.proxyConfigBean.", issues); proxyPassword = proxyConf.resolvePassword(getContext(), "PROXY", "conf.proxyConfigBean.", issues); } if(issues.isEmpty()) { ClientConfig clientConfig = new ClientConfig() .property(ClientProperties.ASYNC_THREADPOOL_SIZE, 1) .property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED); if (databricksConfigBean.useProxy) { clientConfig = clientConfig.connectorProvider(new GrizzlyConnectorProvider(new GrizzlyClientCustomizer( true, proxyUsername, proxyPassword ))); } ClientBuilder builder = getClientBuilder() .withConfig(clientConfig) .register(JacksonJsonProvider.class); HttpAuthenticationFeature auth = null; if (databricksConfigBean.credentialsConfigBean.credentialType == CredentialType.PASSWORD) { String username = databricksConfigBean.credentialsConfigBean.resolveUsername( getContext(), "CREDENTIALS", "conf.credentialsConfigBean.", issues ); String password = databricksConfigBean.credentialsConfigBean.resolvePassword( getContext(), "CREDENTIALS", "conf.credentialsConfigBean.", issues ); auth = HttpAuthenticationFeature.basic(username, password); builder.register(auth); } else { String token = databricksConfigBean.credentialsConfigBean.resolveToken( getContext(), "CREDENTIALS", "conf.credentialsConfigBean.", issues ); builder.register((ClientRequestFilter) requestContext -> requestContext.getHeaders().add("Authorization", "Bearer " + token) ); } JerseyClientUtil.configureSslContext(databricksConfigBean.tlsConfigBean, builder); if(databricksConfigBean.useProxy) { JerseyClientUtil.configureProxy( proxyConf.uri, proxyUsername, proxyPassword, builder ); } client = builder.build(); validateWithDatabricks(getContext(), issues); } return issues; }