use of io.vertigo.vega.webservice.metamodel.WebServiceDefinition in project vertigo by KleeGroup.
the class ValidatorWebServiceHandlerPlugin method handle.
/**
* {@inheritDoc}
*/
@Override
public Object handle(final Request request, final Response response, final WebServiceCallContext routeContext, final HandlerChain chain) throws SessionException {
final WebServiceDefinition webServiceDefinition = routeContext.getWebServiceDefinition();
final UiMessageStack uiMessageStack = routeContext.getUiMessageStack();
for (final WebServiceParam webServiceParam : webServiceDefinition.getWebServiceParams()) {
final Object value = routeContext.getParamValue(webServiceParam);
validateParam(value, uiMessageStack, webServiceParam, routeContext);
}
if (uiMessageStack.hasErrors()) {
throw new ValidationUserException();
}
return chain.handle(request, response, routeContext);
}
use of io.vertigo.vega.webservice.metamodel.WebServiceDefinition in project vertigo by KleeGroup.
the class AnalyticsWebServiceHandlerPlugin method handle.
/**
* {@inheritDoc}
*/
@Override
public Object handle(final Request request, final Response response, final WebServiceCallContext webServiceCallContext, final HandlerChain chain) throws SessionException {
final WebServiceDefinition webServiceDefinition = webServiceCallContext.getWebServiceDefinition();
// On ne prend pas request.pathInfo qui peut contenir des paramètres : on en veut pas ca dans les stats
final String name = "/" + webServiceDefinition.getVerb().name() + "/" + webServiceDefinition.getPath();
return analyticsManager.traceWithReturn("webservices", name, tracer -> {
try {
return chain.handle(request, response, webServiceCallContext);
} catch (final SessionException e) {
throw WrappedException.wrap(e);
}
});
}
use of io.vertigo.vega.webservice.metamodel.WebServiceDefinition in project vertigo by KleeGroup.
the class AbstractSparkJavaWebServerPlugin method registerWebServiceRoute.
/**
* {@inheritDoc}
*/
@Override
public final void registerWebServiceRoute(final HandlerChain handlerChain, final Collection<WebServiceDefinition> webServiceDefinitions) {
Assertion.checkNotNull(handlerChain);
Assertion.checkNotNull(webServiceDefinitions);
// -----
boolean corsProtected = false;
for (final WebServiceDefinition webServiceDefinition : webServiceDefinitions) {
final String routePath = convertJaxRsPathToSpark(apiPrefix.orElse("") + webServiceDefinition.getPath());
final String acceptType = webServiceDefinition.getAcceptType();
final SparkJavaRoute sparkJavaRoute = new SparkJavaRoute(webServiceDefinition, handlerChain, DEFAULT_CONTENT_CHARSET);
switch(webServiceDefinition.getVerb()) {
case GET:
Spark.get(routePath, acceptType, sparkJavaRoute);
break;
case POST:
Spark.post(routePath, acceptType, sparkJavaRoute);
break;
case PUT:
Spark.put(routePath, acceptType, sparkJavaRoute);
break;
case PATCH:
Spark.patch(routePath, acceptType, sparkJavaRoute);
break;
case DELETE:
Spark.delete(routePath, acceptType, sparkJavaRoute);
break;
default:
throw new UnsupportedOperationException();
}
corsProtected = corsProtected || webServiceDefinition.isCorsProtected();
}
if (corsProtected) {
final SparkJavaOptionsRoute sparkJavaOptionsRoute = new SparkJavaOptionsRoute(handlerChain);
Spark.options("*", sparkJavaOptionsRoute);
}
}
use of io.vertigo.vega.webservice.metamodel.WebServiceDefinition in project vertigo by KleeGroup.
the class CatalogWebServices method publishCatalog.
private static List<String> publishCatalog(final Collection<WebServiceDefinition> webServiceDefinitions) {
final List<String> result = new ArrayList<>();
final StringBuilder sb = new StringBuilder();
for (final WebServiceDefinition webServiceDefinition : webServiceDefinitions) {
final String doc = webServiceDefinition.getDoc();
if (!doc.isEmpty()) {
sb.append(" /*").append(webServiceDefinition.getDoc()).append("*/").append('\n');
}
sb.append(webServiceDefinition.getVerb().name()).append(' ').append(webServiceDefinition.getPath()).append(" (");
String sep = "";
for (final WebServiceParam webServiceParam : webServiceDefinition.getWebServiceParams()) {
sb.append(sep);
sb.append(webServiceParam);
sep = ", ";
}
sb.append(')');
final Type returnType = webServiceDefinition.getMethod().getGenericReturnType();
if (!void.class.isAssignableFrom(webServiceDefinition.getMethod().getReturnType())) {
sb.append(" -> ");
appendTypeToString(sb, returnType);
}
result.add(sb.toString());
sb.setLength(0);
}
return result;
}
use of io.vertigo.vega.webservice.metamodel.WebServiceDefinition in project vertigo by KleeGroup.
the class SwaggerApiBuilder method createPathsObject.
private Map<String, Object> createPathsObject() {
final Map<String, Object> paths = new LinkedHashMap<>();
for (final WebServiceDefinition webServiceDefinition : builderWebServiceDefinitions) {
final Map<String, Object> pathItem = (Map<String, Object>) paths.get(webServiceDefinition.getPath());
if (pathItem != null) {
pathItem.putAll(createPathItemObject(webServiceDefinition));
paths.put(webServiceDefinition.getPath(), pathItem);
} else {
paths.put(webServiceDefinition.getPath(), createPathItemObject(webServiceDefinition));
}
}
return paths;
}
Aggregations