This repository has been archived on 2021-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java

34 lines
703 B
Java

package org.gcube.application.geoportal.service.rest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class GuardedMethod<T> {
private T result=null;
public GuardedMethod<T> execute() throws WebApplicationException{
try {
result=run();
return this;
}catch(WebApplicationException e) {
throw e;
}catch(Throwable t) {
log.error("Unexpected error ",t);
throw new WebApplicationException("Unexpected internal error", t,Status.INTERNAL_SERVER_ERROR);
}
}
public T getResult() {
return result;
}
protected abstract T run() throws Exception,WebApplicationException;
}