use of com.google.api.server.spi.config.model.ApiMethodConfig 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();
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method validateEndpoint1.
private void validateEndpoint1(ApiConfig config, Class<? extends Endpoint1> clazz) throws Exception {
assertEquals("api", config.getName());
assertEquals("v1", config.getVersion());
assertTrue(config.getIsDefaultVersion());
assertFalse(config.getIsAbstract());
assertTrue(config.getApiClassConfig().getUseDatastore());
assertEquals(ImmutableList.of(PassAuthenticator.class), config.getAuthenticators());
ApiAuthConfig auth = config.getAuthConfig();
assertTrue(auth.getAllowCookieAuth());
assertEquals(1, auth.getBlockedRegions().size());
assertEquals("CU", auth.getBlockedRegions().get(0));
ApiFrontendLimitsConfig frontendLimits = config.getFrontendLimitsConfig();
assertEquals(1, frontendLimits.getUnregisteredUserQps());
assertEquals(2, frontendLimits.getUnregisteredQps());
assertEquals(3, frontendLimits.getUnregisteredDaily());
// TODO: After fixing http://b/7459341, add check for number of rules.
assertEquals("match0", frontendLimits.getRules().get(0).getMatch());
assertEquals(1, frontendLimits.getRules().get(0).getQps());
assertEquals(2, frontendLimits.getRules().get(0).getUserQps());
assertEquals(3, frontendLimits.getRules().get(0).getDaily());
assertEquals("analyticsId0", frontendLimits.getRules().get(0).getAnalyticsId());
assertEquals("match10", frontendLimits.getRules().get(1).getMatch());
assertEquals(11, frontendLimits.getRules().get(1).getQps());
assertEquals(12, frontendLimits.getRules().get(1).getUserQps());
assertEquals(13, frontendLimits.getRules().get(1).getDaily());
assertEquals("analyticsId10", frontendLimits.getRules().get(1).getAnalyticsId());
ApiCacheControlConfig cacheControl = config.getCacheControlConfig();
assertEquals(ApiCacheControl.Type.PUBLIC, cacheControl.getType());
assertEquals(1, cacheControl.getMaxAge());
ApiSerializationConfig serialization = config.getSerializationConfig();
assertEquals(1, serialization.getSerializerConfigs().size());
ApiSerializationConfig.SerializerConfig serializerConfig = serialization.getSerializerConfig(TypeToken.of(SimpleBean.class));
assertEquals(TypeToken.of(SimpleBean.class), serializerConfig.getSourceType());
assertEquals(DumbSerializer1.class, serializerConfig.getSerializer());
String[] defaultScopes = { "ss0", "ss1 ss2" };
String[] defaultAudiences = { "aa0", "aa1" };
String[] defaultClientIds = { "cc0", "cc1" };
ApiMethodConfig listFoos = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("listFoos")));
String[] expectedScopes = { "s0", "s1 s2" };
String[] expectedAudiences = { "a0", "a1" };
String[] expectedClientIds = { "c0", "c1" };
validateMethod(listFoos, "foos.list", "foos", ApiMethod.HttpMethod.GET, expectedScopes, expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class), ImmutableList.of(FailPeerAuthenticator.class));
assertEquals(0, listFoos.getParameterConfigs().size());
ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("getFoo", String.class)));
validateMethod(getFoo, "foos.get", "foos/{id}", ApiMethod.HttpMethod.GET, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, getFoo.getParameterConfigs().size());
validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class);
ApiMethodConfig insertFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("insertFoo", Foo.class)));
validateMethod(insertFoo, "foos.insert", "foos", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, insertFoo.getParameterConfigs().size());
validateParameter(insertFoo.getParameterConfigs().get(0), null, false, null, Foo.class);
ApiMethodConfig updateFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("updateFoo", String.class, Foo.class)));
validateMethod(updateFoo, "foos.update", "foos/{id}", ApiMethod.HttpMethod.PUT, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(2, updateFoo.getParameterConfigs().size());
validateParameter(updateFoo.getParameterConfigs().get(0), "id", false, null, String.class);
validateParameter(updateFoo.getParameterConfigs().get(1), null, false, null, Foo.class);
ApiMethodConfig removeFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("removeFoo", String.class)));
validateMethod(removeFoo, "foos.remove", "foos/{id}", ApiMethod.HttpMethod.DELETE, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, removeFoo.getParameterConfigs().size());
validateParameter(removeFoo.getParameterConfigs().get(0), "id", false, null, String.class);
ApiMethodConfig execute0 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute0", String.class, int.class, Integer.class, long.class, Long.class, boolean.class, Boolean.class, float.class, Double.class)));
validateMethod(execute0, "foos.execute0", "execute0", "POST", defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(9, execute0.getParameterConfigs().size());
validateParameter(execute0.getParameterConfigs().get(0), "id", false, null, String.class);
validateParameter(execute0.getParameterConfigs().get(1), "i0", false, null, int.class);
validateParameter(execute0.getParameterConfigs().get(2), "i1", true, null, Integer.class);
validateParameter(execute0.getParameterConfigs().get(3), "long0", false, null, long.class);
validateParameter(execute0.getParameterConfigs().get(4), "long1", true, null, Long.class);
validateParameter(execute0.getParameterConfigs().get(5), "b0", false, null, boolean.class);
validateParameter(execute0.getParameterConfigs().get(6), "b1", true, null, Boolean.class);
validateParameter(execute0.getParameterConfigs().get(7), "f", false, null, float.class);
validateParameter(execute0.getParameterConfigs().get(8), "d", true, null, Double.class);
ApiMethodConfig execute1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute1", Foo.class)));
validateMethod(execute1, clazz.getSimpleName() + ".execute1", "execute1", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, execute1.getParameterConfigs().size());
validateParameter(execute1.getParameterConfigs().get(0), null, false, null, Foo.class);
ApiMethodConfig execute2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute2", SimpleBean.class)));
validateMethod(execute2, "foos.execute2", "execute2/{serialized}", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, execute2.getParameterConfigs().size());
validateParameter(execute2.getParameterConfigs().get(0), "serialized", false, null, SimpleBean.class, DumbSerializer1.class, String.class);
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testMethodDescription.
@Test
public void testMethodDescription() throws Exception {
@Api
final class MethodDescriptionEndpoint {
public void noAnnotation() {
}
@ApiMethod
public void noDescription() {
}
@ApiMethod(description = "description")
public void withDescription() {
}
}
ApiConfig config = createConfig(MethodDescriptionEndpoint.class);
annotationReader.loadEndpointMethods(serviceContext, MethodDescriptionEndpoint.class, config.getApiClassConfig().getMethods());
ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("noAnnotation")));
assertNull(method1.getDescription());
ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("noDescription")));
assertNull(method2.getDescription());
ApiMethodConfig method3 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("withDescription")));
assertEquals("description", method3.getDescription());
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testServiceWithOverridingInheritance.
@Test
public void testServiceWithOverridingInheritance() throws Exception {
ApiConfig config = createConfig(SubclassedOverridingEndpoint.class);
annotationReader.loadEndpointClass(serviceContext, SubclassedOverridingEndpoint.class, config);
assertEquals("api", config.getName());
assertEquals("v2", config.getVersion());
assertEquals("overridden description", config.getDescription());
assertFalse(config.getIsDefaultVersion());
assertFalse(config.getIsDiscoverable());
assertFalse(config.getUseDatastore());
ApiAuthConfig auth = config.getAuthConfig();
assertTrue(auth.getAllowCookieAuth());
ApiFrontendLimitsConfig frontendLimits = config.getFrontendLimitsConfig();
assertEquals(1, frontendLimits.getUnregisteredUserQps());
assertEquals(4, frontendLimits.getUnregisteredQps());
ApiCacheControlConfig cacheControl = config.getCacheControlConfig();
assertEquals(2, cacheControl.getMaxAge());
assertEquals(ApiCacheControl.Type.PUBLIC, cacheControl.getType());
annotationReader.loadEndpointMethods(serviceContext, SubclassedOverridingEndpoint.class, config.getApiClassConfig().getMethods());
String[] defaultScopes = { "ss0a", "ss1a" };
String[] defaultAudiences = { "aa0a", "aa1a" };
String[] defaultClientIds = { "cc0a", "cc1a" };
assertEquals(8, config.getApiClassConfig().getMethods().size());
ApiMethodConfig listFoos = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SubclassedOverridingEndpoint.class.getMethod("listFoos")));
String[] expectedScopes = { "s0", "s1 s2" };
String[] expectedAudiences = { "a0", "a1" };
String[] expectedClientIds = { "c0", "c1" };
validateMethod(listFoos, "foos.list", "foos", ApiMethod.HttpMethod.GET, expectedScopes, expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class), ImmutableList.of(FailPeerAuthenticator.class));
assertEquals(0, listFoos.getParameterConfigs().size());
ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SubclassedOverridingEndpoint.class.getMethod("getFoo", String.class)));
validateMethod(getFoo, "foos.get2", "foos/{id}", ApiMethod.HttpMethod.GET, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, getFoo.getParameterConfigs().size());
validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class);
ApiMethodConfig insertFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("insertFoo", Foo.class)));
validateMethod(insertFoo, "foos.insert", "foos", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, insertFoo.getParameterConfigs().size());
validateParameter(insertFoo.getParameterConfigs().get(0), null, false, null, Foo.class);
ApiMethodConfig execute2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint1.class.getMethod("execute2", SimpleBean.class)));
validateMethod(execute2, "foos.execute2", "execute2/{serialized}", ApiMethod.HttpMethod.POST, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
assertEquals(1, execute2.getParameterConfigs().size());
validateParameter(execute2.getParameterConfigs().get(0), "serialized", false, null, SimpleBean.class, DumbSerializer2.class, Integer.class);
}
use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testSimpleCovarianceEndpoint.
@Test
public void testSimpleCovarianceEndpoint() throws Exception {
ApiConfig config = createConfig(SimpleCovarianceEndpoint.class);
annotationReader.loadEndpointMethods(serviceContext, SimpleCovarianceEndpoint.class, config.getApiClassConfig().getMethods());
ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleCovarianceEndpoint.class.getMethod("foo", String.class)));
assertEquals("api.foos.fn", method1.getName());
ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleCovarianceEndpoint.class.getSuperclass().getMethod("foo", Object.class)));
assertEquals("api.foos.base", method2.getName());
}
Aggregations