use of org.eclipse.jetty.server.Response in project camel by apache.
the class JettyHttpComponent method createServer.
protected Server createServer() {
Server s = null;
ThreadPool tp = threadPool;
QueuedThreadPool qtp = null;
// configure thread pool if min/max given
if (minThreads != null || maxThreads != null) {
if (getThreadPool() != null) {
throw new IllegalArgumentException("You cannot configure both minThreads/maxThreads and a custom threadPool on JettyHttpComponent: " + this);
}
qtp = new QueuedThreadPool();
if (minThreads != null) {
qtp.setMinThreads(minThreads.intValue());
}
if (maxThreads != null) {
qtp.setMaxThreads(maxThreads.intValue());
}
tp = qtp;
}
if (tp != null) {
try {
if (!Server.getVersion().startsWith("8")) {
s = Server.class.getConstructor(ThreadPool.class).newInstance(tp);
} else {
s = new Server();
if (isEnableJmx()) {
enableJmx(s);
}
Server.class.getMethod("setThreadPool", ThreadPool.class).invoke(s, tp);
}
} catch (Exception e) {
//ignore
}
}
if (s == null) {
s = new Server();
}
if (qtp != null) {
// let the thread names indicate they are from the server
qtp.setName("CamelJettyServer(" + ObjectHelper.getIdentityHashCode(s) + ")");
try {
qtp.start();
} catch (Exception e) {
throw new RuntimeCamelException("Error starting JettyServer thread pool: " + qtp, e);
}
}
ContextHandlerCollection collection = new ContextHandlerCollection();
s.setHandler(collection);
// setup the error handler if it set to Jetty component
if (getErrorHandler() != null) {
s.addBean(getErrorHandler());
} else if (!Server.getVersion().startsWith("8")) {
//need an error handler that won't leak information about the exception
//back to the client.
ErrorHandler eh = new ErrorHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
String msg = HttpStatus.getMessage(response.getStatus());
request.setAttribute(RequestDispatcher.ERROR_MESSAGE, msg);
if (response instanceof Response) {
//need to use the deprecated method to support compiling with Jetty 8
((Response) response).setStatus(response.getStatus(), msg);
}
super.handle(target, baseRequest, request, response);
}
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException {
super.writeErrorPage(request, writer, code, message, false);
}
};
s.addBean(eh, false);
}
return s;
}
use of org.eclipse.jetty.server.Response in project jetty.project by eclipse.
the class StatisticsHandler method updateResponse.
protected void updateResponse(Request request) {
Response response = request.getResponse();
if (request.isHandled()) {
switch(response.getStatus() / 100) {
case 1:
_responses1xx.increment();
break;
case 2:
_responses2xx.increment();
break;
case 3:
_responses3xx.increment();
break;
case 4:
_responses4xx.increment();
break;
case 5:
_responses5xx.increment();
break;
default:
break;
}
} else
// will fall through to not found handler
_responses4xx.increment();
_responsesTotalBytes.add(response.getContentCount());
}
use of org.eclipse.jetty.server.Response in project jetty.project by eclipse.
the class DebugHandler method handle.
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
*/
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
final Response base_response = baseRequest.getResponse();
final Thread thread = Thread.currentThread();
final String old_name = thread.getName();
boolean suspend = false;
boolean retry = false;
String name = (String) request.getAttribute("org.eclipse.jetty.thread.name");
if (name == null)
name = old_name + ":" + baseRequest.getHttpURI();
else
retry = true;
String ex = null;
try {
if (retry)
print(name, "RESUME");
else
print(name, "REQUEST " + baseRequest.getRemoteAddr() + " " + request.getMethod() + " " + baseRequest.getHeader("Cookie") + "; " + baseRequest.getHeader("User-Agent"));
thread.setName(name);
getHandler().handle(target, baseRequest, request, response);
} catch (IOException ioe) {
ex = ioe.toString();
throw ioe;
} catch (ServletException se) {
ex = se.toString() + ":" + se.getCause();
throw se;
} catch (RuntimeException rte) {
ex = rte.toString();
throw rte;
} catch (Error e) {
ex = e.toString();
throw e;
} finally {
thread.setName(old_name);
suspend = baseRequest.getHttpChannelState().isSuspended();
if (suspend) {
request.setAttribute("org.eclipse.jetty.thread.name", name);
print(name, "SUSPEND");
} else
print(name, "RESPONSE " + base_response.getStatus() + (ex == null ? "" : ("/" + ex)) + " " + base_response.getContentType());
}
}
use of org.eclipse.jetty.server.Response in project jetty.project by eclipse.
the class ScopedHandlerTest method testDouble.
@Test
public void testDouble() throws Exception {
Request request = new Request(null, null);
Response response = new Response(null, null);
TestHandler handler0 = new TestHandler("0");
OtherHandler handlerA = new OtherHandler("A");
TestHandler handler1 = new TestHandler("1");
OtherHandler handlerB = new OtherHandler("B");
handler0.setServer(new Server());
handlerA.setServer(handler0.getServer());
handler1.setServer(handler0.getServer());
handlerB.setServer(handler0.getServer());
handler0.setHandler(handlerA);
handlerA.setHandler(handler1);
handler1.setHandler(handlerB);
handler0.start();
handler0.handle("target", request, request, response);
handler0.stop();
String history = _history.toString();
assertEquals(">S0>S1>W0>HA>W1>HB<HB<W1<HA<W0<S1<S0", history);
}
use of org.eclipse.jetty.server.Response in project jetty.project by eclipse.
the class ScopedHandlerTest method testTriple.
@Test
public void testTriple() throws Exception {
Request request = new Request(null, null);
Response response = new Response(null, null);
TestHandler handler0 = new TestHandler("0");
OtherHandler handlerA = new OtherHandler("A");
TestHandler handler1 = new TestHandler("1");
OtherHandler handlerB = new OtherHandler("B");
TestHandler handler2 = new TestHandler("2");
OtherHandler handlerC = new OtherHandler("C");
handler0.setServer(new Server());
handlerA.setServer(handler0.getServer());
handler1.setServer(handler0.getServer());
handlerB.setServer(handler0.getServer());
handler2.setServer(handler0.getServer());
handlerC.setServer(handler0.getServer());
handler0.setHandler(handlerA);
handlerA.setHandler(handler1);
handler1.setHandler(handlerB);
handlerB.setHandler(handler2);
handler2.setHandler(handlerC);
handler0.start();
handler0.handle("target", request, request, response);
handler0.stop();
String history = _history.toString();
assertEquals(">S0>S1>S2>W0>HA>W1>HB>W2>HC<HC<W2<HB<W1<HA<W0<S2<S1<S0", history);
}
Aggregations