Java Code Examples for org.apache.catalina.connector.Response#getStatus()
The following examples show how to use
org.apache.catalina.connector.Response#getStatus() .
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: AbstractAccessLogValve.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void addElement(CharArrayWriter buf, Date date, Request request, Response response, long time) { if (response != null) { // This approach is used to reduce GC from toString conversion int status = response.getStatus(); if (100 <= status && status < 1000) { buf.append((char) ('0' + (status / 100))) .append((char) ('0' + ((status / 10) % 10))) .append((char) ('0' + (status % 10))); } else { buf.append(Integer.toString(status)); } } else { buf.append('-'); } }
Example 2
Source File: StandardHostValveInvokeInterceptor.java From pinpoint with Apache License 2.0 | 5 votes |
private int getStatusCode(final HttpServletResponse response) { try { // Tomcat 6 if (response instanceof Response) { final Response r = (Response) response; return r.getStatus(); } else { response.getStatus(); } } catch (Exception ignored) { } return 0; }
Example 3
Source File: Servlet2ApiHelper.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public int getStatus(HttpServletResponse response) { if (response instanceof Response) { // JBoss 4 (Spring 2.X) final Response r = (Response) response; return r.getStatus(); } return 0; }
Example 4
Source File: MinimumErrorReportValve.java From tomee with Apache License 2.0 | 5 votes |
@Override protected void report(final Request request, final Response response, final Throwable throwable) { final int statusCode = response.getStatus(); if (statusCode < 400 || response.getContentWritten() > 0 || !response.isError()) { return; } try { try { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); } catch (final Throwable t) { ExceptionUtils.handleThrowable(t); if (container.getLogger().isDebugEnabled()) { container.getLogger().debug("status.setContentType", t); } } final Writer writer = response.getReporter(); if (writer != null) { writer.write("<html>\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n" + "</head>\n" + "<body>\n" + "<h1>HTTP Error " + statusCode +"</h1>\n" + "</body>\n" + "</html>\n"); } } catch (final IOException | IllegalStateException e) { // Ignore } }
Example 5
Source File: JDBCAccessLogValve.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void log(Request request, Response response, long time) { if (!getState().isAvailable()) { return; } final String EMPTY = "" ; String remoteHost; if(resolveHosts) { if (requestAttributesEnabled) { Object host = request.getAttribute(REMOTE_HOST_ATTRIBUTE); if (host == null) { remoteHost = request.getRemoteHost(); } else { remoteHost = (String) host; } } else { remoteHost = request.getRemoteHost(); } } else { if (requestAttributesEnabled) { Object addr = request.getAttribute(REMOTE_ADDR_ATTRIBUTE); if (addr == null) { remoteHost = request.getRemoteAddr(); } else { remoteHost = (String) addr; } } else { remoteHost = request.getRemoteAddr(); } } String user = request.getRemoteUser(); String query=request.getRequestURI(); long bytes = response.getBytesWritten(true); if(bytes < 0) { bytes = 0; } int status = response.getStatus(); String virtualHost = EMPTY; String method = EMPTY; String referer = EMPTY; String userAgent = EMPTY; String logPattern = pattern; if (logPattern.equals("combined")) { virtualHost = request.getServerName(); method = request.getMethod(); referer = request.getHeader("referer"); userAgent = request.getHeader("user-agent"); } synchronized (this) { int numberOfTries = 2; while (numberOfTries>0) { try { open(); ps.setString(1, remoteHost); ps.setString(2, user); ps.setTimestamp(3, new Timestamp(getCurrentTimeMillis())); ps.setString(4, query); ps.setInt(5, status); if(useLongContentLength) { ps.setLong(6, bytes); } else { if (bytes > Integer.MAX_VALUE) { bytes = -1 ; } ps.setInt(6, (int) bytes); } if (logPattern.equals("combined")) { ps.setString(7, virtualHost); ps.setString(8, method); ps.setString(9, referer); ps.setString(10, userAgent); } ps.executeUpdate(); return; } catch (SQLException e) { // Log the problem for posterity container.getLogger().error(sm.getString("jdbcAccessLogValve.exception"), e); // Close the connection so that it gets reopened next time if (conn != null) { close(); } } numberOfTries--; } } }
Example 6
Source File: JDBCAccessLogValve.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void log(Request request, Response response, long time) { if (!getState().isAvailable()) { return; } final String EMPTY = "" ; String remoteHost; if(resolveHosts) { if (requestAttributesEnabled) { Object host = request.getAttribute(REMOTE_HOST_ATTRIBUTE); if (host == null) { remoteHost = request.getRemoteHost(); } else { remoteHost = (String) host; } } else { remoteHost = request.getRemoteHost(); } } else { if (requestAttributesEnabled) { Object addr = request.getAttribute(REMOTE_ADDR_ATTRIBUTE); if (addr == null) { remoteHost = request.getRemoteAddr(); } else { remoteHost = (String) addr; } } else { remoteHost = request.getRemoteAddr(); } } String user = request.getRemoteUser(); String query=request.getRequestURI(); long bytes = response.getBytesWritten(true); if(bytes < 0) { bytes = 0; } int status = response.getStatus(); String virtualHost = EMPTY; String method = EMPTY; String referer = EMPTY; String userAgent = EMPTY; String logPattern = pattern; if (logPattern.equals("combined")) { virtualHost = request.getServerName(); method = request.getMethod(); referer = request.getHeader("referer"); userAgent = request.getHeader("user-agent"); } synchronized (this) { int numberOfTries = 2; while (numberOfTries>0) { try { open(); ps.setString(1, remoteHost); ps.setString(2, user); ps.setTimestamp(3, new Timestamp(getCurrentTimeMillis())); ps.setString(4, query); ps.setInt(5, status); if(useLongContentLength) { ps.setLong(6, bytes); } else { if (bytes > Integer.MAX_VALUE) { bytes = -1 ; } ps.setInt(6, (int) bytes); } if (logPattern.equals("combined")) { ps.setString(7, virtualHost); ps.setString(8, method); ps.setString(9, referer); ps.setString(10, userAgent); } ps.executeUpdate(); return; } catch (SQLException e) { // Log the problem for posterity container.getLogger().error(sm.getString("jdbcAccessLogValve.exception"), e); // Close the connection so that it gets reopened next time if (conn != null) { close(); } } numberOfTries--; } } }
Example 7
Source File: JDBCAccessLogValve.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void log(Request request, Response response, long time) { if (!getState().isAvailable()) { return; } final String EMPTY = "" ; String remoteHost; if(resolveHosts) { if (requestAttributesEnabled) { Object host = request.getAttribute(REMOTE_HOST_ATTRIBUTE); if (host == null) { remoteHost = request.getRemoteHost(); } else { remoteHost = (String) host; } } else { remoteHost = request.getRemoteHost(); } } else { if (requestAttributesEnabled) { Object addr = request.getAttribute(REMOTE_ADDR_ATTRIBUTE); if (addr == null) { remoteHost = request.getRemoteAddr(); } else { remoteHost = (String) addr; } } else { remoteHost = request.getRemoteAddr(); } } String user = request.getRemoteUser(); String query=request.getRequestURI(); long bytes = response.getBytesWritten(true); if(bytes < 0) { bytes = 0; } int status = response.getStatus(); String virtualHost = EMPTY; String method = EMPTY; String referer = EMPTY; String userAgent = EMPTY; String logPattern = pattern; if (logPattern.equals("combined")) { virtualHost = request.getServerName(); method = request.getMethod(); referer = request.getHeader("referer"); userAgent = request.getHeader("user-agent"); } synchronized (this) { int numberOfTries = 2; while (numberOfTries>0) { try { open(); ps.setString(1, remoteHost); ps.setString(2, user); ps.setTimestamp(3, new Timestamp(getCurrentTimeMillis())); ps.setString(4, query); ps.setInt(5, status); if(useLongContentLength) { ps.setLong(6, bytes); } else { if (bytes > Integer.MAX_VALUE) { bytes = -1 ; } ps.setInt(6, (int) bytes); } if (logPattern.equals("combined")) { ps.setString(7, virtualHost); ps.setString(8, method); ps.setString(9, referer); ps.setString(10, userAgent); } ps.executeUpdate(); return; } catch (SQLException e) { // Log the problem for posterity container.getLogger().error(sm.getString("jdbcAccessLogValve.exception"), e); // Close the connection so that it gets reopened next time if (conn != null) { close(); } } numberOfTries--; } } }
Example 8
Source File: AccessValve.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
@Override public void invoke (Request request, Response response) throws IOException, ServletException { // Case of Valve disabled. if (!isEnable()) { getNext().invoke(request, response); return; } final AccessInformation ai = new AccessInformation(); ai.setConnectionStatus(new PendingConnectionStatus()); // To be sure not to retrieve the same date trough concurrency calls. synchronized (this) { ai.setStartTimestamp(System.nanoTime()); ai.setStartDate (new Date ()); } try { this.doLog(request, response, ai); } finally { Element cached_element = new Element(UUID.randomUUID(), ai); getCache().put(cached_element); try { // Log of the pending request command. if (isUseLogger()) LOGGER.info ("Access " + ai); getNext().invoke(request, response); } catch (Throwable e) { response.addHeader("cause-message", e.getClass().getSimpleName() + " : " + e.getMessage()); //ai.setConnectionStatus(new FailureConnectionStatus(e)); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); //throw e; } finally { ai.setReponseSize(response.getContentLength()); ai.setWrittenResponseSize(response.getContentWritten()); if (response.getStatus()>=400) { String message = RequestUtil.filter(response.getMessage()); if (message==null) { // The cause-message has been inserted into the reponse header // at error handler time. It no message is retrieved in the // standard response, the cause-message is used. message = response.getHeader("cause-message"); } Throwable throwable = null; if (message != null) throwable = new Throwable(message); else throwable = (Throwable) request.getAttribute( RequestDispatcher.ERROR_EXCEPTION); if (throwable==null) throwable = new Throwable(); ai.setConnectionStatus(new FailureConnectionStatus(throwable)); } else ai.setConnectionStatus(new SuccessConnectionStatus()); ai.setEndTimestamp(System.nanoTime()); if ((getPattern()==null) || ai.getRequest().matches(getPattern())) { cached_element.updateUpdateStatistics(); if (isUseLogger()) LOGGER.info ("Access " + ai); } } } }