use of io.undertow.client.ClientResponse in project light-portal by networknt.
the class UserEmailGetHandlerTest method testUserEmailGetHandlerTest.
@Test
public void testUserEmailGetHandlerTest() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/v1/user/email?email=aaa.bbb.@google.com").setMethod(Methods.GET);
connection.sendRequest(request, client.createClientCallback(reference, latch));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
System.out.println("response:" + body);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of io.undertow.client.ClientResponse in project light-portal by networknt.
the class UserIdDeleteHandlerTest method testUserIdDeleteHandlerTest.
@Test
public void testUserIdDeleteHandlerTest() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/v1/user/12222").setMethod(Methods.DELETE);
connection.sendRequest(request, client.createClientCallback(reference, latch));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
System.out.println("response:" + body);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of io.undertow.client.ClientResponse in project light-portal by networknt.
the class UserIdGetHandlerTest method testUserIdGetHandlerTest.
@Test
public void testUserIdGetHandlerTest() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/v1/user/12222").setMethod(Methods.GET);
connection.sendRequest(request, client.createClientCallback(reference, latch));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
System.out.println("response:" + body);
Assert.assertNotNull(body);
}
use of io.undertow.client.ClientResponse in project light-portal by networknt.
the class UserIdPutHandlerTest method testUserIdPutHandlerTestUserUpdate.
@Test
public void testUserIdPutHandlerTestUserUpdate() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
UserDto userDto = new UserDto("aaa.bbb@gmail.com", "testUser");
userDto.setHost("google");
userDto.setPassword("12345678");
userDto.getContactData().setFirstName("test1");
userDto.getContactData().setLastName("bbb1");
userDto.getContactData().setGender(Gender.MALE);
AddressData address = new AddressData();
address.setCountry(Country.CA);
address.setState(State.AK);
address.setCity("BaBa");
address.setAddressType(AddressType.SHIPPING);
address.setAddressLine1("222 Bay Street");
userDto.getContactData().addAddresses(address);
String json = JSonMapper.toJson(userDto);
System.out.println(json);
try {
ClientRequest request = new ClientRequest().setPath("/v1/user/1233333").setMethod(Methods.PUT);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
System.out.println("response:" + body);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of io.undertow.client.ClientResponse in project light-portal by networknt.
the class UserLoginPutHandlerTest method testUserLoginPutHandlerTest.
@Test
public void testUserLoginPutHandlerTest() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
LoginForm login = new LoginForm();
login.setPassword("password");
login.setNameOrEmail("user_login");
String json = JSonMapper.toJson(login);
System.out.println(json);
try {
ClientRequest request = new ClientRequest().setPath("/v1/user/login").setMethod(Methods.PUT);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
System.out.println("response:" + body);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
Aggregations