use of org.eclipse.jetty.servlet.ServletHolder in project camel by apache.
the class WebsocketComponentTest method testCreateServlet.
@Test
public void testCreateServlet() throws Exception {
component.createServlet(sync, PATH_SPEC_ONE, servlets, handler);
InOrder inOrder = inOrder(servlet, consumer, sync, servlets, handler);
ArgumentCaptor<WebsocketComponentServlet> servletCaptor = ArgumentCaptor.forClass(WebsocketComponentServlet.class);
inOrder.verify(servlets, times(1)).put(eq(PATH_SPEC_ONE), servletCaptor.capture());
ArgumentCaptor<ServletHolder> holderCaptor = ArgumentCaptor.forClass(ServletHolder.class);
inOrder.verify(handler, times(1)).addServlet(holderCaptor.capture(), eq(PATH_SPEC_ONE));
inOrder.verifyNoMoreInteractions();
assertEquals(servletCaptor.getValue(), holderCaptor.getValue().getServlet());
}
use of org.eclipse.jetty.servlet.ServletHolder in project rest.li by linkedin.
the class HttpServerBuilder method build.
public Server build() {
Server server = new Server();
// HTTP Configuration
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSendXPoweredBy(true);
configuration.setSendServerVersion(true);
configuration.setSendXPoweredBy(false);
configuration.setSendServerVersion(false);
configuration.setSendDateHeader(false);
// HTTP Connector
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(configuration), new HTTP2CServerConnectionFactory(configuration));
http.setIdleTimeout(_idleTimeout);
http.setPort(HTTP_PORT);
server.addConnector(http);
ServletContextHandler handler = new ServletContextHandler(server, "");
handler.addServlet(new ServletHolder(new HttpServlet() {
private static final long serialVersionUID = 0;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
awaitLatch();
readEntity(req.getReader());
addStatus(resp);
addHeader(resp);
addContent(resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
awaitLatch();
readEntity(req.getReader());
addStatus(resp);
addHeader(resp);
addContent(resp);
}
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
awaitLatch();
readEntity(req.getReader());
addStatus(resp);
addHeader(resp);
addContent(resp);
}
private void addStatus(HttpServletResponse resp) throws IOException {
resp.setStatus(_status);
}
private void addHeader(HttpServletResponse resp) throws IOException {
if (_headerSize <= 0) {
return;
}
int valueSize = _headerSize - HEADER_NAME.length();
char[] headerValue = new char[valueSize];
Arrays.fill(headerValue, 'a');
resp.addHeader(HEADER_NAME, new String(headerValue));
}
private void addContent(HttpServletResponse resp) throws IOException {
if (_responseSize <= 0) {
return;
}
char[] content = new char[_responseSize];
Arrays.fill(content, 'a');
resp.getWriter().write(content);
}
private void awaitLatch() {
if (_responseLatch != null) {
try {
_responseLatch.await(RESPONSE_LATCH_TIMEOUT, RESPONSE_LATCH_TIMEUNIT);
} catch (InterruptedException e) {
}
}
}
private void readEntity(BufferedReader reader) throws IOException {
while (true) {
char[] bytes = new char[8192];
int read = reader.read(bytes);
if (read < 0) {
break;
}
}
}
}), "/*");
return server;
}
use of org.eclipse.jetty.servlet.ServletHolder in project rest.li by linkedin.
the class HttpJettyServer method start.
@Override
public void start() throws IOException {
_server = new Server(new QueuedThreadPool(_threadPoolSize));
_server.setConnectors(getConnectors(_server));
ServletContextHandler root = new ServletContextHandler(_server, _contextPath, ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(_servlet), "/*");
try {
_server.start();
} catch (Exception e) {
throw new IOException("Failed to start Jetty", e);
}
}
use of org.eclipse.jetty.servlet.ServletHolder in project v7files by thiloplanz.
the class ServeCommand method main.
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Configuration.checkEndpoints();
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("/");
// WebDAV
{
String[] endpoints = Configuration.getArrayProperty("webdav.endpoints");
for (String endpoint : endpoints) {
ServletHolder servlet = new ServletHolder(new MiltonServlet());
servlet.setInitParameter("webdav.endpoint", endpoint);
servlet.setInitParameter("resource.factory.factory.class", Configuration.getProperty("resource.factory.factory.class"));
handler.addServlet(servlet, endpoint.equals("/") ? "/*" : (endpoint + "/*"));
}
}
// Buckets
{
String[] endpoints = Configuration.getArrayProperty("buckets.endpoints");
for (String endpoint : endpoints) {
ServletHolder servlet = new ServletHolder(new BucketsServlet(Configuration.getEndpointProperties(endpoint)));
handler.addServlet(servlet, endpoint.equals("/") ? "/*" : (endpoint + "/*"));
}
}
int port = Integer.parseInt(Configuration.getProperty("http.port"));
final Server server = new Server(port);
server.setHandler(handler);
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
System.err.println("failed to start HTTP server");
try {
server.stop();
} catch (Exception f) {
f.printStackTrace();
System.exit(1);
}
}
try {
System.in.read();
server.stop();
} catch (IOException e) {
System.err.println("STDIN unavailable, continue running in daemon mode");
try {
synchronized (args) {
// forever
args.wait();
}
} catch (InterruptedException e1) {
}
}
}
use of org.eclipse.jetty.servlet.ServletHolder in project gocd by gocd.
the class FakeGoServer method addFakeArtifactiPublisherServlet.
private static void addFakeArtifactiPublisherServlet(WebAppContext wac) {
ServletHolder holder = new ServletHolder();
holder.setServlet(new FakeArtifactPublisherServlet());
wac.addServlet(holder, "/remoting/repository/*");
wac.addServlet(holder, "/remoting/files/*");
}
Aggregations