Skip to content

Commit

Permalink
jsp errorPage
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.caucho.com/resin/trunk@8503 9c94448d-38f1-0310-a231-d98308ff1ebf
  • Loading branch information
ferg committed Oct 19, 2011
1 parent 75fdd46 commit 899d575
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 25 deletions.
5 changes: 3 additions & 2 deletions modules/resin/src/com/caucho/jsp/PageContextImpl.java
Expand Up @@ -1263,8 +1263,8 @@ else if (e instanceof DisplayableException) {
}
}

// jsp/01ck
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
// jsp/01ck, server/02ei
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (FileNotFoundException e2) {
log.log(Level.WARNING, e.toString(), e2);
throw new ServletException(L.l("`{0}' is an unknown error page. The JSP errorPage directive must refer to a valid URL relative to the current web-app.",
Expand Down Expand Up @@ -1305,6 +1305,7 @@ else if (e instanceof Error) {
/**
* Returns the error data
*/
@Override
public ErrorData getErrorData()
{
String uri = (String) getCauchoRequest().getAttribute(RequestDispatcher.ERROR_REQUEST_URI);
Expand Down
96 changes: 88 additions & 8 deletions modules/resin/src/com/caucho/server/http/AbstractHttpResponse.java
Expand Up @@ -42,6 +42,8 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.caucho.env.meter.CountSensor;
import com.caucho.env.meter.MeterService;
import com.caucho.server.dispatch.BadRequestException;
import com.caucho.server.session.CookieImpl;
import com.caucho.server.session.SessionImpl;
Expand All @@ -58,9 +60,32 @@
* response stream.
*/
abstract public class AbstractHttpResponse {
static final protected Logger log
private static final Logger log
= Logger.getLogger(AbstractHttpResponse.class.getName());
static final L10N L = new L10N(AbstractHttpResponse.class);
private static final L10N L = new L10N(AbstractHttpResponse.class);

private static final CountSensor _statusXxxSensor
= MeterService.createCountMeter("Resin|HTTP|xxx");
private static final CountSensor _status2xxSensor
= MeterService.createCountMeter("Resin|HTTP|2xx");
private static final CountSensor _status200Sensor
= MeterService.createCountMeter("Resin|HTTP|200");
private static final CountSensor _status3xxSensor
= MeterService.createCountMeter("Resin|HTTP|3xx");
private static final CountSensor _status304Sensor
= MeterService.createCountMeter("Resin|HTTP|304");
private static final CountSensor _status4xxSensor
= MeterService.createCountMeter("Resin|HTTP|4xx");
private static final CountSensor _status400Sensor
= MeterService.createCountMeter("Resin|HTTP|400");
private static final CountSensor _status404Sensor
= MeterService.createCountMeter("Resin|HTTP|404");
private static final CountSensor _status5xxSensor
= MeterService.createCountMeter("Resin|HTTP|5xx");
private static final CountSensor _status500Sensor
= MeterService.createCountMeter("Resin|HTTP|500");
private static final CountSensor _status503Sensor
= MeterService.createCountMeter("Resin|HTTP|503");

protected static final CaseInsensitiveIntMap _headerCodes;
protected static final int HEADER_CACHE_CONTROL = 1;
Expand Down Expand Up @@ -799,12 +824,7 @@ public final boolean writeHeaders(int length)

int statusCode = res.getStatus();

int majorCode = statusCode / 100;

if (webApp != null) {
if (majorCode == 5)
webApp.addStatus500();
}
addSensorCount(statusCode, webApp);

if (req != null) {
HttpSession session = req.getMemorySession();
Expand All @@ -816,7 +836,67 @@ public final boolean writeHeaders(int length)

return writeHeadersInt(length, isHead);
}

private void addSensorCount(int statusCode, WebApp webApp)
{
int majorCode = statusCode / 100;

switch (majorCode) {
case 2:
switch (statusCode) {
case 200:
_status200Sensor.start();
break;
default:
_status2xxSensor.start();
break;
}
break;
case 3:
switch (statusCode) {
case 304:
_status304Sensor.start();
break;
default:
_status3xxSensor.start();
break;
}
break;
case 4:
switch (statusCode) {
case 400:
_status400Sensor.start();
break;
case 404:
_status404Sensor.start();
break;
default:
_status4xxSensor.start();
break;
}
break;
case 5:
if (webApp != null)
webApp.addStatus500();

switch (statusCode) {
case 500:
_status500Sensor.start();
break;
case 503:
_status503Sensor.start();
break;
default:
_status5xxSensor.start();
break;
}
break;
default:
_statusXxxSensor.start();
break;
}
}

abstract protected boolean writeHeadersInt(int length,
boolean isHead)
throws IOException;
Expand Down
34 changes: 20 additions & 14 deletions modules/resin/src/com/caucho/server/http/HttpResponse.java
Expand Up @@ -32,10 +32,13 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import com.caucho.env.meter.CountSensor;
import com.caucho.env.meter.MeterService;
import com.caucho.network.listen.TcpSocketLink;
import com.caucho.server.cluster.Server;
import com.caucho.server.webapp.WebApp;
Expand All @@ -45,20 +48,23 @@

public class HttpResponse extends AbstractHttpResponse
{
static final byte []_http10ok = "HTTP/1.0 200 OK".getBytes();
static final byte []_http11ok = "HTTP/1.1 200 OK".getBytes();
static final byte []_contentLengthBytes = "\r\nContent-Length: ".getBytes();
static final byte []_contentTypeBytes = "\r\nContent-Type: ".getBytes();
static final byte []_textHtmlBytes = "\r\nContent-Type: text/html".getBytes();
static final byte []_charsetBytes = "; charset=".getBytes();
static final byte []_textHtmlLatin1Bytes = "\r\nContent-Type: text/html; charset=iso-8859-1".getBytes();

static final byte []_connectionCloseBytes = "\r\nConnection: close".getBytes();

final byte []_resinServerBytes;

static final char []_connectionCb = "Connection".toCharArray();
static final CharBuffer _closeCb = new CharBuffer("Close");
private static final Logger log
= Logger.getLogger(HttpResponse.class.getName());

private static final byte []_http10ok = "HTTP/1.0 200 OK".getBytes();
private static final byte []_http11ok = "HTTP/1.1 200 OK".getBytes();
private static final byte []_contentLengthBytes = "\r\nContent-Length: ".getBytes();
private static final byte []_contentTypeBytes = "\r\nContent-Type: ".getBytes();
private static final byte []_textHtmlBytes = "\r\nContent-Type: text/html".getBytes();
private static final byte []_charsetBytes = "; charset=".getBytes();
private static final byte []_textHtmlLatin1Bytes = "\r\nContent-Type: text/html; charset=iso-8859-1".getBytes();

private static final byte []_connectionCloseBytes = "\r\nConnection: close".getBytes();

private static final char []_connectionCb = "Connection".toCharArray();
private static final CharBuffer _closeCb = new CharBuffer("Close");

private final byte []_resinServerBytes;

private final HttpRequest _request;

Expand Down
Expand Up @@ -1584,6 +1584,7 @@ public AbstractHttpResponse getAbstractHttpResponse()
return _response;
}

@Override
public int getStatus()
{
return _status;
Expand Down
Expand Up @@ -50,6 +50,8 @@

import com.caucho.VersionFactory;
import com.caucho.config.LineException;
import com.caucho.env.meter.MeterService;
import com.caucho.env.meter.TimeSensor;
import com.caucho.env.shutdown.ExitCode;
import com.caucho.env.shutdown.ShutdownSystem;
import com.caucho.i18n.CharacterEncoding;
Expand Down Expand Up @@ -89,7 +91,7 @@ public class ErrorPageManager {
public static String JSP_EXCEPTION = "javax.servlet.jsp.jspException";

public static String SHUTDOWN = "com.caucho.shutdown";

private final Server _server;
private final Host _host;
private final WebApp _webApp;
Expand Down

0 comments on commit 899d575

Please sign in to comment.