Registering Pebble Extensions with Java

I am attempting to register pebble extensions, but I dont think I am able to in Java.

Here is a portion of Engine.java

public class Engine {

   public static void main(String[] args) {
      GatlingPropertiesBuilder props = new GatlingPropertiesBuilder()
 
   List<Extension> extensions = List.of(
        new CustomExtensions()
   );
   
   PebbleExtensions.register(extensions);

   Gatling.fromMap(props.build());
   }
}

Here is a custom extensions class

public class CustomExtensions extends AbstractExtension {

   public CustomExtensions(){
   }

   @Override
    public Map<String, Filter> getFilters(){
	   Map<String, Filter> filters = new HashMap<>();
	   filters.put("OrNull", new OrNull());
	   return filters;
    }
}

We just converted the project from Scala to Java, I really hope we dont need to go back. I do believe we need Pebble templates for Gatling to be efficient for us, and extensions would go a long way in helping use Pebble templates effectively.

You’re not registering Pebble extensions the correct way.

You’re not supposed to use PebbleExtensions directly, it’s a Gatling internal. Its visibility is private[gatling].

Instead, you’re supposed to use registerPebbleExtensions directly in your Simulation, as described in the documentation.

I looked for that method but was unable to find it initially. That launched me down a rabbit hole. Your response made me dig again and I was able to find it at

import static io.gatling.javaapi.core.CoreDsl.registerPebbleExtensions;

Thank you

As (poorly?) explained in the documentation for your first scenario, there are several required imports.

For java:

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

(Yes, even with the empty line, the four imports are mandatory in all your java file that use Gatling DSL)

Cheers

Ah theres the disconnect. Since I am registering the Custom Extensions in the Engine class, I didnt even think of adding those imports.

Really, you’re not supposed to do it in Engine but in your Simulations.
And your not supposed to use the Engine class for anything than launching manually from your IDE.

I can understand the logic of registering extensions in simulations, as that allows various combinations of extensions to be available as needed.

Engine just seemed a convenient place to make it available to all simulations.