本文整理汇总了Java中org.jboss.resteasy.client.jaxrs.ResteasyClient类的典型用法代码示例。如果您正苦于以下问题:Java ResteasyClient类的具体用法?Java ResteasyClient怎么用?Java ResteasyClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResteasyClient类属于org.jboss.resteasy.client.jaxrs包,在下文中一共展示了ResteasyClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddSkill
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testAddSkill(@ArquillianResource URL baseUrl) throws IOException {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(baseUrl.toExternalForm() + "rest");
SkillRestService skillRestService = target.proxy(SkillRestService.class);
int tenantId = generateDatabase(baseUrl);
skillRestService.addSkill(tenantId, new Skill(tenantId, "D"));
List<Skill> skills = skillRestService.getSkillList(tenantId);
assertEquals("List size don't match", SKILLS.length + 1, skills.size());
for (String name : SKILLS) {
assertContainsSkill(skills, tenantId, name);
}
assertContainsSkill(skills, tenantId, "D");
}
示例2: getAccessToken
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
/**
* get access token form realm
*
* @param userName
* the user login
* @param password
* the user password
* @return json OpenID token
*/
public AccessToken getAccessToken(String userName, String password) {
ResteasyClient client = new ResteasyClientBuilder().register(AccessTokenProvider.class).build();
//queryParameters.add("grant_type", "id_token");
queryParameters.add("grant_type","password");
queryParameters.add("username", userName);
queryParameters.add("password", password);
queryParameters.add("client_id", clientID);
//queryParameters.add("secret", "7812f8e6-3d9d-4013-a253-9cbbe0b4fb54");
Response response = client.target(this.url).request()
.accept(MediaType.APPLICATION_JSON).post(Entity.entity(queryParameters, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
LOG.debug("get accesstoken response status: " + response.getStatus());
AccessToken accessToken = response.readEntity(AccessToken.class);
response.close();
return accessToken;
}
示例3: testGetSkill
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testGetSkill(@ArquillianResource URL baseUrl) throws IOException {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(baseUrl.toExternalForm() + "rest");
SkillRestService skillRestService = target.proxy(SkillRestService.class);
int tenantId = generateDatabase(baseUrl);
List<Skill> skills = skillRestService.getSkillList(tenantId);
Skill skill1 = getSkill(skills, "A").get();
Skill skill2 = skillRestService.getSkill(tenantId, skill1.getId());
assertNotNull("REST method did not return a result", skill2);
assertEquals(skill1.getId(), skill2.getId());
assertEquals(skill1.getName(), skill2.getName());
assertEquals(skill1.getTenantId(), skill2.getTenantId());
assertEquals("List size don't match", SKILLS.length, skills.size());
for (String name : SKILLS) {
assertContainsSkill(skills, tenantId, name);
}
}
示例4: main
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Client client = ClientBuilder.newClient();
// Client client = ClientBuilder.newBuilder().build();
// WebTarget target = client.target("http://localhost:8082/rest/hello/v1/echo?name=netboy");
// Response response = target.request().get();
// String value = response.readEntity(String.class);
// response.close();
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://localhost:8082/rest/hello/v1/echo?name=netboy");
Response response = target.request().get();
String value = response.readEntity(String.class);
System.out.println(value);
response.close();
}
示例5: testSinglePOST
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testSinglePOST() {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(buildUrl("hello/login"));
UserLogin userLogin = new UserLogin("003","xyz");
Response response = target.request().post(Entity.entity(userLogin,MediaType.APPLICATION_JSON));
String userToken = response.readEntity(String.class);
System.out.println(userToken);
response.close();
Article article = new Article(2,"NAME");
ResteasyClient client2 = new ResteasyClientBuilder().build();
ResteasyWebTarget target2 = client2.target(buildUrl("hello/singlesave"));
Response response2 = target2.request().header("UserToken",userToken).post(Entity.entity(article,MediaType.APPLICATION_JSON));
Article rtv = response2.readEntity(Article.class);
response2.close();
assertNotNull(rtv);
assertTrue(rtv.getId().equals(2));
assertTrue(rtv.getName().equals("NAME"));
}
示例6: testPOSTbyList
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testPOSTbyList() {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(buildUrl("hello/login"));
UserLogin userLogin = new UserLogin("002","abc");
Response response = target.request().post(Entity.entity(userLogin,MediaType.APPLICATION_JSON));
String userToken = response.readEntity(String.class);
System.out.println(userToken);
response.close();
Article article = new Article(2,"NAME");
ResteasyClient client2 = new ResteasyClientBuilder().build();
ResteasyWebTarget target2 = client2.target(buildUrl("hello/multisave?multi=true"));
Response response2 = target2.request().header("UserToken",userToken).post(Entity.entity(Collections.singletonList(article),MediaType.APPLICATION_JSON));
GenericType<List<Article>> ArticleListType = new GenericType<List<Article>>() {};
List<Article> list = response2.readEntity(ArticleListType);
assertEquals(1, list.size());
response2.close();
}
示例7: testPOSTbyList2
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testPOSTbyList2() {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(buildUrl("hello/login"));
UserLogin userLogin = new UserLogin("002","abc");
Response response = target.request().post(Entity.entity(userLogin,MediaType.APPLICATION_JSON));
String userToken = response.readEntity(String.class);
System.out.println(userToken);
response.close();
List<Article> list = new ArrayList<Article>();
list.add(new Article(1,"book1"));
list.add(new Article(2,"book2"));
ResteasyClient client2 = new ResteasyClientBuilder().build();
ResteasyWebTarget target2 = client2.target(buildUrl("hello/multisave?multi=true"));
Response response2 = target2.request().header("UserToken",userToken).post(Entity.entity(list,MediaType.APPLICATION_JSON));
GenericType<List<Article>> ArticleListType = new GenericType<List<Article>>() {};
List<Article> list2 = response2.readEntity(ArticleListType);
assertEquals(2, list2.size());
response2.close();
}
示例8: testSinglePOST
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testSinglePOST() throws JsonProcessingException {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(buildUrl("hello/loginecho"));
String userName = "abc";
String password = "efg";
UserLogin userLogin = new UserLogin(userName,password);
String accessRandomStr = RandomStringUtils.randomAlphanumeric(8);
Long time = System.currentTimeMillis();
ObjectMapper mapper = new ObjectMapper();
// Convert object to JSON string
String Json = mapper.writeValueAsString(userLogin);
String signature = Coder.genSignature(Json);
Response response = target.request().header("ACCESS_RANDOM_STR", accessRandomStr).header("ACCESS_TIME", time).header("ACCESS_SIGNATURE",signature).post(Entity.entity(userLogin,MediaType.APPLICATION_JSON));
GenericType<SafeResponse<UserLogin>> SafeResponseType = new GenericType<SafeResponse<UserLogin>>() {};
SafeResponse<UserLogin> sr = response.readEntity(SafeResponseType);
System.out.println(sr.getContent());
System.out.println(sr.getSignature());
String returnJson = mapper.writeValueAsString(sr.getContent());
String returnSinature = Coder.genSignature(returnJson);
assertTrue(sr.getSignature().equals(returnSinature));
response.close();
}
示例9: testSpanLogging
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Test
public void testSpanLogging() throws Exception {
ResteasyClient client = (ResteasyClient) ResteasyClientBuilder.newClient();
client.register(ClientRequestInterceptor.class);
client.register(ClientResponseInterceptor.class);
Response response = client.target("http://localhost:8080").request(MediaType.TEXT_PLAIN).get();
Assert.assertEquals(200, response.getStatus());
// check log file for span reporting & the specified service name
// the default zipkin fraction logs to system out
List<String> logContent = Files.readAllLines(Paths.get(LOG_FILE));
boolean spanPresent = logContent.stream().anyMatch(line -> line.contains(SPAN_COLLECTOR));
Assert.assertTrue("Span logging missing from log file", spanPresent);
boolean serviceNamePresent = logContent.stream().anyMatch(line -> line.contains(SERVICE_NAME));
Assert.assertTrue("Service name " + SERVICE_NAME + " missing from log file", serviceNamePresent);
}
示例10: 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();
}
}
示例11: 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();
}
}
示例12: 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();
}
}
示例13: newClient
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
@Override
protected Client newClient() {
ResteasyClientBuilder resteasyClientBuilder = new ResteasyClientBuilder();
ResteasyClient client = resteasyClientBuilder.establishConnectionTimeout(getTimeout(), TimeUnit.MILLISECONDS).socketTimeout(getTimeout(), TimeUnit.MILLISECONDS).build();
AbstractHttpClient httpClient = (AbstractHttpClient) ((ApacheHttpClient4Engine) client.httpEngine()).getHttpClient();
httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
protected boolean isRedirectable(String method) {
return true;
}
});
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
request.setParams(new AllowRedirectHttpParams(request.getParams()));
}
});
return client;
}
示例14: createTest
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
/**
* Creates the test.
*
* @throws Exception the exception
*/
@Test
@InSequence(1)
@RunAsClient
public void createTest() throws Exception {
try {
Comment comment = new Comment();
comment.setAuthor("author_test");
comment.setText("text_test");
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target =
client.target(deploymentUrl.toString() + RESOURCE_PREFIX + "/comments");
Response response = target.request().post(Entity.entity(comment, MediaType.APPLICATION_JSON));
Assert.assertEquals(200, response.getStatus());
System.out.println("POST /comments\n" + response.readEntity(String.class));
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: updateTest
import org.jboss.resteasy.client.jaxrs.ResteasyClient; //导入依赖的package包/类
/**
* Update test.
*
* @throws Exception the exception
*/
@Test
@InSequence(2)
@RunAsClient
public void updateTest() throws Exception {
try {
Comment comment = new Comment();
comment.setId(1L);
comment.setAuthor("changed_author_test");
comment.setText("changed_text_test");
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target =
client.target(deploymentUrl.toString() + RESOURCE_PREFIX + "/comments/1");
Response response = target.request().put(Entity.entity(comment, MediaType.APPLICATION_JSON));
Assert.assertEquals(200, response.getStatus());
System.out.println("PUT /comments\n" + response.readEntity(String.class));
} catch (Exception e) {
e.printStackTrace();
}
}