本文整理汇总了Java中javax.ws.rs.client.ClientBuilder.register方法的典型用法代码示例。如果您正苦于以下问题:Java ClientBuilder.register方法的具体用法?Java ClientBuilder.register怎么用?Java ClientBuilder.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.client.ClientBuilder
的用法示例。
在下文中一共展示了ClientBuilder.register方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callTokenService
import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
/**
* Invoke the token web service with specified parameters.
*/
@Nullable
private AccessTokenResponse callTokenService( @Nonnull final MultivaluedMap<String, String> parameters )
{
final ClientBuilder builder =
ClientBuilder.newBuilder().register( JacksonFeature.class );
final String clientSecret = _config.getClientSecret();
if ( null != clientSecret )
{
builder.register( new BasicAuthFilter( _config.getClientID(), clientSecret ) );
}
final Client client = builder.build();
try
{
final WebTarget target = client.
target( _config.getServerUrl() ).
path( "/realms/" ).path( _config.getRealm() ).path( "/protocol/openid-connect/token" );
final Response response = target.
request( MediaType.APPLICATION_FORM_URLENCODED ).
accept( MediaType.APPLICATION_JSON ).
post( Entity.form( parameters ) );
if ( Response.Status.Family.SUCCESSFUL == response.getStatusInfo().getFamily() )
{
return response.readEntity( AccessTokenResponse.class );
}
else
{
return null;
}
}
finally
{
client.close();
}
}
示例2: 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);
}