Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda