List of usage examples for javax.servlet ServletContext log
public void log(String message, Throwable throwable);
Throwable
exception to the servlet log file. From source file:nl.strohalm.cyclos.utils.WebImageHelper.java
/** * Update an image or thumbnail/*ww w . ja v a 2s. co m*/ * @param overrite */ private static void updateImage(final ServletContext context, final boolean isThumbnail, final Image image, final File dir, final boolean overrite) { // Update nothing if no path is given if (dir == null) { return; } InputStream in = null; OutputStream out = null; final File file = new File(dir, image.getName()); try { dir.mkdirs(); final long lastModified = image.getLastModified() == null ? System.currentTimeMillis() : image.getLastModified().getTimeInMillis(); if (overrite || file.lastModified() != lastModified) { out = new FileOutputStream(file); in = (isThumbnail ? image.getThumbnail() : image.getImage()).getBinaryStream(); IOUtils.copy(in, out); file.setLastModified(lastModified); } } catch (final IOException e) { context.log("Error writing image file " + file, e); } catch (final SQLException e) { context.log("Error writing image file " + file + " from db", e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:org.jasig.cas.web.init.SafeContextLoaderListener.java
public void contextInitialized(final ServletContextEvent sce) { try {//from w ww . j ava 2 s . co m this.delegate.contextInitialized(sce); } catch (Throwable t) { /* * no matter what went wrong, our role is to capture this error and * prevent it from blocking initialization of the context. logging * overkill so that our deployer will find a record of this problem * even if unfamiliar with Commons Logging and properly configuring * it. */ final String message = "SafeContextLoaderListener: \n" + "The Spring ContextLoaderListener we wrap threw on contextInitialized.\n" + "But for our having caught this error, the web application context would not have initialized."; // log it via Commons Logging log.fatal(message, t); // log it to System.err System.err.println(message); t.printStackTrace(); // log it to the ServletContext ServletContext context = sce.getServletContext(); context.log(message, t); /* * record the error so that the application has access to later * display a proper error message based on the exception. */ context.setAttribute(CAUGHT_THROWABLE_KEY, t); } }
From source file:ContextLog.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { String yourMessage = request.getParameter("mine"); //Call the two ServletContext.log methods //the javax.servlet.GenericServlet.getServletContext method ServletContext context = getServletContext(); if (yourMessage == null || yourMessage.equals("")) //log version with Throwable parameter context.log("No message received:", new IllegalStateException("Missing parameter")); else//w ww .ja v a2s. co m context.log("Here is the visitor's message: " + yourMessage); response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); //logging servlets probably want to display more HTML; this is 'lazy // HTML' out.println("<html><head><title>ServletContext logging</title></head><body>"); out.println("<h2>Messages sent</h2>"); out.println("</body></html>"); }
From source file:org.jasig.cas.web.init.SafeDispatcherServlet.java
public void init(final ServletConfig config) { try {/*from ww w .ja v a2s .c om*/ this.delegate.init(config); } catch (final Throwable t) { // let the service method know initialization failed. this.initSuccess = false; /* * no matter what went wrong, our role is to capture this error and * prevent it from blocking initialization of the servlet. logging * overkill so that our deployer will find a record of this problem * even if unfamiliar with Commons Logging and properly configuring * it. */ final String message = "SafeDispatcherServlet: \n" + "The Spring DispatcherServlet we wrap threw on init.\n" + "But for our having caught this error, the servlet would not have initialized."; // log it via Commons Logging log.fatal(message, t); // log it to System.err System.err.println(message); t.printStackTrace(); // log it to the ServletContext ServletContext context = config.getServletContext(); context.log(message, t); /* * record the error so that the application has access to later * display a proper error message based on the exception. */ context.setAttribute(CAUGHT_THROWABLE_KEY, t); } }
From source file:org.mifos.reports.MifosViewerServletContextListener.java
private void error(ServletContext servletContext, String msg, Exception e) throws RuntimeException { LOGGER.error(msg, e);// ww w . j ava2 s .c o m if (servletContext != null) { servletContext.log(msg, e); } throw new RuntimeException(msg, e); }
From source file:net.sourceforge.vulcan.web.VulcanContextListener.java
public void contextDestroyed(ServletContextEvent event) { final ServletContext context = event.getServletContext(); context.removeAttribute(Keys.STATE_MANAGER); context.removeAttribute(Keys.EVENT_POOL); if (stateManager == null) { // startup probably failed. return;//from w w w . j a v a 2 s. co m } try { stateManager.shutdown(); } catch (Exception e) { context.log("Error during shutdown of stateManager", e); } }
From source file:com.openmeap.web.servlet.Log4JConfiguratorListener.java
@Override public void contextInitialized(ServletContextEvent arg0) { BasicConfigurator.configure();/*from w w w .j av a2s. co m*/ ServletContext servletContext = arg0.getServletContext(); String xmlLoc = servletContext.getInitParameter("openmeap-log4j-xml"); if (xmlLoc == null) { return; } try { Resource res = new ClassPathResource(xmlLoc); DOMConfigurator.configure(XmlUtils.getDocument(res.getInputStream()).getDocumentElement()); } catch (Exception ioe) { servletContext.log("The configuration failed.", ioe); } }
From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java
private void logException(String msg, Exception e, HttpServletResponse response) { ServletContext servletContext = getServletContext(); servletContext.log(msg, e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }