本文整理汇总了Java中org.glassfish.jersey.client.JerseyClientBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JerseyClientBuilder类的具体用法?Java JerseyClientBuilder怎么用?Java JerseyClientBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JerseyClientBuilder类属于org.glassfish.jersey.client包,在下文中一共展示了JerseyClientBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSwaggerJson
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testSwaggerJson() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/v1/docs");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/json", response.getMediaType().toString());
target = client.target("http://localhost:" + port + "/v2/docs");
response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/json", response.getMediaType().toString());
}
示例2: testSwaggerYaml
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testSwaggerYaml() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/v1/docs").queryParam("type", "yaml");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/yaml", response.getMediaType().toString());
target = client.target("http://localhost:" + port + "/v2/docs").queryParam("type", "yaml");
response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/yaml", response.getMediaType().toString());
}
示例3: testSwaggerJson
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testSwaggerJson() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/docs1");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/json", response.getMediaType().toString());
target = client.target("http://localhost:" + port + "/docs2");
response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/json", response.getMediaType().toString());
}
示例4: testSwaggerYaml
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testSwaggerYaml() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/docs1").queryParam("type", "yaml");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/yaml", response.getMediaType().toString());
target = client.target("http://localhost:" + port + "/docs2").queryParam("type", "yaml");
response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/yaml", response.getMediaType().toString());
}
示例5: testBasic
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
@Ignore
public void testBasic() {
String clientName = "community";
Client client = new JerseyClientBuilder().build();
Publication p = new Publication();
p.setPublicationUid(1L);
p.setTitle("Test title");
String url = String.format("http://localhost:%d%s/publications", APP.getLocalPort(),
APP.getEnvironment().getApplicationContext().getContextPath());
Response response = client.target(url)
.request()
.header("X-Client-Id", clientName)
.post(Entity.entity(p, MediaType.APPLICATION_JSON_TYPE));
Publication p2 = response.readEntity(Publication.class);
assertNotEquals(p, p2);
assertEquals(clientName, p2.getLastModificationClientId());
}
示例6: testExternalDao
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testExternalDao() {
Client client = new JerseyClientBuilder().build();
Publication p = new Publication();
p.setPublicationUid(1L);
p.setTitle("Test title");
String url = String.format("http://localhost:%d%s/publications", APP.getLocalPort(),
APP.getEnvironment().getApplicationContext().getContextPath());
client.target(url)
.request()
.post(Entity.entity(p, MediaType.APPLICATION_JSON_TYPE));
url = String.format("http://localhost:%d%s/publications/external/1", APP.getLocalPort(),
APP.getEnvironment().getApplicationContext().getContextPath());
Publication p2 = client.target(url).request().get(Publication.class);
assertEquals(p, p2);
}
示例7: testListGroup
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
public void testListGroup() {
String uri = getUrl("listGroup");
Client client= JerseyClientBuilder.newBuilder().build();
ListGroupRequest req = new ListGroupRequest();
req.showAll = true;
Response rsp = client.target(uri).request().accept(MediaType.APPLICATION_JSON).headers(fixedHeader).buildPost(Entity.entity(req, MediaType.APPLICATION_JSON)).invoke();
GenericResponseObj ret = rsp.readEntity(GenericResponseObj.class);
if (!ret.isSuccess()) {
System.out.println(ret.getError());
} else {
// List<Group> groups = ret.getData(List<Group>.class);
System.out.println();
}
}
示例8: initUsers
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
public void initUsers() throws ImException {
Client client= JerseyClientBuilder.newBuilder().build();
Map<String ,Object> header = new HashMap<String, Object>();
header.put("appId", "sfa");
header.put("tenantId", "hengda");
header.put("operatorId", "1");
for (Integer index = 0; index < 1; index++) {
Map<String, Object> body = new HashMap<String, Object>();
body.put("gatewayUserId", index);
Response rsp = client.target("http://172.16.0.22:8090/api/im/groupManager/createUser")
.request()
.accept(MediaType.APPLICATION_JSON)
.headers(new MultivaluedHashMap<String, Object>(header))
.buildPost(Entity.entity(body, MediaType.APPLICATION_JSON))
.invoke();
HashMap<String, Object> ret = rsp.readEntity(HashMap.class);
if("1".equals(ret.get("status").toString())){
System.out.println("Create user success --> " + index);
}
}
}
示例9: tenureTest
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的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();
}
示例10: upload
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的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();
}
示例11: Pandora
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
public Pandora(AnnaConfig config) {
this.appId = config.getPandora().getAppId();
this.userKey = config.getPandora().getUserKey();
this.pandoraBot = config.getPandora().getBot();
ClientConfig cfg = new ClientConfig(JacksonJsonProvider.class);
cfg.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
client = JerseyClientBuilder.createClient(cfg);
}
示例12: getClient
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Override
protected Client getClient() {
ClientConfig config = new ClientConfig();
config = config.register(TestContextResolver.class).property(GsonFeature.JAXRS_DISABLE_GSON_CONTEXT_RESOLVER,
"");
return JerseyClientBuilder.createClient(config);
}
示例13: testEndpoint
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testEndpoint() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/api/test").path("ping");
String response = target.request().get(String.class);
Assert.assertEquals("pong", response);
}
示例14: testSwaggerJson
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testSwaggerJson() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/api/docs");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/json", response.getMediaType().toString());
}
示例15: testSwaggerYaml
import org.glassfish.jersey.client.JerseyClientBuilder; //导入依赖的package包/类
@Test
public void testSwaggerYaml() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/api/docs").queryParam("type", "yaml");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/yaml", response.getMediaType().toString());
}