use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class UserGetHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
List<User> users = service.getUser();
List<UserDto> result = users.stream().map(e -> service.toUserDto(e)).collect(Collectors.toList());
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// exchange.endExchange();
}
use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class UserIdPutHandlerTest method testUserIdPutHandlerTestEmailChange.
@Test
public void testUserIdPutHandlerTestEmailChange() 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.bbb2@gmail.com", "testUser");
userDto.setEmailChange(true);
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 com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class UserIdPutHandlerTest method testUserIdPutHandlerTestPasswordReset.
@Test
public void testUserIdPutHandlerTestPasswordReset() 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.setPassword("new_password");
userDto.setPasswordReset(true);
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 com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class GetNewUser method handle.
@Override
public ByteBuffer handle(HttpServerExchange exchange, Object input) {
ObjectMapper mapper = new ObjectMapper();
ResponseResult response = new ResponseResult();
String result = "[Ok!]";
try {
String json = mapper.writeValueAsString(input);
UserDto userDto = mapper.readValue(json, UserDto.class);
User user = service.fromUserDto(userDto);
System.out.println("user:" + user.getScreenName());
service.signup(user, userDto.getPassword(), false);
response.setCompleted(true);
response.setMessage("created User:" + user.getScreenName());
result = Config.getInstance().getMapper().writeValueAsString(response);
} catch (Exception e) {
result = e.getMessage();
}
return NioUtils.toByteBuffer(result);
}
use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class UserGetHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
List<User> users = service.getUser();
List<UserDto> result = users.stream().map(e -> service.toUserDto(e)).collect(Collectors.toList());
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// // exchange.endExchange();
}
Aggregations