use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRJerseyExceptionMapper method toResponse.
@Override
public Response toResponse(Exception exc) {
LOGGER.warn(() -> "Error while processing request " + request.getRequestURI(), exc);
Response response = getResponse(exc);
if (headers.getAcceptableMediaTypes().contains(MediaType.TEXT_HTML_TYPE)) {
// try to return a html error page
if (!MCRSessionMgr.getCurrentSession().isTransactionActive()) {
MCRSessionMgr.getCurrentSession().beginTransaction();
}
try {
int status = response.getStatus();
String source = exc.getStackTrace().length > 0 ? exc.getStackTrace()[0].toString() : null;
Document errorPageDocument = MCRErrorServlet.buildErrorPage(exc.getMessage(), status, request.getRequestURI(), null, source, exc);
MCRContent result = MCRJerseyUtil.transform(errorPageDocument, request);
return Response.serverError().entity(result.getInputStream()).type(MediaType.valueOf(result.getMimeType())).status(status).build();
} catch (Exception transformException) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(transformException).build();
} finally {
MCRSessionMgr.getCurrentSession().commitTransaction();
}
}
return response;
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRContainerLoginFormServlet method render.
/* (non-Javadoc)
* @see org.mycore.frontend.servlets.MCRServlet#render(org.mycore.frontend.servlets.MCRServletJob, java.lang.Exception)
*/
@Override
protected void render(MCRServletJob job, Exception ex) throws Exception {
if (ex != null) {
throw ex;
}
MCRContent source = (MCRContent) job.getRequest().getAttribute(LOGIN_ATTR);
getLayoutService().doLayout(job.getRequest(), job.getResponse(), source);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRMETSServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws Exception {
HttpServletRequest request = job.getRequest();
HttpServletResponse response = job.getResponse();
LOGGER.info(request.getPathInfo());
String derivate = getOwnerID(request.getPathInfo());
MCRPath rootPath = MCRPath.getPath(derivate, "/");
if (!Files.isDirectory(rootPath)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, MessageFormat.format("Derivate {0} does not exist.", derivate));
return;
}
request.setAttribute("XSL.derivateID", derivate);
Collection<String> linkList = MCRLinkTableManager.instance().getSourceOf(derivate);
if (linkList.isEmpty()) {
MCRDerivate derivate2 = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivate));
MCRObjectID ownerID = derivate2.getOwnerID();
if (ownerID != null && ownerID.toString().length() != 0) {
linkList.add(ownerID.toString());
} else {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, MessageFormat.format("Derivate {0} is not linked with a MCRObject. Please contact an administrator.", derivate));
return;
}
}
request.setAttribute("XSL.objectID", linkList.iterator().next());
response.setContentType("text/xml");
long lastModified = Files.getLastModifiedTime(rootPath).toMillis();
MCRFrontendUtil.writeCacheHeaders(response, (long) CACHE_TIME, lastModified, useExpire);
long start = System.currentTimeMillis();
MCRContent metsContent = getMetsSource(job, useExistingMets(request), derivate);
MCRLayoutService.instance().doLayout(request, response, metsContent);
LOGGER.info("Generation of code by {} took {} ms", this.getClass().getSimpleName(), System.currentTimeMillis() - start);
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRGoobiMetsPostUploadProcessor method processFile.
@Override
public Path processFile(String path, Path tempFile, Supplier<Path> tempFileSupplier) throws IOException {
try (InputStream in = Files.newInputStream(tempFile)) {
MCRStreamContent streamContent = new MCRStreamContent(in);
MCRContent transform = goobiMetsTransformer.transform(streamContent);
Path result = tempFileSupplier.get();
try (OutputStream out = Files.newOutputStream(result)) {
out.write(transform.asByteArray());
return result;
}
}
}
use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.
the class MCRPDFThumbnailServlet method getContent.
/* (non-Javadoc)
* @see org.mycore.frontend.servlets.MCRContentServlet#getContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public MCRContent getContent(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
ThumnailInfo thumbnailInfo = getThumbnailInfo(req.getPathInfo());
MCRPath pdfFile = MCRPath.getPath(thumbnailInfo.derivate, thumbnailInfo.filePath);
LOGGER.info("PDF file: {}", pdfFile);
if (Files.notExists(pdfFile)) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, MessageFormat.format("Could not find pdf file for {0}{1}", thumbnailInfo.derivate, thumbnailInfo.filePath));
return null;
}
String centerThumb = req.getParameter("centerThumb");
String imgSize = req.getParameter("ts");
// defaults to "yes"
boolean centered = !"no".equals(centerThumb);
int thumbnailSize = imgSize == null ? this.thumbnailSize : Integer.parseInt(imgSize);
BasicFileAttributes attrs = Files.readAttributes(pdfFile, BasicFileAttributes.class);
MCRContent imageContent = pdfTools.getThumnail(pdfFile, attrs, thumbnailSize, centered);
if (imageContent != null) {
resp.setHeader("Cache-Control", "max-age=" + MAX_AGE);
Date expires = new Date(System.currentTimeMillis() + MAX_AGE * 1000);
LOGGER.debug("Last-Modified: {}, expire on: {}", new Date(attrs.lastModifiedTime().toMillis()), expires);
resp.setDateHeader("Expires", expires.getTime());
}
return imageContent;
} finally {
LOGGER.debug("Finished sending {}", req.getPathInfo());
}
}
Aggregations