diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2016-04-09 14:22:20 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2016-04-09 15:48:01 -0700 |
commit | 3102d8bce3426d9cf41aeaf201c360d342677770 (patch) | |
tree | 38c4f1e8828f9af9c4b77a173bee0d312b321698 /src/com/p4square/fmfacade/ftl/GetMethod.java | |
parent | bbf907e51dfcf157bdee24dead1d531122aa25db (diff) |
Switching from Ivy+Ant to Maven.
Diffstat (limited to 'src/com/p4square/fmfacade/ftl/GetMethod.java')
-rw-r--r-- | src/com/p4square/fmfacade/ftl/GetMethod.java | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/src/com/p4square/fmfacade/ftl/GetMethod.java b/src/com/p4square/fmfacade/ftl/GetMethod.java deleted file mode 100644 index a47c4b0..0000000 --- a/src/com/p4square/fmfacade/ftl/GetMethod.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2013 Jesse Morgan - */ - -package com.p4square.fmfacade.ftl; - -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import java.io.IOException; - -import freemarker.core.Environment; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateMethodModel; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; - -import org.apache.log4j.Logger; - -import org.restlet.data.Status; -import org.restlet.data.Method; -import org.restlet.representation.Representation; -import org.restlet.Request; -import org.restlet.Response; -import org.restlet.Restlet; - -import org.restlet.ext.jackson.JacksonRepresentation; - -/** - * This method allows templates to make GET requests. - * - * @author Jesse Morgan <jesse@jesterpm.net> - */ -public class GetMethod implements TemplateMethodModel { - private static final Logger cLog = Logger.getLogger(GetMethod.class); - - private final Restlet mDispatcher; - - public GetMethod(Restlet dispatcher) { - mDispatcher = dispatcher; - } - - /** - * @param args List with exactly two arguments: - * * The variable in which to put the result. - * * The URI to GET. - */ - public TemplateModel exec(List args) throws TemplateModelException { - final Environment env = Environment.getCurrentEnvironment(); - - if (args.size() != 2) { - throw new TemplateModelException( - "Expecting exactly one argument containing the URI"); - } - - Request request = new Request(Method.GET, (String) args.get(1)); - Response response = mDispatcher.handle(request); - Status status = response.getStatus(); - Representation representation = response.getEntity(); - - try { - if (response.getStatus().isSuccess()) { - JacksonRepresentation<Map> mapRepresentation; - if (representation instanceof JacksonRepresentation) { - mapRepresentation = (JacksonRepresentation<Map>) representation; - } else { - mapRepresentation = new JacksonRepresentation<Map>( - representation, Map.class); - } - try { - TemplateModel mapModel = env.getObjectWrapper().wrap(mapRepresentation.getObject()); - - env.setVariable((String) args.get(0), mapModel); - - } catch (IOException e) { - cLog.warn("Exception occurred when calling getObject(): " - + e.getMessage(), e); - status = Status.SERVER_ERROR_INTERNAL; - } - } - - Map statusMap = new HashMap(); - statusMap.put("code", status.getCode()); - statusMap.put("reason", status.getReasonPhrase()); - statusMap.put("succeeded", status.isSuccess()); - return env.getObjectWrapper().wrap(statusMap); - } finally { - if (representation != null) { - representation.release(); - } - } - } -} |