javax.servlet.jsp.el.ELException Java Examples

The following examples show how to use javax.servlet.jsp.el.ELException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpressionEvaluatorImpl.java    From Tomcat8-Source-Read with MIT License 7 votes vote down vote up
@Override
public Expression parseExpression(String expression,
        @SuppressWarnings("rawtypes") Class expectedType,
        FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx =
            new ELContextImpl(ELContextImpl.getDefaultResolver(factory));
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve, factory);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
 
Example #2
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public Object evaluate(VariableResolver vResolver) throws ELException {

            ELContext elContext;
            if (vResolver instanceof VariableResolverImpl) {
                elContext = pageContext.getELContext();
            }
            else {
                // The provided variable Resolver is a custom resolver,
                // wrap it with a ELResolver 
                elContext = new ELContextImpl(new ELResolverWrapper(vResolver));
            }
            try {
                return valueExpr.getValue(elContext);
            } catch (javax.el.ELException ex) {
                throw new ELException(ex);
            }
        }
 
Example #3
Source File: ExpressionEvaluatorImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Expression parseExpression(String expression,
        @SuppressWarnings("rawtypes") // API does not use generics
        Class expectedType,
        FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx =
            new ELContextImpl(ELContextImpl.getDefaultResolver());
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
 
Example #4
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public Expression parseExpression(String expression,
                                  Class expectedType,
                                  FunctionMapper fMapper )
        throws ELException {

    ExpressionFactory fac = ExpressionFactory.newInstance();
    javax.el.ValueExpression expr;
    ELContextImpl elContext = new ELContextImpl(null);
    javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper);
    elContext.setFunctionMapper(fm);
    try {
        expr = fac.createValueExpression(
                       elContext,
                       expression, expectedType);
    } catch (javax.el.ELException ex) {
        throw new ELException(ex);
    }
    return new ExpressionImpl(expr, pageContext);
}
 
Example #5
Source File: ExpressionEvaluatorImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Expression parseExpression(String expression,
        @SuppressWarnings("rawtypes") // API does not use generics
        Class expectedType,
        FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx =
            new ELContextImpl(ELContextImpl.getDefaultResolver());
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
 
Example #6
Source File: UpgraderAction.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private String evaluate (final Map<String, Object> configs, String expression) throws
    ELEvalException {
  try {
    CONFIGS_TL.set(configs);
    return (String) EVALUATOR.evaluate(
        expression,
        String.class,
        name -> null,
        (prefix, name) -> (prefix.equals("") && name.equals("value")) ? CONFIG_VALUE_FUNCTION : null
    );
  } catch (ELException e) {
    // Apache evaluator is not using the getCause exception chaining that is available in Java but rather a custom
    // chaining mechanism. This doesn't work well for us as we're effectively swallowing the cause that is not
    // available in log, ...
    Throwable t = e;
    if(e.getRootCause() != null) {
      t = e.getRootCause();
      if(e.getCause() == null) {
        e.initCause(t);
      }
    }
    LOG.debug(Errors.YAML_UPGRADER_12.getMessage(), getName(), expression, t.toString(), e);
    throw new ELEvalException(Errors.YAML_UPGRADER_12, getName(), expression, t.toString());
  } finally {
    CONFIGS_TL.remove();
  }
}
 
Example #7
Source File: JspContextWrapper.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * VariableResolver interface
 */
@Override
@Deprecated
public Object resolveVariable(String pName) throws ELException {
    ELContext ctx = this.getELContext();
    return ctx.getELResolver().getValue(ctx, null, pName);
}
 
Example #8
Source File: ELEvaluator.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T evaluate (final ELVars vars, String expression, Class<T> returnType) throws ELEvalException {
  VariableResolver variableResolver = new VariableResolver() {

    @Override
    public Object resolveVariable(String name) throws ELException {
      Object value = constants.get(name);
      if (!vars.hasVariable(name)) {
        if (value == null && !constants.containsKey(name)) {
          throw new ELException(Utils.format("Constants/Variable '{}' cannot be resolved", name));
        }
      } else {
        value = vars.getVariable(name);
      }
      return value;
    }
  };
  try {
    return (T) EVALUATOR.evaluate(expression, returnType, variableResolver, functionMapper);
  } catch (ELException e) {
    // Apache evaluator is not using the getCause exception chaining that is available in Java but rather a custom
    // chaining mechanism. This doesn't work well for us as we're effectively swallowing the cause that is not
    // available in log, ...
    Throwable t = e;
    if(e.getRootCause() != null) {
      t = e.getRootCause();
      if(e.getCause() == null) {
        e.initCause(t);
      }
    }
    LOG.debug("Error valuating EL '{}': {}", expression, e.toString(), e);
    throw new ELEvalException(ContainerCommonError.CTRCMN_0100, expression, t.toString(), e);
  }
}
 
Example #9
Source File: ELEvaluator.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public static void parseEL(String el) throws ELEvalException {
  try {
    EVALUATOR.parseExpressionString(el);
  } catch (ELException e) {
    LOG.debug("Error parsering EL '{}': {}", el, e.toString(), e);
    throw new ELEvalException(ContainerCommonError.CTRCMN_0101, el, e.toString(), e);
  }
}
 
Example #10
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public Object getValue(ELContext context,
                       Object base,
                       Object property)
        throws javax.el.ELException {
    if (base == null) {
        context.setPropertyResolved(true);
        try {
            return vResolver.resolveVariable(property.toString());
        } catch (ELException ex) {
            throw new javax.el.ELException(ex);
        }
    }
    return null;
}
 
Example #11
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public Object evaluate(String expression,
                        Class expectedType,
                        VariableResolver vResolver,
                        FunctionMapper fMapper )
            throws ELException {

    ELContextImpl elContext;
    if (vResolver instanceof VariableResolverImpl) {
        elContext = (ELContextImpl) pageContext.getELContext();
    }
    else {
        // The provided variable Resolver is a custom resolver,
        // wrap it with a ELResolver 
        elContext = new ELContextImpl(new ELResolverWrapper(vResolver));
    }

    javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper);
    elContext.setFunctionMapper(fm);
    ExpressionFactory fac = ExpressionFactory.newInstance();
    Object value;
    try {
        ValueExpression expr = fac.createValueExpression(
                             elContext,
                             expression,
                             expectedType);
        value = expr.getValue(elContext);
    } catch (javax.el.ELException ex) {
        throw new ELException(ex);
    }
    return value;
}
 
Example #12
Source File: ExpressionEvaluatorImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluate(String expression,
        @SuppressWarnings("rawtypes") // API does not use generics
        Class expectedType,
        VariableResolver vResolver, FunctionMapper fMapper)
        throws ELException {
    return this.parseExpression(expression, expectedType, fMapper).evaluate(vResolver);
}
 
Example #13
Source File: JspContextWrapper.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * VariableResolver interface
 */
@Override
@Deprecated
public Object resolveVariable(String pName) throws ELException {
    ELContext ctx = this.getELContext();
    return ctx.getELResolver().getValue(ctx, null, pName);
}
 
Example #14
Source File: ExpressionEvaluatorImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Object evaluate(String expression,
        @SuppressWarnings("rawtypes") Class expectedType,
        VariableResolver vResolver, FunctionMapper fMapper)
        throws ELException {
    return this.parseExpression(expression, expectedType, fMapper).evaluate(vResolver);
}
 
Example #15
Source File: ExpressionEvaluatorImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluate(String expression,
        @SuppressWarnings("rawtypes") // API does not use generics
        Class expectedType,
        VariableResolver vResolver, FunctionMapper fMapper)
        throws ELException {
    return this.parseExpression(expression, expectedType, fMapper).evaluate(vResolver);
}
 
Example #16
Source File: JspContextWrapper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * VariableResolver interface
 */
@Override
@Deprecated
public Object resolveVariable(String pName) throws ELException {
    ELContext ctx = this.getELContext();
    return ctx.getELResolver().getValue(ctx, null, pName);
}
 
Example #17
Source File: VariableResolverImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public Object resolveVariable(String pName) throws ELException {
    return this.ctx.getELResolver().getValue(this.ctx, null, pName);
}
 
Example #18
Source File: PageContextImpl.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void doHandlePageException(Throwable t) throws IOException,
        ServletException {

    if (errorPageURL != null && !errorPageURL.equals("")) {

        /*
         * Set request attributes. Do not set the
         * javax.servlet.error.exception attribute here (instead, set in the
         * generated servlet code for the error page) in order to prevent
         * the ErrorReportValve, which is invoked as part of forwarding the
         * request to the error page, from throwing it if the response has
         * not been committed (the response will have been committed if the
         * error page is a JSP page).
         */
        request.setAttribute(PageContext.EXCEPTION, t);
        request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,
                Integer.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
        request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
                ((HttpServletRequest) request).getRequestURI());
        request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
                config.getServletName());
        try {
            forward(errorPageURL);
        } catch (IllegalStateException ise) {
            include(errorPageURL);
        }

        // The error page could be inside an include.

        Object newException =
                request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);

        // t==null means the attribute was not set.
        if ((newException != null) && (newException == t)) {
            request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION);
        }

        // now clear the error code - to prevent double handling.
        request.removeAttribute(RequestDispatcher.ERROR_STATUS_CODE);
        request.removeAttribute(RequestDispatcher.ERROR_REQUEST_URI);
        request.removeAttribute(RequestDispatcher.ERROR_SERVLET_NAME);
        request.removeAttribute(PageContext.EXCEPTION);

    } else {
        // Otherwise throw the exception wrapped inside a ServletException.
        // Set the exception as the root cause in the ServletException
        // to get a stack trace for the real problem
        if (t instanceof IOException)
            throw (IOException) t;
        if (t instanceof ServletException)
            throw (ServletException) t;
        if (t instanceof RuntimeException)
            throw (RuntimeException) t;

        Throwable rootCause = null;
        if (t instanceof JspException) {
            rootCause = ((JspException) t).getCause();
        } else if (t instanceof ELException) {
            rootCause = ((ELException) t).getCause();
        }

        if (rootCause != null) {
            throw new ServletException(t.getClass().getName() + ": "
                    + t.getMessage(), rootCause);
        }

        throw new ServletException(t);
    }
}
 
Example #19
Source File: ExpressionImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public Object evaluate(VariableResolver vResolver) throws ELException {
    ELContext ctx =
            new ELContextImpl(new ELResolverImpl(vResolver, factory));
    return ve.getValue(ctx);
}
 
Example #20
Source File: ExpressionEvaluator.java    From Benchmark with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Expression parseExpression(String arg0, Class arg1, FunctionMapper arg2) throws ELException {
	return null;
}
 
Example #21
Source File: ExpressionEvaluator.java    From Benchmark with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object evaluate(String arg0, Class arg1, VariableResolver arg2, FunctionMapper arg3) throws ELException {
	return null;
}
 
Example #22
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isReadOnly(ELContext context,
                          Object base,
                          Object property)
        throws javax.el.ELException {
    return false;
}
 
Example #23
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public void setValue(ELContext context,
                     Object base,
                     Object property,
                     Object value)
        throws javax.el.ELException {
}
 
Example #24
Source File: ExpressionEvaluatorImpl.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public Class getType(ELContext context,
                     Object base,
                     Object property)
        throws javax.el.ELException {
    return null;
}
 
Example #25
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void doHandlePageException(Throwable t) throws IOException,
        ServletException {

    if (errorPageURL != null && !errorPageURL.equals("")) {

        /*
         * Set request attributes. Do not set the
         * javax.servlet.error.exception attribute here (instead, set in the
         * generated servlet code for the error page) in order to prevent
         * the ErrorReportValve, which is invoked as part of forwarding the
         * request to the error page, from throwing it if the response has
         * not been committed (the response will have been committed if the
         * error page is a JSP page).
         */
        request.setAttribute(PageContext.EXCEPTION, t);
        request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,
                Integer.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
        request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
                ((HttpServletRequest) request).getRequestURI());
        request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
                config.getServletName());
        try {
            forward(errorPageURL);
        } catch (IllegalStateException ise) {
            include(errorPageURL);
        }

        // The error page could be inside an include.

        Object newException =
                request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);

        // t==null means the attribute was not set.
        if ((newException != null) && (newException == t)) {
            request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION);
        }

        // now clear the error code - to prevent double handling.
        request.removeAttribute(RequestDispatcher.ERROR_STATUS_CODE);
        request.removeAttribute(RequestDispatcher.ERROR_REQUEST_URI);
        request.removeAttribute(RequestDispatcher.ERROR_SERVLET_NAME);
        request.removeAttribute(PageContext.EXCEPTION);

    } else {
        // Otherwise throw the exception wrapped inside a ServletException.
        // Set the exception as the root cause in the ServletException
        // to get a stack trace for the real problem
        if (t instanceof IOException)
            throw (IOException) t;
        if (t instanceof ServletException)
            throw (ServletException) t;
        if (t instanceof RuntimeException)
            throw (RuntimeException) t;

        Throwable rootCause = null;
        if (t instanceof JspException) {
            rootCause = ((JspException) t).getCause();
        } else if (t instanceof ELException) {
            rootCause = ((ELException) t).getCause();
        }

        if (rootCause != null) {
            throw new ServletException(t.getClass().getName() + ": "
                    + t.getMessage(), rootCause);
        }

        throw new ServletException(t);
    }
}
 
Example #26
Source File: VariableResolverImpl.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public Object resolveVariable(String pName) throws ELException {
    return this.ctx.getELResolver().getValue(this.ctx, null, pName);
}
 
Example #27
Source File: ExpressionImpl.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public Object evaluate(VariableResolver vResolver) throws ELException {
    ELContext ctx = new ELContextImpl(new ELResolverImpl(vResolver));
    return ve.getValue(ctx);
}
 
Example #28
Source File: ExpressionImpl.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public Object evaluate(VariableResolver vResolver) throws ELException {
    ELContext ctx = new ELContextImpl(new ELResolverImpl(vResolver));
    return ve.getValue(ctx);
}
 
Example #29
Source File: VariableResolverImpl.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public Object resolveVariable(String pName) throws ELException {
    return this.ctx.getELResolver().getValue(this.ctx, null, pName);
}