use of com.google.api.server.spi.config.ApiConfigException in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReader method loadEndpointClass.
@Override
public void loadEndpointClass(ServiceContext serviceContext, Class<?> endpointClass, ApiConfig config) throws ApiConfigException {
try {
Annotation api = getDeclaredAnnotation(endpointClass, annotationTypes.get("Api"));
Annotation apiClass = getDeclaredAnnotation(endpointClass, annotationTypes.get("ApiClass"));
if (!readEndpointClass(config, endpointClass, api, apiClass, endpointClass)) {
throw new ApiConfigException(endpointClass + " has no @Api annotation.");
}
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
throw new ApiConfigException(e);
}
}
use of com.google.api.server.spi.config.ApiConfigException in project endpoints-java by cloudendpoints.
the class ProxyingDiscoveryProvider method getDirectory.
@Override
public DirectoryList getDirectory(String root) throws InternalServerErrorException {
try {
Map<ApiKey, String> configStrings = configWriter.writeConfig(rewriteConfigsWithRoot(getAllApiConfigs(), root));
ApiConfigs configs = new ApiConfigs();
configs.setConfigs(Lists.newArrayList(configStrings.values()));
return discovery.apis().generateDirectory(configs).execute();
} catch (IOException | ApiConfigException e) {
logger.atSevere().withCause(e).log("Could not generate or cache directory");
throw new InternalServerErrorException("Internal Server Error", e);
}
}
use of com.google.api.server.spi.config.ApiConfigException in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testEndpointNoApiAnnotation.
@Test
public void testEndpointNoApiAnnotation() throws Exception {
ApiConfig config = createConfig(Object.class);
try {
annotationReader.loadEndpointClass(serviceContext, Object.class, config);
fail("No @Api annotation should've caused reader to fail.");
} catch (ApiConfigException expected) {
assertEquals("class java.lang.Object has no @Api annotation.", expected.getMessage());
}
}
use of com.google.api.server.spi.config.ApiConfigException in project endpoints-java by cloudendpoints.
the class SwaggerGenerator method addDefinedMetricCosts.
private void addDefinedMetricCosts(Map<String, ApiLimitMetricConfig> limitMetrics, Operation operation, List<ApiMetricCostConfig> metricCosts) throws ApiConfigException {
if (!metricCosts.isEmpty()) {
Map<String, Integer> costs = new HashMap<>();
for (ApiMetricCostConfig cost : metricCosts) {
if (!limitMetrics.containsKey(cost.name())) {
throw new ApiConfigException(String.format("Could not add a metric cost for metric '%s'. The limit metric must be " + "defined at the API level.", cost.name()));
}
costs.put(cost.name(), cost.cost());
}
operation.setVendorExtension("x-google-quota", ImmutableMap.of("metricCosts", costs));
}
}
use of com.google.api.server.spi.config.ApiConfigException in project endpoints-java by cloudendpoints.
the class SwaggerGenerator method addNonConflictingSecurityDefinition.
private static String addNonConflictingSecurityDefinition(Swagger swagger, IssuerConfig issuerConfig, ImmutableSet<String> audiences) throws ApiConfigException {
Map<String, SecuritySchemeDefinition> securityDefinitions = getOrCreateSecurityDefinitionMap(swagger);
String issuerPlusHash = String.format("%s-%x", issuerConfig.getName(), audiences.hashCode());
SecuritySchemeDefinition existingDef = securityDefinitions.get(issuerConfig.getName());
SecuritySchemeDefinition newDef = toScheme(issuerConfig, audiences);
if (existingDef != null && !existingDef.equals(newDef)) {
throw new ApiConfigException("Multiple conflicting definitions found for issuer " + issuerConfig.getName());
}
swagger.securityDefinition(issuerPlusHash, newDef);
return issuerPlusHash;
}
Aggregations