本文整理汇总了Java中org.glassfish.jersey.client.ClientProperties类的典型用法代码示例。如果您正苦于以下问题:Java ClientProperties类的具体用法?Java ClientProperties怎么用?Java ClientProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientProperties类属于org.glassfish.jersey.client包,在下文中一共展示了ClientProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RadioBrowser
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/** Custom constructor for mocked unit testing.
* @param apiUrl the base URL of the API.
* @param timeout the timeout in milliseconds for connecting
* and reading.
* @param myUserAgent the user agent string to use.
* */
RadioBrowser(final String apiUrl,
final int timeout,
final String myUserAgent) {
if (timeout <= 0) {
throw new IllegalArgumentException(
"timeout must be > 0, but is "
+ timeout);
}
this.userAgent = Objects.requireNonNull(myUserAgent,
"User agent is null");
Client client = ClientBuilder.newBuilder()
.register(JacksonFeature.class)
.build();
client.property(ClientProperties.CONNECT_TIMEOUT, timeout);
client.property(ClientProperties.READ_TIMEOUT, timeout);
webTarget = client.target(apiUrl);
}
示例2: handleAssignment
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
private void handleAssignment(TaskAssignmentDto taskAssignment)
throws CallbackException {
try {
String callbackUrl = taskAssignment.getTask().getCallbackUrl();
Response response = client.target(callbackUrl)
.property(ClientProperties.FOLLOW_REDIRECTS, configuration.getClientFollowRedirects())
.request(MediaType.WILDCARD_TYPE)
.post(Entity.entity(taskAssignment, MediaType.APPLICATION_JSON_TYPE));
if (response.getStatus() == Status.SERVICE_UNAVAILABLE.getStatusCode()) {
// On 503 response we will try again
// TODO Retry-After header?!
throw new CallbackException();
}
} catch (ProcessingException e) {
throw new CallbackException();
}
}
示例3: testDelete
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/**
* Tests removing a tenant id with DELETE request.
*/
@Test
public void testDelete() {
expect(mockVnetAdminService.getTenantIds())
.andReturn(ImmutableSet.of(tenantId2)).anyTimes();
mockVnetAdminService.unregisterTenantId(anyObject());
expectLastCall();
replay(mockVnetAdminService);
WebTarget wt = target()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
Response response = wt.path("tenants/" + tenantId2)
.request(MediaType.APPLICATION_JSON_TYPE)
.delete();
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
verify(mockVnetAdminService);
}
示例4: testRemoveDevicesDelete
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/**
* Tests deleting a set of devices contained in the given region with DELETE.
*/
@Test
public void testRemoveDevicesDelete() {
mockRegionAdminService.removeDevices(anyObject(), anyObject());
expectLastCall();
replay(mockRegionAdminService);
WebTarget wt = target()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
InputStream jsonStream = RegionsResourceTest.class
.getResourceAsStream("region-deviceIds.json");
// FIXME: need to consider whether to use jsonStream for entry deletion
Response response = wt.path("regions/" +
region1.id().toString() + "/devices")
.request().method("DELETE", Entity.json(jsonStream));
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
verify(mockRegionAdminService);
}
示例5: testDeleteVirtualNetwork
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/**
* Tests removing a virtual network with DELETE request.
*/
@Test
public void testDeleteVirtualNetwork() {
mockVnetAdminService.removeVirtualNetwork(anyObject());
expectLastCall();
replay(mockVnetAdminService);
WebTarget wt = target()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
Response response = wt.path("vnets/" + "2")
.request(MediaType.APPLICATION_JSON_TYPE)
.delete();
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
verify(mockVnetAdminService);
}
示例6: testDeleteVirtualDevice
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/**
* Tests removing a virtual device with DELETE request.
*/
@Test
public void testDeleteVirtualDevice() {
NetworkId networkId = networkId3;
DeviceId deviceId = devId2;
mockVnetAdminService.removeVirtualDevice(networkId, deviceId);
expectLastCall();
replay(mockVnetAdminService);
WebTarget wt = target()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
String reqLocation = "vnets/" + networkId.toString() + "/devices/" + deviceId.toString();
Response response = wt.path(reqLocation)
.request(MediaType.APPLICATION_JSON_TYPE)
.delete();
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
verify(mockVnetAdminService);
}
示例7: testDeleteVirtualPort
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/**
* Tests removing a virtual port with DELETE request.
*/
@Test
public void testDeleteVirtualPort() {
NetworkId networkId = networkId3;
DeviceId deviceId = devId2;
PortNumber portNum = portNumber(2);
mockVnetAdminService.removeVirtualPort(networkId, deviceId, portNum);
expectLastCall();
replay(mockVnetAdminService);
WebTarget wt = target()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
String reqLocation = "vnets/" + networkId.toString()
+ "/devices/" + deviceId.toString() + "/ports/" + portNum.toLong();
Response response = wt.path(reqLocation)
.request(MediaType.APPLICATION_JSON_TYPE)
.delete();
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
verify(mockVnetAdminService);
}
示例8: testDeleteVirtualLink
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
/**
* Tests removing a virtual link with DELETE request.
*/
@Test
public void testDeleteVirtualLink() {
NetworkId networkId = networkId3;
mockVnetAdminService.removeVirtualLink(networkId, cp22, cp11);
expectLastCall();
replay(mockVnetAdminService);
WebTarget wt = target()
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
InputStream jsonStream = VirtualNetworkWebResourceTest.class
.getResourceAsStream("post-virtual-link.json");
String reqLocation = "vnets/" + networkId.toString() + "/links";
Response response = wt.path(reqLocation).request().method("DELETE", Entity.json(jsonStream));
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
verify(mockVnetAdminService);
}
示例9: testHandleForward
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
@Test
public void testHandleForward() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test forward client");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("en"));
}
示例10: testCorrectLocale
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
@Test
public void testCorrectLocale() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testCorrectLocale");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=de", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("de"));
}
示例11: testCorrectLocaleCountry
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
@Test
public void testCorrectLocaleCountry() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testCorrectLocaleCountry");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=de-ch", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("de-CH"));
}
示例12: testIncorrectLocale
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
@Test
public void testIncorrectLocale() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testIncorrectLocale");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=IAmNotValid", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("en"));
}
示例13: testIncorrectLocaleCountry
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
@Test
public void testIncorrectLocaleCountry() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("testIncorrectLocaleCountry");
client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);
Response response = client.target(
String.format("http://localhost:%d/nominatim?q=berlin&locale=de-zz", RULE.getLocalPort()))
.request()
.get();
assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getLocale().equals("en"));
}
示例14: createConfig
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
protected ClientConfig createConfig(Set<Feature> features) {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.FOLLOW_REDIRECTS, followRedirects);
config.property(ClientProperties.READ_TIMEOUT, readTimeoutMs);
config.property(ClientProperties.CONNECT_TIMEOUT, connectTimeoutMs);
config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, asyncThreadPoolSize);
features.forEach(f -> config.register(f));
if (compression) {
config.register(new EncodingFeature(GZipEncoder.class));
}
configRequestLogging(config);
return config;
}
示例15: testCreateClientFactory
import org.glassfish.jersey.client.ClientProperties; //导入依赖的package包/类
@Test
public void testCreateClientFactory() {
HttpClientFactoryFactory factoryFactory = new HttpClientFactoryFactory();
factoryFactory.setAsyncThreadPoolSize(5);
factoryFactory.setConnectTimeoutMs(101);
factoryFactory.setFollowRedirects(true);
factoryFactory.setReadTimeoutMs(203);
HttpClientFactory factory = factoryFactory.createClientFactory(mockInjector, Collections.emptySet());
assertNotNull(factory);
Client client = factory.newClient();
try {
assertEquals(5, client.getConfiguration().getProperty(ClientProperties.ASYNC_THREADPOOL_SIZE));
assertEquals(101, client.getConfiguration().getProperty(ClientProperties.CONNECT_TIMEOUT));
assertEquals(true, client.getConfiguration().getProperty(ClientProperties.FOLLOW_REDIRECTS));
assertEquals(203, client.getConfiguration().getProperty(ClientProperties.READ_TIMEOUT));
} finally {
client.close();
}
}