This repository has been archived by the owner on Jul 19, 2020. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses #73, which was discussed quite some time ago. JAX-RS does NOT depend on the Servlet API and can therefore be used in other environments. As MVC is built on top of JAX-RS, it makes no sense to introduce a dependency on the Servlet API.
The only class which currently depends on the Servlet API is
ViewEngineContext
, which exposes theHttpServletRequest
and theHttpServletResponse
. Beside the fact that this is the only reason for us to depend on Servlet, exposing these Servlet specific classes is bad for other reasons:HttpServletResponse.getOutputStream()
which basically completely bypasses JAX-RS.HttpServletResponse.getWriter()
which may use a completely different encoding from the one negotiated via@Produces
.This pull request contains the following changes:
pom.xml
.MvcContext
javadocs.ViewEngineContext.getRequest()
andViewEngineContext.getResponse()
.ViewEngineContext.getOutputStream()
which will be the primary way to obtain the stream to write the view to.ViewEngineContext.getResponseHeaders()
which exposes a mutable map which can be used to modify the HTTP response headers. I don't really the mutable map approach, but that's the way JAX-RS exposes such headers forMessageBodyWriter
, so we should be consistent with JAX-RS here.ViewEngineContext.getMediaType()
to provide theViewEngine
with all required information about the negotiated media type and character encoding.ViewEngine
implementation to need theHttpServletRequest
orHttpServletResponse
. For these cases I addedViewEngineContext.getRequest(Class<T>)
andViewEngineContext.getResponse(Class<T>)
. These methods don't have a hard dependency on the Servlet API but allow to obtain the request viagetRequest(HttpServletRequest.class)
. It is a bit similar to JSF'sExternalContext.getRequest()
but more type safe likeEntityManager.unwrap(Class)
. The nice thing about these methods is that they also support other request/response objects in non-servlet environments.I already modified Ozark to support this new API on a private branch. It worked great! And I was even able to fix some really serve encoding issues in some of the 3rd party view engines.
This is a very huge change. But it is worth the effort. So any feedback is welcome.