> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to set up an XMLA interceptor in an Atoti application

In this guide, we set up an XMLA interceptor, rewriting an MDX Select query when queried on a specific measure.<br />
We implement the following rewriting logic: `TradeID` is a high-cardinality hierarchy. It must be filtered for measures heavy to compute. `contributors.COUNT` plays the role of such a measure.

<Warning>
  This part must be updated according to the hierarchies present in your project.
</Warning>

## 0. Prerequisites

This guide assumes that the project is using Maven and Spring Boot and is already depending on the [Atoti Server Starter](../atoti_starter).

## 1. Define the interceptor

An XMLA interceptor is defined by implementing the interface `com.activeviam.activepivot.xmla.intf.api.IXmlaInterceptor`.

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
public class MyXmlaInterceptor implements IXmlaInterceptor {
  @Nullable
  @Override
  public RewrittenQuery rewriteSelect(
      final String mdx, final Collection<IContextValue> contextValues) {
    if (!mdx.contains("WHERE")
        && mdx.contains("[Measures].[contributors.COUNT]")
        && !mdx.contains("[TradeID].[TradeID]")) {
      return RewrittenQuery.builder()
          .mdx(mdx + " WHERE ([TradeID].[TradeID].[ALL].[AllMember].FirstChild)")
          .build();
    } else {
      return null;
    }
  }
}
```

In the code above, we inspect the MDX query to be executed. If the query contains the measure `contributors.COUNT` and no filter on `TradeID`, using a WHERE clause, not changing the shape of the MDX result.

## 2. Add the interceptor to the application

The interceptor integrates into the application by returning it as a bean, in a configuration class loaded by the application.

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
@Configuration
class ExtraConfig {
  @Bean
  public MyXmlaInterceptor xmlaInterceptor() {
    return new MyXmlaInterceptor();
  }
}
```

## 3. See the interceptor in action

Connecting your application to Excel - described [here](../../user_guide/querying/front_ends/excel_xmla) - you can see your queries being filtered on a single value trade value whenever the hierarchy `TradeID` is not expressed.

## Going further

See [this section](../atoti_starter#xmla-interceptor) to deep dive into the capabilities of the interceptor.
