use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRLayoutService method doLayout.
public void doLayout(HttpServletRequest req, HttpServletResponse res, MCRContent source) throws IOException, TransformerException, SAXException {
if (res.isCommitted()) {
LOGGER.warn("Response already committed: {}:{}", res.getStatus(), res.getContentType());
return;
}
String docType = source.getDocType();
try {
MCRParameterCollector parameter = new MCRParameterCollector(req);
MCRContentTransformer transformer = getContentTransformer(docType, parameter);
String filename = getFileName(req, parameter);
transform(res, transformer, source, parameter, filename);
} catch (IOException | TransformerException | SAXException ex) {
throw ex;
} catch (MCRException ex) {
// generating an error page when there is an error in the stylesheet
if (!"mcr_error".equals(docType)) {
throw ex;
}
String msg = "Error while generating error page!";
LOGGER.warn(msg, ex);
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
} catch (Exception e) {
throw new MCRException(e);
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCREventManager method handleEvent.
/**
* This method is called by the component that created the event and acts as
* a multiplexer that invokes all registered event handlers doHandleEvent
* methods. If something goes wrong and an exception is caught, the
* undoHandleEvent methods of all event handlers that are at a position
* BEFORE the failed one, will be called in reversed order. The parameter
* direction controls the order in which the event handlers are called.
*
* @see MCREventHandler#doHandleEvent
* @see MCREventHandlerBase
*
* @param evt
* the event that happened
* @param direction
* the order in which the event handlers are called
*/
public void handleEvent(MCREvent evt, boolean direction) {
List<MCREventHandler> list = handlers.get(evt.getObjectType());
if (list == null) {
return;
}
int first = direction ? 0 : list.size() - 1;
int last = direction ? list.size() - 1 : 0;
int step = direction ? 1 : -1;
int undoPos = first;
Exception handleEventExceptionCaught = null;
for (int i = first; i != last + step; i += step) {
MCREventHandler eh = list.get(i);
logger.debug("EventManager {} {} calling handler {}", evt.getObjectType(), evt.getEventType(), eh.getClass().getName());
try {
eh.doHandleEvent(evt);
} catch (Exception ex) {
handleEventExceptionCaught = ex;
logger.error("Exception caught while calling event handler", ex);
logger.error("Trying rollback by calling undo method of event handlers");
undoPos = i;
break;
}
}
// Rollback by calling undo of successfull handlers
for (int i = undoPos - step; i != first - step; i -= step) {
MCREventHandler eh = list.get(i);
logger.debug("EventManager {} {} calling undo of handler {}", evt.getObjectType(), evt.getEventType(), eh.getClass().getName());
try {
eh.undoHandleEvent(evt);
} catch (Exception ex) {
logger.error("Exception caught while calling undo of event handler", ex);
}
}
if (handleEventExceptionCaught != null) {
String msg = "Exception caught in EventHandler, rollback by calling undo of successfull handlers done.";
throw new MCRException(msg, handleEventExceptionCaught);
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImpl method buildCategoryFromPrefetchedList.
private static MCRCategoryImpl buildCategoryFromPrefetchedList(List<MCRCategoryDTO> list, MCRCategoryID returnID) {
LOGGER.debug(() -> "using prefetched list: " + list);
MCRCategoryImpl predecessor = null;
for (MCRCategoryDTO entry : list) {
predecessor = entry.merge(predecessor);
}
return MCRStreamUtils.flatten(predecessor.getRoot(), MCRCategory::getChildren, Collection::parallelStream).filter(c -> c.getId().equals(returnID)).findFirst().map(MCRCategoryImpl.class::cast).orElseThrow(() -> new MCRException("Could not find " + returnID + " in database result."));
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRShutdownHandler method addCloseable.
public void addCloseable(MCRShutdownHandler.Closeable c) {
Objects.requireNonNull(c);
init();
boolean hasShutDownLock;
try {
hasShutDownLock = shutdownLock.readLock().tryLock(ADD_CLOSEABLE_TIMEOUT, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new MCRException("Could not aquire shutdown lock in time", e);
}
try {
if (hasShutDownLock && !shuttingDown) {
requests.add(c);
} else {
throw new MCRException("Cannot register Closeable while shutting down application.");
}
} finally {
if (hasShutDownLock) {
shutdownLock.readLock().unlock();
}
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRBibUtilsTransformer method export.
private MCRContent export(File modsFile) {
String[] arguments = buildCommandArguments(modsFile);
MCRExternalProcess ep = null;
try {
ep = new MCRExternalProcess(arguments);
ep.run();
String errors = ep.getErrors();
if (!errors.isEmpty())
LOGGER.warn(errors);
return ep.getOutput();
} catch (Exception ex) {
String msg = "Exception invoking external command " + command;
throw new MCRException(msg, ex);
}
}
Aggregations