use of com.tvd12.ezyhttp.core.net.URITree in project ezyhttp by youngmonkeys.
the class RequestHandlerManager method addHandler.
public void addHandler(RequestURI uri, RequestHandler handler) {
RequestHandler old = this.handlers.put(uri, handler);
if (old != null && !allowOverrideURI) {
throw new DuplicateURIMappingHandlerException(uri, old, handler);
}
this.handledURIs.add(uri.getUri());
this.logger.info("add mapping uri: {}", uri);
this.handlerListByURI.computeIfAbsent(uri, k -> new ArrayList<>()).add(handler);
this.requestURIManager.addHandledURI(uri.getMethod(), uri.getUri());
if (uri.isApi()) {
this.requestURIManager.addApiURI(uri.getMethod(), uri.getUri());
this.requestURIManager.addApiURI(uri.getMethod(), uri.getSameURI());
}
if (uri.isAuthenticated()) {
this.requestURIManager.addAuthenticatedURI(uri.getMethod(), uri.getUri());
this.requestURIManager.addAuthenticatedURI(uri.getMethod(), uri.getSameURI());
}
if (uri.isManagement()) {
this.requestURIManager.addManagementURI(uri.getMethod(), uri.getUri());
this.requestURIManager.addManagementURI(uri.getMethod(), uri.getSameURI());
}
if (uri.isPayment()) {
this.requestURIManager.addPaymentURI(uri.getMethod(), uri.getUri());
this.requestURIManager.addPaymentURI(uri.getMethod(), uri.getSameURI());
}
if (EzyStrings.isNotBlank(uri.getFeature())) {
this.featureURIManager.addFeatureURI(uri.getFeature(), uri.getMethod(), uri.getUri());
this.featureURIManager.addFeatureURI(uri.getFeature(), uri.getMethod(), uri.getSameURI());
}
URITree uriTree = uriTreeByMethod.get(uri.getMethod());
uriTree.addURI(uri.getUri());
}
use of com.tvd12.ezyhttp.core.net.URITree in project ezyhttp by youngmonkeys.
the class URITreeTest method getMatchedURIChildNull.
@Test
public void getMatchedURIChildNull() {
// given
URITree tree = new URITree();
tree.addURI("/api/v1/hello/{world}/{foo}/{bar}");
// when
// then
System.out.println(tree);
Asserts.assertNull(tree.getMatchedURI("/api/v1"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}/{foo}"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}/{foo}/{bar}/unknown"));
}
use of com.tvd12.ezyhttp.core.net.URITree in project ezyhttp by youngmonkeys.
the class RequestHandlerManager method getMatchedURI.
public String getMatchedURI(HttpMethod method, String requestURI) {
String matchedURI = null;
if (handledURIs.contains(requestURI)) {
matchedURI = requestURI;
}
if (matchedURI == null && requestURI != null) {
URITree uriTree = uriTreeByMethod.get(method);
matchedURI = uriTree.getMatchedURI(requestURI);
}
return matchedURI;
}
use of com.tvd12.ezyhttp.core.net.URITree in project ezyhttp by youngmonkeys.
the class URITreeTest method test.
@Test
public void test() {
// given
String uri11 = "/api/v1/customer/{name}/create";
String uri12 = "/api/v1/customer/{name}/delete";
String uri2 = "/api/v1/user";
// when
URITree tree = new URITree();
tree.addURI(uri11);
tree.addURI(uri12);
tree.addURI(uri2);
// then
System.out.println("tree: " + tree);
String check11 = "/api/v1/customer/dung/create";
String check12 = "/api/v1/customer/dung/create/1";
Assert.assertEquals("/api/v1/customer/{name}/create", tree.getMatchedURI(check11));
System.out.println("check11: " + tree.getMatchedURI(check11));
Assert.assertNull(tree.getMatchedURI(check12));
System.out.println("check12: " + tree.getMatchedURI(check12));
}
use of com.tvd12.ezyhttp.core.net.URITree in project ezyhttp by youngmonkeys.
the class URITreeTest method getMatchedURIChildNull2.
@Test
public void getMatchedURIChildNull2() {
// given
URITree tree = new URITree();
tree.addURI("/api/v1/hello/{world}/{foo}/bar");
// when
// then
System.out.println(tree);
Asserts.assertNull(tree.getMatchedURI("/api/v1"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}/{foo}"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}/{foo}/{bar}/unknown"));
}
Aggregations