use of org.eclipse.jetty.servlet.ServletContextHandler in project jena by apache.
the class SPARQLServer method buildServer.
// Later : private and in constructor.
private ServletContextHandler buildServer(String jettyConfig, boolean enableCompression) {
if (jettyConfig != null) {
// --jetty-config=jetty-fuseki.xml
// for detailed configuration of the server using Jetty features.
server = configServer(jettyConfig);
} else
server = defaultServerConfig(serverConfig.port, serverConfig.loopback);
// Keep the server to a maximum number of threads.
// server.setThreadPool(new QueuedThreadPool(ThreadPoolSize)) ;
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setErrorHandler(new FusekiErrorHandler());
context.addEventListener(new FusekiServletContextListener(this));
// Increase form size.
context.getServletContext().getContextHandler().setMaxFormContentSize(10 * 1000 * 1000);
// Wire up authentication if appropriate
if (jettyConfig == null && serverConfig.authConfigFile != null) {
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "fuseki" });
constraint.setAuthenticate(true);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setPathSpec("/*");
IdentityService identService = new DefaultIdentityService();
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.addConstraintMapping(mapping);
securityHandler.setIdentityService(identService);
HashLoginService loginService = new HashLoginService("Fuseki Authentication", serverConfig.authConfigFile);
loginService.setIdentityService(identService);
securityHandler.setLoginService(loginService);
securityHandler.setAuthenticator(new BasicAuthenticator());
context.setSecurityHandler(securityHandler);
serverLog.debug("Basic Auth Configuration = " + serverConfig.authConfigFile);
}
// Wire up context handler to server
server.setHandler(context);
// Constants. Add RDF types.
MimeTypes mt = new MimeTypes();
mt.addMimeMapping("rdf", WebContent.contentTypeRDFXML + ";charset=utf-8");
mt.addMimeMapping("ttl", WebContent.contentTypeTurtle + ";charset=utf-8");
mt.addMimeMapping("nt", WebContent.contentTypeNTriples + ";charset=ascii");
mt.addMimeMapping("nq", WebContent.contentTypeNQuads + ";charset=ascii");
mt.addMimeMapping("trig", WebContent.contentTypeTriG + ";charset=utf-8");
// mt.addMimeMapping("tpl", "text/html;charset=utf-8") ;
context.setMimeTypes(mt);
server.setHandler(context);
serverLog.debug("Pages = " + serverConfig.pages);
boolean installManager = true;
boolean installServices = true;
String validationRoot = "/validate";
if (installManager || installServices) {
// TODO Respect port.
if (serverConfig.pagesPort != serverConfig.port)
serverLog.warn("Not supported yet - pages on a different port to services");
if (serverConfig.pages != null) {
if (!FileOps.exists(serverConfig.pages))
serverLog.warn("No pages directory - " + serverConfig.pages);
String base = serverConfig.pages;
Map<String, Object> data = new HashMap<>();
data.put("mgt", new MgtFunctions());
SimpleVelocityServlet templateEngine = new SimpleVelocityServlet(base, data);
addServlet(context, templateEngine, "*.tpl", false);
}
}
if (installManager) {
// Action when control panel selects a dataset.
HttpServlet datasetChooser = new ActionDataset();
addServlet(context, datasetChooser, PageNames.actionDatasetNames, false);
}
if (installServices) {
// Validators
HttpServlet validateQuery = new QueryValidator();
HttpServlet validateUpdate = new UpdateValidator();
HttpServlet validateData = new DataValidator();
HttpServlet validateIRI = new IRIValidator();
HttpServlet dumpService = new DumpServlet();
HttpServlet generalQueryService = new SPARQL_QueryGeneral();
addServlet(context, validateQuery, validationRoot + "/query", false);
addServlet(context, validateUpdate, validationRoot + "/update", false);
addServlet(context, validateData, validationRoot + "/data", false);
addServlet(context, validateIRI, validationRoot + "/iri", false);
// general query processor.
addServlet(context, generalQueryService, HttpNames.ServiceGeneralQuery, enableCompression);
}
if (installManager || installServices) {
String[] files = { "fuseki.html", "index.html" };
context.setWelcomeFiles(files);
addContent(context, "/", serverConfig.pages);
}
return context;
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project jena by apache.
the class ManagementServer method createManagementServer.
public static Server createManagementServer(int mgtPort) {
Fuseki.serverLog.info("Adding management functions");
// Separate Jetty server
Server server = new Server();
// BlockingChannelConnector bcConnector = new BlockingChannelConnector() ;
// bcConnector.setUseDirectBuffers(false) ;
// Connector connector = bcConnector ;
Connector connector = new SelectChannelConnector();
// Ignore idle time.
// If set, then if this goes off, it keeps going off and you get a lot of log messages.
// Jetty outputs a lot of messages if this goes off.
connector.setMaxIdleTime(0);
connector.setPort(mgtPort);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setErrorHandler(new FusekiErrorHandler());
server.setHandler(context);
// Add the server control servlet
addServlet(context, new MgtCmdServlet(), "/mgt");
addServlet(context, new DumpServlet(), "/dump");
addServlet(context, new StatsServlet(), "/stats");
addServlet(context, new PingServlet(), "/ping");
return server;
// Old plan
// // Development : server control panel.
// addServlet(context, new ServerServlet(), "/server") ;
// addServlet(context, new ActionBackup(), "/backup") ;
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project sling by apache.
the class VirtualInstance method startJetty.
public synchronized void startJetty() throws Throwable {
if (jettyServer != null) {
return;
}
servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
servletContext.setContextPath("/");
TopologyConnectorServlet servlet = new TopologyConnectorServlet();
PrivateAccessor.setField(servlet, "config", config);
PrivateAccessor.setField(servlet, "clusterViewService", clusterViewService);
PrivateAccessor.setField(servlet, "announcementRegistry", announcementRegistry);
Mockery context = new JUnit4Mockery();
final HttpService httpService = context.mock(HttpService.class);
context.checking(new Expectations() {
{
allowing(httpService).registerServlet(with(any(String.class)), with(any(Servlet.class)), with(any(Dictionary.class)), with(any(HttpContext.class)));
}
});
PrivateAccessor.setField(servlet, "httpService", httpService);
ComponentContext cc = null;
PrivateAccessor.invoke(servlet, "activate", new Class[] { ComponentContext.class }, new Object[] { cc });
ServletHolder holder = new ServletHolder(servlet);
servletContext.addServlet(holder, "/system/console/topology/*");
jettyServer = new Server();
jettyServer.setHandler(servletContext);
Connector connector = new SelectChannelConnector();
jettyServer.setConnectors(new Connector[] { connector });
jettyServer.start();
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project spring-framework by spring-projects.
the class JettyHttpServer method initServer.
@Override
protected void initServer() throws Exception {
this.jettyServer = new Server();
ServletHttpHandlerAdapter servlet = createServletAdapter();
ServletHolder servletHolder = new ServletHolder(servlet);
this.contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
this.contextHandler.addServlet(servletHolder, "/");
this.contextHandler.start();
ServerConnector connector = new ServerConnector(this.jettyServer);
connector.setHost(getHost());
connector.setPort(getPort());
this.jettyServer.addConnector(connector);
}
use of org.eclipse.jetty.servlet.ServletContextHandler 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;
}
Aggregations