use of org.xwiki.container.servlet.ServletResponse in project xwiki-platform by xwiki.
the class BatikSVGRasterizer method rasterizeToResponse.
@Override
public void rasterizeToResponse(String content, int width, int height) throws IOException {
if (!(this.container.getResponse() instanceof ServletResponse)) {
return;
}
HttpServletResponse response = ((ServletResponse) this.container.getResponse()).getHttpServletResponse();
File result = rasterizeToTemporaryFile(content, width, height);
if (result == null) {
return;
}
response.setContentLength((int) result.length());
response.setContentType("image/png");
OutputStream os = response.getOutputStream();
FileUtils.copyFile(result, os);
os.flush();
}
use of org.xwiki.container.servlet.ServletResponse in project xwiki-platform by xwiki.
the class DefaultXWikiContextInitializer method initialize.
@Override
public XWikiContext initialize(ExecutionContext econtext) throws XWikiException {
Request request = this.container.getRequest();
XWikiContext xcontext;
if (!(request instanceof ServletRequest)) {
if (this.fallbackOnStub) {
xcontext = this.contextProvider.createStubContext();
} else {
throw new XWikiException(XWikiException.MODULE_XWIKI_USER, XWikiException.ERROR_XWIKI_USER_INIT, "Unsupported request type [" + request.getClass() + "]");
}
} else {
try {
HttpServletRequest httpServletRequest = ((ServletRequest) request).getHttpServletRequest();
HttpServletResponse httpServletReponse = ((ServletResponse) this.container.getResponse()).getHttpServletResponse();
xcontext = initializeXWikiContext(httpServletRequest, httpServletReponse);
// Put the XWikiContext in the ExecutionContext in case the authenticator needs it
if (econtext != null) {
xcontext.declareInExecutionContext(econtext);
}
if (this.authenticate) {
authenticate(xcontext);
}
} catch (XWikiException e) {
if (this.fallbackOnStub) {
xcontext = this.contextProvider.createStubContext();
} else {
throw new XWikiException(XWikiException.MODULE_XWIKI_USER, XWikiException.ERROR_XWIKI_USER_INIT, "Failed to initialize XWikiContext", e);
}
}
}
// Put the XWikiContext in the ExecutionContext
if (econtext != null) {
xcontext.declareInExecutionContext(econtext);
}
return xcontext;
}
use of org.xwiki.container.servlet.ServletResponse in project xwiki-platform by xwiki.
the class AbstractServletResourceReferenceHandler method setResponseHeaders.
/**
* Sets the response headers needed to cache the resource permanently, if the resource can be cached.
*
* @param response the response
* @param resourceReference the resource that is being served
*/
private void setResponseHeaders(Response response, R resourceReference) {
// Cache the resource if possible.
if (response instanceof ServletResponse && isResourceCacheable(resourceReference)) {
HttpServletResponse httpResponse = ((ServletResponse) response).getHttpServletResponse();
httpResponse.setHeader(HttpHeaders.CACHE_CONTROL, "public");
httpResponse.setDateHeader(HttpHeaders.EXPIRES, new Date().getTime() + CACHE_DURATION);
// Even if the resource is cached permanently, most browsers are still sending a request if the user reloads
// the page using F5. We send back the "Last-Modified" header in the response so that the browser will send
// us an "If-Modified-Since" request for any subsequent call for this static resource. When this happens we
// return a 304 to tell the browser to use its cached version.
httpResponse.setDateHeader(HttpHeaders.LAST_MODIFIED, new Date().getTime());
}
}
Aggregations