本文整理汇总了Java中org.eclipse.jetty.util.resource.ResourceCollection类的典型用法代码示例。如果您正苦于以下问题:Java ResourceCollection类的具体用法?Java ResourceCollection怎么用?Java ResourceCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceCollection类属于org.eclipse.jetty.util.resource包,在下文中一共展示了ResourceCollection类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customize
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
@Override
public void customize(Server server) {
Handler[] childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class);
final WebAppContext webAppContext = (WebAppContext) childHandlersByClass[0];
try {
ClassPathResource classPathResource = new ClassPathResource(this.jettyProperties.getClassPathResource());
webAppContext.setBaseResource(new ResourceCollection(classPathResource.getURI().toString()));
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
webAppContext.setClassLoader(new URLClassLoader(new URL[0], this.getClass().getClassLoader()));
return null;
}
});
log.info("Setting Jetty classLoader to {} directory", this.jettyProperties.getClassPathResource());
}
catch (IOException exception) {
log.error("Unable to configure Jetty classLoader to {} directory {}", this.jettyProperties.getClassPathResource(), exception.getMessage());
throw new RuntimeException(exception);
}
}
示例2: createDocsWebApp
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
private ContextHandler createDocsWebApp(final String contextPath) throws IOException {
final ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
// load the docs directory
final File docsDir = Paths.get("docs").toRealPath().toFile();
final Resource docsResource = Resource.newResource(docsDir);
// load the rest documentation
final File webApiDocsDir = new File(webApiContext.getTempDirectory(), "webapp/docs");
if (!webApiDocsDir.exists()) {
final boolean made = webApiDocsDir.mkdirs();
if (!made) {
throw new RuntimeException(webApiDocsDir.getAbsolutePath() + " could not be created");
}
}
final Resource webApiDocsResource = Resource.newResource(webApiDocsDir);
// create resources for both docs locations
final ResourceCollection resources = new ResourceCollection(docsResource, webApiDocsResource);
resourceHandler.setBaseResource(resources);
// create the context handler
final ContextHandler handler = new ContextHandler(contextPath);
handler.setHandler(resourceHandler);
logger.info("Loading documents web app with context path set to " + contextPath);
return handler;
}
示例3: addClassPath
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
/**
* @param resource Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
*/
public void addClassPath(Resource resource)
throws IOException {
if (resource instanceof ResourceCollection) {
for (Resource r : ((ResourceCollection) resource).getResources())
addClassPath(r);
} else {
addClassPath(resource.toString());
}
}
示例4: sendDirectory
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
protected void sendDirectory(HttpServletRequest request, HttpServletResponse response, Resource resource, String pathInContext)
throws IOException
{
if (!_dirAllowed)
{
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
byte[] data = null;
String base = URIUtil.addPaths(request.getRequestURI(), URIUtil.SLASH);
//If the DefaultServlet has a resource base set, use it
if (_resourceBase != null)
{
// handle ResourceCollection
if (_resourceBase instanceof ResourceCollection)
resource = _resourceBase.addPath(pathInContext);
}
//Otherwise, try using the resource base of its enclosing context handler
else if (_contextHandler.getBaseResource() instanceof ResourceCollection)
resource = _contextHandler.getBaseResource().addPath(pathInContext);
String dir = resource.getListHTML(base, pathInContext.length() > 1);
if (dir == null)
{
response.sendError(HttpServletResponse.SC_FORBIDDEN, "No directory");
return;
}
data = dir.getBytes("utf-8");
response.setContentType("text/html;charset=utf-8");
response.setContentLength(data.length);
response.getOutputStream().write(data);
}
示例5: getStaticResources
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
@Override
public ResourceCollection getStaticResources() {
if (enableQuickstartPage) {
return new ResourceCollection(Resource.newClassPathResource("/io/confluent/ksql/rest/"));
} else {
return super.getStaticResources();
}
}
示例6: EmbeddedJettyHttpServer
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
public EmbeddedJettyHttpServer() {
super(8123);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(new ResourceCollection(new String[]{"src/main/webapp", "src/main/resources"}));
context.setParentLoaderPriority(true);
setHandler(context);
}
示例7: createServer
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
protected Server createServer() {
Server server = new Server(getPort());
setBaseDirSystemProperty();
if (useWebAppContext()) {
File tmpDir = new File(System.getProperty("basedir") + "/target/jetty-tmp");
tmpDir.mkdirs();
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath(getContextName());
String[] fullRelativeWebappRoots = new String[this.relativeWebappRoots.size()];
for (int i = 0; i < this.relativeWebappRoots.size(); i++) {
String fullRelativeWebappRoot = this.relativeWebappRoots.get(i);
fullRelativeWebappRoots[i] = System.getProperty("basedir") + fullRelativeWebappRoot;
if (LOG.isInfoEnabled()) {
LOG.info("WebAppRoot = " + fullRelativeWebappRoots[i]);
}
}
webAppContext.setBaseResource(new ResourceCollection(fullRelativeWebappRoots));
webAppContext.setTempDirectory(tmpDir);
webAppContext.setAttribute(JETTYSERVER_TESTMODE_ATTRIB, String.valueOf(isTestMode()));
context = webAppContext;
server.setHandler(context);
} else {
ServletContextHandler root = new ServletContextHandler(server,"/",ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(servletClass), getContextName());
root.setAttribute(JETTYSERVER_TESTMODE_ATTRIB, String.valueOf(isTestMode()));
context = root;
}
return server;
}
示例8: startWebSocketServer
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
public void startWebSocketServer(final Injector injector) {
httpServer = new Server();
List<Connector> connectors = getSelectChannelConnectors(httpAddresses);
if (connectors.isEmpty()) {
LOG.severe("No valid http end point address provided!");
}
for (Connector connector : connectors) {
httpServer.addConnector(connector);
}
final WebAppContext context = new WebAppContext();
context.setParentLoaderPriority(true);
if (jettySessionManager != null) {
// This disables JSessionIDs in URLs redirects
// see: http://stackoverflow.com/questions/7727534/how-do-you-disable-jsessionid-for-jetty-running-with-the-eclipse-jetty-maven-plu
// and: http://jira.codehaus.org/browse/JETTY-467?focusedCommentId=114884&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-114884
jettySessionManager.setSessionIdPathParameterName(null);
context.getSessionHandler().setSessionManager(jettySessionManager);
}
final ResourceCollection resources = new ResourceCollection(resourceBases);
context.setBaseResource(resources);
addWebSocketServlets();
try {
final Injector parentInjector = injector;
final ServletModule servletModule = getServletModule(parentInjector);
ServletContextListener contextListener = new GuiceServletContextListener() {
private final Injector childInjector = parentInjector.createChildInjector(servletModule);
@Override
protected Injector getInjector() {
return childInjector;
}
};
context.addEventListener(contextListener);
context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
context.addFilter(GzipFilter.class, "/webclient/*", EnumSet.allOf(DispatcherType.class));
httpServer.setHandler(context);
httpServer.start();
restoreSessions();
} catch (Exception e) { // yes, .start() throws "Exception"
LOG.severe("Fatal error starting http server.", e);
return;
}
LOG.fine("WebSocket server running.");
}
示例9: main
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server();
// traditional blocking IO and threading model, used if NIO not available
// SocketConnector connector = new SocketConnector();
// efficient NIO buffers with a non-blocking threading model, required for WebSockets
SelectChannelConnector connector = new SelectChannelConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(3600000);
connector.setSoLingerTime(-1);
connector.setPort(8080);
server.addConnector(connector);
/*
Resource keystore = Resource.newClassPathResource("/keystore");
if (keystore != null && keystore.exists()) {
connector.setConfidentialPort(8443);
SslContextFactory factory = new SslContextFactory();
factory.setKeyStoreResource(keystore);
factory.setKeyStorePassword("jettyjetty");
factory.setTrustStoreResource(keystore);
factory.setKeyManagerPassword("jettyjetty");
SslSocketConnector sslConnector = new SslSocketConnector(factory);
sslConnector.setMaxIdleTime(3600000);
sslConnector.setPort(8443);
sslConnector.setAcceptors(4);
server.addConnector(sslConnector);
System.out.println("SSL access to the quickstart has been enabled on port 8443");
System.out.println("You can access the application using SSL on https://localhost:8443");
System.out.println();
}
*/
String includeJarPattern =
".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$";
ResourceCollection resources = new ResourceCollection(new String[] {
"src/main/webapp", "target/gwt-webapp"
});
WebAppContext webCtx = new WebAppContext();
webCtx.setServer(server);
webCtx.setContextPath("/");
// webCtx.setDescriptor("src/test/resources/web/test-web.xml");
webCtx.setBaseResource(resources);
webCtx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
includeJarPattern);
server.setHandler(webCtx);
// BrowserListener gwtBrowserListener = new BrowserListener(null, "0.0.0.0",
// 9997, null);
try {
System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
server.start();
System.in.read();
System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
示例10: getStaticResources
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
@Override
protected ResourceCollection getStaticResources() {
return new ResourceCollection(Resource.newClassPathResource("static"));
}
示例11: startWebSocketServer
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
public void startWebSocketServer(final Injector injector) {
httpServer = new Server();
List<Connector> connectors = getSelectChannelConnectors(httpAddresses);
if (connectors.isEmpty()) {
LOG.severe("No valid http end point address provided!");
}
for (Connector connector : connectors) {
httpServer.addConnector(connector);
}
final WebAppContext context = new WebAppContext();
context.setParentLoaderPriority(true);
if (jettySessionManager != null) {
// This disables JSessionIDs in URLs redirects
// see: http://stackoverflow.com/questions/7727534/how-do-you-disable-jsessionid-for-jetty-running-with-the-eclipse-jetty-maven-plu
// and: http://jira.codehaus.org/browse/JETTY-467?focusedCommentId=114884&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-114884
jettySessionManager.setSessionIdPathParameterName(null);
context.getSessionHandler().setSessionManager(jettySessionManager);
}
final ResourceCollection resources = new ResourceCollection(resourceBases);
context.setBaseResource(resources);
addWebSocketServlets();
try {
final ServletModule servletModule = getServletModule();
ServletContextListener contextListener = new GuiceServletContextListener() {
private final Injector childInjector = injector.createChildInjector(servletModule);
@Override
protected Injector getInjector() {
return childInjector;
}
};
context.addEventListener(contextListener);
context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
context.addFilter(GzipFilter.class, "/webclient/*", EnumSet.allOf(DispatcherType.class));
httpServer.setHandler(context);
httpServer.start();
restoreSessions();
} catch (Exception e) { // yes, .start() throws "Exception"
LOG.severe("Fatal error starting http server.", e);
return;
}
LOG.fine("WebSocket server running.");
}
示例12: main
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(3600000);
connector.setSoLingerTime(-1);
connector.setPort(8080);
server.addConnector(connector);
Resource keystore = Resource.newClassPathResource("/keystore");
if (keystore != null && keystore.exists()) {
// if a keystore for a SSL certificate is available, start a SSL
// connector on port 8443.
// By default, the quickstart comes with a Apache Wicket Quickstart
// Certificate that expires about half way september 2021. Do not
// use this certificate anywhere important as the passwords are
// available in the source.
connector.setConfidentialPort(8443);
SslContextFactory factory = new SslContextFactory();
factory.setKeyStoreResource(keystore);
factory.setKeyStorePassword("jettyjetty");
factory.setTrustStoreResource(keystore);
factory.setKeyManagerPassword("jettyjetty");
SslSocketConnector sslConnector = new SslSocketConnector(factory);
sslConnector.setMaxIdleTime(3600000);
sslConnector.setPort(8443);
sslConnector.setAcceptors(4);
server.addConnector(sslConnector);
System.out.println("SSL access to the quickstart has been enabled on port 8443");
System.out.println("You can access the application using SSL on https://localhost:8443");
System.out.println();
}
String includeJarPattern =
".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$";
// includeJarPattern =
// ".*/org\\.apache\\.taglibs\\.standard\\.glassfish-1\\.2\\.0\\.v201112081803\\.jar";
ResourceCollection resources = new ResourceCollection(new String[]{
"src/main/webapp", "target/webapp",
});
WebAppContext webCtx = new WebAppContext();
webCtx.setServer(server);
webCtx.setContextPath("/");
webCtx.setDescriptor("src/test/resources/web/test-web.xml");
webCtx.setBaseResource(resources);
webCtx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
includeJarPattern);
server.setHandler(webCtx);
// BrowserListener gwtBrowserListener = new BrowserListener(null, "0.0.0.0", 9997, null);
try {
System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
server.start();
System.in.read();
System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
示例13: getStaticResources
import org.eclipse.jetty.util.resource.ResourceCollection; //导入依赖的package包/类
/**
* Returns a list of static resources to serve using the default servlet.
*
* <p>For example, static files can be served from class loader resources by returning
* {@code
* new ResourceCollection(Resource.newClassPathResource("static"));
* }
*
* <p>For those resources to get served, it is necessary to add a static resources property to the
* config in @link{{@link #setupResources(Configurable, RestConfig)}}, e.g. using something like
* {@code
* config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(static/.*|.*\\.html|)");
* }
*
* @return static resource collection
*/
protected ResourceCollection getStaticResources() {
return null;
}