use of io.vertigo.vega.webservice.WebServices in project vertigo by KleeGroup.
the class WebServiceManagerImpl method scanComponents.
/**
* Scan WebServices as WebServiceDefinitions on all the components.
* @param componentSpace ComponentSpace
* @return Scanned webServiceDefinitions
*/
List<WebServiceDefinition> scanComponents(final ComponentSpace componentSpace) {
final AopPlugin aopPlugin = Home.getApp().getConfig().getBootConfig().getAopPlugin();
final ListBuilder<WebServiceDefinition> allWebServiceDefinitionListBuilder = new ListBuilder<>();
// 1- We introspect all RestfulService class
for (final String componentId : componentSpace.keySet()) {
final Object component = componentSpace.resolve(componentId, Object.class);
if (component instanceof WebServices) {
final WebServices webServices = aopPlugin.unwrap(WebServices.class.cast(component));
final List<WebServiceDefinition> webServiceDefinitions = webServiceScannerPlugin.scanWebService(webServices.getClass());
allWebServiceDefinitionListBuilder.addAll(webServiceDefinitions);
}
}
// 2- We sort by path, parameterized path should be after strict path
return allWebServiceDefinitionListBuilder.sort(Comparator.comparing(WebServiceDefinition::getName)).unmodifiable().build();
}
use of io.vertigo.vega.webservice.WebServices 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;
}
}
Aggregations