tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Najeed Ahmed Khan" <nak...@interwoven.com>
Subject javax.el.ELContext.getFunctionMapper().resolveFunction() returns null always
Date Tue, 17 Feb 2009 21:33:11 GMT
Hi,

 

I'm developing an application to parse EL expressions from a file and
evaluate them. I am using Java Unified EL for the same. The value
expressions are resolving fine however the  functions are not. I'm using
Tomcat 6.0.10 which is bundled with JBoss 4.2.3. I've posted this query
to the Tomcat user mailing list earlier but it is related to the Tomcat
source so I'm it posting here as I didn't receive any response from the
user forums.

 

The way I am evaluating the expression is:

 

final MethodExpression methodExpr =

exprFactory.createMethodExpression(jspContext.getELContext(), el,
expectedType, paramTypes);

Object result = methodExpr.invoke(jspContext.getELContext(), params);

 

 

However, the function is not being invoked and I get a stack trace like
such:

 

2009-02-12 22:35:13,629 [http-0.0.0.0-8080-5] ERROR STDERR () -
javax.el.ELException: Function 'testtld:escapeJava' not found

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
org.apache.el.lang.ExpressionBuilder.visit(ExpressionBuilder.java:171)

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
org.apache.el.parser.SimpleNode.accept(SimpleNode.java:129)

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
org.apache.el.lang.ExpressionBuilder.prepare(ExpressionBuilder.java:133)

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:147)

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
org.apache.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBu
ilder.java:197)

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
org.apache.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFac
toryImpl.java:57)

2009-02-12 22:35:13,630 [http-0.0.0.0-8080-5] ERROR STDERR () -     at
test.util.ELExpressionEvaluator.evaluate(ELExpressionEvaluator.java:120)

 

 

The jsp page that I am using to obtain the ELContext has the taglib
directive to include that particular tld. If I invoke that JSP function
from a JSP page(using EL), it works fine. However, when I try to resolve
the function programmatically as above, I get the above error.

 

 

When I checked the Tomcat source code, I noticed in
org.apache.jasper.el.ELContextImpl :

 

private final static FunctionMapper NullFunctionMapper = new
FunctionMapper() {

        public Method resolveFunction(String prefix, String localName) {

            return null;

        }

    };

 

 

And a few lines below that,

 

private FunctionMapper functionMapper = NullFunctionMapper; // immutable

 

Although there is a 

 

    public void setFunctionMapper(FunctionMapper functionMapper) {

        this.functionMapper = functionMapper;

    }

 

 

I am not sure whether that is invoked or how to have it invoked.

 

This could be the problem for me as the
ELContext.getFunctionMapper().resolveFunction(...) would return null and
I receive a message which corresponds to the Method object resolving to
null. From org.apache.el.lang.ExpressionBuilder.visit, the code
generating the exception:

 

Method m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode

                    .getLocalName());

if (m == null) {

        throw new ELException(MessageFactory.get(

               "error.fnMapper.method", funcNode.getOutputName()));

}

 

 

When I check the generated servlet for the jsp that contains the same
EL, I see:

 

static private org.apache.jasper.runtime.ProtectedFunctionMapper
_jspx_fnmap_0;

 

static {

  _jspx_fnmap_0=
org.apache.jasper.runtime.ProtectedFunctionMapper.getMapForFunction("tes
ttld:escapeJava", org.apache.commons.lang.StringEscapeUtils.class,
"escapeJava", new Class[] {java.lang.String.class});

}

 

And

 

_jspx_th_c_005fset_005f0.setValue(new
org.apache.jasper.el.JspValueExpression("/test/scratchPad.jsp(7,0)
'${testtld:escapeJava(\"Test
String\")}'",_el_expressionfactory.createValueExpression(new
org.apache.jasper.el.ELContextWrapper(_jspx_page_context.getELContext(),
_jspx_fnmap_0),"${testtld:escapeJava(\"Test
String\")}",java.lang.Object.class)).getValue(_jspx_page_context.getELCo
ntext()));

 

But if I put the following test code within the same jsp in a scriptlet,
I see the exception above(javax.el.ELException: Function
'testtld:escapeJava' not found):

 

<%

    JspApplicationContext jspAppCtx =
JspFactory.getDefaultFactory().getJspApplicationContext(pageContext.getS
ervletContext());

    ExpressionFactory exprFactory = jspAppCtx.getExpressionFactory();

    ELContext elCtx = pageContext.getELContext();

    Class[] klass = {String.class};

    String[] param = {"Test String"};

    MethodExpression methodExpr =

        exprFactory.createMethodExpression(elCtx,
"${testtld:escapeJava('Test String')}", String.class, klass);

    String result = methodExpr.invoke(elCtx, param).toString();

    out.println(result);

%>

 

I searched over the internet and did not come up with anything
related/conclusive that could point me towards a configuration or
programmatic step that I could've missed.

 

I'd appreciate it if you could give me some pointers as to what might be
the problem here and how to fix it. Also, I do not understand why the
org.apache.jasper.el package is being used for the ELContext and other
implementations instead of the org.apache.el package which has the newer
implementation.

 

Thanks,

Najeed.

 

 

 

 

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message