Search in sources :

Example 1 with PathDispatcher

use of com.google.api.server.spi.dispatcher.PathDispatcher in project endpoints-java by cloudendpoints.

the class EndpointsServlet method createDispatcher.

private PathDispatcher<EndpointsContext> createDispatcher() {
    PathDispatcher.Builder<EndpointsContext> builder = PathDispatcher.builder();
    List<EndpointNode> endpoints = systemService.getEndpoints();
    // We're building an ImmutableList here, because it will eventually be used for JSON-RPC.
    ImmutableList.Builder<EndpointsMethodHandler> handlersBuilder = ImmutableList.builder();
    for (EndpointNode endpoint : endpoints) {
        ApiConfig apiConfig = endpoint.getConfig();
        MethodConfigMap methods = apiConfig.getApiClassConfig().getMethods();
        for (Entry<EndpointMethod, ApiMethodConfig> methodEntry : methods.entrySet()) {
            if (!methodEntry.getValue().isIgnored()) {
                handlersBuilder.add(new EndpointsMethodHandler(initParameters, getServletContext(), methodEntry.getKey(), apiConfig, methodEntry.getValue(), systemService));
            }
        }
    }
    ImmutableList<EndpointsMethodHandler> handlers = handlersBuilder.build();
    for (EndpointsMethodHandler handler : handlers) {
        builder.add(handler.getRestMethod(), Strings.stripTrailingSlash(handler.getRestPath()), handler.getRestHandler());
    }
    ExplorerHandler explorerHandler = new ExplorerHandler();
    builder.add("GET", EXPLORER_PATH, explorerHandler);
    builder.add("GET", EXPLORER_PATH + "/", explorerHandler);
    builder.add("GET", "static/proxy.html", new ApiProxyHandler());
    return builder.build();
}
Also used : EndpointsMethodHandler(com.google.api.server.spi.handlers.EndpointsMethodHandler) EndpointNode(com.google.api.server.spi.SystemService.EndpointNode) ApiProxyHandler(com.google.api.server.spi.handlers.ApiProxyHandler) ImmutableList(com.google.common.collect.ImmutableList) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) PathDispatcher(com.google.api.server.spi.dispatcher.PathDispatcher) ExplorerHandler(com.google.api.server.spi.handlers.ExplorerHandler) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) MethodConfigMap(com.google.api.server.spi.config.model.ApiClassConfig.MethodConfigMap)

Aggregations

EndpointNode (com.google.api.server.spi.SystemService.EndpointNode)1 MethodConfigMap (com.google.api.server.spi.config.model.ApiClassConfig.MethodConfigMap)1 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)1 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)1 PathDispatcher (com.google.api.server.spi.dispatcher.PathDispatcher)1 ApiProxyHandler (com.google.api.server.spi.handlers.ApiProxyHandler)1 EndpointsMethodHandler (com.google.api.server.spi.handlers.EndpointsMethodHandler)1 ExplorerHandler (com.google.api.server.spi.handlers.ExplorerHandler)1 ImmutableList (com.google.common.collect.ImmutableList)1