本文整理汇总了Java中org.jboss.resteasy.client.jaxrs.ResteasyClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java ResteasyClient.close方法的具体用法?Java ResteasyClient.close怎么用?Java ResteasyClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.resteasy.client.jaxrs.ResteasyClient
的用法示例。
在下文中一共展示了ResteasyClient.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProducts
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public static List<String> getProducts()
{
ResteasyClient client = new ResteasyClientBuilder()
.disableTrustManager() // shouldn't really do this, but I'm being lazy
.build();
Form form = new Form().param("grant_type", "client_credentials");
ResteasyWebTarget target = client.target("https://localhost:8443/auth-server/j_oauth_token_grant");
// this is resteasy specific, check spec to make sure it hasn't added a way to do basic auth
target.register(new BasicAuthentication("[email protected]", "password"));
AccessTokenResponse res = target
.request()
.post(Entity.form(form), AccessTokenResponse.class);
try
{
Response response = client.target("https://localhost:8443/database/products").request()
.header(HttpHeaders.AUTHORIZATION, "Bearer " + res.getToken()).get();
return response.readEntity(new GenericType<List<String>>(){});
}
finally
{
client.close();
}
}
示例2: getProducts
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public static List<String> getProducts(HttpServletRequest request)
{
SkeletonKeySession session = (SkeletonKeySession)request.getAttribute(SkeletonKeySession.class.getName());
ResteasyProviderFactory factory = new ResteasyProviderFactory();
RegisterBuiltin.register(factory);
ResteasyClient client = new ResteasyClientBuilder()
// .providerFactory(factory)
.trustStore(session.getMetadata().getTruststore())
.hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY).build();
try
{
Response response = client.target("https://localhost:8443/database/products").request()
.header(HttpHeaders.AUTHORIZATION, "Bearer " + session.getToken()).get();
return response.readEntity(new GenericType<List<String>>(){});
}
finally
{
client.close();
}
}
示例3: getCustomers
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public static List<String> getCustomers(HttpServletRequest request)
{
SkeletonKeySession session = (SkeletonKeySession)request.getAttribute(SkeletonKeySession.class.getName());
ResteasyClient client = new ResteasyClientBuilder()
.trustStore(session.getMetadata().getTruststore())
.hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY).build();
try
{
Response response = client.target("https://localhost:8443/database/customers").request()
.header(HttpHeaders.AUTHORIZATION, "Bearer " + session.getToken()).get();
return response.readEntity(new GenericType<List<String>>(){});
}
finally
{
client.close();
}
}
示例4: getCompactDiscs
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public static List<String> getCompactDiscs() {
ResteasyClient rsClient = new ResteasyClientBuilder().disableTrustManager().build();
Form form = new Form().param("grant_type", "client_credentials");
ResteasyWebTarget resourceTarget = rsClient.target(urlAuth);
resourceTarget.register(new BasicAuthentication("andres", "andres"));
AccessTokenResponse accessToken = resourceTarget.request().post(Entity.form(form),
AccessTokenResponse.class);
try {
String bearerToken = "Bearer " + accessToken.getToken();
Response response = rsClient.target(urlDiscs).request()
.header(HttpHeaders.AUTHORIZATION, bearerToken).get();
return response.readEntity(new GenericType<List<String>>() {
});
} finally {
rsClient.close();
}
}
示例5: getCompactDiscs
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public static List<String> getCompactDiscs(HttpServletRequest request) {
ServletOAuthClient oAuthClient = (ServletOAuthClient) request
.getServletContext().getAttribute(
ServletOAuthClient.class.getName());
KeyStore truststore = oAuthClient.getTruststore();
ResteasyClient rsClient = new ResteasyClientBuilder()
.disableTrustManager().trustStore(truststore).build();
String urlDiscs = "https://localhost:8443/discstore/discs";
try {
String bearerToken = "Bearer "
+ oAuthClient.getBearerToken(request);
Response response = rsClient.target(urlDiscs).request()
.header(HttpHeaders.AUTHORIZATION, bearerToken).get();
return response.readEntity(new GenericType<List<String>>() {
});
} catch (BadRequestException bre) {
bre.printStackTrace();
} catch (InternalServerErrorException isee) {
isee.printStackTrace();
} finally {
rsClient.close();
}
return null;
}
示例6: testVerification
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
@Test
public void testVerification() {
// Keys repository
DosetaKeyRepository repository = new DosetaKeyRepository();
repository.setKeyStorePath("demo.jks");
repository.setKeyStorePassword("changeit");
repository.start();
// Building the client
ResteasyClient client = new ResteasyClientBuilder().build();
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
WebTarget target = client
.target("http://localhost:8080/signatures-1.0/signed");
Invocation.Builder request = target.request();
request.property(Verifier.class.getName(), verifier);
// Invocation to Restful web service
Response response = request.post(Entity.text("Rene"));
// Status 200 OK
Assert.assertEquals(200, response.getStatus());
System.out.println(response.readEntity(String.class));
response.close();
client.close();
}
示例7: execute
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
<Q> Q execute(final Function<T, Q> function, final Sort<S> sort, final RoboZonkyFilter filter) {
sort.apply(filter);
final ResteasyClient client = ProxyFactory.newResteasyClient(filter);
try {
return execute(function, client);
} finally {
client.close();
}
}
示例8: testProxy
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
@Test
public void testProxy() throws Exception
{
ResteasyClient client = new ResteasyClientBuilder().build();
// or you can do...
// ResteasyClient client = (ResteasyClient)ClientBuilder.newClient();
CustomerProxy proxy = client.target("http://localhost:9095").proxy(CustomerProxy.class);
Customer cust = proxy.getCustomer("Monica");
Assert.assertEquals("Monica", cust.getName());
client.close();
}
示例9: pullFile
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public void pullFile(String sessionId, String space, String path, String outputPath) throws Exception {
String uriTmpl = (new StringBuilder(restEndpointURL)).append(addSlashIfMissing(restEndpointURL))
.append("scheduler/dataspace/")
.append(space)
.append(URLEncoder.encode(path, "UTF-8"))
.toString();
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine)
.providerFactory(providerFactory)
.build();
ResteasyWebTarget target = client.target(uriTmpl);
Response response = target.request().header("sessionid", sessionId).get();
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Cannot retrieve the file. Status code: %s", response.getStatus()),
response);
}
}
try {
File file = new File(outputPath);
if (response.hasEntity()) {
copyInputStreamToFile(response.readEntity(InputStream.class), file);
} else {
// creates an empty file
file.createNewFile();
}
} catch (Exception e) {
throw e;
} finally {
if (response != null) {
response.close();
}
if (!client.isClosed()) {
client.close();
}
}
}
示例10: main
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String truststorePath = "C:/Users/Andres/jboss/2do_jboss/jboss-as-7.1.1.Final/standalone/configuration/client-truststore.ts";
String truststorePassword = "changeit";
truststorePath = EnvUtil.replace(truststorePath);
KeyStore truststore = loadKeyStore(truststorePath, truststorePassword);
ResteasyClient client = new ResteasyClientBuilder()
.disableTrustManager().trustStore(truststore).build();
Form form = new Form().param("grant_type", "client_credentials");
ResteasyWebTarget target = client
.target("https://localhost:8443/oauth-server/j_oauth_token_grant");
target.register(new BasicAuthentication("andres", "andres"));
AccessTokenResponse tokenResponse = target.request().post(
Entity.form(form), AccessTokenResponse.class);
Response response = client
.target("https://localhost:8443/discstore/discs")
.request()
.header(HttpHeaders.AUTHORIZATION,
"Bearer " + tokenResponse.getToken()).get();
try {
String xml = response.readEntity(String.class);
System.out.println(xml);
} finally {
client.close();
}
}