![JAR search and dependency download from the Maven repository](/logo.png)
it.cosenonjaviste.security.jwt.catalinawriters.ResponseWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tomcat-jwt-security Show documentation
Show all versions of tomcat-jwt-security Show documentation
JWT Tomcat Valve and utility classes for handling JWT tokens
The newest version!
package it.cosenonjaviste.security.jwt.catalinawriters;
import org.apache.catalina.connector.Response;
import java.io.IOException;
/**
* Abstract class for catalina response writing.
* Supported media type are json and xml. Html is default
*
* @author acomo
*
*/
public abstract class ResponseWriter {
static final String APPLICATION_XML = "application/xml";
static final String APPLICATION_JSON = "application/json";
/**
* Create a new {@link ResponseWriter} instance based on provided mimetype.
*
* Supported mimetype are:
*
* - application/json
* - application/xml
* - text/html is default
*
*
* @param mimeType accepted mimetype from client
* @return a new {@link ResponseWriter} instance
*/
public static ResponseWriter get(String mimeType) {
String nullSafeMimeType = mimeType != null ? mimeType : "";
if (nullSafeMimeType.contains(APPLICATION_JSON)) {
return new JsonResponseWriter();
} else if (nullSafeMimeType.contains(APPLICATION_XML)) {
return new XmlResponseWriter();
} else {
return new HtmlResponseWriter();
}
}
/**
* Write body values to response with provided status code. Body serialization depends on concrete class
*
* @param response HTTP response object
* @param statusCode response status code to set
* @param body response body
* @throws IOException exception on writing response data to response object
*/
public abstract void write(Response response, int statusCode, Object body) throws IOException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy