public RedirectController(String uri) throws PragmatachException { try { this.uri = new URI(uri); } catch (final Exception e) { throw new PragmatachException(e); } }
public Response render() throws PragmatachException { try { final Map<String, String> parameters = new HashMap<String, String>(); parameters.put("message", exception.getMessage()); final String trace = PragmatachException.getExceptionTrace(exception); parameters.put("trace", trace); return template("system/error.html", parameters); } catch (final Exception e) { throw new PragmatachException("Exception in render", e); } } }
public InputStream getInputStream() throws PragmatachException { try { return httpServletRequest.getInputStream(); } catch (final Exception e) { throw new PragmatachException("Exception in getInputStream", e); } }
/** * get a PragmatachController instance */ public static PragmatachController getInstance(Class<?> clazz) throws PragmatachException { try { return (PragmatachController) clazz.newInstance(); } catch (final Exception e) { throw new PragmatachException("Exception in getInstance", e); } }
@Override public void render(HttpServletResponse httpServletResponse) throws PragmatachException { try { if (null != resourceInputStream) { IOUtils.copy(resourceInputStream, httpServletResponse.getOutputStream()); } } catch (final Exception e) { throw new PragmatachException("Exception in render", e); } } }
private static Object deserializeField(String json, Class<?> type) throws PragmatachException { try { final Gson gson = new Gson(); return gson.fromJson(json, type); } catch (final Exception e) { throw new PragmatachException("Exception in deserializeField", e); } }
private static String serializeField(Object object) throws PragmatachException { try { final Gson gson = new Gson(); return gson.toJson(object); } catch (final Exception e) { throw new PragmatachException("Exception in serializeField", e); } } }
/** * parse YAML to map */ @SuppressWarnings("unchecked") public static Map<String, String> parseYAML(String YAML) throws PragmatachException { try { final Yaml yaml = new Yaml(); return (Map<String, String>) yaml.load(YAML); } catch (final Exception e) { throw new PragmatachException("Exception in parseYAML", e); } }
public RedirectController(String uri, String[] parameters) throws PragmatachException { try { String completeURI = uri; if (null != parameters) { for (final String parameter : parameters) { completeURI += "/" + URLEncoder.encode(parameter, "UTF-8"); } } this.uri = new URI(completeURI); } catch (final Exception e) { throw new PragmatachException(e); } }
private String getTemplateAsString(InputStream templateInputStream) throws PragmatachException { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(templateInputStream, baos); return baos.toString("UTF-8"); } catch (final Exception e) { throw new PragmatachException("Exception in getTemplateAsString", e); } }
@Override public void render(HttpServletResponse httpServletResponse) throws PragmatachException { try { final Writer writer = new PrintWriter(httpServletResponse.getOutputStream()); template.process(context, writer); } catch (final Exception e) { throw new PragmatachException("Exception in render", e); } } }
@Override public void render(HttpServletResponse httpServletResponse) throws PragmatachException { try { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(json.getBytes()); IOUtils.copy(byteArrayInputStream, httpServletResponse.getOutputStream()); } catch (final Exception e) { throw new PragmatachException("Exception in render", e); } } }
/** * set a cookie */ public void setCookie(String name, String value) throws PragmatachException { try { final Cookie cookie = new Cookie(name, value); cookie.setMaxAge(SECONDS_PER_YEAR); cookie.setPath("/"); httpServletResponse.addCookie(cookie); } catch (final Exception e) { throw new PragmatachException("Exception in setCookie", e); } }
/** * resolve a string */ public static String resolveString(String value) throws PragmatachException { try { if (null != value) { if (value.startsWith(JAVA)) { final InitialContext initialContext = new InitialContext(); return (String) initialContext.lookup(value); } else { return value; } } else { return null; } } catch (final Exception e) { throw new PragmatachException("Exception in resolveString: '" + value + "'", e); } }
@Override public void render(HttpServletResponse httpServletResponse) throws PragmatachException { try { if (null != response) { final PrintWriter printWriter = new PrintWriter(httpServletResponse.getOutputStream()); printWriter.write(response); printWriter.flush(); printWriter.close(); } } catch (final Exception e) { throw new PragmatachException("Exception in render", e); } } }
private Hashtable<String, String> findJavaProperties() throws PragmatachException { try { final Hashtable<String, String> ret = new Hashtable<String, String>(); final Properties props = System.getProperties(); final Enumeration<Object> enumer = props.keys(); while (enumer.hasMoreElements()) { final String key = (String) enumer.nextElement(); ret.put(key, props.getProperty(key)); } return ret; } catch (final Exception e) { throw new PragmatachException("Exception in findJavaProperties", e); } }
/** * resolve an object */ public static Object resolveObject(String value) throws PragmatachException { try { if (null != value) { if (value.startsWith(JAVA)) { final InitialContext initialContext = new InitialContext(); return initialContext.lookup(value); } else { return value; } } else { return null; } } catch (final Exception e) { throw new PragmatachException("Exception in resolveObject: '" + value + "'", e); } }
@Override public void render(HttpServletResponse httpServletResponse) throws PragmatachException { try { streamingController.render(inputStream, httpServletResponse.getOutputStream()); } catch (final Exception e) { throw new PragmatachException("Exception in render", e); } } }
/** * get the HTTP POST body */ public String getPostBody() throws PragmatachException { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(getInputStream(), baos); return baos.toString("UTF-8"); } catch (final Exception e) { throw new PragmatachException("Exception in getRequestBody", e); } }
public static String serialize(PragmatachController pragmatachController) throws PragmatachException { try { final JSONObject jSONObject = new JSONObject(); for (final Field field : pragmatachController.getClass().getDeclaredFields()) { final String fieldValue = serializeField(PropertyUtils.getProperty(pragmatachController, field.getName())); jSONObject.put(field.getName(), fieldValue); } return jSONObject.toString(); } catch (final Exception e) { throw new PragmatachException("Exception in serialize", e); } }