Casting ServletRequest to HttpServletRequest

Sometimes is a need to convert ServletRequest object into HttpServletRequest object, because, for example, we need more metadata about a request to get from. There is a simple way to do that (taken from Josh Long's course):

// Let's check if request is of type HttpServletRequest
Assert.isTrue(servletRequest instanceof HttpServletRequest, "this assumes you have an HTTP request");

// Now do casting
HttpServletRequest httpServletRequest = HttpServletRequest.class.cast(servletRequest);

Comments

Popular posts from this blog

Install Kubeflow locally

RabbitMQ and OpenShift