System.out.println(" reference = " + mie.getReferenceName() ); System.out.println(" method = " + mie.getMethodName() ); Throwable t = mie.getWrappedThrowable(); System.out.println(" throwable = " + t ); System.out.println(" reference = " + mie.getReferenceName() ); System.out.println(" method = " + mie.getMethodName() ); Throwable t = mie.getWrappedThrowable(); System.out.println(" throwable = " + t ); System.out.println(" reference = " + mie.getReferenceName() ); System.out.println(" method = " + mie.getMethodName() ); Throwable t = mie.getWrappedThrowable(); System.out.println(" throwable = " + t ); System.out.println(" reference = " + mie.getReferenceName() ); System.out.println(" method = " + mie.getMethodName() ); Throwable t = mie.getWrappedThrowable(); System.out.println(" throwable = " + t );
/** * Merge the template with the context. * Can be overridden to customize the behavior. * @param template the template to merge * @param context the Velocity context to use for rendering * @param response servlet response (use this to get the OutputStream or Writer) * @throws Exception if thrown by Velocity * @see Template#merge */ protected void mergeTemplate( Template template, Context context, HttpServletResponse response) throws Exception { try { template.merge(context, response.getWriter()); } catch (MethodInvocationException ex) { Throwable cause = ex.getWrappedThrowable(); throw new NestedServletException( "Method invocation failed during rendering of Velocity view with name '" + getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() + "], method '" + ex.getMethodName() + "'", cause==null ? ex : cause); } }
protected String merge(Template template, VelocityContext context) { if (template == null) { return ""; } StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (ResourceNotFoundException e) { e.printStackTrace(); } catch (ParseErrorException e) { e.printStackTrace(); } catch (MethodInvocationException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } String ret = writer.toString(); writer.flush(); return ret; }
/** * Merge the template with the context. Can be overridden to customize the behavior. * * @param template the template to merge * @param context the Velocity context to use for rendering * @param response servlet response (use this to get the OutputStream or Writer) * @throws Exception if thrown by Velocity * @see org.apache.velocity.Template#merge */ protected void mergeTemplate( Template template, Context context, HttpServletResponse response) throws Exception { try { response.setCharacterEncoding(Config.DEFAULT_ENCODING); template.merge(context, response.getWriter()); } catch (MethodInvocationException ex) { Throwable cause = ex.getCause(); throw new NestedServletException( "Method invocation failed during rendering of Velocity view with name '" + getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() + "], method '" + ex.getMethodName() + "'", cause == null ? ex : cause); } } }
public void printStackTrace(PrintWriter s) { super.printStackTrace(s); if (exception != null) { s.write("\n\nWrapped Exception:\n\n"); if (exception.getCause()!=null) exception.getCause().printStackTrace(s); else if (exception instanceof org.hibernate.JDBCException) { (((JDBCException) exception).getSQLException()).printStackTrace(s); } else if (exception instanceof MethodInvocationException) { (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s); } else if (exception instanceof ServletException) { (((ServletException) exception).getRootCause()).printStackTrace(s); } else { exception.printStackTrace(s); } } }
throw new MethodInvocationException( "Invocation of method 'get(\"" + args[0] + "\")'" + " in " + o.getClass()
public String evaluate(Map<String, Object> context, TemplatePack templatePack, Template template) throws IOException { StringWriter sw = new StringWriter(); try { engine.evaluate(new VelocityContext(context), sw, template.getName(), template.getTemplate()); return sw.toString(); } catch (ParseErrorException parseException) { handleStopFileGeneration(parseException); log.error("In " + templatePack.getName() + ":" + template.getName() + " template, parse exception " + parseException.getMessage(), parseException.getCause()); displayLinesInError(parseException, templatePack, template); throw new IllegalStateException(); } catch (MethodInvocationException mie) { handleStopFileGeneration(mie); log.error("In " + templatePack.getName() + ":" + mie.getTemplateName() + " method [" + mie.getMethodName() + "] has not been set", mie.getCause()); displayLinesInError(mie, templatePack, template); throw mie; } finally { closeQuietly(sw); } }
rsvc.error("Method " + mie.getMethodName() + " threw exception for reference $" + rootString + this.getColumn() + "]"); mie.setReferenceName(rootString); throw mie;
logger.error(e.toString()); } catch (MethodInvocationException e) { logger.error(e.getMessage()); } catch (FileNotFoundException e) { logger.error(e.toString());
mie.setReferenceName(rootString); throw mie;
public void printStackTrace(PrintStream s) { super.printStackTrace(s); if (exception != null) { s.print("\n\nWrapped Exception:\n\n"); if (exception.getCause()!=null) exception.getCause().printStackTrace(s); else if (exception instanceof org.hibernate.JDBCException) { (((JDBCException) exception).getSQLException()).printStackTrace(s); } else if (exception instanceof MethodInvocationException) { (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s); } else if (exception instanceof ServletException) { (((ServletException) exception).getRootCause()).printStackTrace(s); } else { exception.printStackTrace(s); } } }
throw new MethodInvocationException( "Invocation of method '" + methodName + "' in " + o.getClass() throw new MethodInvocationException( "Invocation of method '" + methodName + "' in " + o.getClass()
public String evaluate(Map<String, Object> context, TemplatePack templatePack, Template template) throws IOException { StringWriter sw = new StringWriter(); try { engine.evaluate(new VelocityContext(context), sw, template.getName(), template.getTemplate()); return sw.toString(); } catch (ParseErrorException parseException) { handleStopFileGeneration(parseException); log.error("In " + templatePack.getName() + ":" + template.getName() + " template, parse exception " + parseException.getMessage(), parseException.getCause()); displayLinesInError(parseException, templatePack, template); throw new IllegalStateException(); } catch (MethodInvocationException mie) { handleStopFileGeneration(mie); log.error("In " + templatePack.getName() + ":" + mie.getTemplateName() + " method [" + mie.getMethodName() + "] has not been set", mie.getCause()); displayLinesInError(mie, templatePack, template); throw mie; } finally { closeQuietly(sw); } }
public String generateMail( String templateName, AuthenticationKey authkey, String baseUrl ) { VelocityContext context = createVelocityContext( authkey, baseUrl ); String packageName = getClass().getPackage().getName().replace( '.', '/' ); String templateFile = packageName + "/template/" + templateName + ".vm"; StringWriter writer = new StringWriter(); try { velocity.getEngine().mergeTemplate( templateFile, context, writer ); } catch ( ResourceNotFoundException e ) { getLogger().error( "No such template: '" + templateFile + "'." ); } catch ( ParseErrorException e ) { getLogger().error( "Unable to generate email for template '" + templateFile + "': " + e.getMessage(), e ); } catch ( MethodInvocationException e ) { getLogger().error( "Unable to generate email for template '" + templateFile + "': " + e.getMessage(), e ); } catch ( Exception e ) { getLogger().error( "Unable to generate email for template '" + templateFile + "': " + e.getMessage(), e ); } return writer.getBuffer().toString(); }
mie.setReferenceName(rootString); throw mie;
throw e; } catch(MethodInvocationException e) { throw new BuildException("Exception thrown by '" + e.getReferenceName() + "." + e.getMethodName() +"'", e.getWrappedThrowable()); } catch(ParseErrorException e) { throw new BuildException("Velocity syntax error", e);
/** * Merge the template with the context. * Can be overridden to customize the behavior. * @param template the template to merge * @param context the Velocity context to use for rendering * @param response servlet response (use this to get the OutputStream or Writer) * @throws Exception if thrown by Velocity * @see Template#merge */ protected void mergeTemplate( Template template, Context context, HttpServletResponse response) throws Exception { try { template.merge(context, response.getWriter()); } catch (MethodInvocationException ex) { Throwable cause = ex.getWrappedThrowable(); throw new NestedServletException( "Method invocation failed during rendering of Velocity view with name '" + getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() + "], method '" + ex.getMethodName() + "'", cause==null ? ex : cause); } }
private void exceptionHandling(final Writer writer, Exception e, final String templateDirectory, String template) throws IOException { if (e instanceof ResourceNotFoundException) { log.error("ResourceNotFoundException occurred whilst loading resource " + template); URL templateUrl = ClassLoaderUtils.getResource(templateDirectory + template, this.getClass()); if (templateUrl == null) { throw new VelocityException("Could not find template '" + templateDirectory + template + "' ensure it is in the classpath."); } writer.write("Could not locate resource " + templateDirectory + template); } else if (e instanceof MethodInvocationException) { Throwable t = ((MethodInvocationException) e).getWrappedThrowable(); log.error("MethodInvocationException occurred getting message body from Velocity: " + t, t); writer.write(getErrorMessageForException(e)); } else { log.error("Exception getting message body from Velocity: " + e, e); writer.write(getErrorMessageForException(e)); } }
throw new MethodInvocationException( "Invocation of method '" + methodName + "' in " + o.getClass() throw new MethodInvocationException( "Invocation of method '" + methodName + "' in " + o.getClass()
@Test public void testEvaluateStrict() { String template = "${baz}"; Map<String, Object> variables = new HashMap<>(); variables.put("foo", "bar"); String logTag = "test"; try { velocityNonStrictHelper.evaluate(template, variables, logTag); fail(); } catch (MethodInvocationException methodInvocationException) { Assert.assertEquals("Exception message not equal.", "Variable $baz has not been set at test[line 1, column 1]", methodInvocationException.getMessage()); } }