Search in sources :

Example 1 with HttpHandlerFactory

use of io.cdap.cdap.internal.app.runtime.service.http.HttpHandlerFactory in project cdap by caskdata.

the class DefaultServiceConfigurer method verifyHandlers.

private void verifyHandlers(List<? extends HttpServiceHandler> handlers) {
    Preconditions.checkArgument(!handlers.isEmpty(), "Service %s should have at least one handler", name);
    new HttpHandlerFactory("", TransactionControl.IMPLICIT).validateHttpHandler(handlers);
    for (HttpServiceHandler handler : handlers) {
        // check that a system service handler is only used in system namespace
        if (!deployNamespace.equals(Id.Namespace.fromEntityId(NamespaceId.SYSTEM))) {
            TypeToken<?> contextType = TypeToken.of(handler.getClass()).resolveType(HttpServiceHandler.class.getTypeParameters()[0]);
            if (SystemHttpServiceContext.class.isAssignableFrom(contextType.getRawType())) {
                throw new IllegalArgumentException(String.format("Invalid service handler '%s'. Service handlers can only use a SystemHttpServiceContext if the " + "application is deployed in the system namespace.", handler.getClass().getSimpleName()));
            }
            TypeToken<?> configurerType = TypeToken.of(handler.getClass()).resolveType(HttpServiceHandler.class.getTypeParameters()[1]);
            if (SystemHttpServiceConfigurer.class.isAssignableFrom(configurerType.getRawType())) {
                throw new IllegalArgumentException(String.format("Invalid service handler '%s'. Service handlers can only use a SystemHttpServiceConfigurer if the " + "application is deployed in the system namespace.", handler.getClass().getSimpleName()));
            }
        }
    }
}
Also used : HttpHandlerFactory(io.cdap.cdap.internal.app.runtime.service.http.HttpHandlerFactory) HttpServiceHandler(io.cdap.cdap.api.service.http.HttpServiceHandler)

Aggregations

HttpServiceHandler (io.cdap.cdap.api.service.http.HttpServiceHandler)1 HttpHandlerFactory (io.cdap.cdap.internal.app.runtime.service.http.HttpHandlerFactory)1