本文整理汇总了Java中org.glassfish.jersey.client.RequestEntityProcessing类的典型用法代码示例。如果您正苦于以下问题:Java RequestEntityProcessing类的具体用法?Java RequestEntityProcessing怎么用?Java RequestEntityProcessing使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestEntityProcessing类属于org.glassfish.jersey.client包,在下文中一共展示了RequestEntityProcessing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createClientConfig
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
protected ClientConfig createClientConfig() {
ClientConfig config = new ClientConfig();
if ( proxy != null && proxy.getUri() != null ) {
config.property(ClientProperties.PROXY_URI, proxy.getUriString());
config.property(ClientProperties.PROXY_USERNAME, proxy.getUserName());
config.property(ClientProperties.PROXY_PASSWORD, proxy.getPassword());
}
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
config.property(ApacheClientProperties.CREDENTIALS_PROVIDER, getCredentialsProvider());
config.property(ApacheClientProperties.SERVICE_UNAVAILABLE_RETRY_STRATEGY, getServiceUnavailableRetryStrategy());
config.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, doPreemptiveBasicAuthentication());
config.connectorProvider(new ApacheConnectorProvider());
config.register(JacksonFeature.class);
config.register(new LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), Level.FINE, LoggingFeature.Verbosity.PAYLOAD_ANY, 10000));
return config;
}
示例2: upgradeToJerseyConfigBean
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
/**
* Helper method to upgrade both HTTP stages to the JerseyConfigBean
* @param configs List of configs to upgrade.
*/
public static void upgradeToJerseyConfigBean(List<Config> configs) {
List<Config> configsToAdd = new ArrayList<>();
List<Config> configsToRemove = new ArrayList<>();
List<String> movedConfigs = ImmutableList.of(
"conf.requestTimeoutMillis",
"conf.numThreads",
"conf.authType",
"conf.oauth",
"conf.basicAuth",
"conf.useProxy",
"conf.proxy",
"conf.sslConfig"
);
for (Config config : configs) {
if (hasPrefixIn(movedConfigs, config.getName())) {
configsToRemove.add(config);
configsToAdd.add(new Config(config.getName().replace("conf.", "conf.client."), config.getValue()));
}
}
configsToAdd.add(new Config("conf.client.transferEncoding", RequestEntityProcessing.CHUNKED));
configs.removeAll(configsToRemove);
configs.addAll(configsToAdd);
}
示例3: ExtensionsService
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
@Autowired
public ExtensionsService(
@Value("${org.osiam.endpoint:}") String osiamEndpoint,
@Value("${org.osiam.resourceServerEndpoint:}") String resourceServerEndpoint,
GeneralSessionData sessionData, ObjectMapper mapper
) {
this.sessionData = sessionData;
this.mapper = mapper;
Client client = ClientBuilder.newClient(new ClientConfig()
.connectorProvider(new ApacheConnectorProvider())
.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED)
.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT)
.property(ClientProperties.READ_TIMEOUT, READ_TIMEOUT)
.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager()));
if (!Strings.isNullOrEmpty(osiamEndpoint)) {
target = client.target(osiamEndpoint);
} else if (!Strings.isNullOrEmpty(resourceServerEndpoint)) {
target = client.target(resourceServerEndpoint);
} else {
throw new BeanCreationException("Error creating extension client. No OSIAM endpoint set.");
}
}
示例4: initializeClient
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
private void initializeClient(String username, String password) {
reentrantLock.lock();
try {
if (client != null)
return;
// build client
ClientConfig clientConfig = new ConfigLoader<>(ClientConfig.class, "interfax-api-config.yaml").getTestConfig();
HttpAuthenticationFeature httpAuthenticationFeature = HttpAuthenticationFeature.basic(username, password);
client = ClientBuilder.newClient();
client.register(httpAuthenticationFeature);
client.register(MultiPartFeature.class);
client.register(RequestEntityProcessing.CHUNKED);
client.register(JacksonFeature.class);
// required for the document upload API, to set Content-Length header
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
// for automatically deriving content type given a file
tika = new Tika();
// read config from yaml
scheme = clientConfig.getInterFAX().getScheme();
hostname = clientConfig.getInterFAX().getHostname();
port = clientConfig.getInterFAX().getPort();
readConfigAndInitializeEndpoints(clientConfig);
} finally {
reentrantLock.unlock();
}
}
示例5: getUriHttpRequest
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
private HttpUriRequest getUriHttpRequest(final ClientRequest clientRequest) {
final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig);
final int connectTimeout = clientRequest.resolveProperty(ClientProperties.CONNECT_TIMEOUT, -1);
final int socketTimeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, -1);
if (connectTimeout >= 0) {
requestConfigBuilder.setConnectTimeout(connectTimeout);
}
if (socketTimeout >= 0) {
requestConfigBuilder.setSocketTimeout(socketTimeout);
}
final Boolean redirectsEnabled =
clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, requestConfig.isRedirectsEnabled());
requestConfigBuilder.setRedirectsEnabled(redirectsEnabled);
final Boolean bufferingEnabled = clientRequest.resolveProperty(ClientProperties.REQUEST_ENTITY_PROCESSING,
RequestEntityProcessing.class) == RequestEntityProcessing.BUFFERED;
final HttpEntity entity = getHttpEntity(clientRequest, bufferingEnabled);
return RequestBuilder
.create(clientRequest.getMethod())
.setUri(clientRequest.getUri())
.setConfig(requestConfigBuilder.build())
.setEntity(entity)
.build();
}
示例6: getClientConfig
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
@Test
public void getClientConfig() {
AuthenticationInfo info = new AuthenticationInfo("user1", "pass", "server1", "4display");
final ClientConfig config = RestClientHelper.getClientConfig(ServerContext.Type.TFS, info, false);
final Map<String, Object> properties = config.getProperties();
Assert.assertEquals(3, properties.size());
Assert.assertEquals(false, properties.get(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION));
Assert.assertEquals(RequestEntityProcessing.BUFFERED, properties.get(ClientProperties.REQUEST_ENTITY_PROCESSING));
final CredentialsProvider cp = (CredentialsProvider) properties.get(ApacheClientProperties.CREDENTIALS_PROVIDER);
final Credentials credentials = cp.getCredentials(AuthScope.ANY);
Assert.assertEquals(info.getPassword(), credentials.getPassword());
Assert.assertEquals(info.getUserName(), credentials.getUserPrincipal().getName());
// Make sure Fiddler properties get set if property is on
final ClientConfig config2 = RestClientHelper.getClientConfig(ServerContext.Type.TFS, info, true);
final Map<String, Object> properties2 = config2.getProperties();
//proxy setting doesn't automatically mean we need to setup ssl trust store anymore
Assert.assertEquals(4, properties2.size());
Assert.assertNotNull(properties2.get(ClientProperties.PROXY_URI));
Assert.assertNull(properties2.get(ApacheClientProperties.SSL_CONFIG));
info = new AuthenticationInfo("users1", "pass", "https://tfsonprem.test", "4display");
final ClientConfig config3 = RestClientHelper.getClientConfig(ServerContext.Type.TFS, info, false);
final Map<String, Object> properties3 = config3.getProperties();
Assert.assertEquals(4, properties3.size());
Assert.assertNull(properties3.get(ClientProperties.PROXY_URI));
Assert.assertNotNull(properties3.get(ApacheClientProperties.SSL_CONFIG));
}
示例7: createJaxrsClient
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
private static javax.ws.rs.client.Client createJaxrsClient(
final HttpClientConnectionManager connectionManager, final int connectionTimeout,
final int socketTimeout, @Nullable final ProxyConfig proxy) {
// Configure requests
final RequestConfig requestConfig = RequestConfig.custom()//
.setExpectContinueEnabled(false) //
.setRedirectsEnabled(false) //
.setConnectionRequestTimeout(connectionTimeout) //
.setConnectTimeout(connectionTimeout) //
.setSocketTimeout(socketTimeout)
.build();
// Configure client
final ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
config.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
config.property(ApacheClientProperties.DISABLE_COOKIES, true); // not needed
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING,
RequestEntityProcessing.CHUNKED); // required to stream data to the server
if (proxy != null) {
config.property(ClientProperties.PROXY_URI, proxy.getURL());
config.property(ClientProperties.PROXY_USERNAME, proxy.getUsername());
config.property(ClientProperties.PROXY_PASSWORD, proxy.getPassword());
}
// Register filter and custom serializer
config.register(Serializer.class);
config.register(GZipEncoder.class);
// Create and return a configured JAX-RS client
return ClientBuilder.newClient(config);
}
示例8: setup
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
public OAuth2ConfigBean setup(Client client, WebTarget target, Invocation.Builder builder, Response response, OAuth2GrantTypes grantType) {
OAuth2ConfigBean configBean = new OAuth2ConfigBean();
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
RequestEntityProcessing transferEncoding = RequestEntityProcessing.BUFFERED;
if (grantType == OAuth2GrantTypes.CLIENT_CREDENTIALS) {
params.put(OAuth2ConfigBean.CLIENT_ID_KEY, Collections.singletonList(clientId));
params.put(OAuth2ConfigBean.CLIENT_SECRET_KEY, Collections.singletonList(clientSecret));
params.put(OAuth2ConfigBean.GRANT_TYPE_KEY, Collections.singletonList(OAuth2ConfigBean.CLIENT_CREDENTIALS_GRANT));
configBean.clientId = () -> clientId;
configBean.clientSecret = () -> clientSecret;
} else {
params.put(OAuth2ConfigBean.RESOURCE_OWNER_KEY, Collections.singletonList(clientId));
params.put(OAuth2ConfigBean.PASSWORD_KEY, Collections.singletonList(clientSecret));
params.put(OAuth2ConfigBean.GRANT_TYPE_KEY, Collections.singletonList(OAuth2ConfigBean.RESOURCE_OWNER_GRANT));
configBean.username = () -> clientId;
configBean.password = () -> clientSecret;
}
configBean.credentialsGrantType = grantType;
configBean.transferEncoding = RequestEntityProcessing.BUFFERED;
configBean.tokenUrl = "https://example.com";
Mockito.when(response.readEntity(String.class)).thenReturn(TOKEN_RESPONSE);
Mockito.when(response.getStatus()).thenReturn(200);
Mockito.when(builder.post(Mockito.argThat(new FormMatcher(Entity.form(params))))).thenReturn(response);
Mockito.when(builder.property(ClientProperties.REQUEST_ENTITY_PROCESSING, transferEncoding)).thenReturn(builder);
Mockito.when(builder.header(any(String.class), any(Object.class))).thenReturn(builder);
Mockito.when(target.request()).thenReturn(builder);
Mockito.when(client.target(configBean.tokenUrl)).thenReturn(target);
return configBean;
}
示例9: getHttpClientConfigBean
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
private HttpClientConfigBean getHttpClientConfigBean(
int start,
int limit,
PaginationMode mode,
boolean keepAllFields
) {
HttpClientConfigBean conf = new HttpClientConfigBean();
conf.client.authType = AuthenticationType.NONE;
conf.httpMode = HttpClientMode.BATCH;
conf.resourceUrl = getBaseUri() + String.format(
"paging?pageNum=${startAt}&limit=%d&mode=%s",
limit,
mode.name()
);
conf.client.readTimeoutMillis = 0;
conf.client.connectTimeoutMillis = 0;
conf.client.transferEncoding = RequestEntityProcessing.BUFFERED;
conf.basic.maxBatchSize = 10;
conf.basic.maxWaitTime = 10000;
conf.pollingInterval = 1000;
conf.httpMethod = HttpMethod.GET;
conf.dataFormat = DataFormat.JSON;
conf.dataFormatConfig.jsonContent = JsonMode.MULTIPLE_OBJECTS;
conf.pagination.mode = mode;
conf.pagination.startAt = start;
conf.pagination.resultFieldPath = "/results";
conf.pagination.rateLimit = 0;
conf.pagination.keepAllFields = keepAllFields;
conf.pagination.nextPageFieldPath = "/next";
conf.pagination.stopCondition = "${!record:exists('/next')}";
return conf;
}
示例10: createRestClient
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
private Client createRestClient() {
ClientConfig cc = new ClientConfig();
if (configuration.getProperty("performance.platform.proxyHost", "").length() > 0) {
cc.property(ClientProperties.PROXY_URI, configuration.getProperty("performance.platform.proxyHost"));
cc.property(ClientProperties.PROXY_USERNAME, configuration.getProperty("performance.platform.proxyUsername"));
cc.property(ClientProperties.PROXY_PASSWORD, configuration.getProperty("performance.platform.proxyPassword"));
}
cc.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
cc.connectorProvider(new ApacheConnectorProvider());
return ClientBuilder.newClient(cc);
}
示例11: getClientConfig
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
public static ClientConfig getClientConfig(PoolingHttpClientConnectionManager connectionManager) {
ClientConfig clientConfig = new ClientConfig();
// We want to use the Apache connector for chunk POST support.
clientConfig.connectorProvider(new ApacheConnectorProvider());
connectionManager.setDefaultMaxPerRoute(20);
connectionManager.setMaxTotal(80);
connectionManager.closeIdleConnections(30, TimeUnit.SECONDS);
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
clientConfig.register(GZipEncoder.class);
clientConfig.register(new MoxyXmlFeature());
clientConfig.register(new LoggingFilter(java.util.logging.Logger.getGlobal(), true));
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
// Apache specific configuration.
RequestConfig.Builder custom = RequestConfig.custom();
custom.setExpectContinueEnabled(true);
custom.setRelativeRedirectsAllowed(true);
custom.setRedirectsEnabled(true);
custom.setSocketTimeout(Integer.parseInt(System.getProperty(TCP_SO_TIMEOUT, Integer.toString(SO_TIMEOUT))));
custom.setConnectTimeout(Integer.parseInt(System.getProperty(TCP_CONNECT_TIMEOUT, Integer.toString(CONNECT_TIMEOUT))));
custom.setConnectionRequestTimeout(Integer.parseInt(System.getProperty(TCP_CONNECT_REQUEST_TIMEOUT, Integer.toString(CONNECT_REQUEST_TIMEOUT))));
clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, custom.build());
return clientConfig;
}
示例12: getClient
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
private Client getClient(URI uri, TfsClientFactoryImpl.ServiceProvider provider, String username, Secret password) {
ClientConfig clientConfig = new ClientConfig();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (TfsClientFactoryImpl.ServiceProvider.TFS == provider) {
/* NTLM auth for on premise installation */
String domain = null;
int idx = Math.max(username.indexOf('/'), username.indexOf('\\'));
if (idx > 0) {
domain = username.substring(0, idx);
username = username.substring(idx + 1);
}
credentialsProvider.setCredentials(
new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM, AuthSchemes.NTLM),
new NTCredentials(username, Secret.toString(password), uri.getHost(), domain));
logger.info("Using NTLM authentication for on premise TeamFoundationServer");
} else if (TfsClientFactoryImpl.ServiceProvider.VSO == provider) {
// Basic Auth for VSO services
credentialsProvider.setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, Secret.toString(password)));
logger.info("Using user/pass authentication for Visual Studio Online services");
// Preemptive send basic auth header, or we will be redirected for oauth login
clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
}
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
if (System.getProperty(PROXY_URL_PROPERTY) != null) {
clientConfig.property(ClientProperties.PROXY_URI, System.getProperty(PROXY_URL_PROPERTY));
clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator());
}
clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
clientConfig.connectorProvider(new ApacheConnectorProvider());
return ClientBuilder.newClient(clientConfig);
}
示例13: getClientConfig
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
public static ClientConfig getClientConfig(final ServerContext.Type type,
final Credentials credentials,
final String serverUri,
final boolean includeProxySettings) {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
final ConnectorProvider connectorProvider = new ApacheConnectorProvider();
// custom json provider ignores new fields that aren't recognized
final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final ClientConfig clientConfig = new ClientConfig(jacksonJsonProvider).connectorProvider(connectorProvider);
clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
// For TFS OnPrem we only support NTLM authentication right now. Since 2016 servers support Basic as well,
// we need to let the server and client negotiate the protocol instead of preemptively assuming Basic.
// TODO: This prevents PATs from being used OnPrem. We need to fix this soon to support PATs onPrem.
clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, type != ServerContext.Type.TFS);
//Define a local HTTP proxy
if (includeProxySettings) {
final HttpProxyService proxyService = PluginServiceProvider.getInstance().getHttpProxyService();
final String proxyUrl = proxyService.getProxyURL();
clientConfig.property(ClientProperties.PROXY_URI, proxyUrl);
if (proxyService.isAuthenticationRequired()) {
// To work with authenticated proxies and TFS, we provide the proxy credentials if they are registered
final AuthScope ntlmAuthScope =
new AuthScope(proxyService.getProxyHost(), proxyService.getProxyPort(),
AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
credentialsProvider.setCredentials(ntlmAuthScope,
new UsernamePasswordCredentials(proxyService.getUserName(), proxyService.getPassword()));
}
}
// if this is a onPrem server and the uri starts with https, we need to setup ssl
if (isSSLEnabledOnPrem(type, serverUri)) {
clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator());
}
// register a filter to set the User Agent header
clientConfig.register(new ClientRequestFilter() {
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
// The default user agent is something like "Jersey/2.6"
final String defaultUserAgent = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", HttpClientBuilder.class);
// We get the user agent string from the Telemetry context
final String userAgent = PluginServiceProvider.getInstance().getTelemetryContextInitializer().getUserAgent(defaultUserAgent);
// Finally, we can add the header
requestContext.getHeaders().add(HttpHeaders.USER_AGENT, userAgent);
}
});
return clientConfig;
}
示例14: init
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
@Override
public List<Stage.ConfigIssue> init(Stage.Context context, SparkExecutorConfigBean configs) {
List<Stage.ConfigIssue> issues = new ArrayList<>();
databricksConfigBean = configs.databricksConfigBean;
Optional
.ofNullable(databricksConfigBean.init(context, PREFIX))
.ifPresent(issues::addAll);
baseUrl = databricksConfigBean.baseUrl.endsWith("/") ?
databricksConfigBean.baseUrl.substring(0, databricksConfigBean.baseUrl.length() - 1) :
databricksConfigBean.baseUrl;
com.streamsets.pipeline.lib.http.HttpProxyConfigBean proxyConf = databricksConfigBean.proxyConfigBean
.getUnderlyingConfig();
boolean useProxy = !StringUtils.isEmpty(proxyConf.uri);
String proxyUsername = null;
String proxyPassword = null;
if(useProxy) {
proxyUsername = proxyConf.resolveUsername(context, "PROXY", "conf.databricksConfigBean.proxyConfigBean.", issues);
proxyPassword = proxyConf.resolvePassword(context, "PROXY", "conf.databricksConfigBean.proxyConfigBean.", issues);
}
if(issues.isEmpty()) {
ClientConfig clientConfig = new ClientConfig()
.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 1)
.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
if(useProxy) {
clientConfig = clientConfig.connectorProvider(new GrizzlyConnectorProvider(new GrizzlyClientCustomizer(
useProxy,
proxyUsername,
proxyPassword
)));
}
HttpAuthenticationFeature auth = configs.credentialsConfigBean.init();
ClientBuilder builder = getClientBuilder()
.withConfig(clientConfig)
.register(JacksonJsonProvider.class);
if (auth != null) {
builder.register(auth);
}
JerseyClientUtil.configureSslContext(databricksConfigBean.sslConfigBean.getUnderlyingConfig(), builder);
if(useProxy) {
JerseyClientUtil.configureProxy(
proxyConf.uri,
proxyUsername,
proxyPassword,
builder
);
}
client = builder.build();
validateWithDatabricks(context, issues);
}
return issues;
}
示例15: RequestEntityProcessingChooserValues
import org.glassfish.jersey.client.RequestEntityProcessing; //导入依赖的package包/类
public RequestEntityProcessingChooserValues() {
super (RequestEntityProcessing.class);
}