Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
How to invoke Java function multiple times from inline Javascript Expression using ScriptEngine

I am evaluating an inline Javascript Expression using Java 8's ScriptEngine.

Example Expression

(_tranxAmount > 100) && (profile.received('daily', 'avg', false) < 100)

Where profile is a global scope bind Java class object and received() is its local function. I successfully evaluated this expression using scriptingEngine.eval(script) and it is calling profile.received('daily', 'avg', false) I mean to say functionsManager.received('daily', 'avg', false) as well.

The Scripting engine failed to evaluate JavaScript expression if it contains more than one Java function. In that case, only the first Java function gest called. How to resolve this issue?

For example

(_tranxAmount > 100) && (profile.received('daily', 'avg', false) < 100) && (profile.sent('monthly', 'count', false) < 5)

Script Engine:

private static ScriptEngine scriptingEngine;

Inside constructor of main class

scriptingEngine = new ScriptEngineManager().getEngineByName("JavaScript");
scriptingEngine.getBindings(ScriptContext.GLOBAL_SCOPE).put(PROFILING_FUNCTIONS_PREFIX, functionsManager);

Evaluating Expression

Bindings bindings = new SimpleBindings(customMapOfVaraibles);
CompiledScript compiled = ((Compilable) scriptingEngine).compile(" (_tranxAmount > 100) && (profile.received('daily', 'avg', false) < 100) && (profile.sent('monthly', 'count', false) < 5)");
compiled .eval(bindings)

functionsManager's methods look like this

public BigDecimal received(String intervalType, String statisticsType, boolean considerTranxType)
            throws InvalidRequirementsException {
   //Do calculations
   return calculatedValue;
}

public BigDecimal sent(String intervalType, String statisticsType, boolean considerTranxType)
            throws InvalidRequirementsException {
   //Do calculations
   return calculatedValue;
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda