Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

fixes #278 add total to the Oauth2ClientGetHandler to support UI pagi… #279

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hazelcast.query.PagingPredicate;
import com.hazelcast.query.impl.predicates.LikePredicate;
import com.networknt.config.Config;
import com.networknt.config.JsonMapper;
import com.networknt.handler.LightHttpHandler;
import com.networknt.oauth.cache.CacheStartupHookProvider;
import com.networknt.oauth.cache.model.Client;
Expand All @@ -14,10 +15,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.List;
import java.util.*;

public class Oauth2ClientGetHandler extends ClientAuditHandler implements LightHttpHandler {
static final Logger logger = LoggerFactory.getLogger(Oauth2ClientGetHandler.class);
Expand All @@ -43,8 +41,11 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
c.setClientSecret(null);
results.add(c);
}
Map<String, Object> map = new HashMap<>();
map.put("clients", results);
map.put("total", clients.size());
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(results));
exchange.getResponseSender().send(JsonMapper.toJson(map));
processAudit(exchange);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.networknt.client.Http2Client;
import com.networknt.config.Config;
import com.networknt.config.JsonMapper;
import com.networknt.status.Status;
import com.networknt.exception.ApiException;
import com.networknt.exception.ClientException;
Expand All @@ -21,6 +22,7 @@

import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -54,13 +56,16 @@ public void testOauth2ClientGetHandler() throws ClientException, ApiException {
logger.debug("body = " + body);
Assert.assertEquals(200, statusCode);
if(statusCode == 200) {
// make sure that there are two services in the result.
List<com.networknt.oauth.cache.model.Client> clients = Config.getInstance().getMapper().readValue(body, new TypeReference<List<com.networknt.oauth.cache.model.Client>>(){});
// make sure that there are two clients in the clients list.
Map<String, Object> map = JsonMapper.string2Map(body);
int total = (Integer)map.get("total");
Assert.assertTrue(total > 5);
List<Map<String, Object>> clients = (List)map.get("clients");
Assert.assertTrue(clients.size() >= 1 && clients.size() <= 10);
// make sure that the first is AACT0001
// Assert.assertEquals("PetStore Web Server", clients.get(0).getClientName());
// make sure that client_secret is null.
Assert.assertNull(clients.get(0).getClientSecret());
Assert.assertNull(clients.get(0).get("clientSecret"));
}
} catch (Exception e) {
logger.error("Exception: ", e);
Expand Down