use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ResponseBuilder method extractApiMethod.
@Override
public ApiMethod extractApiMethod(ApiMethod.HttpMethod httpMethod, String namespace, String resourceName) throws ApiException {
ApiMethod api = null;
String signature = this.buildApiSignature(httpMethod, namespace, resourceName);
try {
api = this.getApiCatalogManager().getMethod(httpMethod, namespace, resourceName);
if (null == api) {
ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
throw new ApiException(error);
}
if (!api.isActive()) {
ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
throw new ApiException(error);
}
} catch (ApiException ae) {
_logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), ae);
throw ae;
} catch (Throwable t) {
_logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), t);
throw new ApiException(IApiErrorCodes.SERVER_ERROR, signature + " is not supported", Response.Status.INTERNAL_SERVER_ERROR);
}
return api;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ResponseBuilder method invokePutPostMethod.
private Object invokePutPostMethod(ApiMethod api, Object bean, Properties parameters, Object bodyObject) throws NoSuchMethodException, InvocationTargetException, Throwable {
Object result = null;
Class beanClass = bean.getClass();
String methodName = api.getSpringBeanMethod();
try {
Class[] parameterTypes = new Class[] { bodyObject.getClass(), Properties.class };
Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
result = method.invoke(bean, bodyObject, parameters);
} catch (NoSuchMethodException e) {
// the first exception of type "NoSuchMethodException" will not catched... the second yes
Class[] parameterTypes = new Class[] { bodyObject.getClass() };
Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
result = method.invoke(bean, bodyObject);
} catch (InvocationTargetException e) {
throw e;
} catch (Throwable t) {
throw t;
}
return result;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ApiCatalogManager method getMethods.
@Deprecated
@Override
public Map<String, ApiMethod> getMethods() throws ApsSystemException {
Map<String, ApiMethod> map = new HashMap<>();
List<ApiMethod> list = this.getMethods(ApiMethod.HttpMethod.GET);
for (int i = 0; i < list.size(); i++) {
ApiMethod apiMethod = list.get(i);
map.put(apiMethod.getResourceName(), apiMethod);
}
return map;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ApiCatalogManager method saveService.
@Override
public void saveService(ApiService service) throws ApsSystemException {
try {
if (null == service) {
throw new ApsSystemException("Null api service to save");
}
ApiMethod master = service.getMaster();
if (null == master || null == this.getMethod(master.getHttpMethod(), master.getNamespace(), master.getResourceName())) {
throw new ApsSystemException("null or invalid master method of service to save");
}
if (null != this.getServiceCacheWrapper().getMasterServices().get(service.getKey())) {
this.getApiCatalogDAO().updateService(service);
} else {
this.getApiCatalogDAO().addService(service);
}
this.getServiceCacheWrapper().addService(service);
} catch (Throwable t) {
logger.error("Error saving service", t);
throw new ApsSystemException("Error saving service", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ApiResourcesDefDOM method getResources.
public Map<String, ApiResource> getResources() {
Map<String, ApiResource> apiResources = new HashMap<String, ApiResource>();
try {
List<Element> methodElements = this._doc.getRootElement().getChildren(METHOD_ELEMENT_NAME);
if (null != methodElements) {
for (int i = 0; i < methodElements.size(); i++) {
Element methodElement = methodElements.get(i);
ApiMethod apiMethod = new ApiMethod(methodElement);
ApiResource resource = new ApiResource();
resource.setResourceName(apiMethod.getResourceName());
resource.setNamespace(apiMethod.getNamespace());
resource.setDescription(apiMethod.getDescription());
resource.setPluginCode(apiMethod.getPluginCode());
resource.setSource(apiMethod.getSource());
resource.setMethod(apiMethod);
this.checkResource(resource, apiResources);
}
}
List<Element> resourceElements = this._doc.getRootElement().getChildren(RESOURCE_ELEMENT_NAME);
if (null != resourceElements) {
for (int j = 0; j < resourceElements.size(); j++) {
Element resourceElement = resourceElements.get(j);
String resourceName = resourceElement.getAttributeValue(RESOURCE_ATTRIBUTE_NAME);
String namespace = resourceElement.getAttributeValue(RESOURCE_ATTRIBUTE_NAMESPACE);
Element descriptionElement = resourceElement.getChild(RESOURCE_DESCRIPTION_ELEMENT_NAME);
String resourceDescription = (null != descriptionElement) ? descriptionElement.getText() : null;
Element sourceElement = resourceElement.getChild(ApiResourcesDefDOM.SOURCE_ELEMENT_NAME);
String source = null;
String pluginCode = null;
if (null != sourceElement) {
source = sourceElement.getText();
pluginCode = sourceElement.getAttributeValue(PLUGIN_CODE_ATTRIBUTE_NAME);
}
ApiResource resource = new ApiResource();
resource.setResourceName(resourceName);
resource.setNamespace(namespace);
resource.setDescription(resourceDescription);
resource.setPluginCode(pluginCode);
resource.setSource(source);
List<Element> resourceMethodElements = resourceElement.getChildren(METHOD_ELEMENT_NAME);
for (int k = 0; k < resourceMethodElements.size(); k++) {
Element methodElement = resourceMethodElements.get(k);
ApiMethod apiMethod = new ApiMethod(resourceName, namespace, source, pluginCode, methodElement);
this.checkMethod(apiMethod, resource);
}
this.checkResource(resource, apiResources);
}
}
} catch (Throwable t) {
_logger.error("Error building api resources", t);
}
return apiResources;
}
Aggregations