Search in sources :

Example 1 with DuplicateURIMappingHandlerException

use of com.tvd12.ezyhttp.server.core.exception.DuplicateURIMappingHandlerException 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());
}
Also used : Setter(lombok.Setter) Getter(lombok.Getter) DuplicateURIMappingHandlerException(com.tvd12.ezyhttp.server.core.exception.DuplicateURIMappingHandlerException) EzyLoggable(com.tvd12.ezyfox.util.EzyLoggable) Set(java.util.Set) HashMap(java.util.HashMap) EzyStrings(com.tvd12.ezyfox.io.EzyStrings) EzyDestroyable(com.tvd12.ezyfox.util.EzyDestroyable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) HttpMethod(com.tvd12.ezyhttp.core.constant.HttpMethod) Collections(java.util.Collections) URITree(com.tvd12.ezyhttp.core.net.URITree) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) URITree(com.tvd12.ezyhttp.core.net.URITree) DuplicateURIMappingHandlerException(com.tvd12.ezyhttp.server.core.exception.DuplicateURIMappingHandlerException) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) ArrayList(java.util.ArrayList)

Aggregations

EzyStrings (com.tvd12.ezyfox.io.EzyStrings)1 EzyDestroyable (com.tvd12.ezyfox.util.EzyDestroyable)1 EzyLoggable (com.tvd12.ezyfox.util.EzyLoggable)1 HttpMethod (com.tvd12.ezyhttp.core.constant.HttpMethod)1 URITree (com.tvd12.ezyhttp.core.net.URITree)1 DuplicateURIMappingHandlerException (com.tvd12.ezyhttp.server.core.exception.DuplicateURIMappingHandlerException)1 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)1 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1