• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JerseyWebTarget类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.glassfish.jersey.client.JerseyWebTarget的典型用法代码示例。如果您正苦于以下问题:Java JerseyWebTarget类的具体用法?Java JerseyWebTarget怎么用?Java JerseyWebTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JerseyWebTarget类属于org.glassfish.jersey.client包,在下文中一共展示了JerseyWebTarget类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: create

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的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();
}
 
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:19,代码来源:ClientStarter.java


示例2: upload

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的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();
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:27,代码来源:TracingXmlOutNodeModel.java


示例3: mockFeedClientRequest

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
private FeedClient mockFeedClientRequest(String json) throws URISyntaxException {
    FlexCredentials flexCredentials = new FlexCredentials("appId", "appKey");
    JerseyClient jerseyClient = Mockito.mock(JerseyClient.class);
    JerseyWebTarget jerseyWebTarget = Mockito.mock(JerseyWebTarget.class);
    JerseyInvocation.Builder builder = Mockito.mock(JerseyInvocation.Builder.class);

    Mockito.when(jerseyClient.target(Matchers.any(URI.class))).thenReturn(jerseyWebTarget);
    Mockito.when(jerseyWebTarget.request(Matchers.any(MediaType.class))).thenReturn(builder);
    Mockito.when(builder.get(String.class)).thenReturn(json);

    return new FeedClient(flexCredentials, uri, jerseyClient);
}
 
开发者ID:flightstats,项目名称:flex-example-clients,代码行数:13,代码来源:FeedClientTest.java


示例4: execute

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
@Override
public CreatubblesRequest<OAuthAccessTokenResponse> execute() {
    resetResponse();
    String url = CreatubblesAPI.buildURL(OAUTH_TOKEN);

    JerseyWebTarget webTarget = CreatubblesAPI.CLIENT.target(url);
    Invocation.Builder invocationBuilder = webTarget
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .accept(MediaType.APPLICATION_JSON);

    Form form;
    
    if (username != null && password != null) {
        form = new Form()
            .param("grant_type", "password")
            .param("client_id", clientId)
            .param("client_secret", clientSecret)
            .param("username", username)
            .param("password", password);
    } else {
        form = new Form()
            .param("grant_type", "client_credentials")
            .param("client_id", clientId)
            .param("client_secret", clientSecret);
    }
    
    setResponse(invocationBuilder.post(Entity.form(form)));
    return this;
}
 
开发者ID:creatubbles,项目名称:ctb-api-java,代码行数:30,代码来源:OAuthAccessTokenRequest.java


示例5: execute

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
public CreatubblesRequest<T> execute() {
    resetResponse();
    String url = CreatubblesAPI.buildURL(endPoint);

    JerseyWebTarget webTarget = CreatubblesAPI.CLIENT.target(url);
    for (String paramKey : urlParameters.keySet()) {
        String paramValue = urlParameters.get(paramKey);
        if (paramValue != null && !paramValue.isEmpty()) {
            webTarget = webTarget.queryParam(paramKey, paramValue);
        }
    }

    Invocation.Builder invocationBuilder = webTarget.request(APPLICATION_VND_API_JSON).accept(APPLICATION_VND_API_JSON);

    if (acceptLanguage != null && acceptLanguage.length() == 2) {
        invocationBuilder.header("Accept-Language", acceptLanguage.toLowerCase());
    }
    if (accessToken != null && !accessToken.isEmpty()) {
        invocationBuilder.header("Authorization", "Bearer " + accessToken);
    }

    if (httpMethod == HttpMethod.GET) {
        response = invocationBuilder.get();
    } else if (httpMethod == HttpMethod.POST) {
        response = invocationBuilder.post(Entity.entity(data, APPLICATION_VND_API_JSON));
    } else if (httpMethod == HttpMethod.PUT) {
        response = invocationBuilder.put(Entity.entity(data, APPLICATION_VND_API_JSON));
    }

    return this;
}
 
开发者ID:creatubbles,项目名称:ctb-api-java,代码行数:32,代码来源:CreatubblesRequest.java


示例6: async

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
public CreatubblesRequest<T> async() {
    resetResponse();
    String url = CreatubblesAPI.buildURL(endPoint);

    JerseyWebTarget webTarget = CreatubblesAPI.CLIENT.target(url);
    for (String paramKey : urlParameters.keySet()) {
        String paramValue = urlParameters.get(paramKey);
        if (paramValue != null && !paramValue.isEmpty()) {
            webTarget = webTarget.queryParam(paramKey, paramValue);
        }
    }

    Invocation.Builder invocationBuilder = webTarget.request(APPLICATION_VND_API_JSON).accept(APPLICATION_VND_API_JSON);

    if (acceptLanguage != null && acceptLanguage.length() == 2) {
        invocationBuilder.header("Accept-Language", acceptLanguage.toLowerCase());
    }
    if (accessToken != null && !accessToken.isEmpty()) {
        invocationBuilder.header("Authorization", "Bearer " + accessToken);
    }

    if (httpMethod == HttpMethod.GET) {
        futureResponse = invocationBuilder.async().get();
    } else if (httpMethod == HttpMethod.POST) {
        futureResponse = invocationBuilder.async().post(Entity.entity(data, APPLICATION_VND_API_JSON));
    } else if (httpMethod == HttpMethod.PUT) {
        futureResponse = invocationBuilder.async().put(Entity.entity(data, APPLICATION_VND_API_JSON));
    }

    return this;
}
 
开发者ID:creatubbles,项目名称:ctb-api-java,代码行数:32,代码来源:CreatubblesRequest.java


示例7: setUp

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
@Before
public void setUp() {
  configureBean();
  clientBuilder = spy(ClientBuilder.newBuilder());
  JerseyClient client = mock(JerseyClient.class);
  JerseyWebTarget listTarget = mock(JerseyWebTarget.class);
  JerseyInvocation.Builder builder = mock(JerseyInvocation.Builder.class);
  getInvocation = mock(JerseyInvocation.class);
  JerseyInvocation postInvocation = mock(JerseyInvocation.class);
  listResponse = mock(Response.class);
  runResponse = mock(Response.class);

  doReturn(listTarget).when(client).target(anyString());
  doReturn(listTarget).when(listTarget).queryParam("job_id", configBean.databricksConfigBean.jobId);
  doReturn(builder).when(listTarget).request(MediaType.APPLICATION_JSON_TYPE);
  doReturn(getInvocation).when(builder).buildGet();
  doReturn(listResponse).when(getInvocation).invoke();
  doReturn(postInvocation).when(builder).buildPost(any());
  doReturn(runResponse).when(postInvocation).invoke();

  doReturn(builder).when(listTarget).request();

  doReturn(postInvocation).when(builder)
      .buildPost(Entity.json((
          new RunJarJobJson(configBean.databricksConfigBean.jobId, configBean.databricksConfigBean.jarParams))));

  doReturn(client).when(clientBuilder).build();

}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:30,代码来源:TestSparkExecutor.java


示例8: method

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
@Override
public String method(String name, Entity<?> entity) {
    JerseyWebTarget target = client.target(CumulonimbusClient.getInstance().getTargetUrl())
                                    .path("/later/all");
    return doMethod(target, name, entity);
}
 
开发者ID:martinjmares,项目名称:javaone2015-cloudone,代码行数:7,代码来源:LaterAllInvokerImpl.java


示例9: target

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
@Override
public JerseyWebTarget target(String uri) {
    return client.target(uri);
}
 
开发者ID:martinjmares,项目名称:javaone2015-cloudone,代码行数:5,代码来源:C1ClientImpl.java


示例10: getPath

import org.glassfish.jersey.client.JerseyWebTarget; //导入依赖的package包/类
private JerseyWebTarget getPath() {
    return new JerseyClientBuilder().build()
            .target("http://localhost:8745")
            .path("/thing");
}
 
开发者ID:martindow,项目名称:dropwizard-hazelcast-session,代码行数:6,代码来源:HazelcastSessionBundleTest.java



注:本文中的org.glassfish.jersey.client.JerseyWebTarget类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ValidationResult类代码示例发布时间:2022-05-22
下一篇:
Java ContextHelpAction类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap