LuciadFusion Platform is the server-side component of the LuciadFusion Studio web application. It is a Spring based application and as such, you can use the Spring framework to plug in your own custom service endpoints.

Your custom service endpoints have no direct access to the database used by LuciadFusion Studio. The only way to access the information from LuciadFusion Studio is through the LuciadFusion Studio REST API.

This article describes how to add a custom REST service to the LuciadFusion Platform. This is demonstrated in the samples.fusion.platform.service sample by adding a 'hello world' service. This sample shows which steps are needed to add a service. The following steps are required:

  1. Create a custom (REST) controller. The controller added in the sample is a simple Spring REST controller that returns a Hello world response for a GET request, or a Hello <name> response for a GET request with a parameter. See Program: Custom hello world REST controller for an example controller.

  2. Enable access to controller endpoints. Spring Security blocks access to all endpoints by default, we must therefore register a SecurityFilterChain which permits access to our new controller’s endpoints. See Program: Custom hello world security configuration for an example SecurityFilterChain configuration.

  3. Make sure that the application can find the controller and security configuration. To find the new controller and security configuration, we need to tell the Spring framework where to look for it. The LuciadFusion Platform allows you to specify additional packages that should be scanned by the Spring framework using the fusion.config.additionalScanPackages configuration property. See config/fusion.common.yml for more information on how to use this configuration property. The result is that you can run the LuciadFusion Platform main class, TLfnFusionPlatformApplication, with this extra property value. All Spring components/services in that additional package (or imported by a class in that new package) are also picked up by the LuciadFusion Platform framework.

Program: Custom hello world REST controller (from samples/fusion/platform/service/controller/HelloWorldController)
/**
 * A Simple Hello World Controller.
 * Exposed endpoints: /hello and /hello/{name}
 */
@Controller
@RequestMapping(path = "/hello")
public class HelloWorldController {

  @GetMapping
  public @ResponseBody String helloWorld() {
    return "Hello World";
  }

  @GetMapping(path = "{name}")
  public @ResponseBody String hello(@PathVariable("name") String name) {
    return "Hello " + name;
  }
}
Program: Custom hello world security configuration (from samples/fusion/platform/service/controller/HelloWorldConfiguration)
@Configuration
public class HelloWorldConfiguration {

  /**
   * SecurityFilterChain which permits access to the HelloWorldController endpoints: /hello and /hello/{name}
   */
  @Bean
  @Order(Ordered.HIGHEST_PRECEDENCE)
  public SecurityFilterChain helloWorldFilter(HttpSecurity aHttpSecurity) throws Exception {
    return aHttpSecurity
        // make sure to only apply this SecurityFilterChain to url patterns /hello and /hello/*
        // so as not to override the LuciadFusion SecurityFilterChains
        .securityMatcher("/hello", "/hello/*")
        // permits all access (authenticated and anonymous) to the /hello and /hello/* endpoints
        .authorizeHttpRequests(authorizedRequests -> authorizedRequests.requestMatchers("/hello", "/hello/*")
                                                                       .permitAll())
        .build();
  }

}

Adding a custom service type to LuciadFusion is discussed in the Example: adding a custom service using height data article.