use of org.eclipse.microprofile.rest.client.RestClientDefinitionException in project wildfly-swarm by wildfly-swarm.
the class BuilderImpl method verifyInterface.
private <T> void verifyInterface(Class<T> typeDef) {
Method[] methods = typeDef.getMethods();
// multiple verbs
for (Method method : methods) {
boolean hasHttpMethod = false;
for (Annotation annotation : method.getAnnotations()) {
boolean isHttpMethod = (annotation.annotationType().getAnnotation(HttpMethod.class) != null);
if (!hasHttpMethod && isHttpMethod) {
hasHttpMethod = true;
} else if (hasHttpMethod && isHttpMethod) {
throw new RestClientDefinitionException("Ambiguous @Httpmethod defintion on type " + typeDef);
}
}
}
// invalid parameter
Path classPathAnno = typeDef.getAnnotation(Path.class);
final Set<String> classLevelVariables = new HashSet<>();
ResteasyUriBuilder classTemplate = null;
if (classPathAnno != null) {
classTemplate = (ResteasyUriBuilder) UriBuilder.fromUri(classPathAnno.value());
classLevelVariables.addAll(classTemplate.getPathParamNamesInDeclarationOrder());
}
ResteasyUriBuilder template;
for (Method method : methods) {
Path methodPathAnno = method.getAnnotation(Path.class);
if (methodPathAnno != null) {
template = classPathAnno == null ? (ResteasyUriBuilder) UriBuilder.fromUri(methodPathAnno.value()) : (ResteasyUriBuilder) UriBuilder.fromUri(classPathAnno.value() + "/" + methodPathAnno.value());
} else {
template = classTemplate;
}
if (template == null) {
continue;
}
// it's not executed, so this can be anything - but a hostname needs to present
template.host("localhost");
Set<String> allVariables = new HashSet<>(template.getPathParamNamesInDeclarationOrder());
Map<String, Object> paramMap = new HashMap<>();
for (Parameter p : method.getParameters()) {
PathParam pathParam = p.getAnnotation(PathParam.class);
if (pathParam != null) {
paramMap.put(pathParam.value(), "foobar");
}
}
if (allVariables.size() != paramMap.size()) {
throw new RestClientDefinitionException("Parameters and variables don't match on " + typeDef + "::" + method.getName());
}
try {
template.resolveTemplates(paramMap, false).build();
} catch (IllegalArgumentException ex) {
throw new RestClientDefinitionException("Parameter names don't match variable names on " + typeDef + "::" + method.getName(), ex);
}
}
}
Aggregations