本文整理汇总了Java中org.glassfish.jersey.client.JerseyClient类的典型用法代码示例。如果您正苦于以下问题:Java JerseyClient类的具体用法?Java JerseyClient怎么用?Java JerseyClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JerseyClient类属于org.glassfish.jersey.client包,在下文中一共展示了JerseyClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAuthorisedClient
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
private JerseyInvocation.Builder buildAuthorisedClient(String url) {
final JerseyClient client = createClient();
return client.target(url)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, authService + "/service")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword);
}
示例2: test404IsAProblem
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void test404IsAProblem() {
String url = "http://localhost:" + APP.getLocalPort() + "/404";
JerseyClient clientNoAuth = ServerSuite.client();
Response response = clientNoAuth.target(url)
.request()
.get();
assertTrue(response.getStatus() == 404);
final String raw = response.readEntity(String.class);
Gson gson = new Gson();
final Problem problem = gson.fromJson(raw, Problem.class);
assertTrue(problem.title() != null);
assertTrue(problem.data().containsKey("trace_id"));
assertTrue(problem.status() == 404);
}
示例3: testGetWithNonGrantedServiceCauses401_Basic
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testGetWithNonGrantedServiceCauses401_Basic() {
String url = createFeatureUrl();
JerseyClient client = createClient();
final String featureKey = Ulid.random();
final String groupKey = seedGroupOneKey;
final String serviceName = "unknownService";
Response response = client.target(url + "/" + groupKey + "/" + featureKey)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, serviceName + "/service")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.get();
assertTrue(response.getStatus() == 401);
String jsonRes = response.readEntity(String.class);
final Problem problem = gson.fromJson(jsonRes, Problem.class);
assertTrue(problem.status() == 401);
assertTrue(problem.title().contains("invalid_or_missing_credentials"));
assertEquals(Problem.AUTH_TYPE, problem.type());
}
示例4: testGetWithNonGrantedMemberCauses401_Basic
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testGetWithNonGrantedMemberCauses401_Basic() {
String url = createFeatureUrl();
JerseyClient client = createClient();
final String featureKey = Ulid.random();
final String groupKey = seedGroupOneKey;
final String serviceName = "unknownMember";
Response response = client.target(url + "/" + groupKey + "/" + featureKey)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, serviceName + "/member")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.get();
assertTrue(response.getStatus() == 401);
String jsonRes = response.readEntity(String.class);
final Problem problem = gson.fromJson(jsonRes, Problem.class);
assertTrue(problem.status() == 401);
assertTrue(problem.title().contains("Member not authenticated"));
assertEquals(Problem.AUTH_TYPE, problem.type());
}
示例5: testGetWithUnknownScopedMemberCauses401_Basic
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testGetWithUnknownScopedMemberCauses401_Basic() {
String url = createFeatureUrl();
JerseyClient client = createClient();
final String featureKey = Ulid.random();
final String groupKey = seedGroupOneKey;
final String serviceName = "unknownMember";
final String accessName = "unknownKind";
Response response = client.target(url + "/" + groupKey + "/" + featureKey)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, serviceName + "/" + accessName)
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.get();
assertTrue(response.getStatus() == 401);
String jsonRes = response.readEntity(String.class);
final Problem problem = gson.fromJson(jsonRes, Problem.class);
assertTrue(problem.status() == 401);
assertTrue(problem.title().contains("Unknown access type"));
assertEquals(Problem.AUTH_TYPE, problem.type());
}
示例6: testMissingGroupThrows404
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testMissingGroupThrows404() throws Exception {
String url = createFeatureUrl();
JerseyClient client = createClient();
String key = "testMissingGroupThrows404";
String groupKey = Ulid.random();
String serviceCaller = seedServiceBar;
Feature feature = buildTestFeature(groupKey, key);
String jsonReq = Protobuf3Support.toJsonString(feature);
Response post = client.target(url)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, serviceCaller + "/service")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.post(Entity.entity(jsonReq, MediaType.APPLICATION_JSON_TYPE));
assertTrue(post.getStatus() == 404);
}
示例7: setup
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Override
protected void setup(Binder binder)
{
binder.disableCircularProxies();
binder.bind(AgentMap.class).to(DiscoveryAgentMap.class).in(Scopes.SINGLETON);
binder.bind(RequestDispatcher.class).in(Scopes.SINGLETON);
binder.bind(Client.class).to(JerseyClient.class).in(Scopes.SINGLETON);
binder.bind(ResponseWrapper.class);
jaxrsBinder(binder).bind(ControllerConfigAPI.class);
jaxrsBinder(binder).bind(ControllerConnectorAPI.class);
jaxrsBinder(binder).bind(ControllerLogsAPI.class);
jaxrsBinder(binder).bind(ControllerPackageAPI.class);
jaxrsBinder(binder).bind(ControllerControlAPI.class);
jaxrsBinder(binder).bind(InstantConverterProvider.class);
discoveryBinder(binder).bindSelector("presto-manager");
}
示例8: create
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
public <RootResponse> Response<RootResponse> create(@NonNull String url, @NonNull Class<RootResponse> clazz,
ClientConfiguration clientConfigurationOrNull) {
Optional<ClientConfiguration> clientConfiguration = Optional.ofNullable(clientConfigurationOrNull);
JerseyClient newClient = jerseyClientBuilder.register(SseFeature.class).withConfig(clientConfig).build();
newClient.register(LastEventIdHeaderFilter.class);
if (clientConfigurationOrNull != null && !Strings.isNullOrEmpty(clientConfigurationOrNull.getAuthorization())) {
newClient.register(new AuthHeaderFilter(clientConfigurationOrNull.getAuthorization()));
}
MediaType mediaType = clientConfiguration.map(c -> c.getMediaType()).orElse(MediaType.APPLICATION_JSON_TYPE);
ResponseBuilder responseBuilder = new ResponseBuilder(newClient, objectMapper, mediaType);
JerseyWebTarget webTarget = newClient.target(url);
Builder requestBuilder = webTarget.request(mediaType);
String readEntity = requestBuilder.get().readEntity(String.class);
return responseBuilder.buildResponse(readEntity, clazz, URI.create(url)).get();
}
示例9: LaterAllInvokerImpl
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
public LaterAllInvokerImpl(JerseyClient client,
UriBuilder targetUri,
ServiceFullName[] serviceFullNames,
String responsePath,
ServiceFullName responseService,
int retentionCount,
long retentionPeriod,
TimeUnit retentionTimeUnit) {
this.client = client;
this.targetUri = targetUri;
this.serviceFullNames = serviceFullNames;
this.responsePath = responsePath;
this.responseService = responseService;
this.retentionCount = retentionCount;
this.retetionPeriod = retentionPeriod;
if (retentionPeriod >= 0 && retentionTimeUnit == null) {
retentionTimeUnit = TimeUnit.MILLISECONDS;
}
this.retentionTimeUnit = retentionTimeUnit;
}
示例10: tenureTest
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void tenureTest() throws Exception {
JerseyClient jerseyClient = new JerseyClientBuilder().build();
long start = System.currentTimeMillis();
long now = start;
int attempt = 1;
while (now - start < 60000) {
String content = jerseyClient.target("http://127.0.0.1:" + appRule.getLocalPort())
.request()
.get()
.readEntity(String.class);
assertThat(content).contains("\"Host\": \"nghttp2.org:443\"");
now = System.currentTimeMillis();
if (attempt++ % 5 == 0) { // 5 attempts reuse the same connection
Thread.sleep(4000); // Force reopening the connection
attempt = 1;
}
}
jerseyClient.close();
}
示例11: upload
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
private void upload(String server, String environment, File file, boolean dryRun) throws Exception {
JerseyClient client = new JerseyClientBuilder()
.register(HttpAuthenticationFeature.basic("user", "pass")) // set.getUser(), set.getPass()
.register(MultiPartFeature.class)
.build();
JerseyWebTarget t = client.target(UriBuilder.fromUri(server).build()).path("rest").path("items").path("upload");
FileDataBodyPart filePart = new FileDataBodyPart("file", file);
String fn = file.getName();
fn = fn.substring(0, fn.lastIndexOf("_report") + 7); // die tempnummer am ende des filenamens noch wegoperieren!
System.out.println(fn);
filePart.setContentDisposition(FormDataContentDisposition.name("file").fileName(fn).build());
FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
MultiPart multipartEntity = formDataMultiPart.field("comment", "Analysis from BfR").bodyPart(filePart);
if (!dryRun) {
Response response = t.queryParam("environment", environment).request().post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA));
System.out.println(response.getStatus() + " \n" + response.readEntity(String.class));
response.close();
}
formDataMultiPart.close();
multipartEntity.close();
}
示例12: testHello
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testHello() {
String url = "http://localhost:" + APP.getLocalPort() + "/hello";
JerseyClient clientNoAuth = ServerSuite.client();
Response response = clientNoAuth.target(url)
.request()
.get();
assertTrue(response.getStatus() == 200);
}
示例13: testUpdateNonMatchingGroupKeyUrlAndDataCauses422
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testUpdateNonMatchingGroupKeyUrlAndDataCauses422() throws Exception {
String url = createFeatureUrl();
JerseyClient client = createClient();
// don't accept mismatched url and body even when authenticated
String featureKey = Ulid.random();
Feature feature = buildTestFeature(seedGroupBarKey, featureKey);
String jsonReq = Protobuf3Support.toJsonString(feature);
// auth is performed relative to the url, so match it with a granted service
final String uri = url + "/" + seedGroupOneKey + "/" + featureKey;
final String basicAuth = seedServiceOne + "/service";
Response response = client.target(uri)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, basicAuth)
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.post(Entity.entity(jsonReq, MediaType.APPLICATION_JSON_TYPE));
assertTrue(response.getStatus() == 422);
String jsonRes = response.readEntity(String.class);
final Problem problem = gson.fromJson(jsonRes, Problem.class);
assertTrue(problem.status() == 422);
assertTrue(problem.detail().get().contains("url_group"));
assertTrue(problem.detail().get().contains("data_group"));
assertEquals(Problem.CLIENT_TYPE, problem.type());
}
示例14: testUpdateNonMatchingFeatureUrlAndDataCauses422
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testUpdateNonMatchingFeatureUrlAndDataCauses422() throws Exception {
final String groupKey = seedGroupOneKey;
String urlFeatureKey = Ulid.random();
String dataFeatureKey = Ulid.random();
String url = createFeatureUrl();
JerseyClient client = createClient();
Feature feature = buildTestFeature(groupKey, dataFeatureKey);
String jsonReq = Protobuf3Support.toJsonString(feature);
final String uri = url + "/" + groupKey + "/" + urlFeatureKey;
Response response = client.target(uri)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, seedServiceOne + "/service")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.post(Entity.entity(jsonReq, MediaType.APPLICATION_JSON_TYPE));
assertTrue(response.getStatus() == 422);
String jsonRes = response.readEntity(String.class);
Gson gson = new Gson();
final Problem problem = gson.fromJson(jsonRes, Problem.class);
assertTrue(problem.status() == 422);
assertTrue(problem.detail().get().contains("url_feature_key"));
assertTrue(problem.detail().get().contains("data_feature_key"));
assertEquals(Problem.CLIENT_TYPE, problem.type());
}
示例15: testIdempotentPost
import org.glassfish.jersey.client.JerseyClient; //导入依赖的package包/类
@Test
public void testIdempotentPost() throws Exception {
String url = createFeatureUrl() + "/" + seedGroupOneKey;
JerseyClient client = createClient();
final String idempotencyKey = Ulid.random();
String featureKey = Ulid.random();
Feature feature = buildTestFeature(seedGroupOneKey, featureKey);
String featureJson = Protobuf3Support.toJsonString(feature);
Response post = client.target(url)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, seedServiceOne + "/service")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.header(IdempotencyChecker.REQ_HEADER, idempotencyKey)
.post(Entity.entity(featureJson, MediaType.APPLICATION_JSON_TYPE));
assertTrue(post.getStatus() == 201);
assertNull(post.getHeaderString(IdempotencyChecker.RES_HEADER));
Response post2 = client.target(url)
.request()
.property(HTTP_AUTHENTICATION_BASIC_USERNAME, seedServiceOne + "/service")
.property(HTTP_AUTHENTICATION_BASIC_PASSWORD, basicPassword)
.header(IdempotencyChecker.REQ_HEADER, idempotencyKey)
.post(Entity.entity(featureJson, MediaType.APPLICATION_JSON_TYPE));
assertTrue(post2.getStatus() == 201);
assertNotNull(post2.getHeaderString(IdempotencyChecker.RES_HEADER));
assertTrue(
post2.getHeaderString(IdempotencyChecker.RES_HEADER).contains("key=" + idempotencyKey));
}