Search in sources :

Example 6 with WebServiceDefinition

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);
}
Also used : WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition) WebServiceParam(io.vertigo.vega.webservice.metamodel.WebServiceParam) ValidationUserException(io.vertigo.vega.webservice.validation.ValidationUserException) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) UiObject(io.vertigo.vega.webservice.model.UiObject) UiMessageStack(io.vertigo.vega.webservice.validation.UiMessageStack)

Example 7 with WebServiceDefinition

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);
        }
    });
}
Also used : WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition) SessionException(io.vertigo.vega.webservice.exception.SessionException)

Example 8 with WebServiceDefinition

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);
    }
}
Also used : WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition)

Example 9 with WebServiceDefinition

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;
}
Also used : WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WebServiceParam(io.vertigo.vega.webservice.metamodel.WebServiceParam) ArrayList(java.util.ArrayList)

Example 10 with WebServiceDefinition

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;
}
Also used : WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition) DtObject(io.vertigo.dynamo.domain.model.DtObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

WebServiceDefinition (io.vertigo.vega.webservice.metamodel.WebServiceDefinition)10 WebServiceParam (io.vertigo.vega.webservice.metamodel.WebServiceParam)4 DtObject (io.vertigo.dynamo.domain.model.DtObject)3 WebServices (io.vertigo.vega.webservice.WebServices)3 SessionException (io.vertigo.vega.webservice.exception.SessionException)3 ValidationUserException (io.vertigo.vega.webservice.validation.ValidationUserException)3 DtListState (io.vertigo.dynamo.domain.model.DtListState)2 VUserException (io.vertigo.lang.VUserException)2 VSecurityException (io.vertigo.vega.webservice.exception.VSecurityException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Home (io.vertigo.app.Home)1 AopPlugin (io.vertigo.core.component.AopPlugin)1 DtList (io.vertigo.dynamo.domain.model.DtList)1 WebServiceDefinitionModelTs (io.vertigo.studio.plugins.mda.webservice.model.WebServiceDefinitionModelTs)1 WebServiceInitializerModelTs (io.vertigo.studio.plugins.mda.webservice.model.WebServiceInitializerModelTs)1 ClassUtil (io.vertigo.util.ClassUtil)1 ListBuilder (io.vertigo.util.ListBuilder)1