HTTP-Aware Processors

Appkit provides many 'abstract' processor classes that act as blueprints for particular types of processing of the search query and response. A simple AbstractHttpAwareProcessor is provided, which can be extended and typed to either Query or Response.

Examples

For processing on a search query:

public class RedirectProcessor extends AbstractHttpAwareProcessor<Query> {

    @Override
    public Query change(Query payload) {
        if (/*some logic*/) {
            getHttpResponse().sendRedirect(/*some location*/);
        }
    }

}

For processing on a search response:

public class RedirectProcessor extends AbstractHttpAwareProcessor<Response> {

    @Override
    public Response change(Response payload) {
        if (/*some logic*/) {
            getHttpResponse().sendRedirect(/*some location*/);
        }
    }

}

This is useful for being aware of the HTTP request/response context using the getHttpRequest() and getHttpResponse() methods. It lets you implement behaviour which can make use of information coming from the browser for an individual request and also modify the outcome of the overall workflow of the users interaction with the application via the web.

I am getting an error about casting the request or response

If you receive these errors:

java.lang.ClassCastException: org.tuckey.web.filters.urlrewrite.UrlRewriteWrappedRequest cannot be cast to twigkit.model.Request

java.lang.ClassCastException: org.tuckey.web.filters.urlrewrite.UrlRewriteWrappedResponse cannot be cast to twigkit.model.Response

This is because, to enable this HTTP aware processing feature, the terms 'request' and 'response' are reserved parameter names, and you might have set these on a custom processor you created. Changing the name will fix the issue.