Search in sources :

Example 1 with ValidationUserException

use of io.vertigo.vega.webservice.validation.ValidationUserException in project vertigo by KleeGroup.

the class RestfulServiceWebServiceHandlerPlugin 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 Object[] serviceArgs = makeArgs(routeContext);
    final Method method = webServiceDefinition.getMethod();
    final WebServices webServices = (WebServices) Home.getApp().getComponentSpace().resolve(method.getDeclaringClass());
    if (method.getName().startsWith("create")) {
        // by convention, if method starts with 'create', an http 201 status code is returned (if ok)
        response.status(HttpServletResponse.SC_CREATED);
    }
    try {
        return ClassUtil.invoke(webServices, method, serviceArgs);
    } catch (final RuntimeException e) {
        // If throwed exception was ValidationUserException, VUserException, SessionException, VSecurityException, RuntimeException
        // we re throw it
        final Throwable cause = e.getCause();
        if (cause instanceof InvocationTargetException) {
            final Throwable targetException = ((InvocationTargetException) cause).getTargetException();
            if (targetException instanceof ValidationUserException) {
                throw (ValidationUserException) targetException;
            } else if (targetException instanceof VUserException) {
                throw (VUserException) targetException;
            } else if (targetException instanceof SessionException) {
                throw (SessionException) targetException;
            } else if (targetException instanceof VSecurityException) {
                throw (VSecurityException) targetException;
            } else if (targetException instanceof RuntimeException) {
                throw (RuntimeException) targetException;
            }
        }
        throw e;
    }
}
Also used : WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition) ValidationUserException(io.vertigo.vega.webservice.validation.ValidationUserException) WebServices(io.vertigo.vega.webservice.WebServices) SessionException(io.vertigo.vega.webservice.exception.SessionException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) VSecurityException(io.vertigo.vega.webservice.exception.VSecurityException) VUserException(io.vertigo.lang.VUserException)

Example 2 with ValidationUserException

use of io.vertigo.vega.webservice.validation.ValidationUserException 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)

Aggregations

WebServiceDefinition (io.vertigo.vega.webservice.metamodel.WebServiceDefinition)2 ValidationUserException (io.vertigo.vega.webservice.validation.ValidationUserException)2 DtObject (io.vertigo.dynamo.domain.model.DtObject)1 VUserException (io.vertigo.lang.VUserException)1 WebServices (io.vertigo.vega.webservice.WebServices)1 SessionException (io.vertigo.vega.webservice.exception.SessionException)1 VSecurityException (io.vertigo.vega.webservice.exception.VSecurityException)1 WebServiceParam (io.vertigo.vega.webservice.metamodel.WebServiceParam)1 ExtendedObject (io.vertigo.vega.webservice.model.ExtendedObject)1 UiObject (io.vertigo.vega.webservice.model.UiObject)1 UiMessageStack (io.vertigo.vega.webservice.validation.UiMessageStack)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1