Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeConfluence
linenumberstrue
    ServiceCallInterceptor security = (mtd, args, ctx) -> {
        // Check permission before execution of the method.
        if (!CustomSecurityProvider.get().access(mtd, ctx.value("sessionId")))
            throw new SecurityException("Method invocation is not permitted");

        return null;
    }

    ServiceCallInterceptor audit = (mtd, args, ctx) -> {
        return (res, err) -> {
            // Record an event after the execution of the method.
            AuditProvider.get().recordEvent(mtd, ctx.value("sessionId"), err);
        }
    }

    ServiceConfiguration svcCfg = new ServiceConfiguration()
        .setName("service")
        .setService(new MyServiceImpl())
        .setMaxPerNodeCount(1)
        .setInterceptors(Arrays.asList(security, audit));

    // Deploy service.
    ignite.services().deploy(svcCfg);

    ...

    // Set context parameters for service proxy.
    MyService proxy = ignite.services().serviceProxy("service", MyService.class, false, Collections.singletonMap("sessionId", sessionId), 0);

    // A business method call to be intercepted.
    proxy.placeOrder(order1);
    proxy.placeOrder(order2);
 

...