# Guide to OpenIG
Chapter 12. Customizing OpenIG

Sidebar | Prev | Up | Next

## 12.6. Sample Filter

The following sample filter sets an arbitrary header in the incoming request and outgoing response.

    package com.example.filter;

    // Java Standard Edition
    import java.io.IOException;

    // OpenIG Core Library
    import org.forgerock.openig.filter.Chain;
    import org.forgerock.openig.filter.GenericFilter;
    import org.forgerock.openig.handler.HandlerException;
    import org.forgerock.openig.heap.HeapException;
    import org.forgerock.openig.heap.NestedHeaplet;
    import org.forgerock.openig.http.Exchange;
    import org.forgerock.openig.model.ModelException;

    public class HelloWorldFilter extends GenericFilter {

        public String name;
        public String value;

        @Override
        public void filter(Exchange exchange, Chain chain)
                throws HandlerException, IOException {
            exchange.request.headers.put(name, value); // set header in request
            chain.handle(exchange); // pass to remaining filters & handler in chain
            exchange.response.headers.put(name, value); // set header in response
        }

        public static class Heaplet extends NestedHeaplet {

            @Override
            public Object create() throws HeapException, ModelException {
                HelloWorldFilter filter = new HelloWorldFilter();
                filter.name = config.get("name").required().asString(); // required
                filter.value = config.get("value").required().asString(); // req'd
                return filter;
            }
        }
    }

The corresponding heap object configuration is as follows.

    {
         "name": "HelloWorldFilter",
         "type": "com.example.filter.HelloWorldFilter",
         "config": {
             "name": "X-Hello",
             "value": "World"
         }
    }