Headless access

This section tackles the topic of enabling access to an Apache Causeway application directly, or at least, not through either the Wicket or Restful viewers.

There are a number of use-cases:

  • implementing a REST end point that needs to reach into the Apache Causeway runtime

    • this could be a custom UI

    • this could be to integrate from other systems, eg a subscriber on a pub/sub event bus, pushing changes through an Apache Causeway domain model.

  • calling from Quartz for a background batch process

Note that the calling thread runs in the same process space as the Apache Causeway domain object model (must be physically linked to the JAR files containing the domain classes).

The SimpleApp starter app demonstrates the pattern with a custom UI controller:

class CustomController {

    private final InteractionService interactionService;
    private final TransactionalProcessor transactionalProcessor;
    private final SimpleObjects simpleObjects;

    List<SimpleObject> all() {
        return callAuthenticated(newAuthentication(), () -> simpleObjects.listAll())
                .optionalElseFail() (1)
                .orElse(Collections.emptyList()); (2)

    private SimpleAuthentication newAuthentication() {
        return SimpleAuthentication.validOf(UserMemento.ofName("sven")); (3)

    private <T> Result<T> callAuthenticated(
            final Authentication authentication,
            final Callable<T> task) {

        return interactionFactory.callAuthenticated(
                () -> transactionalProcessor
1 re-throws exception that has occurred, if any
2 handles null case, if required
3 a more sophisticated implementation could inspect the HTTP request

The API described here is reasonably low-level, allowing code to interact very directly with the Apache Causeway metamodel and runtime. Such callers should be considered trusted: they do not (by default) honour any business rules eg implicit in the Causeway annotations or hide/disable/validate methods.