当前位置: 首页>>代码示例>>Java>>正文


Java ClientBuilder.newBuilder方法代码示例

本文整理汇总了Java中javax.ws.rs.client.ClientBuilder.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java ClientBuilder.newBuilder方法的具体用法?Java ClientBuilder.newBuilder怎么用?Java ClientBuilder.newBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.client.ClientBuilder的用法示例。


在下文中一共展示了ClientBuilder.newBuilder方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: obtainAccessToken

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
public String obtainAccessToken(String username, String password) {
    Form form = new Form();
    form.param("grant_type", "password");
    form.param("username", username);
    form.param("password", password);
    form.param("client_id", deployment.getClientId());
    String secret = deployment.getClientCredentials().get("secret").toString();
    form.param("client_secret", secret);
    Client client = null;
    try {
        ClientBuilder clientBuilder = ClientBuilder.newBuilder();
        SSLContext sslcontext = deployment.getSSLContext();
        if(sslcontext != null) {
            client = clientBuilder.sslContext(sslcontext).hostnameVerifier(new AnyHostnameVerifier()).build();
        } else {
            client = clientBuilder.build();
        }

        String tokenURL = String.format("%s/auth/realms/%s/protocol/openid-connect/token",
                deployment.getAuthServerUrl(), deployment.getRealm());
        WebTarget target = client.target(tokenURL);
        if(deployment.getDebug() > 0)
            target.register(new LoggingFilter());
        String json = target.request(MediaType.APPLICATION_JSON_TYPE)
                .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);
        AccessToken accessToken = JsonSerialization.readValue(json, AccessToken.class);
        return accessToken.getToken();
    } catch (Exception e) {
        throw new RuntimeException("Failed to request token", e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
开发者ID:obsidian-toaster-quickstarts,项目名称:redhat-sso,代码行数:36,代码来源:AuthzClient.java

示例2: createClientBuilder

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
/**
 * Create the {@link ClientBuilder} instance to use to create clients.
 * @return the new {@link ClientBuilder} instance
 */
private ClientBuilder createClientBuilder() {
	// check factory
	if (getFactory() != null) {
		return getFactory().createBuilder();
	}
	// default
	return ClientBuilder.newBuilder();
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:13,代码来源:DefaultJaxrsClientBuilder.java

示例3: doGet

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {		
	PrintWriter out = response.getWriter();
	out.println("<html><body><h2>RP Signed JWT App</h2><br>");

	out.println("<HR>RS Invocation<p>");
	// call the RS with the jwt we just built.
	out.println("Using RS JEE Endpoint of : " + RS_JEE_ENDPOINT + "<br>");
       out.println("Using RS SPRING Endpoint of : " + RS_SPRING_ENDPOINT + "<br>");

	ClientBuilder cb = ClientBuilder.newBuilder();
	cb.property("com.ibm.ws.jaxrs.client.disableCNCheck", true);
	cb.property("com.ibm.ws.jaxrs.client.ssl.config", "defaultSSLConfig");
	cb.register(JwtJaxRSClientFilter.class);
	
	Client c = cb.build();
	String result = "";
	try {
		result = c.target(RS_JEE_ENDPOINT).request().get(String.class);
		result = "<hr><br>[START_RESPONSE_FROM_JEE_RS]<br>" + result + "<br>[END_RESPONSE_FROM_JEE_RS]";
	} finally {
		c.close();
	}

	c = cb.build();
	try {
		String springresult = c.target(RS_SPRING_ENDPOINT).request().get(String.class);
		result = result + "<hr><br>[START_RESPONSE_FROM_SPRING_RS]<br>" + springresult + "<br>[END_RESPONSE_FROM_SPRING_RS]";
	} finally {
		c.close();
	}

	// in a real app, the response would likely be some json, or
	// info to use within the app processing. But in this example,
	// the response is just some text for us to display back to the 
	// user to show the processing performed by the RS.
	out.println(result);
}
 
开发者ID:WASdev,项目名称:sample.microservices.security.jwt,代码行数:39,代码来源:TestServletUsingFilter.java

示例4: getRatings

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
private JsonObject getRatings(Cookie user, String xreq, String xtraceid, String xspanid,
                              String xparentspanid, String xsampled, String xflags, String xotspan){
  ClientBuilder cb = ClientBuilder.newBuilder();
  String timeout = star_color.equals("black") ? "10000" : "2500";
  cb.property("com.ibm.ws.jaxrs.client.connection.timeout", timeout);
  cb.property("com.ibm.ws.jaxrs.client.receive.timeout", timeout);
  Client client = cb.build();
  WebTarget ratingsTarget = client.target(ratings_service);
  Invocation.Builder builder = ratingsTarget.request(MediaType.APPLICATION_JSON);
  if(xreq!=null) {
    builder.header("x-request-id",xreq);
  }
  if(xtraceid!=null) {
    builder.header("x-b3-traceid",xtraceid);
  }
  if(xspanid!=null) {
    builder.header("x-b3-spanid",xspanid);
  }
  if(xparentspanid!=null) {
    builder.header("x-b3-parentspanid",xparentspanid);
  }
  if(xsampled!=null) {
    builder.header("x-b3-sampled",xsampled);
  }
  if(xflags!=null) {
    builder.header("x-b3-flags",xflags);
  }
  if(xotspan!=null) {
    builder.header("x-ot-span-context",xotspan);
  }
  if(user!=null) {
    builder.cookie(user);
  }
  Response r = builder.get();
  int statusCode = r.getStatusInfo().getStatusCode();
  if (statusCode == Response.Status.OK.getStatusCode() ) {
    StringReader stringReader = new StringReader(r.readEntity(String.class));
    try (JsonReader jsonReader = Json.createReader(stringReader)) {
       JsonObject j = jsonReader.readObject();
       JsonObjectBuilder jb = Json.createObjectBuilder();
       for(String key : j.keySet()){
         int count = j.getInt(key);
         String stars = "<font color=\""+ star_color +"\">";
         for(int i=0; i<count; i++){
           stars += "<span class=\"glyphicon glyphicon-star\"></span>";
         }
         stars += "</font>";
         if(count<5){
           for(int i=0; i<(5-count); i++){
             stars += "<span class=\"glyphicon glyphicon-star-empty\"></span>";
           }
         }
         jb.add(key,stars);
       }
       JsonObject result = jb.build();
       return result;
    }
  }else{
    System.out.println("Error: unable to contact "+ratings_service+" got status of "+statusCode);
    return null;
  }
}
 
开发者ID:IBM,项目名称:microservices-traffic-management-using-istio,代码行数:63,代码来源:LibertyRestEndpoint.java

示例5: JerseyNiFiRegistryClient

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
private JerseyNiFiRegistryClient(final NiFiRegistryClient.Builder builder) {
    final NiFiRegistryClientConfig registryClientConfig = builder.getConfig();
    if (registryClientConfig == null) {
        throw new IllegalArgumentException("NiFiRegistryClientConfig cannot be null");
    }

    String baseUrl = registryClientConfig.getBaseUrl();
    if (StringUtils.isBlank(baseUrl)) {
        throw new IllegalArgumentException("Base URL cannot be blank");
    }

    if (baseUrl.endsWith("/")) {
        baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
    }

    if (!baseUrl.endsWith(NIFI_REGISTRY_CONTEXT)) {
        baseUrl = baseUrl + "/" + NIFI_REGISTRY_CONTEXT;
    }

    try {
        new URI(baseUrl);
    } catch (final Exception e) {
        throw new IllegalArgumentException("Invalid base URL: " + e.getMessage(), e);
    }

    final SSLContext sslContext = registryClientConfig.getSslContext();
    final HostnameVerifier hostnameVerifier = registryClientConfig.getHostnameVerifier();

    final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    if (sslContext != null) {
        clientBuilder.sslContext(sslContext);
    }
    if (hostnameVerifier != null) {
        clientBuilder.hostnameVerifier(hostnameVerifier);
    }

    final int connectTimeout = registryClientConfig.getConnectTimeout() == null ? DEFAULT_CONNECT_TIMEOUT : registryClientConfig.getConnectTimeout();
    final int readTimeout = registryClientConfig.getReadTimeout() == null ? DEFAULT_READ_TIMEOUT : registryClientConfig.getReadTimeout();

    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout);
    clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
    clientConfig.register(jacksonJaxbJsonProvider());
    clientBuilder.withConfig(clientConfig);
    this.client = clientBuilder.build();

    this.baseTarget = client.target(baseUrl);
    this.bucketClient = new JerseyBucketClient(baseTarget);
    this.flowClient = new JerseyFlowClient(baseTarget);
    this.flowSnapshotClient = new JerseyFlowSnapshotClient(baseTarget);
    this.itemsClient = new JerseyItemsClient(baseTarget);
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:53,代码来源:JerseyNiFiRegistryClient.java


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