Dashboard > Jetty > ... > Jetty Xml Configuration Syntax Reference > Syntax Reference
Syntax Reference Log In | Sign Up   View a printable version of the current page.

Added by Ludwig D. Laman , last edited by Jesse McConnell on Dec 20, 2007  (view change)
Labels: 
(None)

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Syntax

configure.dtd

This is the document type descriptor which specifies a straightforward mapping of xml elements to the java api.

The first lines in a jetty xml configuration file must reference this dtd as follows:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

Java objects are configured by a sequence of <New>, <Set>, <Put> and <Call> elements. Here is a small example to give you the flavour of it:

<Set name="Test">value</Set> == obj.setTest("value");
<Put  name="Test">value</Put> == obj.put("Test","value");
<Call name="test"><Arg>value</Arg></Call> == obj.test("value");
<New class="com.acme.MyStuff"><Arg/></New> == new com.acme.MyStuff();

Values are coerced to match method arguments on a best effort approach, but explicit types may also be specified.

Jetty xml files are parsed by the org.mortbay.util.XmlConfiguration class using the configure.dtd descriptor.

<Configure> Element

This is the root element that specifies the class of object that is to be configured:

<Configure class="org.mortbay.jetty.Server> . . . </Configure>

Alternatively, if the object already exists and has an id, then it can be referenced in the Configure element like so:

<Configure id="Server" class="org.mortbay.jetty.Server">

The Configure element can contain the New, Set, _Put, Call or Ref elements.

<Set> Element

This element maps to a call to a set method on the current object.  The name and optional type attributes are used to select the set method.  If the name given is xxx, then a setXxx method is used, or the xxx field is used of setXxx cannot be found. 

A Set element can contain value text and/or the value elements Call, New and SystemProperty.  If no value type is specified, then white space is trimmed out of the value.  If it contains multiple value elements they are added as strings before being converted to any specified type.

A Set with a class attribute is treated as a static set method invocation.

<Set name="xyz">
 . . .
</Set>

<Get> Element

This element maps to a call to a get method of field on the current object.  The name attribute is used to select the get method.  If the name given is xxx, then a getXxx method is used, or the xxx field is used of setXxx cannot be found. 

A Get element can contain Set, Put and/or Call elements which act on the object returned by the get call.

<Get name="xyz">
  <Set name="xyzMethod"><New class="org.mortbay.jetty.xyz"/></Set>
</Get>

A Get with a class attribute is treated as a static get method or field.

<Put> Element

This element maps to a call to a put method on the current object, which must implement the Map interface.  The name attribute is used as the put key and the optional type attribute can force the type of  the value. 

A Put element can contain value text and/or the value elements Call, New and SystemProperty.  If no value type is specified, the white space is trimmed out of the value.  If it contains multiple value elements, they are added as strings before being converted to any specified type.

<Put name="admin">admin</Put>

<Call> Element

This element maps to an arbitrary call to a method on the current object.  The name attribute and Arg elements are used to select the method.

A Call element can contain a sequence of Arg elements followed by a sequence of Set, Put and/or Call elements which act on any object returned by the original call:

<Call name="test">
  <Arg>value1</Arg>
  <Set name="Test">Value2</Set>
</Call>

This is equivalent to:

Object o2 = o1.test("value1");
o2.setTest("value2");

A Call with a class attribute is treated as a static call:

<Call class="com.acme.Foo" name="setString">
  <Arg>somestring</Arg>
</Call>

Is equivalent to:

com.acme.Foo.setString("somestring");

<Arg> Element

This element defines a positional argument for the Call element.  The optional type attribute can force the type of the value.

An Arg element can contain value text and/or the value elements Call, New and SystemProperty. If no value type is specified, then white space is trimmed out of the value. If it contains multiple value elements they are added as strings before being converted to any specified type.

<Arg><Ref id="Server"/></Arg>
<Arg>./webapps</Arg>
<Arg>org/mortbay/jetty/webapp/webdefault.xml</Arg>
<Arg type="boolean">True</Arg>
<Arg type="boolean">False</Arg>

The Ref tag here points to a previously created object with an id parameter.

<New> Element

This element allows the creation of a new object as part of a value of a Set, Put or Arg element. The class attribute determines the type of the new object and the contained Arg elements are used to select the constructor for the new object. A New element may have an id parameter which gives a unique name to the object which can be referenced later by Ref elements.

A New element can contain a sequence of Arg elements followed bya sequence of Set, Put and/or Call elements which act on the new object:

<New id="myobject" class="com.acme.MyClass">
  <Arg>value1</Arg><Set name="Test">Value2</Set>
</New>

This is equivalent to:

Object o = new com.acme.MyClass("value1");
o.setTest("value2");

<Ref> Element

This element allows a previously created object to be referenced by unique name.

A Ref element can contain a sequence of Set, Put and/or Call elements which act on the referenced object:

<Ref id="myobject" />
  <Set name="Test">Value2</Set>
</Ref>

Alternatively, the Ref element can be used as the value of an Arg or Set element:

<Set name="someMethod"><Ref id="myobj"/></Set>

<Array> Element

This element allows the creation of a new array as part of a value of a Set, Put or Arg element. The type attribute determines the type of the new array and the contained Item elements are used for each element of the array.

<Array type="java.lang.String">
  <Item>value0</Item>
  <Item><New class="java.lang.String"><Arg>value1</Arg></New></Item>
</Array>

This is equivalent to

String[] a = new String[]{"value0", new String("value1")};

<Map> Element

This element allows the creation of a new HashMap and to populate it with (key,value) pairs.

<Map>
  <Entry>
   <Item>keyName</Item>
   <Item><New class="java.lang.String"><Arg>value1</Arg></New></Item>
  </Entry>
</Map>

This is equivalent to

java.util.Map map = new java.util.HashMap();
map.put("keyName", "value1"};

<Item> Element

This element defines an entry for the Array or Map Entry elements. The optional type attribute can force the type of the value.

An Item element can contain value text and/or the value elements Call, New and SystemProperty. If no value type is specified, then white space is trimmed out of the value. If it contains multiple value elements they are added as strings before being converted to any specified type.

<Item>
  <New class="org.mortbay.jetty.nio.SelectChannelConnector">
    <Set name="port">8080</Set>
    <Set name="maxIdleTime">30000</Set>
    <Set name="Acceptors">10</Set>
 </New>
</Item>

<SystemProperty> Element

This element allows JVM System properties to be retrieved as part of the value of a Set, Put or Arg element.  The name attribute specifies the property name and the optional default argument provides a default value.
   

<SystemProperty name="Test" default="value"/>

This is equivalent to:

System.getProperty("Test","value");
Server server = new Server();XmlConfiguration configuration = new XmlConfiguration(new File("myJetty.xml").toURL());
configuration.configure(server);
server.start();    

I can use the codes above to start the server.

But,the server does not support chinese characters display .The chinese characters are the GET method returned.

how can I do?how can I add these sets below to the codes above?

<SystemProperty name="org.mortbay.util.URI.charset" default="GBK"/> 

I am from China,and my english is poor . If someone don't understand the meanings, I use chinease to describe :

 如何在服务器启动时,URI编码为GBK?

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators