org.apache.tomcat.util.ExceptionUtils Java Examples
The following examples show how to use
org.apache.tomcat.util.ExceptionUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpgradeServletOutputStream.java From Tomcat8-Source-Read with MIT License | 6 votes |
private final void onError(Throwable t) { if (listener == null) { return; } ClassLoader oldCL = processor.getUpgradeToken().getContextBind().bind(false, null); try { listener.onError(t); } catch (Throwable t2) { ExceptionUtils.handleThrowable(t2); log.warn(sm.getString("upgrade.sos.onErrorFail"), t2); } finally { processor.getUpgradeToken().getContextBind().unbind(false, oldCL); } try { close(); } catch (IOException ioe) { if (log.isDebugEnabled()) { log.debug(sm.getString("upgrade.sos.errorCloseFail"), ioe); } } }
Example #2
Source File: HostManagerServlet.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException (sm.getString("hostManagerServlet.noWrapper")); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } }
Example #3
Source File: ApplicationContextFacade.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") // doPrivileged() returns the correct type public <T extends EventListener> T createListener(Class<T> c) throws ServletException { if (SecurityUtil.isPackageProtectionEnabled()) { try { return (T) invokeMethod(context, "createListener", new Object[]{c}); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); if (t instanceof ServletException) { throw (ServletException) t; } return null; } } else { return context.createListener(c); } }
Example #4
Source File: WsSession.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
private void fireEndpointOnClose(CloseReason closeReason) { // Fire the onClose event InstanceManager instanceManager = webSocketContainer.getInstanceManager(); Thread t = Thread.currentThread(); ClassLoader cl = t.getContextClassLoader(); t.setContextClassLoader(applicationClassLoader); try { localEndpoint.onClose(this, closeReason); if (instanceManager != null) { instanceManager.destroyInstance(localEndpoint); } } catch (Throwable throwable) { ExceptionUtils.handleThrowable(throwable); localEndpoint.onError(this, throwable); } finally { t.setContextClassLoader(cl); } }
Example #5
Source File: TesterWsClientAutobahn.java From Tomcat8-Source-Read with MIT License | 6 votes |
public static void main(String[] args) throws Exception { WebSocketContainer wsc = ContainerProvider.getWebSocketContainer(); int testCaseCount = getTestCaseCount(wsc); System.out.println("There are " + testCaseCount + " test cases"); for (int testCase = 1; testCase <= testCaseCount; testCase++) { if (testCase % 50 == 0) { System.out.println(testCase); } else { System.out.print('.'); } try { executeTestCase(wsc, testCase); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); t.printStackTrace(); } } System.out.println("Testing complete"); updateReports(wsc); }
Example #6
Source File: ResponseIncludeWrapper.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void addHeader(String name, String value) { super.addHeader(name, value); String lname = name.toLowerCase(Locale.ENGLISH); if (lname.equals(LAST_MODIFIED)) { try { synchronized(RFC1123_FORMAT) { lastModified = RFC1123_FORMAT.parse(value).getTime(); } } catch (Throwable ignore) { ExceptionUtils.handleThrowable(ignore); } } else if (lname.equals(CONTENT_TYPE)) { contentType = value; } }
Example #7
Source File: StandardManager.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { super.startInternal(); // Load unloaded sessions, if any try { load(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("standardManager.managerLoad"), t); } setState(LifecycleState.STARTING); }
Example #8
Source File: ApplicationContextFacade.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Use reflection to invoke the requested method. Cache the method object * to speed up the process * @param methodName The method to invoke. * @param clazz The class where the method is. * @param params The arguments passed to the called method. */ private Object doPrivileged(final String methodName, final Class<?>[] clazz, Object[] params) { try{ Method method = context.getClass().getMethod(methodName, clazz); return executeMethod(method,context,params); } catch (Exception ex){ try { handleException(ex); } catch (Throwable t){ ExceptionUtils.handleThrowable(t); throw new RuntimeException(t.getMessage()); } return null; } finally { params = null; } }
Example #9
Source File: CharsetMapper.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Construct a new CharsetMapper using the specified properties resource. * * @param name Name of a properties resource to be loaded * * @exception IllegalArgumentException if the specified properties * resource could not be loaded for any reason. */ public CharsetMapper(String name) { InputStream stream = null; try { stream = this.getClass().getResourceAsStream(name); map.load(stream); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); throw new IllegalArgumentException(t.toString()); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } }
Example #10
Source File: AccessLogValve.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Rename the existing log file to something else. Then open the * old log file name up once again. Intended to be called by a JMX * agent. * * * @param newFileName The file name to move the log file entry to * @return true if a file was rotated with no error */ public synchronized boolean rotate(String newFileName) { if (currentLogFile != null) { File holder = currentLogFile; close(false); try { holder.renameTo(new File(newFileName)); } catch (Throwable e) { ExceptionUtils.handleThrowable(e); log.error(sm.getString("accessLogValve.rotateFail"), e); } /* Make sure date is correct */ dateStamp = fileDateFormatter.format( new Date(System.currentTimeMillis())); open(); return true; } else { return false; } }
Example #11
Source File: AccessLogValve.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Move a current but rotated log file back to the unrotated * one. Needed if date stamp inclusion is deferred to rotation * time. */ private void restore() { File newLogFile = getLogFile(false); File rotatedLogFile = getLogFile(true); if (rotatedLogFile.exists() && !newLogFile.exists() && !rotatedLogFile.equals(newLogFile)) { try { if (!rotatedLogFile.renameTo(newLogFile)) { log.error(sm.getString("accessLogValve.renameFail", rotatedLogFile, newLogFile)); } } catch (Throwable e) { ExceptionUtils.handleThrowable(e); log.error(sm.getString("accessLogValve.renameFail", rotatedLogFile, newLogFile), e); } } }
Example #12
Source File: HostManagerServlet.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Initialize this servlet. */ @Override public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException (sm.getString("hostManagerServlet.noWrapper")); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } }
Example #13
Source File: JIoEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Process a new connection from a new client. Wraps the socket so * keep-alive and other attributes can be tracked and then passes the socket * to the executor for processing. * * @param socket The socket associated with the client. * * @return <code>true</code> if the socket is passed to the * executor, <code>false</code> if something went wrong or * if the endpoint is shutting down. Returning * <code>false</code> is an indication to close the socket * immediately. */ protected boolean processSocket(Socket socket) { // Process the request from this socket try { SocketWrapper<Socket> wrapper = new SocketWrapper<Socket>(socket); wrapper.setKeepAliveLeft(getMaxKeepAliveRequests()); wrapper.setSecure(isSSLEnabled()); // During shutdown, executor may be null - avoid NPE if (!running) { return false; } getExecutor().execute(new SocketProcessor(wrapper)); } catch (RejectedExecutionException x) { log.warn("Socket processing request was rejected for:"+socket,x); return false; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // This means we got an OOM or similar creating a thread, or that // the pool and its queue are full log.error(sm.getString("endpoint.process.fail"), t); return false; } return true; }
Example #14
Source File: TesterWsClientAutobahn.java From tomcatsrc with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { WebSocketContainer wsc = ContainerProvider.getWebSocketContainer(); int testCaseCount = getTestCaseCount(wsc); System.out.println("There are " + testCaseCount + " test cases"); for (int testCase = 1; testCase <= testCaseCount; testCase++) { if (testCase % 50 == 0) { System.out.println(testCase); } else { System.out.print('.'); } try { executeTestCase(wsc, testCase); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); t.printStackTrace(); } } System.out.println("Testing complete"); updateReports(wsc); }
Example #15
Source File: ApplicationContextFacade.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") // doPrivileged() returns the correct type public <T extends Filter> T createFilter(Class<T> c) throws ServletException { if (SecurityUtil.isPackageProtectionEnabled()) { try { return (T) invokeMethod(context, "createFilter", new Object[]{c}); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); if (t instanceof ServletException) { throw (ServletException) t; } return null; } } else { return context.createFilter(c); } }
Example #16
Source File: JIoEndpoint.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Configure the socket. */ protected boolean setSocketOptions(Socket socket) { try { // 1: Set socket options: timeout, linger, etc socketProperties.setProperties(socket); } catch (SocketException s) { //error here is common if the client has reset the connection if (log.isDebugEnabled()) { log.debug(sm.getString("endpoint.err.unexpected"), s); } // Close the socket return false; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("endpoint.err.unexpected"), t); // Close the socket return false; } return true; }
Example #17
Source File: ApplicationContextFacade.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") // doPrivileged() returns the correct type public <T extends Filter> T createFilter(Class<T> c) throws ServletException { if (SecurityUtil.isPackageProtectionEnabled()) { try { return (T) invokeMethod(context, "createFilter", new Object[]{c}); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); if (t instanceof ServletException) { throw (ServletException) t; } return null; } } else { return context.createFilter(c); } }
Example #18
Source File: PojoEndpointBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public final void onError(Session session, Throwable throwable) { if (methodMapping.getOnError() == null) { log.error(sm.getString("pojoEndpointBase.onError", pojo.getClass().getName()), throwable); } else { try { methodMapping.getOnError().invoke( pojo, methodMapping.getOnErrorArgs(pathParameters, session, throwable)); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("pojoEndpointBase.onErrorFail", pojo.getClass().getName()), t); } } }
Example #19
Source File: ApplicationContextFacade.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * @deprecated As of Java Servlet API 2.1, with no direct replacement. */ @Override @Deprecated public Servlet getServlet(String name) throws ServletException { if (SecurityUtil.isPackageProtectionEnabled()) { try { return (Servlet) invokeMethod(context, "getServlet", new Object[]{name}); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); if (t instanceof ServletException) { throw (ServletException) t; } return null; } } else { return context.getServlet(name); } }
Example #20
Source File: StandardWrapper.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * @return <code>true</code> if the specified class name represents a * container provided servlet class that should be loaded by the * server class loader. * * @param classname Name of the class to be checked * * @deprecated Unused. Will be removed in Tomcat 9 */ @Deprecated protected boolean isContainerProvidedServlet(String classname) { if (classname.startsWith("org.apache.catalina.")) { return true; } try { Class<?> clazz = this.getClass().getClassLoader().loadClass(classname); return (ContainerServlet.class.isAssignableFrom(clazz)); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); return false; } }
Example #21
Source File: AsyncContextImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void fireOnComplete() { if (log.isDebugEnabled()) { log.debug(sm.getString("asyncContextImpl.fireOnComplete")); } List<AsyncListenerWrapper> listenersCopy = new ArrayList<>(); listenersCopy.addAll(listeners); ClassLoader oldCL = context.bind(Globals.IS_SECURITY_ENABLED, null); try { for (AsyncListenerWrapper listener : listenersCopy) { try { listener.fireOnComplete(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.warn(sm.getString("asyncContextImpl.onCompleteError", listener.getClass().getName()), t); } } } finally { context.fireRequestDestroyEvent(request.getRequest()); clearServletRequestResponse(); this.context.decrementInProgressAsyncCount(); context.unbind(Globals.IS_SECURITY_ENABLED, oldCL); } }
Example #22
Source File: StandardManager.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { super.startInternal(); // Load unloaded sessions, if any try { load(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("standardManager.managerLoad"), t); } setState(LifecycleState.STARTING); }
Example #23
Source File: StandardWrapper.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Return <code>true</code> if the specified class name represents a * container provided servlet class that should be loaded by the * server class loader. * * @param classname Name of the class to be checked */ protected boolean isContainerProvidedServlet(String classname) { if (classname.startsWith("org.apache.catalina.")) { return (true); } try { Class<?> clazz = this.getClass().getClassLoader().loadClass(classname); return (ContainerServlet.class.isAssignableFrom(clazz)); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); return (false); } }
Example #24
Source File: UpgradeServletOutputStream.java From Tomcat8-Source-Read with MIT License | 6 votes |
private void flushInternal(boolean block, boolean updateFlushing) throws IOException { try { synchronized (writeLock) { if (updateFlushing) { flushing = socketWrapper.flush(block); if (flushing) { socketWrapper.registerWriteInterest(); } } else { socketWrapper.flush(block); } } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); onError(t); if (t instanceof IOException) { throw (IOException) t; } else { throw new IOException(t); } } }
Example #25
Source File: WebappLoader.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
private String getClasspath( ClassLoader loader ) { try { Method m=loader.getClass().getMethod("getClasspath", new Class[] {}); if( log.isTraceEnabled()) log.trace("getClasspath " + m ); if( m==null ) return null; Object o=m.invoke( loader, new Object[] {} ); if( log.isDebugEnabled() ) log.debug("gotClasspath " + o); if( o instanceof String ) return (String)o; return null; } catch( Exception ex ) { Throwable t = ExceptionUtils.unwrapInvocationTargetException(ex); ExceptionUtils.handleThrowable(t); if (log.isDebugEnabled()) log.debug("getClasspath ", ex); } return null; }
Example #26
Source File: DefaultInstanceManager.java From Tomcat8-Source-Read with MIT License | 5 votes |
protected Class<?> loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { if (className.startsWith("org.apache.catalina")) { return containerClassLoader.loadClass(className); } try { Class<?> clazz = containerClassLoader.loadClass(className); if (ContainerServlet.class.isAssignableFrom(clazz)) { return clazz; } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } return classLoader.loadClass(className); }
Example #27
Source File: AsyncContextImpl.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public void setStarted(Context context, ServletRequest request, ServletResponse response, boolean originalRequestResponse) { synchronized (asyncContextLock) { this.request.getCoyoteRequest().action( ActionCode.ASYNC_START, this); this.context = context; this.servletRequest = request; this.servletResponse = response; this.hasOriginalRequestAndResponse = originalRequestResponse; this.event = new AsyncEvent(this, request, response); List<AsyncListenerWrapper> listenersCopy = new ArrayList<AsyncListenerWrapper>(); listenersCopy.addAll(listeners); listeners.clear(); for (AsyncListenerWrapper listener : listenersCopy) { try { listener.fireOnStartAsync(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.warn("onStartAsync() failed for listener of type [" + listener.getClass().getName() + "]", t); } } } }
Example #28
Source File: AprEndpoint.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Process given socket. This is called when the socket has been * accepted. */ protected boolean processSocketWithOptions(long socket) { try { // During shutdown, executor may be null - avoid NPE if (running) { if (log.isDebugEnabled()) { log.debug(sm.getString("endpoint.debug.socket", Long.valueOf(socket))); } AprSocketWrapper wrapper = new AprSocketWrapper(Long.valueOf(socket)); wrapper.setKeepAliveLeft(getMaxKeepAliveRequests()); wrapper.setSecure(isSSLEnabled()); connections.put(Long.valueOf(socket), wrapper); // todo 为了方便测试,修改为单线程 //getExecutor().execute(new SocketWithOptionsProcessor(wrapper)); new SocketWithOptionsProcessor(wrapper).run(); } } catch (RejectedExecutionException x) { log.warn("Socket processing request was rejected for:"+socket,x); return false; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // This means we got an OOM or similar creating a thread, or that // the pool and its queue are full log.error(sm.getString("endpoint.process.fail"), t); return false; } return true; }
Example #29
Source File: DeltaManager.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { super.startInternal(); // Load unloaded sessions, if any try { if (cluster == null) { log.error(sm.getString("deltaManager.noCluster", getName())); return; } else { if (log.isInfoEnabled()) { String type = "unknown" ; if( cluster.getContainer() instanceof Host){ type = "Host" ; } else if( cluster.getContainer() instanceof Engine){ type = "Engine" ; } log.info(sm.getString("deltaManager.registerCluster", getName(), type, cluster.getClusterName())); } } if (log.isInfoEnabled()) { log.info(sm.getString("deltaManager.startClustering", getName())); } getAllClusterSessions(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("deltaManager.managerLoad"), t); } setState(LifecycleState.STARTING); }
Example #30
Source File: DeltaManager.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { super.startInternal(); // Load unloaded sessions, if any try { if (cluster == null) { log.error(sm.getString("deltaManager.noCluster", getName())); return; } else { if (log.isInfoEnabled()) { String type = "unknown" ; if( cluster.getContainer() instanceof Host){ type = "Host" ; } else if( cluster.getContainer() instanceof Engine){ type = "Engine" ; } log.info(sm.getString("deltaManager.registerCluster", getName(), type, cluster.getClusterName())); } } if (log.isInfoEnabled()) log.info(sm.getString("deltaManager.startClustering", getName())); getAllClusterSessions(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("deltaManager.managerLoad"), t); } setState(LifecycleState.STARTING); }