net.sf.aguacate.function.spi.impl.FunctionResponse Maven / Gradle / Ivy
package net.sf.aguacate.function.spi.impl;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.function.Parameter;
import net.sf.aguacate.function.spi.AbstractFunction;
import net.sf.aguacate.http.HttpBodyBuilerCoupling;
public class FunctionResponse extends AbstractFunction {
private final Parameter parameter;
public FunctionResponse(Collection methods, String name, Parameter parameter) {
super(methods, name);
this.parameter = parameter;
}
@Override
public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
try {
String parameterName = parameter.getName();
Object object = context.get(parameterName);
if (object == null) {
functionContext.response().setStatus(HttpServletResponse.SC_NOT_FOUND);
} else {
HttpBodyBuilerCoupling.defaultInstance().build(functionContext.response(), object,
functionContext.getOutputFields());
}
return new FunctionEvalResult(null, null);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy