XmlConfiguration example

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@635 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-08-05 01:05:19 +00:00
parent 05abaec2af
commit eb6c8d5a12
3 changed files with 64 additions and 1 deletions

View File

@ -21,10 +21,13 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.log.Log;
/* ------------------------------------------------------------ */
/**
/** Simple Jetty FileServer.
* This is a simple example of Jetty configured as a FileServer.
*
* File server Usage - java org.eclipse.jetty.server.example.FileServer [ port [
* docroot ]]
*
* @see FileServerXml for the equivalent example done in XML configuration.
* @author gregw
*
*/

View File

@ -0,0 +1,25 @@
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
/* ------------------------------------------------------------ */
/** A Jetty FileServer.
* This server is identical to {@link FileServer}, except that it
* is configured via an {@link XmlConfiguration} config file that
* does the identical work.
* @see http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/example-jetty-embedded/src/main/resources/fileserver.xml
*/
public class FileServerXml
{
public static void main(String[] args) throws Exception
{
Resource fileserver_xml = Resource.newSystemResource("fileserver.xml");
XmlConfiguration configuration = new XmlConfiguration(fileserver_xml.getInputStream());
Server server = (Server)configuration.configure();
server.start();
server.join();
}
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="FileServer" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="port">8080</Set>
</New>
</Arg>
</Call>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.HandlerList">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="directoriesListed">true</Set>
<Set name="welcomeFiles">
<Array type="String"><Item>index.html</Item></Array>
</Set>
<Set name="resourceBase">.</Set>
</New>
</Item>
<Item>
<New class="org.eclipse.jetty.server.handler.DefaultHandler">
</New>
</Item>
</Array>
</Set>
</New>
</Set>
</Configure>