Java Reference
In-Depth Information
logger.info(responseContext.getStatusInfo().toString());
}
@Override
public void filter(ContainerRequestContext
requestContext) throws IOException {
logger.info(requestContext.getMethod() + " on " +
requestContext.getUriInfo().getPath());
}
}
As you can see, we implement two pretty straightforward interfaces:
Container-
RequestFilter
and
ContainerResponseFilter
. We simply log some informa-
tion about the HTTP request and response. To activate the filter, we use the
@Provider
annotation; without additional configuration, the filter will work for every REST resource
in our application. Additionally, if we would like to reject a request in the filter, there is a
requestContext.abortWith
method.
The client side has two corresponding interfaces:
ClientRequestFilter
and
Cli-
entResponseFilter
. The implementations, however, must be registered manually.
Now the REST service is complete and we can start deploying it in the usual way:
mvn package wildfly:deploy
If you followed all the steps so far, the
http://localhost:8080/ticket-
agency-ws/rest/seat GET
method issued by your browser should print out the list
of available seats:
[{"id":0,"name":"Stalls","price":40,"booked":false},{"id":1,"name":"Stalls","price":40,"booked":false},{"id":2,"name":"Stalls","price":40,"booked":false},{"id":3,"name":"Stalls","price":40,"booked":false},{"id":4,"name":"Stalls","price":40,"booked":false},
. . . . . .
Going to
http://localhost:8080/ticket-agency-ws/rest/account
will
result in:
{"balance":100}
You should also see some log statements from our filter in the console, for instance: