Search in sources :

Example 26 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.

the class V018HttpClientTest method main.

public static void main(String[] args) throws Exception {
    HttpClient client = HttpClient.builder().build();
    PostRequest loveRequest = new PostRequest().setURL("http://localhost:8083/love");
    System.out.println(client.request(loveRequest));
    DeleteRequest deleteRequest = new DeleteRequest().setURL("http://localhost:8083/api/v1/customer/delete").setEntity(RequestEntity.builder().header("token", "123456").build());
    System.out.println(client.request(deleteRequest));
    System.out.println(client.request(deleteRequest).getBody().toString());
    GetRequest textRequest = new GetRequest().setURL("http://localhost:8083/text");
    System.out.println((String) client.call(textRequest));
    GetRequest listRequest = new GetRequest().setResponseType(List.class).setURL("http://localhost:8083/list");
    System.out.println(client.call(listRequest).toString());
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) List(java.util.List) DeleteRequest(com.tvd12.ezyhttp.client.request.DeleteRequest)

Example 27 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyfox-examples by tvd12.

the class FacebookService method getAccessToken.

@SuppressWarnings("unchecked")
@Override
public String getAccessToken(String code) {
    Map<String, Object> requestBody = EzyMapBuilder.mapBuilder().put("client_id", clientId).put("client_secret", clientSecret).put("redirect_uri", redirectUri).put("code", code).build();
    PostRequest request = new PostRequest().setURL(getTokenUri).setEntity(RequestEntity.builder().contentType(ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED).body(requestBody).build()).setResponseType(Map.class);
    try {
        Map<String, Object> response = httpClientProxy.call(request, DEFAULT_GOOGLE_AUTH_TIMEOUT);
        return (String) response.get("access_token");
    } catch (Exception e) {
        logger.info("get facebook access token error", e);
        return null;
    }
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest)

Example 28 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyfox-examples by tvd12.

the class GoogleService method getAccessToken.

@SuppressWarnings("unchecked")
@Override
public String getAccessToken(String code) {
    Map<String, Object> requestBody = EzyMapBuilder.mapBuilder().put("client_id", clientId).put("client_secret", clientSecret).put("redirect_uri", redirectUri).put("code", code).put("grant_type", "authorization_code").build();
    PostRequest request = new PostRequest().setURL(getTokenUri).setEntity(RequestEntity.builder().contentType(ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED).body(requestBody).build()).setResponseType(Map.class);
    try {
        Map<String, Object> response = httpClientProxy.call(request, DEFAULT_GOOGLE_AUTH_TIMEOUT);
        return (String) response.get("access_token");
    } catch (Exception e) {
        logger.info("get google access token error", e);
        return null;
    }
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest)

Aggregations

PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)22 BeforeTest (org.testng.annotations.BeforeTest)21 Test (org.testng.annotations.Test)21 HttpClient (com.tvd12.ezyhttp.client.HttpClient)20 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)5 BaseTest (com.tvd12.test.base.BaseTest)5 RequestEntity (com.tvd12.ezyhttp.client.request.RequestEntity)3 BadRequestException (com.tvd12.ezyfox.exception.BadRequestException)2 ClientNotActiveException (com.tvd12.ezyhttp.client.exception.ClientNotActiveException)2 DownloadCancelledException (com.tvd12.ezyhttp.client.exception.DownloadCancelledException)2 RequestQueueFullException (com.tvd12.ezyhttp.client.exception.RequestQueueFullException)2 HelloRequest (com.tvd12.ezyhttp.client.test.request.HelloRequest)2 UnknownHostException (java.net.UnknownHostException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RequestCallback (com.tvd12.ezyhttp.client.callback.RequestCallback)1 DeleteRequest (com.tvd12.ezyhttp.client.request.DeleteRequest)1 GetRequest (com.tvd12.ezyhttp.client.request.GetRequest)1 Request (com.tvd12.ezyhttp.client.request.Request)1 Customer (com.tvd12.ezyhttp.client.test.request.Customer)1 ResponseEntity (com.tvd12.ezyhttp.core.response.ResponseEntity)1