# Apache Juneau {@property juneauVersion} Documentation

Apache Juneau™ is a single cohesive Java ecosystem consisting of the following parts:

Group | Component | Description
--- | --- | ---
Juneau Core | juneau-marshall | A universal toolkit for marshalling POJOs to a wide variety of content types using a common framework with no external library dependencies.
juneau-marshall-rdf | Extended marshalling support for RDF languages.
juneau-dto | A variety of predefined DTOs for serializing and parsing languages such as HTML5, Swagger and ATOM.
juneau-config | A sophisticated configuration file API.
Juneau REST | juneau-rest-server | A universal REST server API for creating Swagger-based self-documenting REST interfaces using POJOs, simply deployed as one or more top-level servlets in any Servlet 3.1.0+ container.
juneau-rest-server-springboot | Spring boot integration support.
juneau-rest-server-jaxrs | JAX/RS integration support.
juneau-rest-client | A universal REST client API for interacting with Juneau or 3rd-party REST interfaces using POJOs and proxy interfaces.
juneau-rest-mock | Mocking APIs for server-less end-to-end testing of REST server and client APIs.
Examples | juneau-examples-core | Juneau Core API examples.
juneau-examples-rest | Juneau REST API examples.
juneau-examples-rest-jetty | Juneau REST API examples using Jetty deployment.
juneau-examples-rest-springboot | Juneau REST API examples using Spring Boot deployment.

##### Table of Contents

## 1 - Introduction

Apache Juneau™ is a single cohesive Java ecosystem consisting of the following parts:

Group | Component | Description
--- | --- | ---
Juneau Core | juneau-marshall | A universal toolkit for marshalling POJOs to a wide variety of content types using a common framework with no external library dependencies.
juneau-marshall-rdf | Extended marshalling support for RDF languages.
juneau-dto | A variety of predefined DTOs for serializing and parsing languages such as HTML5, Swagger and ATOM.
juneau-config | A sophisticated configuration file API.
Juneau REST | juneau-rest-server | A universal REST server API for creating Swagger-based self-documenting REST interfaces using POJOs, simply deployed as one or more top-level servlets in any Servlet 3.1.0+ container.
juneau-rest-server-springboot | Spring boot integration support.
juneau-rest-server-jaxrs | JAX/RS integration support.
juneau-rest-client | A universal REST client API for interacting with Juneau or 3rd-party REST interfaces using POJOs and proxy interfaces.
juneau-rest-mock | Mocking APIs for server-less end-to-end testing of REST server and client APIs.
Examples | juneau-examples-core | Juneau Core API examples.
juneau-examples-rest | Juneau REST API examples.
juneau-examples-rest-jetty | Juneau REST API examples using Jetty deployment.
juneau-examples-rest-springboot | Juneau REST API examples using Spring Boot deployment.

Questions via email to dev@juneau.apache.org are always welcome.

Juneau is packed with features that may not be obvious at first. Users are encouraged to ask for code reviews by providing links to specific source files such as through GitHub. Not only can we help you with feedback, but it helps us understand usage patterns to further improve the product.

##### History

Juneau started off as a popular internal IBM toolkit called Juno. Originally used for serializing POJOs to and from JSON (at a time when the concept was new), it later expanded in scope to include a variety of content types, and then later REST servlet, client, and microservice APIs. It's use grew to more than 50 projects and was one of the most popular community source projects within IBM.

In June of 2016, the code was donated to the Apache Foundation under the project Apache Juneau where it has continued to evolve to where it is today.

### 1.1 - Features 8.1.0-updated

- Fast memory-efficient serialization.
- Fast, safe, memory-efficient parsing. Parsers are not susceptible to deserialization attacks.
- KISS is our mantra! No auto-wiring. No code generation. No dependency injection. Just add it to your classpath and use it. Extremely simple unit testing!
- Enjoyable to use
- Tiny - ~1MB
- Exhaustively tested
- Lots of up-to-date documentation and examples
- Minimal library dependencies:
  - juneau-marshall, juneau-dto, juneau-svl, juneau-config - No external dependencies. Entirely self-contained.
  - juneau-marshall-rdf - Optional RDF support. Requires Apache Jena 2.7.1+.
  - juneau-rest-server - Any Servlet 3.1.0+ container.
  - juneau-rest-client - Apache HttpClient 4.5+.
  - juneau-microservice - Eclipse Jetty.
- Built on top of Servlet and Apache HttpClient APIs that allow you to use the newest HTTP/2 features such as request/response multiplexing and server push.

### 1.2 - Components

We've strived to keep prerequisites to an absolute minimum in order to make adoption as easy as possible.

The library consists of the following artifacts found in the Maven group "org.apache.juneau":

Category | Maven Artifacts | Description | Prereqs
--- | --- | --- | ---
juneau-core | juneau-marshall | Serializers and parsers for: JSON XML HTML UON URL-Encoding MessagePack OpenAPI SOAP/XML CSV BSON (coming soon) YAML (coming soon) Protobuf (coming soon) Amazon Ion (coming soon) | Java 8
juneau-marshall-rdf | Serializers and parsers for: RDF/XML RDF/XML-Abbrev N-Triple Turtle N3 | Java 8 Apache Jena 2.7.1
juneau-dto | Data Transfer Objects for: HTML5 Atom Cognos JSON-Schema Swagger 2.0 | Java 8+
juneau-config | Configuration file API | Java 8+
juneau-rest | juneau-rest-server | REST Servlet API | Java 8 Servlet 3.1+
juneau-rest-server-springboot | Spring Boot integration support | Java 8+ Spring Boot 2.0+
juneau-rest-server-jaxrs | JAX-RS support | Java 8+ JAX-RS 2.0
juneau-rest-client | REST Client API | Java 8+ Apache HttpClient 4.5+
juneau-microservice | juneau-microservice-core | Microservice API | Java 8+
juneau-microservice-jetty | Jetty Microservice API | Java 8+ Eclipse Jetty 9.4+
my-jetty-microservice | Developer template project for Jetty-based microservices. | Java 8+ Eclipse Jetty 9.4+
my-springboot-microservice | Developer template project for Spring-Boot-based microservices. | Java 8+ Spring Boot 2.0+
juneau-examples | juneau-examples-core | Core code examples |
juneau-examples-rest | REST code examples |
juneau-examples-rest-jetty | REST code examples deployed using Jetty |
juneau-examples-rest-springboot | REST code examples deployed using Spring Boot |
juneau-all | juneau-all | Combination of the following: juneau-marshall juneau-dto juneau-config juneau-rest-server juneau-rest-client | Java 8+ Servlet 3.1+ Apache HttpClient 4.5+

The current version of Juneau is {@property juneauVersion}. The easiest way to pull in the library is through the following maven dependency:

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-all</artifactId> <version>{@property juneauVersion}</version> </dependency>

If you would like to work with the bleeding-edge code, you can access the {@property juneauVersionNext}-SNAPSHOT version through the following repository:

<pluginRepositories> <pluginRepository> <id>apache.snapshots</id> <url>http://repository.apache.org/snapshots/</url> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories>

Each of the components are also packaged as stand-alone OSGi modules.

## 2 - juneau-marshall

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-marshall</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-marshall-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.marshall_{@property juneauVersion}.jar

The juneau-marshall artifact contains the API for defining serializers and parsers, and marshalling support for JSON, XML, HTML, URL-Encoding, UON and others.

It also defines many convenience utility classes used throughout the framework.

### 2.1 - Serializers

One of the goals of Juneau was to make serialization as simple as possible. In a single line of code, you should be able to serialize and parse most POJOs. Despite this simplicity, Juneau provides lots of extensibility and configuration properties for tailoring how POJOs are serialized and parsed.

The built-in serializers in Juneau are fast, efficient, and highly configurable. They work by serializing POJOs directly to streams instead of using intermediate Document Object Model objects.

In most cases, you can serialize objects in one line of code by using one of the default serializers:

// A simple bean public class Person { public String name = "John Smith"; public int age = 21; } // Serialize to JSON, XML, or HTML Person p = new Person(); // Produces: // "{\"name\":\"John Smith\",\"age\":21}" String json = JsonSerializer.DEFAULT.serialize(p); // Produces: // "{name:'John Smith',age:21}" String json = SimpleJsonSerializer.DEFAULT.serialize(p); // Produces: // <object> // <name>John Smith</name> // <age>21</age> // </object> String xml = XmlSerializer.DEFAULT.serialize(p); // Produces: // <table> // <tr><th>key</th><th>value</th></tr> // <tr><td>name</td><td>John Smith</td></tr> // <tr><td>age</td><td>21</td></tr> // </table> String html = HtmlSerializer.DEFAULT.serialize(p); // Produces: // "(name='John Smith',age=21)" String uon = UonSerializer.DEFAULT.serialize(p); // Produces: // "name='John+Smith'&age=21" String urlencoding = UrlEncodingSerializer.DEFAULT.serialize(p); // Produces: // 82 A4 6E 61 6D 65 AA 4A 6F 68 6E 20 53 6D 69 74 68 A3 61 67 65 15 byte[] b = MsgPackSerializer.DEFAULT.serialize(p);

In addition to the default serializers, customized serializers can be created using various built-in options:

// Use one of the default serializers to serialize a POJO String json = JsonSerializer.DEFAULT.serialize(someObject); // Create a custom serializer for lax syntax using single quote characters JsonSerializer serializer = JsonSerializer.create().simple().sq().build(); // Clone an existing serializer and modify it to use single-quotes JsonSerializer serializer = JsonSerializer.DEFAULT.builder().sq().build(); // Serialize a POJO to JSON String json = serializer.serialize(someObject);

Default serialization support is provided for Java primitives, Maps, Collections, beans, and arrays. Extensible support for other data types such as Calendars, Dates, Iterators is available through the use of POJO swaps (described later).

The class hierarchy for the serializers (excluding specialized subclasses) are:

- {@link org.apache.juneau.serializer.Serializer}
  - {@link org.apache.juneau.serializer.WriterSerializer}
    - {@link org.apache.juneau.json.JsonSerializer}
      - {@link org.apache.juneau.json.JsonSchemaSerializer}
      - {@link org.apache.juneau.json.SimpleJsonSerializer}
    - {@link org.apache.juneau.plaintext.PlainTextSerializer}
    - {@link org.apache.juneau.jena.RdfSerializer}
      - {@link org.apache.juneau.jena.N3Serializer}
      - {@link org.apache.juneau.jena.NTripleSerializer}
      - {@link org.apache.juneau.jena.RdfXmlSerializer}
      - {@link org.apache.juneau.jena.RdfXmlAbbrevSerializer}
      - {@link org.apache.juneau.jena.TurtleSerializer}
    - {@link org.apache.juneau.uon.UonSerializer}
      - {@link org.apache.juneau.oapi.OpenApiSerializer}
      - {@link org.apache.juneau.urlencoding.UrlEncodingSerializer}
    - {@link org.apache.juneau.xml.XmlSerializer}
      - {@link org.apache.juneau.html.HtmlSerializer}
        - {@link org.apache.juneau.html.HtmlSchemaSerializer}
        - {@link org.apache.juneau.html.HtmlStrippedDocSerializer}
          - {@link org.apache.juneau.html.HtmlDocSerializer}
            - {@link org.apache.juneau.html.HtmlSchemaDocSerializer}
      - {@link org.apache.juneau.soap.SoapXmlSerializer}
      - {@link org.apache.juneau.xml.XmlDocSerializer}
      - {@link org.apache.juneau.xmlschema.XmlSchemaSerializer}
        - {@link org.apache.juneau.xmlschema.XmlSchemaDocSerializer}
  - {@link org.apache.juneau.serializer.OutputStreamSerializer}
    - {@link org.apache.juneau.jso.JsoSerializer}
    - {@link org.apache.juneau.msgpack.MsgPackSerializer}

### 2.2 - Parsers

Parsers work by parsing input directly into POJOs instead of having to create intermediate Document Object Models. This allows them to parse input with minimal object creation.

Like the serializers, you can often parse objects in one line of code by using one of the default parsers:

// Use one of the predefined parsers. Parser parser = JsonParser.DEFAULT; // Parse a JSON object as a bean. String json = "{name:'John Smith',age:21}"; Person p = parser.parse(json, Person.class); // Or parse it into a generic Map. Map m1 = parser.parse(json, Map.class); // Parse a JSON string. json = "'foobar'"; String s2 = parser.parse(json, String.class); // Parse a JSON number as a Long or Float. json = "123"; Long l3 = parser.parse(json, Long.class); Float f3 = parser.parse(json, Float.class); // Parse a JSON object as a HashMap<String,Person>. json = "{a:{name:'John Smith',age:21},b:{name:'Joe Smith',age:42}}"; Map<String,Person> m4 = parser.parse(json, HashMap.class, String.class, Person.class) // Parse a JSON object as a HashMap<String,LinkedList<Person>>. json = "{a:[{name:'John Smith',age:21},{name:'Joe Smith',age:42}]}"; Map<String,List<Person>> m5 = parser.parse(json, HashMap.class, String.class, LinkedList.class, Person.class) // Parse a JSON array of integers as a Collection of Integers or int[] array. json = "[1,2,3]"; List<Integer> l6 = parser.parse(json, LinkedList.class, Integer.class); int[] i7 = parser.parse(json, int[].class);

The parsers can also be used to populating existing bean and collection objects:

// Use one of the predefined parsers. Parser parser = JsonParser.DEFAULT; // Populate the properties on an existing bean from a JSON object. String json = "{name:'John Smith',age:21}"; Person p = new Person(); parser.parseIntoBean(json, p); // Populate an existing list from a JSON array of numbers. json = "[1,2,3]"; List<Integer> l2 = new LinkedList<Integer>(); parser.parseIntoCollection(json, l2, Integer.class); // Populate an existing map from a JSON object containing beans. json = "{a:{name:'John Smith',age:21},b:{name:'Joe Smith',age:42}}"; Map<String,Person> m3 = new TreeMap<String,Person>(); parser.parseIntoMap(json, m3, String.class, Person.class);

In the example above, we're parsing "lax" JSON (single quotes, unquoted attributes). The JSON parser can handle any valid JSON syntax (such as quoted or unquoted attributes, single or double quotes). It can also handle JSON fragments and embedded Javascript comments. Many of the JSON examples provided will use lax syntax which is easier to read since we don't have to deal with escapes.

The class hierarchy for the parsers (excluding specialized subclasses) are:

- {@link org.apache.juneau.parser.Parser}
  - {@link org.apache.juneau.parser.ReaderParser}
    - {@link org.apache.juneau.json.JsonParser}
    - {@link org.apache.juneau.plaintext.PlainTextParser}
    - {@link org.apache.juneau.jena.RdfParser}
      - {@link org.apache.juneau.jena.RdfXmlParser}
      - {@link org.apache.juneau.jena.N3Parser}
      - {@link org.apache.juneau.jena.NTripleParser}
      - {@link org.apache.juneau.jena.TurtleParser}
    - {@link org.apache.juneau.uon.UonParser}
      - {@link org.apache.juneau.oapi.OpenApiParser}
      - {@link org.apache.juneau.urlencoding.UrlEncodingParser}
    - {@link org.apache.juneau.xml.XmlParser}
      - {@link org.apache.juneau.html.HtmlParser}
  - {@link org.apache.juneau.parser.InputStreamParser}
    - {@link org.apache.juneau.jso.JsoParser}
    - {@link org.apache.juneau.msgpack.MsgPackParser}

### 2.3 - Marshalls

{@link org.apache.juneau.marshall.Marshall Marshalls} are simple pairings of a {@link org.apache.juneau.serializer.Serializer} and {@link org.apache.juneau.parser.Parser} with convenience methods for serializing and parsing POJOs.

- {@link org.apache.juneau.marshall.Marshall}
  - {@link org.apache.juneau.marshall.Marshall#read(Object,Class) read(Object,Class)}
  - {@link org.apache.juneau.marshall.Marshall#read(Object,Type,Type...) read(Object,Type,Type...)}
  - {@link org.apache.juneau.marshall.Marshall#write(Object) write(Object)}
  - {@link org.apache.juneau.marshall.Marshall#write(Object,Object) write(Object,Object)}
  - {@link org.apache.juneau.marshall.Marshall#toString(Object) toString(Object)}
  - {@link org.apache.juneau.marshall.Marshall#println(Object) println(Object)}

Marshalls are often cleaner to use on-the-fly since they have simplified names.

The following shows the {@link org.apache.juneau.marshall.Json} marshall in action:

##### Examples:

// Using instance. Json json = new Json(); MyPojo myPojo = json.read(string, MyPojo.class); String string = json.write(myPojo);

// Using DEFAULT instance. MyPojo myPojo = Json.DEFAULT.read(string, MyPojo.class); String string = Json.DEFAULT.write(myPojo);

Marshalls exist for all supported languages:

- {@link org.apache.juneau.marshall.Marshall}
  - {@link org.apache.juneau.marshall.CharMarshall}
    - {@link org.apache.juneau.marshall.Html}
    - {@link org.apache.juneau.marshall.Json}
    - {@link org.apache.juneau.marshall.PlainText}
    - {@link org.apache.juneau.marshall.SimpleJson}
    - {@link org.apache.juneau.marshall.Uon}
    - {@link org.apache.juneau.marshall.UrlEncoding}
    - {@link org.apache.juneau.marshall.Xml}
    - {@link org.apache.juneau.marshall.N3}
    - {@link org.apache.juneau.marshall.NTriple}
    - {@link org.apache.juneau.marshall.RdfXml}
    - {@link org.apache.juneau.marshall.RdfXmlAbbrev}
    - {@link org.apache.juneau.marshall.Turtle}
  - {@link org.apache.juneau.marshall.StreamMarshall}
    - {@link org.apache.juneau.marshall.Jso}
    - {@link org.apache.juneau.marshall.MsgPack}

### 2.4 - HTTP Part Serializers

There is a separate set of serializers for serializing HTTP parts (query, form-data, headers, path variables, and plain-text request bodies). The distinction is that these are designed to serialize directly to strings based on Open-API schema information.

// Schema information about our part. HttpPartSchema schema = HttpPartSchema .create("array") .collectionFormat("pipes") .items( HttpPartSchema .create("array") .collectionFormat("csv") .items( HttpPartSchema.create("integer","int64") ) ) .build(); // Our value to serialize Object value = new long[][]{{1,2,3},{4,5,6},{7,8,9}}; // Produces "1,2,3|4,5,6|7,8,9" String output = OpenApiSerializer.DEFAULT.serialize(HttpPartType.HEADER, schema, value);

The class hierarchy for the part serializers are:

- {@link org.apache.juneau.httppart.HttpPartSerializer}
  - {@link org.apache.juneau.httppart.SimplePartSerializer} - Serializes directly to strings.
  - {@link org.apache.juneau.uon.UonSerializer} - Serializes to UON notation.
    - {@link org.apache.juneau.oapi.OpenApiSerializer} - Serializes using Open-API schema rules.

### 2.5 - HTTP Part Parsers

There is a separate set of parsers for parsing HTTP parts (query, form-data, headers, path variables, and plain-text request bodies). The distinction is that these are designed to parse directly from strings based on Open-API schema information.

// Schema information about our part. HttpPartSchema schema = HttpPartSchema .create("array") .collectionFormat("pipes") .items( HttpPartSchema .create("array") .collectionFormat("csv") .items( HttpPartSchema.create("integer","int64") ) ) .build(); // Our input to parse. String input = "1,2,3|4,5,6|7,8,9"; // Produces "[[1,2,3],[4,5,6],[7,8,9]] long[][] value = OpenApiParser.DEFAULT.parse(HttpPartType.HEADER, schema, input, long[][].class);

The class hierarchy for the part serializers are:

- {@link org.apache.juneau.httppart.HttpPartParser}
  - {@link org.apache.juneau.httppart.SimplePartParser} - Parses directly from strings.
  - {@link org.apache.juneau.uon.UonParser} - Parses from UON notation.
    - {@link org.apache.juneau.oapi.OpenApiParser} - Parses using Open-API schema rules.

### 2.6 - 8.1.3-updated

Serializers and parsers have a wide variety of configurable properties. They all extend from the {@link org.apache.juneau.BeanContextBuilder} class that allows you to easily construct new instances from scratch or build upon existing instances. For example, the following code shows how to configure a JSON serializer:

WriterSerializer s = JsonSerializer .create() // Create a JsonSerializerBuilder .simple() // Simple mode .ws() // Use whitespace .sq() // Use single quotes .build(); // Create a JsonSerializer

Configurable settings can also be set declaratively. The following produces the same serializer.

WriterSerializer s = JsonSerializer .create() .set(JSON_simpleMode, true) .set(WSERIALIZER_useWhitespace, true) .set(WSERIALIZER_quoteChar, "'") .build();

However, each of the serializers and parsers already contain reusable instances with common configurations. For example, JSON has the following predefined reusable serializers and parsers:

- {@link org.apache.juneau.json.JsonSerializer}
  - {@link org.apache.juneau.json.JsonSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.json.JsonSerializer#DEFAULT_READABLE DEFAULT_READABLE}
- {@link org.apache.juneau.json.SimpleJsonSerializer}
  - {@link org.apache.juneau.json.SimpleJsonSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.json.SimpleJsonSerializer#DEFAULT_READABLE DEFAULT_READABLE}
- {@link org.apache.juneau.json.JsonParser}
  - {@link org.apache.juneau.json.JsonParser#DEFAULT DEFAULT}
  - {@link org.apache.juneau.json.JsonParser#DEFAULT_STRICT DEFAULT_STRICT}

These can be used directly, as follows:

// Serialize a POJO to LAX JSON. String json = SimpleJsonSerializer.DEFAULT.serialize(myPojo);

For performance reasons, serializers and parsers are immutable. However, they can be 'copied' and modified using the builder() method.

// Clone and customize an existing serializer. WriterSerializer s = SimpleJsonSerializer.DEFAULT .builder() // Create a new builder with copied settings. .quoteChar('"') // Use a different quote character. .build();

Configurable properties can be set globally using either system properties or environment variables.
For example, the WSERIALIZER_useWhitespace variable resolves to the string "WriterSerializer.useWhitespace.b". This setting can be enabled by setting the system property "WriterSerializer.useWhitespace" or environment variables "WriterSerializer_useWhitespace" or "WRITERSERIALIZER_USEWHITESPACE" to "true".

#### 2.6.1 - Common Serializer Properties

All serializers and parsers extend from the {@link org.apache.juneau.BeanContext} class. Therefore, the following properties are common to all serializers and parsers:

- {@link org.apache.juneau.BeanContext}
  - {@link org.apache.juneau.BeanContext#BEAN_beanClassVisibility BEAN_beanClassVisibility}
  - {@link org.apache.juneau.BeanContext#BEAN_beanConstructorVisibility BEAN_beanConstructorVisibility}
  - {@link org.apache.juneau.BeanContext#BEAN_beanDictionary BEAN_beanDictionary}
  - {@link org.apache.juneau.BeanContext#BEAN_beanFieldVisibility BEAN_beanFieldVisibility}
  - {@link org.apache.juneau.BeanContext#BEAN_beanFilters BEAN_beanFilters}
  - {@link org.apache.juneau.BeanContext#BEAN_beanMapPutReturnsOldValue BEAN_beanMapPutReturnsOldValue}
  - {@link org.apache.juneau.BeanContext#BEAN_beanMethodVisibility BEAN_beanMethodVisibility}
  - {@link org.apache.juneau.BeanContext#BEAN_beansRequireDefaultConstructor BEAN_beansRequireDefaultConstructor}
  - {@link org.apache.juneau.BeanContext#BEAN_beansRequireSerializable BEAN_beansRequireSerializable}
  - {@link org.apache.juneau.BeanContext#BEAN_beansRequireSettersForGetters BEAN_beansRequireSettersForGetters}
  - {@link org.apache.juneau.BeanContext#BEAN_beansRequireSomeProperties BEAN_beansRequireSomeProperties}
  - {@link org.apache.juneau.BeanContext#BEAN_beanTypePropertyName BEAN_beanTypePropertyName}
  - {@link org.apache.juneau.BeanContext#BEAN_bpi BEAN_bpi}
  - {@link org.apache.juneau.BeanContext#BEAN_bpx BEAN_bpx}
  - {@link org.apache.juneau.BeanContext#BEAN_debug BEAN_debug}
  - {@link org.apache.juneau.BeanContext#BEAN_examples BEAN_examples}
  - {@link org.apache.juneau.BeanContext#BEAN_fluentSetters BEAN_fluentSetters}
  - {@link org.apache.juneau.BeanContext#BEAN_ignoreInvocationExceptionsOnGetters BEAN_ignoreInvocationExceptionsOnGetters}
  - {@link org.apache.juneau.BeanContext#BEAN_ignoreInvocationExceptionsOnSetters BEAN_ignoreInvocationExceptionsOnSetters}
  - {@link org.apache.juneau.BeanContext#BEAN_ignorePropertiesWithoutSetters BEAN_ignorePropertiesWithoutSetters}
  - {@link org.apache.juneau.BeanContext#BEAN_ignoreUnknownBeanProperties BEAN_ignoreUnknownBeanProperties}
  - {@link org.apache.juneau.BeanContext#BEAN_ignoreUnknownNullBeanProperties BEAN_ignoreUnknownNullBeanProperties}
  - {@link org.apache.juneau.BeanContext#BEAN_implClasses BEAN_implClasses}
  - {@link org.apache.juneau.BeanContext#BEAN_locale BEAN_locale}
  - {@link org.apache.juneau.BeanContext#BEAN_mediaType BEAN_mediaType}
  - {@link org.apache.juneau.BeanContext#BEAN_notBeanClasses BEAN_notBeanClasses}
  - {@link org.apache.juneau.BeanContext#BEAN_notBeanPackages BEAN_notBeanPackages}
  - {@link org.apache.juneau.BeanContext#BEAN_pojoSwaps BEAN_pojoSwaps}
  - {@link org.apache.juneau.BeanContext#BEAN_propertyNamer BEAN_propertyNamer}
  - {@link org.apache.juneau.BeanContext#BEAN_sortProperties BEAN_sortProperties}
  - {@link org.apache.juneau.BeanContext#BEAN_timeZone BEAN_timeZone}
  - {@link org.apache.juneau.BeanContext#BEAN_useEnumNames BEAN_useEnumNames}
  - {@link org.apache.juneau.BeanContext#BEAN_useInterfaceProxies BEAN_useInterfaceProxies}
  - {@link org.apache.juneau.BeanContext#BEAN_useJavaBeanIntrospector BEAN_useJavaBeanIntrospector}

#### 2.6.2 - Common Serializer Properties 8.1.0-updated

In addition to the common properties above, the following properties are common to all serializers:

- {@link org.apache.juneau.BeanTraverseContext}
  - {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_detectRecursions BEANTRAVERSE_detectRecursions}
  - {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_ignoreRecursions BEANTRAVERSE_ignoreRecursions}
  - {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_initialDepth BEANTRAVERSE_initialDepth}
  - {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_maxDepth BEANTRAVERSE_maxDepth}
  - {@link org.apache.juneau.serializer.Serializer}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addBeanTypes SERIALIZER_addBeanTypes}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addRootType SERIALIZER_addRootType}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_listener SERIALIZER_listener}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_sortCollections SERIALIZER_sortCollections}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_sortMaps SERIALIZER_sortMaps}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimEmptyCollections SERIALIZER_trimEmptyCollections}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimEmptyMaps SERIALIZER_trimEmptyMaps}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimNullProperties SERIALIZER_trimNullProperties}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimStrings SERIALIZER_trimStrings}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriContext SERIALIZER_uriContext}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriRelativity SERIALIZER_uriRelativity}
    - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriResolution SERIALIZER_uriResolution}
    - {@link org.apache.juneau.serializer.WriterSerializer}
      - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_fileCharset WSERIALIZER_fileCharset}
      - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_maxIndent WSERIALIZER_maxIndent}
      - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_quoteChar WSERIALIZER_quoteChar}
      - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_streamCharset WSERIALIZER_streamCharset}
      - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_useWhitespace WSERIALIZER_useWhitespace}
    - {@link org.apache.juneau.serializer.OutputStreamSerializer}
      - {@link org.apache.juneau.serializer.OutputStreamSerializer#OSSERIALIZER_binaryFormat OSSERIALIZER_binaryFormat}

#### 2.6.3 - Common Parser Properties 8.1.3-updated

In addition to the common properties above, the following properties are common to all parsers:

- {@link org.apache.juneau.parser.Parser}
  - {@link org.apache.juneau.parser.Parser#PARSER_autoCloseStreams PARSER_autoCloseStreams}
  - {@link org.apache.juneau.parser.Parser#PARSER_debugOutputLines PARSER_debugOutputLines}
  - {@link org.apache.juneau.parser.Parser#PARSER_listener PARSER_listener}
  - {@link org.apache.juneau.parser.Parser#PARSER_strict PARSER_strict}
  - {@link org.apache.juneau.parser.Parser#PARSER_trimStrings PARSER_trimStrings}
  - {@link org.apache.juneau.parser.Parser#PARSER_unbuffered PARSER_unbuffered}
  - {@link org.apache.juneau.parser.ReaderParser}
    - {@link org.apache.juneau.parser.ReaderParser#RPARSER_fileCharset RPARSER_fileCharset}
    - {@link org.apache.juneau.parser.ReaderParser#RPARSER_streamCharset RPARSER_streamCharset}
  - {@link org.apache.juneau.parser.InputStreamParser}
    - {@link org.apache.juneau.parser.InputStreamParser#ISPARSER_binaryFormat ISPARSER_binaryFormat}

### 2.7 - Configurable Annotations 8.1.0-new, 8.1.3-updated

All configurable properties described in the previous section have annotation equivalents that can be applied on classes or methods.

In the section on the REST server API, we describe how to configure serializers and parsers using @Property annotations such as shown below:

// Configuring serializers/parsers using @Property annotations. @Rest( path="/atom", title="Sample ATOM feed resource", properties={ @Property(name=WSERIALIZER_quoteChar, value="'"), @Property(name=RDF_rdfxml_tab, value="5"), @Property(name=RDF_addRootProperty, value="true"), @Property(name=BEAN_examples, value="{'org.apache.juneau.dto.atom.Feed': $F{AtomFeedResource_example.json}}") } ... ) public class AtomFeedResource extends BasicRestServletJena { ... }

However, an even easier way to configure serializers and parsers are to used provided specialized @XConfig annotations like those shown below:

// Same as above but using specialized annotations. @Rest( path="/atom", title="Sample ATOM feed resource" ... ) @SerializerConfig(quoteChar="'") @RdfConfig(rdfxml_tab="5", addRootProperty="true") @BeanConfig(examples="Feed: $F{AtomFeedResource_example.json}") public class AtomFeedResource extends BasicRestServletJena { ... }

Config annotations are provided for all serializers and parsers:

- {@link org.apache.juneau.annotation.BeanConfig BeanConfig}
- {@link org.apache.juneau.csv.annotation.CsvConfig CsvConfig}
- {@link org.apache.juneau.html.annotation.HtmlConfig HtmlConfig}
- {@link org.apache.juneau.html.annotation.HtmlDocConfig HtmlDocConfig}
- {@link org.apache.juneau.jso.annotation.JsoConfig JsoConfig}
- {@link org.apache.juneau.json.annotation.JsonConfig JsonConfig}
- {@link org.apache.juneau.jsonschema.annotation.JsonSchemaConfig JsonSchemaConfig}
- {@link org.apache.juneau.msgpack.annotation.MsgPackConfig MsgPackConfig}
- {@link org.apache.juneau.oapi.annotation.OpenApiConfig OpenApiConfig}
- {@link org.apache.juneau.parser.annotation.ParserConfig ParserConfig}
- {@link org.apache.juneau.plaintext.annotation.PlainTextConfig PlainTextConfig}
- {@link org.apache.juneau.jena.annotation.RdfConfig RdfConfig}
- {@link org.apache.juneau.serializer.annotation.SerializerConfig SerializerConfig}
- {@link org.apache.juneau.soap.annotation.SoapXmlConfig SoapXmlConfig}
- {@link org.apache.juneau.uon.annotation.UonConfig UonConfig}
- {@link org.apache.juneau.urlencoding.annotation.UrlEncodingConfig UrlEncodingConfig}
- {@link org.apache.juneau.xml.annotation.XmlConfig XmlConfig}

Config annotations defined on classes and methods can be applied to serializers and parsers using the following methods:

- {@link org.apache.juneau.BeanContextBuilder}
  - {@link org.apache.juneau.BeanContextBuilder#applyAnnotations(Class...) applyAnnotations(Class...)} - Apply annotations from class and all parent classes.
  - {@link org.apache.juneau.BeanContextBuilder#applyAnnotations(Method...) applyAnnotations(Method...)} - Apply annotations from method and parent methods.

The following example shows how annotations defined on a dummy class can be applied to a serializer:

@SerializerConfig(quoteChar="'") @BeanConfig(bpi="AddressBean: street,city,state") public static class DummyClass {} WriterSerializer ws = JsonSerializer.create().applyAnnotations(DummyClass.class).build(); String json = ws.toString(addressBean);

### 2.8 - ObjectMap and ObjectList

The {@link org.apache.juneau.ObjectMap} and {@link org.apache.juneau.ObjectList} classes are generic Java representations of JSON objects and arrays. These classes can be used to create "unstructured" models for serialization (as opposed to "structured" models consisting of beans). If you want to quickly generate JSON/XML/HTML from generic maps/collections, or parse JSON/XML/HTML into generic maps/collections, these classes work well.

These classes extend directly from the following JCF classes:

- {@link java.util.LinkedHashMap java.util.LinkedHashMap}
  - {@link org.apache.juneau.ObjectMap org.apache.juneau.ObjectMap}
- {@link java.util.LinkedList java.util.LinkedList}
  - {@link org.apache.juneau.ObjectMap org.apache.juneau.ObjectList}

The ObjectMap and ObjectList classes are very similar to the JSONObject and JSONArray classes found in other libraries. However, the names were chosen because the concepts of Maps and Lists are already familiar to Java programmers, and these classes can be used with any of the serializers or parsers.

These object can be serialized in one of two ways:

1. Using the provided {@link org.apache.juneau.ObjectMap#serializeTo(java.io.Writer)} or {@link org.apache.juneau.ObjectList#serializeTo(java.io.Writer)} methods.
2. Passing them to one of the {@link org.apache.juneau.serializer.Serializer} serialize methods.
3. Simply calling the {@link org.apache.juneau.ObjectMap#toString()} or {@link org.apache.juneau.ObjectList#toString()} methods which will serialize it as Simplified JSON.

Any valid JSON can be parsed into an unstructured model consisting of generic {@link org.apache.juneau.ObjectMap} and {@link org.apache.juneau.ObjectList} objects. (In theory, any valid XML can also be parsed into an unstructured model, although this has not been officially 'tested')

// Parse an arbitrary JSON document into an unstructered data model // consisting of ObjectMaps, ObjectLists, and java primitive objects. Parser parser = JsonParser.DEFAULT; String json = "{a:{name:'John Smith',age:21},b:{name:'Joe Smith',age:42}}"; ObjectMap m = parser.parse(json, ObjectMap.class); // Use ObjectMap API to extract data from the unstructured model. int johnSmithAge = m.getObjectMap("a").getInt("age"); // Convert it back into JSON. json = JsonSerializer.DEFAULT.serialize(m); // Or convert it to XML. String xml = XmlSerializer.DEFAULT.serialize(m); // Or just use toString(). json = m.toString();

The ObjectMap and ObjectList classes have many convenience features:

// Convert the map to a bean. MyBean m = objectMap.cast(MyBean.class); // Find entries by multiple keys. MyBean m = objectMap.find(MyBean.class, "key1", "key2"); // Fluent-style appenders. objectMap.append("key1", "val1").append("key2", "val2"); // REST-like functions for manipulating nodes in the data structure using URL-like notation. objectMap.getAt("foo/bar/myBean", MyBean.class); objectMap.putAt("foo/bar/myBean", MyBean.class); objectMap.postAt("foo/bar/myListOfBeans", MyBean.class); objectMap.deleteAt("foo/bar/myBean"); // Copy with inclusion or exclusion. ObjectMap m2 = objectMap.include("key1", "key2", "key3"); ObjectMap m3 = objectMap.exclude("key1", "key2", "key3"); // Serialize using another serializer. String xml = objectMap.serializeTo(XmlSerializer.DEFAULT); // Nested maps. objectMap.setInner(objectMapInner);

As a general rule, if you do not specify a target type during parsing, or if the target type cannot be determined through reflection, the parsers automatically generate ObjectMaps and ObjectLists.

### 2.9 - SerializerGroups and ParserGroups

Above the serializers and parsers are the {@link org.apache.juneau.serializer.SerializerGroup} and {@link org.apache.juneau.parser.ParserGroup} classes. These classes allow serializers and parsers to be retrieved by W3C-compliant HTTP Accept and Content-Type values...

// Construct a new serializer group with configuration parameters that get applied to all serializers. SerializerGroup sg = SerializerGroup.create() .append(JsonSerializer.class, UrlEncodingSerializer.class); .ws // or .useWhitespace(true) .pojoSwaps(TemporalCalendarSwap.IsoLocalDateTime.class) .build(); // Find the appropriate serializer by Accept type and serialize our POJO to the specified writer. sg.getSerializer("text/invalid, text/json;q=0.8, text/*;q:0.6, *\/*;q=0.0") .serialize(myPersonObject, myWriter); // Construct a new parser group with configuration parameters that get applied to all parsers. ParserGroup pg = ParserGroup.create() .append(JsonSerializer.class, UrlEncodingSerializer.class); .pojoSwaps(CalendarSwap.IsoLocalDateTime.class) .build(); Person p = pg.getParser("text/json").parse(myReader, Person.class);

The REST servlet API builds upon the SerializerGroup and ParserGroup classes to provide annotated REST servlets that automatically negotiate the HTTP media types and allow the developer to work with requests and responses as POJOs.

### 2.10 - Contexts, Builders, Sessions, and PropertyStores

All the serializers, parsers, and REST server/client classes use the following design pattern:

- Context - A thread-safe read-only object.
  - Heavy to construct and designed to be cached and reused.
  - Created by ContextBuilder classes.
  - Examples: BeanContext, JsonSerializer
- Session - A non-thread-safe single-use object with configuration combined from context and runtime args such as locale/timezone.
  - Lightweight objects that take a minimum amount of time to instantiate and are not typically reused.
  - Created by Context objects.
  - Examples: BeanSession, JsonSerializerSession
- PropertyStore - A thread-safe read-only set of configuration properties.
  - Heavier to create than Sessions but lighter than Contexts.
  - Each Context contains one PropertyStore that defines all the configuration about that object.
  - Created by PropertyStoreBuilder classes.

For example, the class hierarchy for JsonSerializer is:

- Object
  - {@link org.apache.juneau.Context}
    - {@link org.apache.juneau.BeanContext}
      - {@link org.apache.juneau.serializer.Serializer}
        - {@link org.apache.juneau.serializer.WriterSerializer}
          - {@link org.apache.juneau.json.JsonSerializer}

Each context object in the hierarchy define properties that can be stored in a PropertyStore such as WSERIALIZER_useWhitespace or JSON_simpleMode.

The class hierarchy for JsonSerializerBuilder is:

- Object
  - {@link org.apache.juneau.ContextBuilder}
    - {@link org.apache.juneau.BeanContextBuilder}
      - {@link org.apache.juneau.serializer.SerializerBuilder}
        - {@link org.apache.juneau.serializer.WriterSerializerBuilder}
          - {@link org.apache.juneau.json.JsonSerializerBuilder}

The class hierarchy for JsonSerializerSession is:

- Object
  - {@link org.apache.juneau.Session}
    - {@link org.apache.juneau.BeanSession}
      - {@link org.apache.juneau.serializer.SerializerSession}
        - {@link org.apache.juneau.serializer.WriterSerializerSession}
          - {@link org.apache.juneau.json.JsonSerializerSession}

The general idea behind a {@link org.apache.juneau.PropertyStore} is to serve as a reusable configuration of an artifact (such as a serializer) such that the artifact can be cached and reused if the property stores are 'equal'.

For example, two serializers of the same type created with the same configuration will always end up being the same serializer:

// Two serializers created with identical configurations will always be the same copy. WriterSerializer s1 = JsonSerializer.create().pojoSwaps(MySwap.class).simple().build(); WriterSerializer s2 = JsonSerializer.create().set(JSON_simpleMode, true).pojoSwaps(MySwap.class).build(); assert(s1 == s2);

This has the effect of significantly improving performance especially if you're creating many serializers and parsers.

The {@link org.apache.juneau.PropertyStoreBuilder} class is used to build up and instantiate immutable PropertyStore objects.

In the example above, the property store being built looks like the following:

PropertyStore ps = PropertyStore .create() .set("BeanContext.pojoSwaps.lc", MySwap.class) .set("JsonSerializer.simpleMode.b", true) .build();

Property stores are immutable, comparable, and their hashcodes are calculated exactly one time. That makes them particularly suited for use as hashmap keys, and thus for caching reusable serializers and parsers.

Refer to the {@link org.apache.juneau.PropertyStore} javadoc for a detailed explaination on how property stores work.

### 2.11 - Transforms

By default, the Juneau framework can serialize and parse a wide variety of POJOs out-of-the-box. However, two special classes are provided tailor how certain Java objects are handled by the framework. These classes are:

- {@link org.apache.juneau.transform.BeanFilter} - Transforms that alter the way beans are handled.
- {@link org.apache.juneau.transform.PojoSwap} - Transforms that swap non-serializable POJOs with serializable POJOs during serialization (and optionally vis-versa during parsing).
  - {@link org.apache.juneau.transform.StringSwap} - Convenience subclass for swaps that convert objects to strings.
  - {@link org.apache.juneau.transform.MapSwap} - Convenience subclass for swaps that convert objects to maps.

Transforms are added to serializers and parsers (and REST clients) using the following configuration properties:

- {@link org.apache.juneau.BeanContext}
  - {@link org.apache.juneau.BeanContext#BEAN_beanFilters BEAN_beanFilters}
  - {@link org.apache.juneau.BeanContext#BEAN_pojoSwaps BEAN_pojoSwaps}

Annotations are also provided for specifying transforms directly on classes and methods (all described in later sections):

- {@link org.apache.juneau.annotation.Swap} - Used to tailor how non-bean POJOs get interpreted by the framework.
- {@link org.apache.juneau.annotation.Bean} - Used to tailor how beans get interpreted by the framework.
- {@link org.apache.juneau.annotation.Beanc} - Maps constructor arguments to property names on beans with read-only properties.
- {@link org.apache.juneau.annotation.Beanp} - Used to tailor how bean properties get interpreted by the framework.
- {@link org.apache.juneau.annotation.BeanIgnore} - Ignore classes, fields, and methods from being interpreted as bean or bean components.
- {@link org.apache.juneau.annotation.NameProperty} - Identifies a setter as a method for setting the name of a POJO as it's known by its parent object.
- {@link org.apache.juneau.annotation.ParentProperty} - Identifies a setter as a method for adding a parent reference to a child object.
- {@link org.apache.juneau.annotation.URI} - Used to identify a class or bean property as a URI.

#### 2.11.1 - PojoSwaps 8.1.0-updated

{@link org.apache.juneau.transform.PojoSwap PojoSwaps} are a critical component of Juneau. They allow the serializers and parsers to handle Java objects that wouldn't normally be serializable.

Swaps are, simply put, 'object swappers' that swap in serializable objects for non-serializable ones during serialization, and vis-versa during parsing.

Some examples of non-serializable POJOs are File, Reader, Iterable, etc... These are classes that aren't beans and cannot be represented as simple maps, collections, or primitives.

In the following example, we introduce a PojoSwap that will swap in a bean of a particular type with a map containing customized key-value pairs:

// Sample swap for converting a bean to a specialized map of key-value pairs. public class MyBeanSwap extends PojoSwap<MyBean,ObjectMap> { // Converts a bean to a generic map. @Override /* PojoSwap */ public ObjectMap swap(BeanSession session, MyBean o) { return new ObjectMap().append("foo", o.getBar()); } // Converts the generic map back into a bean. @Override /* PojoSwap */ public MyBean unswap(BeanSession session, ObjectMap o, ClassMeta hint) throws Exception { MyBean b = new MyBean(); b.setBar(o.getString("foo")); return b; } }

The swap can then be associated with serializers and parsers like so:

// Create a new JSON serializer with our swap. WriterSerializer s = JsonSerializer.create().simple().pojoSwaps(MyBeanSwap.class).build(); String json = s.serialize(new MyBean()); // Create a JSON parser with our swap. ReaderParser p = JsonParser.create().pojoSwaps(MyBeanSwap.class).build(); MyBean bean = p.parse(json, MyBean.class);

Another example of a PojoSwap is one that converts byte[] arrays to BASE64-encoded strings:

public class ByteArrayBase64Swap extends StringSwap<byte[]> { @Override /* StringSwap */ public String swap(byte[] b) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream b64os = MimeUtility.encode(baos, "base64"); b64os.write(b); b64os.close(); return new String(baos.toByteArray()); } @Override /* StringSwap */ public byte[] unswap(String s, ClassMeta<?> hint) throws Exception { byte[] b = s.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(b); InputStream b64is = MimeUtility.decode(bais, "base64"); byte[] tmp = new byte[b.length]; int n = b64is.read(tmp); byte[] res = new byte[n]; System.arraycopy(tmp, 0, res, 0, n); return res; } }

The following example shows the BASE64 swap in use:

// Create a JSON serializer and register the BASE64 encoding swap with it. WriterSerializer s = JsonSerializer.create().simple().pojoSwaps(ByteArrayBase64Swap.class).build(); ReaderParser p = JsonParser.create().pojoSwaps(ByteArrayBase64Swap.class).build(); byte[] bytes = {1,2,3}; String json = s.serialize(bytes); // Produces "'AQID'" bytes = p.parse(json, byte[].class); // Reproduces {1,2,3} byte[][] bytes2d = {{1,2,3},{4,5,6},null}; json = s.serialize(bytes2d); // Produces "['AQID','BAUG',null]" bytes2d = p.parse(json, byte[][].class); // Reproduces {{1,2,3},{4,5,6},null}

#### 2.11.2 - Default PojoSwaps

By default, all serializers and parsers have built in PojoSwaps defined for the following common data types:

- {@link java.util.Enumeration}
- {@link java.util.Iterator}
- {@link java.util.Locale}
- {@link java.util.Class}
- {@link java.util.Calendar} - ISO offset date-time.
- {@link java.util.Date} - Local date-time
- {@link java.time.Instant} - ISO instant.
- {@link java.time.ZonedDateTime} - ISO offset date-time.
- {@link java.time.LocalDate} - ISO local date.
- {@link java.time.LocalDateTime} - ISO local date-time.
- {@link java.time.LocalTime} - ISO local time.
- {@link java.time.OffsetDateTime} - ISO offset date-time.
- {@link java.time.OffsetTime} - ISO offset time.
- {@link java.time.Year} - ISO year.
- {@link java.time.YearMonth} - ISO year-month.
- {@link java.time.Temporal} - ISO instant.
- {@link java.util.TimeZone}
- {@link javax.xml.datatype.XMLGregorianCalendar}
- {@link java.time.ZoneId}

Various other swaps are provided in the org.apache.juneau.transforms package:

- org.apache.juneau.transforms
  - {@link org.apache.juneau.transforms.ByteArraySwap}
    - {@link org.apache.juneau.transforms.ByteArraySwap.Base64}
    - {@link org.apache.juneau.transforms.ByteArraySwap.Hex}
    - {@link org.apache.juneau.transforms.ByteArraySwap.SpacedHex}
  - {@link org.apache.juneau.transforms.InputStreamSwap}
    - {@link org.apache.juneau.transforms.InputStreamSwap.Base64}
    - {@link org.apache.juneau.transforms.InputStreamSwap.Hex}
    - {@link org.apache.juneau.transforms.InputStreamSwap.SpacedHex}
  - {@link org.apache.juneau.transforms.ReaderSwap}
  - {@link org.apache.juneau.transforms.TemporalCalendarSwap}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.BasicIsoDate}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoDate}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoDateTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoInstant}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoLocalDate}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoLocalDateTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoLocalTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoOffsetDate}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoOffsetDateTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoOffsetTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoOrdinalDate}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoWeekDate}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.IsoZonedDateTime}
    - {@link org.apache.juneau.transforms.TemporalCalendarSwap.Rfc1123DateTime}
  - {@link org.apache.juneau.transforms.TemporalDateSwap}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.BasicIsoDate}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoDate}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoDateTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoInstant}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoLocalDate}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoLocalDateTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoLocalTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoOffsetDate}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoOffsetDateTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoOffsetTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoOrdinalDate}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoWeekDate}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.IsoZonedDateTime}
    - {@link org.apache.juneau.transforms.TemporalDateSwap.Rfc1123DateTime}
  - {@link org.apache.juneau.transforms.TemporalSwap}
    - {@link org.apache.juneau.transforms.TemporalSwap.BasicIsoDate}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoDate}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoDateTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoInstant}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoLocalDate}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoLocalDateTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoLocalTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoOffsetDate}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoOffsetDateTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoOffsetTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoOrdinalDate}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoWeekDate}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoYear}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoYearMonth}
    - {@link org.apache.juneau.transforms.TemporalSwap.IsoZonedDateTime}
    - {@link org.apache.juneau.transforms.TemporalSwap.Rfc1123DateTime}

#### 2.11.3 - Auto-detected POJO swaps 8.1.0-new

Various methods can be defined on a class directly to affect how it gets serialized. This can often be simpler than using PojoSwaps.

Objects serialized as Strings can be parsed back into their original objects by implementing one of the following methods on the class:

- public static T fromString(String) method.
  Any of the following method names also work:
  - valueOf(String)
  - parse(String)
  - parseString(String)
  - forName(String)
  - forString(String)
- public T(String) constructor.

Note that these methods cover conversion from several built-in Java types, meaning the parsers can automatically construct these objects from strings:

- fromString(String) - {@link java.util.UUID}
- valueOf(String) - {@link java.lang.Boolean}, {@link java.lang.Byte}, {@link java.lang.Double}, {@link java.lang.Float}, {@link java.lang.Integer}, {@link java.lang.Long}, {@link java.lang.Short}, {@link java.sql.Date}, {@link java.sql.Time}, {@link java.sql.Timestamp}
- parse(String) - {@link java.text.DateFormat}, {@link java.text.MessageFormat}, {@link java.text.NumberFormat}, {@link java.util.Date}, {@link java.util.logging.Level}
- parseString(String) - {@link javax.xml.bind.DatatypeConverter}
- forName(String) - {@link java.lang.Class}

If you want to force a bean-like class to be serialized as a string, you can use the {@link org.apache.juneau.annotation.BeanIgnore @BeanIgnore} annotation on the class to force it to be serialized to a string using the toString() method.

Serializing to other intermediate objects can be accomplished by defining a swap method directly on the class:

- public X swap() method, where X is any serializable object.
- public X swap(BeanSession) method, where X is any serializable object.
- public static MyPojo unswap(X) method, where X is any serializable object.
- public static MyPojo swap(X,BeanSession) method, where X is any serializable object.

Serializing to and from Maps can be accomplished by defining any of the following methods:

- public Map toMap() method. Can be any type of map with string keys and object vals.
- public ObjectMap toMap() method.
- public Map toMap(BeanSession) method. Can be any type of map with string keys and object vals.
- public ObjectMap toMap(BeanSession) method.
- public static MyPojo fromMap(Map) method. Can be any type of map with string keys and object vals.
- public static MyPojo fromMap(ObjectMap) method.
- public static MyPojo fromMap(Map,BeanSession) method. Can be any type of map with string keys and object vals.
- public static MyPojo fromMap(ObjectMap,BeanSession) method.

The BeanSession parameter allows you access to various information about the current serialization session. For example, you could provide customized results based on the media type being produced ({@link org.apache.juneau.BeanSession#getMediaType()}).

The following example shows how an HTML5 form template object can be created that gets serialized as a populated HTML5 {@link org.apache.juneau.dto.html5.Form} bean.

import static org.apache.juneau.dto.html5.HtmlBuilder.*; /** * A simple HTML form template whose serialized form is an HTML5 Form object. */ public class FormTemplate { private String action; private int value1; private boolean value2; // Some constructor that initializes our fields. public FormTemplate(String action, int value1, boolean value2) { this.action = action; this.value1 = value1; this.value2 = value2; } // Special swap method that converts this template to a serializable bean public Form swap(BeanSession session) { return form(action, input("text").name("v1").value(value1), input("text").name("v2").value(value2) ); } }

Swapped objects can be converted back into their original form by the parsers by specifying one of the following methods:

- public static T unswap(BeanSession, X) method where X is the swap class type.
- public T(X) constructor where X is the swap class type.

The following shows how our form template class can be modified to allow the parsers to reconstruct our original object:

import static org.apache.juneau.dto.html5.HtmlBuilder.*; /** * A simple HTML form template whose serialized form is an HTML5 Form object. * This time with parsing support. */ @Bean(dictionary=HtmlBeanDictionary.class) public class FormTemplate { private String action; private int value1; private boolean value2; // Our 'unswap' constructor public FormTemplate(Form f) { this.action = f.getAttr("action"); this.value1 = f.getChild(Input.class, 0) .getAttr(int.class, "value"); this.value2 = f.getChild(Input.class, 1) .getAttr(boolean.class, "value"); } public FormTemplate(String action, int value1, boolean value2) { this.action = action; this.value1 = value1; this.value2 = value2; } public Form swap(BeanSession session) { return form(action, input("text").name("v1").value(value1), input("text").name("v2").value(value2) ); } }

#### 2.11.4 - Per-media-type PojoSwaps 8.1.0-updated

Swaps can also be defined per-media-type.

The {@link org.apache.juneau.transform.PojoSwap#forMediaTypes()} method can be overridden to provide a set of media types that the swap is invoked on. It's also possible to define multiple swaps against the same POJO as long as they're differentiated by media type. When multiple swaps are defined, the best-match media type is used.

In the following example, we define 3 swaps against the same POJO. One for JSON, one for XML, and one for all other types.

public class PojoSwapTest { public static class MyPojo {} public static class MyJsonSwap extends StringSwap<MyPojo> { @Override /* PojoSwap */ public MediaType[] forMediaTypes() { return MediaType.forStrings("*/json"); } @Override /* PojoSwap */ public String swap(BeanSession session, MyPojo o) throws Exception { return "It's JSON!"; } } public static class MyXmlSwap extends StringSwap<MyPojo> { @Override /* PojoSwap */ public MediaType[] forMediaTypes() { return MediaType.forStrings("*/xml"); } @Override /* PojoSwap */ public String swap(BeanSession session, MyPojo o) throws Exception { return "It's XML!"; } } public static class MyOtherSwap extends StringSwap<MyPojo> { @Override /* PojoSwap */ public MediaType[] forMediaTypes() { return MediaType.forStrings("*/*"); } @Override /* PojoSwap */ public String swap(BeanSession session, MyPojo o) throws Exception { return "It's something else!"; } } @Test public void doTest() throws Exception { SerializerGroup g = SerializerGroup.create() .append(JsonSerializer.class, XmlSerializer.class, HtmlSerializer.class) .sq() .pojoSwaps(MyJsonSwap.class, MyXmlSwap.class, MyOtherSwap.class) .build(); MyPojo myPojo = new MyPojo(); String json = g.getWriterSerializer("text/json").serialize(myPojo); assertEquals("'It\\'s JSON!'", json); String xml = g.getWriterSerializer("text/xml").serialize(myPojo); assertEquals("<string>It's XML!</string>", xml); String html = g.getWriterSerializer("text/html").serialize(myPojo); assertEquals("<string>It's something else!</string>", html); } }

When multiple swaps match the same media type, a best-match algorithm is applied to find the correct swap to use.

In later sections we describe how annotations can be used to shorten this syntax:

@Swaps({MyJsonSwap.class,MyXmlSwap.class,MyOtherSwap.class}) public static class MyPojo {} @Swap(mediaTypes="*/json") public static class MyJsonSwap extends PojoSwap<MyPojo,String> {...} @Swap(mediaTypes="*/xml") public static class MyXmlSwap extends PojoSwap<MyPojo,String> {...} @Swap(mediaTypes="*/*") public static class MyOtherSwap extends PojoSwap<MyPojo,String> {...}

#### 2.11.5 - One-way PojoSwaps

In the previous sections, we defined two-way swaps, meaning swaps where the original objects could be reconstructing during parsing. However, there are certain kinds of POJOs that we may want to support for serializing, but that are not possible to reconstruct during parsing. For these, we can use one-way object swaps.

A one-way POJO swap is simply an object transform that only implements the {@code swap()} method. The {@code unswap()} method is simply left unimplemented.

An example of a one-way swaps would be one that allows {@code Iterators} to be serialized as JSON arrays. It can make sense to be able to render {@code Iterators} as arrays, but in general it's not possible to reconstruct an {@code Iterator} during parsing.

public class IteratorSwap extends PojoSwap<Iterator,List> { @Override /* PojoSwap */ public List swap(Iterator o) { List l = new LinkedList(); while (o.hasNext()) l.add(o.next()); return l; } }

Here is an example of our one-way swap being used. Note that trying to parse the original object will cause a {@link org.apache.juneau.parser.ParseException} to be thrown.

// Create a JSON serializer that can serialize Iterators. WriterSerializer s = JsonSerializer.create().simple().pojoSwaps(IteratorSwap.class).build(); // Construct an iterator we want to serialize. Iterator i = new ObjectList(1,2,3).iterator(); // Serialize our Iterator String json = s.serialize(i); // Produces "[1,2,3]" // Try to parse it. ReaderParser p = JsonParser.create().pojoSwaps(IteratorSwap.class).build(); i = p.parse(s, Iterator.class); // Throws ParseException!!!

#### 2.11.6 - @Swap Annotation 8.0.0-updated

{@link org.apache.juneau.annotation.Swap @Swap} can be used to associate a swap class using an annotation. This is often cleaner than using the builder pojoSwaps() method since you can keep your swap class near your POJO class.

@Swap(MyPojoSwap.class) public class MyPojo { ... } // Sample swap for converting MyPojo classes to a simple string. public class MyPojoSwap extends PojoSwap<MyPojo,String> { @Override /* PojoSwap */ public String swap(BeanSession session, MyPojo o) { return o.toSomeSerializableForm(); } }

Multiple swaps can be associated with a POJO by using the {@link org.apache.juneau.annotation.Swaps @Swaps} annotation:

@Swaps( { @Swap(MyJsonSwap.class), @Swap(MyXmlSwap.class), @Swap(MyOtherSwap.class) } ) public class MyPojo {}

Readers get serialized directly to the output of a serializer. Therefore it's possible to implement a swap that provides fully-customized output.

public class MyJsonSwap extends PojoSwap<MyPojo,Reader> { public MediaType[] forMediaTypes() { return MediaType.forStrings("*/json"); } public Reader swap(BeanSession session, MyPojo o) throws Exception { return new StringReader("{message:'Custom JSON!'}"); } }

The @Swap annotation can also be used on getters and setters as well to apply a swap to individual property values:

public class MyBean { private MyPojo myPojo; // Swap applied to bean property. @Beanp(swap=MyPojoSwap.class) public MyPojo getMyPojo() { return myPojo; } }

When applied to bean properties, the swap annotation need only be applied to either the getter, setter, or field.

The swap annotation can also be applied to the private field of a bean property, like so:

public class MyBean { @Beanp(swap=MyPojoSwap.class) private MyPojo myPojo; public MyPojo getMyPojo() { return myPojo; } public MyBean setMyPojo(MyPojo myPojo) { this.myPojo = myPojo; return this; } }

#### 2.11.7 - Templated Swaps

The {@link org.apache.juneau.annotation.Swap#template() @Swap(template)} annotation allows you to associate arbitrary contextual strings with swaps. The primary purpose is for providing template names, such as for Apache FreeMarker, therefore the name 'template'. However, the usage of the string is open-ended.

For example, you could pair a template string like so:

@Swap(impl=FreeMarkerSwap.class, template="MyPojo.div.ftl") public class MyPojo {}

The implementation of the FreeMarker swap would look something like this:

// Our templated swap class. public class FreeMarkerSwap extends PojoSwap<Object,Reader> { public MediaType[] forMediaTypes() { // Make sure this only applies to the HTML serializer. return MediaType.forStrings("*/html"); } public Reader swap(BeanSession session, Object o, String template) throws Exception { // Call some method that uses FreeMarker to convert 'o' to raw HTML using // the 'MyPojo.div.ftl' template. return getFreeMarkerReader(template, o); } }

#### 2.11.8 - Surrogate Classes

Surrogate classes are very similar in concept to PojoSwaps except they're simpler to define.

For example, let's say we want to be able to serialize the following class, but it's not serializable for some reason (for example, there are no properties exposed):

// Not serializable because it's not a bean because it has no public properties. public class MyNonSerializableClass { protected String foo; }

This could be solved with the following PojoSwap.

// A serializable bean with 1 property. public class MySerializableSurrogate { public String foo; } // A PojoSwap that swaps out our non-serializable object with our serializable object. public class MySwap extends PojoSwap<MyNonSerializableClass,MySerializableSurrogate> { @Override /* PojoSwap */ public MySerializableSurrogate swap(MyNonSerializableClass o) { // Create some serializable class and manually copy the data into it. MySerializableSurrogate s = new MySerializableSurrogate(); s.foo = o.foo; return s; } }

However, the same can be accomplished by using a surrogate class that simply contains a constructor with the non-serializable class as an argument:

public class MySerializableSurrogate { public String foo; // Constructor takes in our non-serializable object! public MySerializableSurrogate(MyNonSerializableClass c) { this.foo = c.foo; } }

The surrogate class is registered in the same way as a PojoSwap:

// Create a JSON serializer that can serialize Iterators. WriterSerializer s = JsonSerializer.create().pojoSwaps(MySerializableSurrogate.class).build();

When the serializer encounters the non-serializable class, it will serialize an instance of the surrogate instead.

- {@link org.apache.juneau.transform.Surrogate}

#### 2.11.9 - @Bean Annotation

The {@link org.apache.juneau.annotation.Bean @Bean} annotation is used to tailor how beans are interpreted by the framework.

Bean property inclusion and ordering on a bean class can be done using the {@link org.apache.juneau.annotation.Bean#properties() @Bean(properties)} annotation.

// Address class with only street/city/state properties (in that order). // All other properties are ignored. @Bean(bpi="street,city,state") public class Address { ... }

Bean properties can be excluded using the {@link org.apache.juneau.annotation.Bean#bpx() @Bean(bpx)} annotation.

// Address class with only street/city/state properties (in that order). // All other properties are ignored. @Bean(bpx="city,state"}) public class Address { ... }

Bean properties can be sorted alphabetically using {@link org.apache.juneau.annotation.Bean#sort() @Bean(sort)}

// Address class with only street/city/state properties (in that order). // All other properties are ignored. @Bean(sort=true) public class MyBean { ... }

The {@link org.apache.juneau.annotation.Bean#propertyNamer() @Bean(propertyNamer)} annotation is used to provide customized naming of properties.

Property namers are used to transform bean property names from standard form to some other form. For example, the {@link org.apache.juneau.PropertyNamerDLC} will convert property names to dashed-lowercase, and these will be used as attribute names in JSON and element names in XML.

// Define a class with dashed-lowercase property names. @Bean(propertyNamer=PropertyNamerDashedLC.class) public class MyBean { ... }

The {@link org.apache.juneau.annotation.Bean#interfaceClass @Bean(interfaceClass)} annotation is used to limit properties on beans to specific interface classes. When specified, only the list of properties defined on the interface class will be used during serialization. Additional properties on subclasses will be ignored.

// Parent class @Bean(interfaceClass=A.class) public abstract class A { public String f0 = "f0"; } // Child class public class A1 extends A { public String f1 = "f1"; } JsonSerializer s = SimpleJsonSerializer.DEFAULT; A1 a1 = new A1(); String r = s.serialize(a1); assertEquals("{f0:'f0'}", r); // Note f1 is not serialized.

Note that this annotation can be used on the parent class so that it filters to all child classes. Or can be set individually on the child classes.

The {@link org.apache.juneau.annotation.Bean#stopClass @Bean(stopClass)} annotation is another way to limit which properties are serialized (except from the opposite direction). It's identical in purpose to the stop class specified by {@link java.beans.Introspector#getBeanInfo(Class, Class)}. Any properties in the stop class or in its base classes will be ignored during analysis.

For example, in the following class hierarchy, instances of C3 will include property p3, but not p1 or p2.

public class C1 { public int getP1(); } public class C2 extends C1 { public int getP2(); } @Bean(stopClass=C2.class) public class C3 extends C2 { public int getP3(); }

The {@link org.apache.juneau.annotation.Bean#propertyFilter() @Bean(propertyFilter)} annotation and {@link org.apache.juneau.transform.PropertyFilter} class can be used to perform interception and inline handling of bean getter and setter calls.

// Register filter on bean class. @Bean(propertyFilter=AddressPropertyFilter.class) public class Address { public String getTaxInfo() {...} public void setTaxInfo(String s) {...} } // Property filter that strips out sensitive information in our bean. public class AddressPropertyFilter extends PropertyFilter { @Override /* PropertyFilter */ public Object readProperty(Object bean, String name, Object value) { if ("taxInfo".equals(name)) return "redacted"; return value; } @Override /* PropertyFilter */ public Object writeProperty(Object bean, String name, Object value) { AddressBook a = (Address)bean; if ("taxInfo".equals(name) && "redacted".equals(value)) return TaxInfoUtils.lookUpByName(a.getStreet(), a.getCity(), a.getState()); return value; } }

#### 2.11.10 - @Beanp Annotation 8.1.0-updated, 8.1.2-updated

The {@link org.apache.juneau.annotation.Beanp @Beanp} annotation is used to tailor how individual bean properties are interpreted by the framework.

The {@link org.apache.juneau.annotation.Beanp#name() @Beanp(name)} annotation is used to override the name of the bean property.

public class MyBean { @Beanp(name="Bar") public String getFoo() {...} }

The {@link org.apache.juneau.annotation.Name @Name} annotation is a shortcut for specifying a bean property name:

public class MyBean { @Name("Bar") public String getFoo() {...} }

If the {@link org.apache.juneau.BeanContext#BEAN_beanFieldVisibility} setting on the bean context excludes this field (e.g. the visibility is set to the default of PUBLIC, but the field is PROTECTED), this annotation can be used to force the field to be identified as a property.

public class MyBean { @Beanp protected String getFoo() {...} }

The bean property named "*" is the designated "dynamic property" which allows for "extra" bean properties not otherwise defined. This is similar in concept to the Jackson @JsonGetterAll and @JsonSetterAll annotations, but generalized for all supported marshall languages. The primary purpose is for backwards compatibility in parsing newer streams with addition information into older beans.

The following shows various ways of using dynamic bean properties.

// Option #1 - A simple public Map field. // The field name can be anything. public class BeanWithDynaField { @Beanp(name="*") public Map<String,Object> extraStuff = new LinkedHashMap<String,Object>(); } // Option #2 - Getters and setters. // Method names can be anything. // Getter must return a Map with String keys. // Setter must take in two arguments, a String and Object. public class BeanWithDynaMethods { @Beanp(name="*") public Map<String,Object> getMyExtraStuff() { ... } @Beanp(name="*") public void setAnExtraField(String name, Object value) { ... } } // Option #3 - Getter only. // Properties will be added through the getter. public class BeanWithDynaGetterOnly { @Beanp(name="*") public Map<String,Object> getMyExtraStuff() { ... } }

Similar rules apply for value types and swaps. The property values optionally can be any serializable type or use swaps.

// A serializable type other than Object. public class BeanWithDynaFieldWithListValues { @Beanp(name="*") public Map<String,List<String>> getMyExtraStuff() { ... } } // A swapped value. public class BeanWithDynaFieldWithSwappedValues { @Beanp(name="*", swap=TemporalCalendarSwap.IsoOffsetDateTime.class) public Map<String,Calendar> getMyExtraStuff() { ... } }

Note that if you're not interested in these additional properties, you can also use the {@link org.apache.juneau.BeanContext#BEAN_ignoreUnknownBeanProperties} setting to ignore values that don't fit into existing properties.

The {@link org.apache.juneau.annotation.Beanp#value() @Beanp(value)} annotation is a synonym for {@link org.apache.juneau.annotation.Beanp#name() @Beanp(name)}. Use it in cases where you're only specifying a name so that you can shorten your annotation.

The following annotations are equivalent:

@Beanp(name="foo") @Beanp("foo")

The {@link org.apache.juneau.annotation.Beanp#type() @Beanp(type)} annotation is used to identify a specialized class type for a generalized property. Normally the type is inferred through reflection of the field type or getter return type. However, you'll want to specify this value if you're parsing beans where the bean property class is an interface or abstract class to identify the bean type to instantiate. Otherwise, you may cause an {@link java.lang.InstantiationException} when trying to set these fields.

This property must denote a concrete class with a no-arg constructor.

public class MyBean { // Identify concrete type as a HashMap. @Beanp(type=HashMap.class) public Map p1; }

The {@link org.apache.juneau.annotation.BeanProperty#params() @Beanp(params)} annotation is for bean properties of type map or collection. It's used to identify the class types of the contents of the bean property object when the general parameter types are interfaces or abstract classes.

public class MyBean { // This is a HashMap<String,Integer>. @Beanp(type=HashMap.class, params={String.class,Integer.class}) public Map p1; }

The {@link org.apache.juneau.annotation.Beanp#properties() @Beanp(properties)} annotation is used to limit which child properties are rendered by the serializers. It can be used on any of the following bean property types:

- Beans - Only render the specified properties of the bean.
- Maps - Only render the specified entries in the map.
- Bean/Map arrays - Same, but applied to each element in the array.
- Bean/Map collections - Same, but applied to each element in the collection.

public class MyClass { // Only render 'f1' when serializing this bean property. @Beanp(bpi={"f1"}) public MyChildClass x1 = new MyChildClass(); } public class MyChildClass { public int f1 = 1; public int f2 = 2; } // Renders "{x1:{f1:1}}" String json = JsonSerializer.DEFAULT.serialize(new MyClass());

The {@link org.apache.juneau.annotation.Beanp#format() @Beanp(format)} annotation specifies a String format for converting a bean property value to a formatted string.

// Serialize a float as a string with 2 decimal places. @Beanp(format="$%.2f") public float price;

#### 2.11.11 - @Beanc Annotation 8.1.0-updated, 8.1.2-updated

The {@link org.apache.juneau.annotation.Beanc @Beanc} annotation is used to map constructor arguments to property names on bean with read-only properties. Since method parameter names are lost during compilation, this annotation essentially redefines them so that they are available at runtime.

The definition of a read-only bean is a bean with properties with only getters, like shown below:

// Our read-only bean. public class Person { private final String name; private final int age; @Beanc(properties="name,age"}) public Person(String name, int age) { this.name = name; this.age = age; } // Read only properties. // Getters, but no setters. public String getName() { return name; } public int getAge() { return age; } }

// Parsing into a read-only bean. String json = "{name:'John Smith',age:45}"; Person p = JsonParser.DEFAULT.parse(json); String name = p.getName(); // "John Smith" int age = p.getAge(); // 45

Beans can also be defined with a combination of read-only and read-write properties.

The {@link org.apache.juneau.annotation.Name @Name} annotation can also be used instead of @Beanc(properties):

@Beanc public Person(@Name("name") String name, @Name("age") int age) { this.name = name; this.age = age; }

If neither @Beanc(properties) or @Name is used to identify the bean property names, we will try to use the parameter names if they are available in the bytecode.

#### 2.11.12 - @BeanIgnore Annotation

The {@link org.apache.juneau.annotation.BeanIgnore @BeanIgnore} annotation is used to ignore classes, fields, and methods from being interpreted as beans or bean components.

When applied to classes, objects will be converted to strings even though they look like beans.

// Not really a bean! Use toString() instead! @BeanIgnore public class MyBean {...}

When applied to fields and getters/setters, they will be ignored as bean properties.

public class MyBean { // Not a bean property! @BeanIgnore public String foo; // Not a bean property! @BeanIgnore public String getBar() {...} }

#### 2.11.13 - @NameProperty Annotation

The {@link org.apache.juneau.annotation.NameProperty @NameProperty} annotation is used to identify a setter as a method for setting the name of a POJO as it's known by its parent object.

A commonly-used case is when you're parsing a JSON map containing beans where one of the bean properties is the key used in the map.

// JSON { id1: {name: 'John Smith', sex: 'M'}, id2: {name: 'Jane Doe', sex: 'F'} }

public class Person { @NameProperty public String id; // Value gets assigned from object key public String name; public char sex; }

#### 2.11.14 - @ParentProperty Annotation

The {@link org.apache.juneau.annotation.ParentProperty @ParentProperty} annotation is used to identify a setter as a method for adding a parent reference to a child object.

A commonly-used case is when you're parsing beans and a child bean has a reference to a parent bean.

public class AddressBook { public List<Person> people; } public class Person { @ParentProperty public AddressBook addressBook; // A reference to the containing address book. public String name; public char sex; }

Parsers will automatically set this field for you in the child beans.

#### 2.11.15 - POJO Builders

Juneau parsers can use builders to instantiate POJOs. This is useful in cases where you want to create beans with read-only properties. Note that while it's possible to do this using the {@link org.apache.juneau.annotation.Beanc @Beanc} annotation, using builders can often be cleaner.

A typical builder usage is shown below:

MyBean b = MyBean.create().foo("foo").bar(123).build();

The code for such a builder is shown below:

public class MyBean { // Read-only properties. public final String foo; public final int bar; // Private constructor. private MyBean(MyBeanBuilder b) { this.foo = b.foo; this.bar = b.bar; } // Static method that creates a builder. public static MyBeanBuilder create() { return new MyBeanBuilder(); } // Builder class. public static class MyBeanBuilder { private String foo; private int bar; // Method that creates the bean. public MyBean build() { return new MyBean(this); } // Bean property setters. @Beanp public MyBeanBuilder foo(String foo) { this.foo = foo; return this; } @Beanp public MyBeanBuilder bar(int bar) { this.bar = bar; return this; } } }

The POJO class can be any type including beans. Builders MUST be beans with one or more writable properties. The bean properties themselves do not need to be readable (i.e. getters are optional).

Builders require two parts:

1. A way to detect and instantiate a builder using reflection.
2. A way to instantiate a POJO from a builder.

The first can be accomplished through any of the following:

- A static create() method on the POJO class that returns a builder instance.

  public static MyBuilder create() {...}

- A public constructor on the POJO class that takes in a single parameter that implements the {@link org.apache.juneau.transform.Builder} interface.
  The builder class must have a public no-arg constructor.

  public MyPojo(MyBuilder b) {...}

- A {@link org.apache.juneau.annotation.Builder @Builder} annotation on the POJO class.
  The builder class must have a public no-arg constructor.

  @Builder(MyBuilder.class) public class MyPojo {...}

The second can be accomplished through any of the following:

- The existence of a build() method on the builder class.

  public MyPojo build() {...}

- The existence of a public constructor on the POJO class that takes in the builder instance.

  public MyPojo(MyBuilder b) {...}

- {@link org.apache.juneau.annotation.Builder}
- {@link org.apache.juneau.transform.Builder}

#### 2.11.16 - BeanFilter Class

The {@link org.apache.juneau.transform.BeanFilter} class is the programmatic equivalent to the {@link org.apache.juneau.annotation.Bean @Bean} annotation.

In practice, it's usually simpler to use the {@link org.apache.juneau.annotation.Bean @Bean} and {@link org.apache.juneau.annotation.Beanp @Beanp} annotations on your bean classes. However, bean filters make it possible to accomplish the same when you can't add annotations to existing code.

Bean filters are defined through {@link org.apache.juneau.transform.BeanFilterBuilder BeanFilterBuilders}.

In the previous examples, we defined this bean annotation:

@Bean(bpi="street,city,state") public class Address { ... }

The programmatic equivalent would be:

public class AddressFilter extends BeanFilterBuilder<Address> { // Must provide a no-arg constructor! public AddressFilter() { bpi("street,city,state"); // The properties we want exposed. } }

Bean filters are added to serializers and parsers using the following:

- {@link org.apache.juneau.BeanContext#BEAN_beanFilters}
- {@link org.apache.juneau.BeanContextBuilder#beanFilters(Object...)}

For example:

// Create a new JSON serializer and associate a bean filter with it. WriterSerializer s = JsonSerializer .create() .beanFilters(AddressFilter.class) .build();

Note that if you use the annotation, you do NOT need to set anything on the serializers/parsers. The annotations will be detected and bean filters will automatically be created for them.

The {@link org.apache.juneau.BeanContextBuilder#beanFilters(Object...)} method also allows you to pass in interfaces. Any class that's not a subclass of {@link org.apache.juneau.transform.BeanFilterBuilder} get interpreted as bean interface classes. These cause bean implementations of those interfaces to only expose the properties defined on the interface.

// An interface with the 3 properties we want serialized. public interface AddressInterface { public String getStreet(); public String getCity(); public String getState(); } // Our bean implementation. public class Address implements AddressInterface { public String getStreet() {...}; public String getCity() {...}; public String getState() {...}; public String getCountry() {...}; } // Create a new JSON serializer that only exposes street,city,state on Address bean. // The 'country' field will be ignored. WriterSerializer s = JsonSerializer .create() .beanFilters(AddressInterface.class) .build();

#### 2.11.17 - Interface Filters

Occasionally, you may want to limit bean properties to only those defined on a parent class or interface. This is accomplished through interface filters.

Interface filters are defined through the following:

- {@link org.apache.juneau.BeanContext#BEAN_beanFilters}
- {@link org.apache.juneau.annotation.Bean#interfaceClass() Bean(interfaceClass)}
- {@link org.apache.juneau.transform.BeanFilterBuilder#interfaceClass(Class)}

For example, let's define the following interface and implementation:

// Interface public class MyInterface { public String getFoo(); } // Implementation public class MyInterfaceImpl implements MyInterface { public String getFoo() {...} public String getBar() {...} }

Suppose we only want to render the properties defined on our interface, not the implementation. To do so, we can define the following bean filter:

// Define transform that limits properties to only those defined on MyClass public class MyInterfaceFilter extends BeanFilter<MyInterface> { public MyInterfaceFilter() { interfaceClass(MyInterface.class); } }

When serialized, the serialized bean will only include properties defined on the interface.

WriterSerializer s = JsonSerializer .create() .simple() .beanFilters(MyInterfaceFilter.class) .build(); MyInterface o = new MyInterfaceImpl(); // Prints "{foo:'foo'}" // bar is ignored because it's not on the interface String json = s.serialize(o);

The {@link org.apache.juneau.BeanContextBuilder#beanFilters(Object...)} method will automatically interpret any non-BeanFilter classes passed in as meaning interface classes. So in the previous example, the BeanFilter class could have been avoided altogether by just passing in MyInterface.class to the serializer, like so:

WriterSerializer s = JsonSerializer .create() .beanFilters(MyInterface.class) Shortcut! .build();

The annotation equivalent is {@link org.apache.juneau.annotation.Bean#interfaceClass() Bean#interfaceClass()}.

@Bean(interfaceClass=MyInterface.class) public class MyInterfaceImpl implements MyInterface { public String getFoo() {...} public String getBar() {...} }

The annotation can be used in a couple of ways.

Using the annotation on an interface will be inherited by all children.

@Bean(interfaceClass=MyInterface.class) public class MyInterface { public String getFoo(); }

The annotation can be used on parent classes as well. Child beans will only serialize properties defined on the parent class.

@Bean(interfaceClass=MyAbstractClass.class) public abstract class MyAbstractClass { public String getFoo() {...}; }

#### 2.11.18 - Stop Classes

Whereas interface filters limit properties defined on child classes, stop filters do the opposite and limit properties defined on parent classes.

Stop classes are defined through the following:

- {@link org.apache.juneau.annotation.Bean#stopClass() Bean(stopClass)}
- {@link org.apache.juneau.transform.BeanFilterBuilder#stopClass(Class)}

Stop classes are identical in purpose to the stop class specified by {@link java.beans.Introspector#getBeanInfo(Class, Class)}. Any properties in the stop class or in its base classes will be ignored during serialization.

For example, in the following class hierarchy, instances of C3 will include property p3, but not p1 or p2.

public class C1 { public int getP1(); } public class C2 extends C1 { public int getP2(); } @Bean(stopClass=C2.class) public class C3 extends C2 { public int getP3(); } // Serializes property 'p3', but NOT 'p1' or 'p2'. String json = JsonSerializer.DEFAULT.serialize(new C3());

#### 2.11.19 - Bypass Serialization using Readers and InputStreams

Juneau serializers treat instances of Readers and InputStreams special by simply serializing their contents directly to the output stream or writer. This allows you to embed fully customized serializer output.

public class MyBean { // A bean property that produces raw JSON. public Reader f1 = new StringReader("{'foo':'bar'}"); } // Produces "{f1:{'foo':'bar'}}" String json = SimpleJsonSerializer.DEFAULT .toString(new MyBean());

Note that if you're serializing Readers and InputStreams, it's up to you to make sure you're producing valid output (in this case JSON).

A more typical scenario where this is useful is by using swaps to convert POJOs to Readers whose contents are determined via the {@link org.apache.juneau.BeanSession#getMediaType()} method. In the following example, we're customizing the JSON output for a particular bean type, but leaving all other renditions as-is:

@Swap(MyBeanSwapSometimes.class) public class MyBean {...} // A swap that produces specialized output for JSON, but default serialization for // all other media types. public class MyBeanSwapSometimes extends PojoSwap<MyBean,Object> { public Object swap(BeanSession session, MyPojo o) throws Exception { MediaType mt = session.getMediaType(); if (mt.hasSubType("json")) return new StringReader("{myPojo:'foobar'}"); // Custom JSON output return o; // Otherwise serialize it as a normal bean } }

Due to the nature of the RDF serializers, Readers and InputStreams are serialized as literals, not as RDF text. This is due to the fact that the RDF serializers use a DOM for serialization, so we don't have access to the underlying stream.

### 2.12 - Dynamically Applied Annotations 8.1.3-new

In the section {@doc juneau-marshall.Transforms}, you were introduced to annotations that can be applied to bean classes, methods, fields, and constructors such as {@link org.apache.juneau.annotation.Bean @Bean}:

// Address class with only street/city/state properties (in that order). // All other properties are ignored. @Bean(bpi="street,city,state") public class Address { ... }

An alternate way of applying these annotations is using the @XConfig annotations introduced in section {@doc juneau-marshall.ConfigurableAnnotations}.

// Unannotated class. public class Address { ... } @BeanConfig( applyBean={ @Bean(on="Address", bpi="AddressBean: street,city,state") } } public static class DummyClass {} WriterSerializer ws = JsonSerializer.create().applyAnnotations(DummyClass.class).build(); String json = ws.toString(addressBean);

The advantage to this approach is it allows you to use Juneau annotations on classes/methods/fields/constructors where you might not have access to the source code, or when you only want to selectively apply the annotation under certain scenarios instead of globally.

For example, the following shows the @Bean annotation being selectively applied on a single REST method (described later in {@doc juneau-rest-server}):

@RestMethod @BeanConfig( applyBean={ @Bean(on="Address", bpi="AddressBean: street,city,state") } } public List<Address> getAddresses() {}

Any Juneau annotation that has an on() method can be applied dynamically this way. These include:

- {@link org.apache.juneau.annotation.Bean}
- {@link org.apache.juneau.annotation.Beanc}
- {@link org.apache.juneau.annotation.BeanIgnore}
- {@link org.apache.juneau.annotation.Beanp}
- {@link org.apache.juneau.annotation.Example}
- {@link org.apache.juneau.annotation.NameProperty}
- {@link org.apache.juneau.annotation.ParentProperty}
- {@link org.apache.juneau.annotation.Swap}
- {@link org.apache.juneau.annotation.URI}
- {@link org.apache.juneau.csv.annotation.Csv}
- {@link org.apache.juneau.html.annotation.Html}
- {@link org.apache.juneau.jso.annotation.Jso}
- {@link org.apache.juneau.json.annotation.Json}
- {@link org.apache.juneau.jsonschema.annotation.Schema}
- {@link org.apache.juneau.msgpack.annotation.MsgPack}
- {@link org.apache.juneau.oapi.annotation.OpenApi}
- {@link org.apache.juneau.plaintext.annotation.PlainText}
- {@link org.apache.juneau.soap.annotation.SoapXml}
- {@link org.apache.juneau.uon.annotation.Uon}
- {@link org.apache.juneau.urlencoding.annotation.UrlEncoding}
- {@link org.apache.juneau.xml.annotation.Xml}
- {@link org.apache.juneau.jena.annotation.Rdf}

The valid pattern matches are:

- Classes:
  - Fully qualified:
    - "com.foo.MyClass"
  - Fully qualified inner class:
    - "com.foo.MyClass$Inner1$Inner2"
  - Simple:
    - "MyClass"
  - Simple inner:
    - "MyClass$Inner1$Inner2"
    - "Inner1$Inner2"
    - "Inner2"
- Methods:
  - Fully qualified with args:
    - "com.foo.MyClass.myMethod(String,int)"
    - "com.foo.MyClass.myMethod(java.lang.String,int)"
    - "com.foo.MyClass.myMethod()"
  - Fully qualified:
    - "com.foo.MyClass.myMethod"
  - Simple with args:
    - "MyClass.myMethod(String,int)"
    - "MyClass.myMethod(java.lang.String,int)"
    - "MyClass.myMethod()"
  - Simple:
    - "MyClass.myMethod"
  - Simple inner class:
    - "MyClass$Inner1$Inner2.myMethod"
    - "Inner1$Inner2.myMethod"
    - "Inner2.myMethod"
- Fields:
  - Fully qualified:
    - "com.foo.MyClass.myField"
  - Simple:
    - "MyClass.myField"
  - Simple inner class:
    - "MyClass$Inner1$Inner2.myField"
    - "Inner1$Inner2.myField"
    - "Inner2.myField"
- Constructors:
  - Fully qualified with args:
    - "com.foo.MyClass(String,int)"
    - "com.foo.MyClass(java.lang.String,int)"
    - "com.foo.MyClass()"
  - Simple with args:
    - "MyClass(String,int)"
    - "MyClass(java.lang.String,int)"
    - "MyClass()"
  - Simple inner class:
    - "MyClass$Inner1$Inner2()"
    - "Inner1$Inner2()"
    - "Inner2()"
- A comma-delimited list of anything on this list.

### 2.13 - Bean Names and Dictionaries

While parsing into beans, Juneau attempts to determine the class types of bean properties through reflection on the bean property getter or setter. Often this is insufficient if the property type is an interface or abstract class that cannot be instantiated. This is where bean names and dictionaries come into play.

Bean names and dictionaries are used for identifying class types when they cannot be inferred through reflection.

Bean classes are given names through the {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)} annotation. These names are then added to the serialized output as virtual "_type" properties (or element names in XML).

On the parsing side, these type names are resolved to classes through the use of bean dictionaries.

For example, if a bean property is of type Object, then the serializer will add "_type" attributes so that the class can be determined during parsing.

@Bean(typeName="foo") public class Foo { // A bean property where the object types cannot be inferred since it's an Object[]. @Beanp(dictionary={Bar.class,Baz.class}) public Object[] x = new Object[]{new Bar(), new Baz()}; } @Bean(typeName="bar") public class Bar {} @Bean(typeName="baz") public class Baz {}

When serialized as JSON, "_type" attributes would be added when needed to infer the type during parsing:

{ x: [ {_type:'bar'}, {_type:'baz'} ] }

Type names can be represented slightly differently in different languages. For example, the dictionary name is used as element names when serialized to XML. This allows the typeName annotation to be used as a shortcut for defining element names for beans.

When serialized as XML, the bean is rendered as:

<foo> <x> <bar/> <baz/> </x> </foo>

Bean dictionaries are registered through the following:

- {@link org.apache.juneau.annotation.Beanp#dictionary() Beanp(dictionary)} - On individual bean properties through the annotation.
- {@link org.apache.juneau.annotation.Bean#dictionary() Bean(dictionary)} - On all properties on a bean and all subclasses.
- {@link org.apache.juneau.BeanContext#BEAN_beanDictionary} - Configuration property on serializers and parsers.
- {@link org.apache.juneau.BeanContextBuilder#dictionary(Object...)} - Builder method on serializers and parsers.

The bean dictionary setting can consist of any of the following types:

- Any bean class that specifies a value for {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)}.
- Any subclass of {@link org.apache.juneau.BeanDictionaryList} containing a collection of bean classes with type name annotations.
- Any subclass of {@link org.apache.juneau.BeanDictionaryMap} containing a mapping of type names to classes without type name annotations.
- Any array or collection of the objects above.

// Create a parser and tell it which classes to try to resolve. ReaderParser p = JsonParser .create() .dictionary(Foo.class, Bar.class) .build(); // Same, but use property. ReaderParser p = JsonParser .create() .addTo(BEAN_beanDictionary, Foo.class) .addTo(BEAN_beanDictionary, Bar.class) .build(); // Use the predefined HTML5 bean dictionary which is a BeanDictionaryList. ReaderParser p = HtmlParser .create() .dictionary(HtmlBeanDictionary.class) .build();

The "_type" property name can be overridden through the following:

- {@link org.apache.juneau.annotation.Bean#typePropertyName() Bean(typePropertyName)} - On individual beans through the annotation.
- {@link org.apache.juneau.BeanContext#BEAN_beanTypePropertyName} - Configuration property on serializers and parsers.
- {@link org.apache.juneau.BeanContextBuilder#beanTypePropertyName(String)} - Builder method on serializers and parsers.

When using the annotation, you'll typically want to define it on an interface class so that it can be inherited by all subclasses.

@Bean(typePropertyName="mytype", dictionary={MyClass1.class,MyClass2.class}) public interface MyInterface {...} @Bean(typeName="C1") public class MyClass1 implements MyInterface {...} @Bean(typeName="C2") public class MyClass2 implements MyInterface {...} MyInterface[] x = new MyInterface[]{ new MyClass1(), new MyClass2() }; // Produces "[{mytype:'C1',...},{mytype:'C2',...}]" String json = SimpleJsonSerializer.DEFAULT.serialize(x);

Type names do not need to be universally unique. However, they must be unique within a dictionary.
The following reserved words cannot be used as type names: object, array, number, boolean, null.
Serialized type names are DISABLED by default. They must be enabled on the serializer using the {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addBeanTypes} configuration property.

#### 2.13.1 - Bean Subtypes

In addition to the bean type name support described above, simplified support is provided for bean subtypes.

Bean subtypes are similar in concept to bean type names, except for the following differences:

- You specify the list of possible subclasses through an annotation on a parent bean class.
- You do not need to register the subtype classes on the bean dictionary of the parser.

In the following example, the abstract class has two subclasses:

// Abstract superclass @Bean( dictionary={A1.class, A2.class} ) public abstract class A { public String f0 = "f0"; } // Subclass 1 @Bean(typeName="A1") public class A1 extends A { public String f1; } // Subclass 2 @Bean(typeName="A2") public class A2 extends A { public String f2; }

When serialized, the subtype is serialized as a virtual "_type" property:

JsonSerializer s = SimpleJsonSerializer.DEFAULT; A1 a1 = new A1(); a1.f1 = "f1"; String r = s.serialize(a1); assertEquals("{_type:'A1',f1:'f1',f0:'f0'}", r);

The following shows what happens when parsing back into the original object.

JsonParser p = JsonParser.DEFAULT; A a = p.parse(r, A.class); assertTrue(a instanceof A1);

### 2.14 - Virtual Beans

The {@link org.apache.juneau.BeanContext#BEAN_useInterfaceProxies} setting (enabled by default) allows the Juneau parsers to parse content into virtual beans (bean interfaces without implementation classes).

For example, the following code creates an instance of the specified unimplemented interface:

// Our unimplemented interface public interface Address { String getStreet(); void setStreet(String x); String getCity(); void setCity(String x); StateEnum getState(); void setState(StateEnum x); int getZip(); void setZip(int zip); } // Our code Address address = JsonParser.DEFAULT.parse( "{street:'123 Main St', city:'Anywhere', state:'PR', zip:12345}", Address.class ); int zip = address.getZip(); address.setState(StateEnum.NY);

Getter and setter values can be any {@doc PojoCategories parsable} values, even other virtual beans.

Under-the-covers, a virtual bean is simply a proxy interface on top of an existing BeanMap instance. From a programmatic point-of-view, they're indistinguishable from real beans, and can be manipulated and serialized like any other bean.

Virtual beans can also be created programmatically using the BeanContext class:

Address address = BeanContext.DEFAULT.createSession().newBean(Address.class);

### 2.15 - Non-Tree Models and Recursion Detection

The Juneau Serializer API is designed to be used against POJO tree structures. It expects that there not be loops in the POJO model (e.g. children with references to parents, etc...). If you try to serialize models with loops, you will usually cause a StackOverflowError to be thrown (if {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_maxDepth} is not reached first).

If you still want to use the Juneau serializers on such models, Juneau provides the {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_detectRecursions} setting. It tells the serializer to look for instances of an object in the current branch of the tree and skip serialization when a duplicate is encountered.

For example, let's make a POJO model out of the following classes:

public class A { public B b; } public class B { public C c; } public class C { public A a; }

Now we create a model with a loop and serialize the results.

// Clone an existing serializer and set property for detecting recursions. JsonSerializer s = SimpleJsonSerializer.DEFAULT_READABLE.builder().detectRecursions(true).build(); // Create a recursive loop. A a = new A(); a.b = new B(); a.b.c = new C(); a.b.c.a = a; // Serialize to JSON. String json = s.serialize(a);

What we end up with is the following, which does not serialize the contents of the c field:

{ b: { c: { } } }

Without recursion detection enabled, this would cause a stack-overflow error.

Recursion detection introduces a performance penalty of around 20%. For this reason the setting is disabled by default.

### 2.16 - Parsing into Generic Models

The Juneau parsers are not limited to parsing back into the original bean classes. If the bean classes are not available on the parsing side, the parser can also be used to parse into a generic model consisting of Maps, Collections, and primitive objects.

You can parse into any Map type (e.g. HashMap, TreeMap), but using {@link org.apache.juneau.ObjectMap} is recommended since it has many convenience methods for converting values to various types. The same is true when parsing collections. You can use any Collection (e.g. HashSet, LinkedList) or array (e.g. Object[], String[], String[][]), but using {@link org.apache.juneau.ObjectList} is recommended.

When the map or list type is not specified, or is the abstract Map, Collection, or List types, the parser will use ObjectMap and ObjectList by default.

For example, given the following JSON:

{ id: 1, name: 'John Smith', uri: 'http://sample/addressBook/person/1', addressBookUri: 'http://sample/addressBook', birthDate: '1946-08-12T00:00:00Z', addresses: [ { uri: 'http://sample/addressBook/address/1', personUri: 'http://sample/addressBook/person/1', id: 1, street: '100 Main Street', city: 'Anywhereville', state: 'NY', zip: 12345, isCurrent: true } ] }

We can parse this into a generic ObjectMap:

// Parse JSON into a generic POJO model. ObjectMap m = JsonParser.DEFAULT.parse(json, ObjectMap.class); // Convert it back to JSON. String json = SimpleJsonSerializer.DEFAULT_READABLE.serialize(m);

What we end up with is the exact same output. Even the numbers and booleans are preserved because they are parsed into Number and Boolean objects when parsing into generic models.

{ id: 1, name: 'John Smith', uri: 'http://sample/addressBook/person/1', addressBookUri: 'http://sample/addressBook', birthDate: '1946-08-12T00:00:00Z', addresses: [ { uri: 'http://sample/addressBook/address/1', personUri: 'http://sample/addressBook/person/1', id: 1, street: '100 Main Street', city: 'Anywhereville', state: 'NY', zip: 12345, isCurrent: true } ] }

Once parsed into a generic model, various convenience methods are provided on the ObjectMap and ObjectList classes to retrieve values:

// Parse JSON into a generic POJO model. ObjectMap m = JsonParser.DEFAULT.parse(json, ObjectMap.class); // Get some simple values. String name = m.getString("name"); int id = m.getInt("id"); // Get a value convertable from a String. URI uri = m.get(URI.class, "uri"); // Get a value using a swap. TemporalCalendarSwap swap = new TemporalCalendarSwap.IsoInstant(); Calendar birthDate = m.get(swap, "birthDate"); // Get the addresses. ObjectList addresses = m.getObjectList("addresses"); // Get the first address and convert it to a bean. Address address = addresses.get(Address.class, 0);

As a general rule, parsing into beans is often more efficient than parsing into generic models. And working with beans is often less error prone than working with generic models.

### 2.17 - Reading Continuous Streams

The following parsers can be configured to read continuous streams of objects from the same input stream:

- {@link org.apache.juneau.json.JsonParser}
- {@link org.apache.juneau.uon.UonParser}
- {@link org.apache.juneau.msgpack.MsgPackParser}

The {@link org.apache.juneau.json.JsonParser} and {@link org.apache.juneau.uon.UonParser} classes can read continuous streams by using the {@link org.apache.juneau.parser.Parser#PARSER_unbuffered PARSER_unbuffered} setting. This prevents the parsers from using an internal buffer that would read past the end of the currently parsed POJO.

##### Examples:

// If you're calling parse on the same input multiple times, use a session instead of the parser directly. ReaderParserSession p = JsonParser.create().unbuffered().build().createSession(); Object x; Reader r; r = new StringReader("{foo:'bar'}{baz:'qux'}"); x = p.parse(r, ObjectMap.class); // {foo:'bar'} x = p.parse(r, ObjectMap.class); // {baz:'qux'} r = reader("[123][456]"); x = p.parse(r, int[].class); // [123] x = p.parse(r, int[].class); // [456]

Note that this isn't perfect in all cases since you can't combine two JSON numbers into a single reader (e.g. "123" + "456" = "123456").

For obvious reasons, do not use the following properties when reading continuous streams:

- {@link org.apache.juneau.json.JsonParser#JSON_validateEnd}
- {@link org.apache.juneau.uon.UonParser#UON_validateEnd}
- {@link org.apache.juneau.parser.Parser#PARSER_autoCloseStreams}

The {@link org.apache.juneau.msgpack.MsgPackParser} class doesn't use any internal buffering to begin with, so it can be used with continuous streams without any special properties.

### 2.18 - URIs

Juneau serializers have sophisticated support for transforming relative URIs to absolute form.

The classes and settings that control the behavior are:

- {@link org.apache.juneau.UriResolver}
- {@link org.apache.juneau.UriContext}
- {@link org.apache.juneau.UriRelativity}
- {@link org.apache.juneau.UriResolution}
- {@link org.apache.juneau.serializer.Serializer}
  - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriContext}
  - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriRelativity}
  - {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriResolution}

The following example shows a bean containing URIs of various forms and how they end up serialized.

// Our bean with properties containing various kinds of URIs. public class TestURIs { public URI f1a = URI.create("http://www.apache.org/f1a"), f1b = URI.create("/f1b"), f1c = URI.create("/f1c/x/y"), f1d = URI.create("f1d"), f1e = URI.create("f1e/x/y"), f1f = URI.create(""), f2a = URI.create("context:/f2a/x"), f2b = URI.create("context:/f2b"), f2c = URI.create("context:/"), f2d = URI.create("context:/.."), f3a = URI.create("servlet:/f3a/x"), f3b = URI.create("servlet:/f3b"), f3c = URI.create("servlet:/"), f3d = URI.create("servlet:/.."), f4a = URI.create("request:/f4a/x"), f4b = URI.create("request:/f4b"), f4c = URI.create("request:/"), f4d = URI.create("request:/..");; } // Create a serializer. WriterSerializer s = JsonSerializer create() .simple() .uriContext("{authority:'http://foo.com:123',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/myPath'}") .uriResolution(ABSOLUTE) .uriRelativity(RESOURCE) .build(); // Produces: // { // f1a:'http://www.apache.org/f1a', // f1b:'http://foo.com:123/f1b', // f1c:'http://foo.com:123/f1c/x/y', // f1d:'http://foo.com:123/myContext/myServlet/f1d', // f1e:'http://foo.com:123/myContext/myServlet/f1e/x/y', // f1f:'http://foo.com:123/myContext/myServlet', // f2a:'http://foo.com:123/myContext/f2a/x', // f2b:'http://foo.com:123/myContext/f2b', // f2c:'http://foo.com:123/myContext', // f2d:'http://foo.com:123' // f3a:'http://foo.com:123/myContext/myServlet/f3a/x', // f3b:'http://foo.com:123/myContext/myServlet/f3b', // f3c:'http://foo.com:123/myContext/myServlet', // f3d:'http://foo.com:123/myContext', // f4a:'http://foo.com:123/myContext/myServlet/myPath/f4a/x', // f4b:'http://foo.com:123/myContext/myServlet/myPath/f4b', // f4c:'http://foo.com:123/myContext/myServlet/myPath', // f4d:'http://foo.com:123/myContext/myServlet' // } String json = s.serialize(new TestURIs());

URI resolution is controlled by the following settings:

- {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriContext}
  Setting that defines the URI contextual information used to resolve relative URIs.
- {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriRelativity}
  Setting that defines how relative URIs should be interpreted.
  Possible values:
  - {@link org.apache.juneau.UriRelativity#RESOURCE}
    Relative URIs should be considered relative to the servlet URI.
    (e.g. "http://host:port/context-root/servlet-path").
  - {@link org.apache.juneau.UriRelativity#PATH_INFO}
    Relative URIs should be considered relative to the request URI.
    (e.g. "http://host:port/context-root/servlet-path/path-info").
- {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriResolution}
  Setting that defines the final format of serialized URIs.
  Possible values:
  - {@link org.apache.juneau.UriResolution#ABSOLUTE}
    Resolve to an absolute URL.
    (e.g. "http://host:port/context-root/servlet-path/path-info").
  - {@link org.apache.juneau.UriResolution#ROOT_RELATIVE}
    Resolve to a root-relative URL.
    (e.g. "/context-root/servlet-path/path-info").
  - {@link org.apache.juneau.UriResolution#NONE}
    Don't do any URL resolution.

Juneau automatically interprets any {@link java.net.URL} and {@link java.net.URI} objects as URIs and will resolve them accordingly. The {@link org.apache.juneau.annotation.URI @URI} annotation can be used to extend that to other bean properties and class types so that they also get interpreted as URIs. For example:

// Applied to a class whose toString() method returns a URI. @URI public class MyURI { @Override /* Object */ public String toString() { return "http://localhost:9080/foo/bar"; } } // Applied to bean properties public class MyBean { @URI public String beanUri; @URI public String getParentUri() { ... } }

### 2.19 - Comparison with Jackson

Juneau was developed independently from Jackson, but shares many of the same features and capabilities. Whereas Jackson was created to work primarily with JSON, Juneau was created to work for multiple languages. Therefore, the terminology and annotations in Juneau are similar, but language-agnostic.

The following charts describe equivalent features between the two libraries:

##### Annotations

Jackson | Juneau
--- | ---
@JsonGetter @JsonSetter | {@link org.apache.juneau.annotation.Beanp @Beanp}
@JsonAnyGetter @JsonAnySetter | {@link org.apache.juneau.annotation.Beanp#name() @Beanp(name="*")}
@JsonIgnore @JsonIgnoreType | {@link org.apache.juneau.annotation.BeanIgnore @BeanIgnore}
@JsonIgnoreProperties({...}) | {@link org.apache.juneau.annotation.Bean#bpx @Bean(bpx="...")}
@JsonAutoDetect(fieldVisibility=...) | No equivalent annotation, but can be controlled via: {@link org.apache.juneau.BeanContext#BEAN_beanFieldVisibility} {@link org.apache.juneau.BeanContext#BEAN_beanMethodVisibility} Future annotation support planned.
@JsonCreator @JsonProperty | {@link org.apache.juneau.annotation.Beanc @Beanc}
@JacksonInject | No equivalent. Future support planned.
@JsonSerialize @JsonDeserialize | Juneau uses swaps to convert non-serializable object to serializable forms: {@link org.apache.juneau.annotation.Swap @Swap}
@JsonInclude | No equivalent annotation, but can be controlled via various settings: {@link org.apache.juneau.BeanContext} {@link org.apache.juneau.serializer.Serializer} Future annotation support planned.
@JsonPropertyOrder | {@link org.apache.juneau.annotation.Bean#properties @Bean(bpi="...")} {@link org.apache.juneau.annotation.Bean#sort @Bean(sort=x)}
@JsonValue @JsonRawValue | Can be replicated using swaps with Reader swapped values.

### 2.20 - POJO Categories

The following chart shows POJOs categorized into groups and whether they can be serialized or parsed:

##### General POJO serialization/parsing support

Group | Description | Examples | Can serialize? | Can parse?
--- | --- | --- | --- | ---
1 | Java primitives and primitive objects | {@code String} {@code Integer} {@code Float} {@code Boolean} | yes | yes
2 | Java Collections Framework objects, Java arrays, Java Optionals |  |  |
2a | With standard keys/values Map keys are group [1, 4a, 6a] objects. Map, Collection, Optional, and array values are group [1, 2, 3ac, 4a, 6a] objects. | HashSet<String,Integer> TreeMap<Integer,Bean> List<int[][]> Bean[] Optional<Bean> | yes | yes
2b | With non-standard keys/values Map keys are group [2, 3, 4b, 5, 6b, 7] objects. Map, Collection, and array values are group [3b, 4b, 5, 6b, 7] objects. | HashSet<Bean,Integer> TreeMap<Integer,Reader> Optional<Reader> | yes | no
3 | Java Beans |  |  |
3a | With standard properties These are beans that have one or more properties defined by public getter or public fields. Properties can also be defined as final read-only fields and passed in as constructor args. Property values are group [1, 2, 3ac, 4a, 6a] objects. |  | yes | yes
3b | With non-standard properties or not true beans These include true beans that have one or more properties defined by getter and setter methods or properties, but property types include group [3b, 4b, 5, 6b, 7] objects. This also includes classes that look like beans but aren't true beans. For example, classes that have getters but not setters, or classes without no-arg constructors. |  | yes | no
3c | Virtual beans These are unimplemented bean interfaces with properties of type [1, 2, 3ac, 4a, 6a] objects. Parsers will automatically create interface proxies on top of BeanMap instances. |  | yes | yes
3d | Read-only beans without setters The same as 3a, but without property setters or constructor args. |  | yes | no
4 | Swapped objects These are objects that are not directly serializable, but have {@link org.apache.juneau.transform.PojoSwap PojoSwaps} associated with them. The purpose of a POJO swap is to convert an object to another object that is easier to serialize and parse. For example, the {@link org.apache.juneau.transforms.TemporalDateSwap.IsoLocalDateTime} class can be used to serialize {@link java.util.Date} objects to ISO8601 strings, and parse them back into {@link java.util.Date} objects. |  |  |
4a | 2-way swapped to group [1, 2a, 3ac] objects For example, a swap that converts a {@code Date} to a {@code String}. | java.util.Date java.util.GregorianCalendar | yes | yes
4b | 1-way swapped to group [1, 2, 3] objects For example, a swap that converts an {@code Iterator} to a {@code List}. This would be one way, since you cannot reconstruct an {@code Iterator}. | java.util.Iterator | yes | no
5 | Readers and InputStreams Contents are serialized directly to the output stream or writer. Typically used for low-level language-specific replacement of POJOs using per-Media-Type POJO swaps. | {@code FileInputStream} {@code StringReader} | yes | no
6 | Non-serializable objects with standard methods for converting to a serializable form |  |  |
6a | Classes with a method that converts it to a serializable form: public X swap(BeanSession); where X is in groups [1, 2a, 3ac]. public String toString(); where the string is any meaningful data. And a method that converts it back into the original object: public static T fromString(String); public static T valueOf(String); public static T parse(String); public static T parseString(String); public static T forName(String); public static T forString(String); public T(X); where X is in groups [1, 2a, 3ac]. public static T unswap(BeanSession,X); where X is in groups [1, 2a, 3ac]. | java.lang.Class java.sql.Time java.sql.Timestamp java.text.MessageFormat java.text.NumberFormat java.util.Date java.util.UUID java.util.logging.Level javax.xml.bind.DatatypeConverter | yes | yes
6b | Classes that only have a method to convert to a serializable form: public X swap(BeanSession); where X is in groups [1, 2, 3]. public String toString(); where the string is any meaningful data. |  | yes | no
7 | All other objects Anything that doesn't fall into one of the groups above are simply converted to {@code Strings} using the {@code toString()} method. |  | yes | no

Serializers are designed to work on tree-shaped POJO models. These are models where there are no referential loops (e.g. leaves with references to nodes, or nodes in one branch referencing nodes in another branch). There is a serializer setting {@code detectRecursions} to look for and handle these kinds of loops (by setting these references to null), but it is not enabled by default since it introduces a moderate performance penalty.

##### POJOs convertible to/from Strings

A separate category exists for POJOs that can be converted to and from Strings. These are used in places such as:

- Serializing of POJOs to Strings in the REST client API when no serializers are registered.
- Parsing of POJOs from Strings in the REST server API for "text/plain" requests where "text/plain" is not already mapped to an existing serializer.

As a general rule, all POJOs are converted to Strings using the toString() method. However, there is one exception:

- {@link java.util.TimeZone} - Uses {@link java.util.TimeZone#getID()}

POJOs are convertible from Strings using any of the following (matched in the specified order):

- Any any of the following public static non-deprecated methods:
  - create(String)
  - fromString(String)
  - fromValue(String)
  - valueOf(String)
  - parse(String)
  - parseString(String)
  - forName(String)
  - forString(String)
- Has a public constructor that takes in a String.

Exceptions exist for the following classes:

- {@link java.util.TimeZone} - Uses {@link java.util.TimeZone#getTimeZone(String)}
- {@link java.util.Locale} - Uses {@link java.util.Locale#forLanguageTag(String)} after replacing '_' with '-'.
- {@link java.lang.Boolean} - Blank and "null" are interpreted as null values.
- Primitives (except for void.class) - Uses the primitive wrapper classes for instantiating from Strings.

##### POJOs convertible to/from other types

POJOs are also converted to various other types in places such as the Open-API serializers and parsers. In this section, the type being converted to will be referred to as X.

POJOs are considered convertible from X if it has any of the following (matched in the specified order):

- Any any of the following public static non-deprecated methods:
  - create(X)
  - from*(X)
- Has a public constructor that takes in an X.
- The X class has a public non-static no-arg non-deprecated method called to*().

POJOs are considered convertible from X if any of the reverse of above are true.

### 2.21 - JSON Details

Juneau supports converting arbitrary POJOs to and from JSON using ultra-efficient serializers and parsers. The JSON serializer converts POJOs directly to JSON without the need for intermediate DOM objects using a highly-efficient state machine. Likewise, the JSON parser creates POJOs directly from JSON without the need for intermediate DOM objects.

The following example shows JSON for a typical bean:

##### Sample Beans

public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

##### Sample Code

Person p = new Person() .name("John Smith") .birthDate("1946-08-12T00:00:00Z") .addresses( new Address() .street("100 Main Street") .city("Anywhereville") .state(NY) .zip(12345) .isCurrent(true); );

##### Normal JSON

{ "name": "John Smith", "birthDate": "1946-08-12T00:00:00Z", "addresses": [ { "street": "100 Main Street", "city": "Anywhereville", "state": "NY", "zip": 12345, "isCurrent": true } ] }

##### Simplified JSON

{ name: 'John Smith', birthDate: '1946-08-12T00:00:00Z', addresses: [ { street: '100 Main Street', city: 'Anywhereville', state: 'NY', zip: 12345, isCurrent: true } ] }

#### 2.21.1 - JSON Methodology

The JSON data type produced depends on the Java object type being serialized.

- Primitives and primitive objects are converted to JSON primitives.
- Beans and Maps are converted to JSON objects.
- Collections and arrays are converted to JSON arrays.
- Anything else is converted to JSON strings.

##### Data type conversions:

POJO type | JSON type | Example | Serialized form
--- | --- | --- | ---
String | String | serialize("foobar"); | 'foobar'
Number | Number | serialize(123); | 123
Boolean | Boolean | serialize(true); | true
Null | Null | serialize(null); | null
Beans with properties of any type on this list | Object | serialize(new MyBean()); | {p1:'val1',p2:true}
Maps with values of any type on this list | Object | serialize(new TreeMap()); | {key1:'val1',key2:true}
Collections and arrays of any type on this list | Array | serialize(new Object[]{1,"foo",true}); | [1,'foo',true]

In addition, swaps can be used to convert non-serializable POJOs into serializable forms, such as converting Calendar object to ISO8601 strings, or byte[] arrays to Base-64 encoded strings.

#### 2.21.2 - JSON Serializers

The {@link org.apache.juneau.json.JsonSerializer} class is used to serialize POJOs into JSON.

The JSON serializer provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.json.JsonSerializer}
  - {@link org.apache.juneau.json.JsonSerializer#JSON_addBeanTypes JSON_addBeanTypes}
  - {@link org.apache.juneau.json.JsonSerializer#JSON_escapeSolidus JSON_escapeSolidus}
  - {@link org.apache.juneau.json.JsonSerializer#JSON_simpleMode JSON_simpleMode}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.json.JsonSerializer}
  - {@link org.apache.juneau.json.JsonSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.json.JsonSerializer#DEFAULT_READABLE DEFAULT_READABLE}
- {@link org.apache.juneau.json.SimpleJsonSerializer}
  - {@link org.apache.juneau.json.SimpleJsonSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.json.SimpleJsonSerializer#DEFAULT_READABLE DEFAULT_READABLE}

#### 2.21.3 - Simplified JSON

The {@link org.apache.juneau.json.SimpleJsonSerializer} class can be used to serialized POJOs into Simplified JSON notation.

Simplified JSON is identical to JSON except for the following:

- JSON attributes are only quoted when necessary.
- Uses single-quotes for quoting.

##### Examples:

// Some free-form JSON. ObjectMap m = new ObjectMap() .append("foo", "x1") .append("_bar", "x2") .append(" baz ", "x3") .append("123", "x4") .append("return", "x5"); .append("", "x6");

// Serialized to standard JSON { "foo": "x1", "_bar": "x2", " baz ": "x3", "123": "x4", "return": "x5", "": "x6" }

// Serialized to simplified JSON { foo: 'x1', _bar: 'x2', ' baz ': 'x3', // Quoted due to embedded spaces. '123': 'x4', // Quoted to prevent confusion with number. 'return': 'x5', // Quoted because it's a keyword. '': 'x6' // Quoted because it's an empty string. }

The advantage to simplified JSON is you can represent it in a Java String in minimal form with minimal escaping. This is particularly useful in cases such as unit testing where you can easily validate POJOs by simplifying them to Simplified JSON and do a simple string comparison.

WriterSerializer ws = SimpleJsonSerializer.DEFAULT; assertEquals("{foo:'bar',baz:123}", ws.toString(myPojo));

- {@link org.apache.juneau.json.JsonSerializer#JSON_simpleMode}

#### 2.21.4 - JSON Parsers

The {@link org.apache.juneau.json.JsonParser} class is used to parse JSON into POJOs.

The JSON parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser Properties}
- {@link org.apache.juneau.json.JsonParser}
  - {@link org.apache.juneau.json.JsonParser#JSON_validateEnd JSON_validateEnd}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.json.JsonParser}
  - {@link org.apache.juneau.json.JsonParser#DEFAULT DEFAULT}
  - {@link org.apache.juneau.json.JsonParser#DEFAULT_STRICT DEFAULT_STRICT}

The JSON parser supports ALL valid JSON, including:

- Javascript comments.
- Single or double quoted values.
- Quoted (strict) or unquoted (non-strict) attributes.
- JSON fragments (such as string, numeric, or boolean primitive values).
- Concatenated strings.

#### 2.21.5 - @Json Annotation

The {@link org.apache.juneau.json.annotation.Json @Json} annotation is used to override the behavior of {@link org.apache.juneau.json.JsonSerializer} on individual bean classes or properties.

The annotation can be applied to beans as well as other objects serialized to other types (e.g. strings).

- {@link org.apache.juneau.json.annotation.Json}
  - {@link org.apache.juneau.json.annotation.Json#wrapperAttr() wrapperAttr}

The {@link org.apache.juneau.json.annotation.Json#wrapperAttr() @Json(wrapperAttr)} annotation can be used to wrap beans inside a JSON object with a specified attribute name.

##### Example:

@Json(wrapperAttr="personBean") public class Person { public String name = "John Smith"; }

The following shows the JSON representation with and without the annotation present:

Without annotation | With annotation
--- | ---
{ name: 'John Smith' } | { personBean: { name: 'John Smith' } }

#### 2.21.6 - JSON-Schema Support

Juneau provides the {@link org.apache.juneau.json.JsonSchemaSerializer} class for generating JSON-Schema documents that describe the output generated by the {@link org.apache.juneau.json.JsonSerializer} class. This class shares the same properties as JsonSerializer. For convenience the {@link org.apache.juneau.json.JsonSerializer#getSchemaSerializer()} method has been added for creating instances of schema serializers from the regular serializer instance.

##### Sample Beans

public class Person { // Bean properties public String name; public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

The code for creating our POJO model and generating JSON-Schema is shown below:

// Get the one of the default schema serializers. JsonSchemaSerializer s = JsonSchemaSerializer.DEFAULT_SIMPLE_READABLE; // Get the JSON Schema for the POJO. String jsonSchema = s.serialize(new Person()); // This also works. jsonSchema = s.serialize(Person.class);

##### JSON Schema

{ type: 'object', description: 'org.apache.juneau.sample.Person', properties: { name: { type: 'string', description: 'java.lang.String' }, birthDate: { type: 'string', description: 'java.util.Calendar' }, addresses: { type: 'array', description: 'java.util.LinkedList<org.apache.juneau.sample.Address>', items: { type: 'object', description: 'org.apache.juneau.sample.Address', properties: { street: { type: 'string', description: 'java.lang.String' }, city: { type: 'string', description: 'java.lang.String' }, state: { type: 'string', description: 'java.lang.String' }, zip: { type: 'number', description: 'int' }, isCurrent: { type: 'boolean', description: 'boolean' } } } } } }

### 2.22 - XML Details

Juneau supports converting arbitrary POJOs to and from XML using ultra-efficient serializers and parsers. The XML serializer converts POJOs directly to XML without the need for intermediate DOM objects. Likewise, the XML parser uses a STaX parser and creates POJOs directly without intermediate DOM objects.

Unlike frameworks such as JAXB, Juneau does not require POJO classes to be annotated to produce and consume XML. However, several XML annotations are provided for handling namespaces and fine-tuning the format of the XML produced.

The following example shows XML for a typical bean:

##### Sample Beans

@Bean(typeName="person") public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } @Bean(typeName="address") public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

##### Sample Code

Person p = new Person() .name("John Smith") .birthDate("1946-08-12T00:00:00Z") .addresses( new Address() .street("100 Main Street") .city("Anywhereville") .state(NY) .zip(12345) .isCurrent(true); );

##### Normal XML:

<person> <name>John Smith</name> <birthDate>1946-08-12T04:00:00Z</birthDate> <addresses> <address> <street>100 Main Street</street> <city>Anywhereville</city> <state>NY</state> <zip>12345</zip> <isCurrent>true</isCurrent> </address> </addresses> </person>

Juneau produces JSON-equivalent XML, meaning any valid JSON document can be losslessly converted into an XML equivalent. In fact, all of the Juneau serializers and parsers are built upon this JSON-equivalence.

#### 2.22.1 - XML Methodology

The following examples show how different data types are represented in XML. They mirror how the data structures are represented in JSON.

##### Simple types

The representation of loose (not a direct bean property value) simple types are shown below:

Data type | JSON example | XML
--- | --- | ---
string | 'foo' | <string>foo</string>
boolean | true | <boolean>true</boolean>
integer | 123 | <number>123</number>
float | 1.23 | <number>1.23</number>
null | null | <null/>

##### Maps

Loose maps and beans use the element <object> for encapsulation.

_type attributes are added to bean properties or map entries if the type cannot be inferred through reflection (e.g. an Object or superclass/interface value type).

Data type | JSON example | XML
--- | --- | ---
Map<String,String> | { k1: 'v1' k2: null } | <object> <k1>v1</k1> <k2 _type='null'/> </object>
Map<String,Number> | { k1: 123, k2: 1.23, k3: null } | <object> <k1>123</k1> <k2>1.23</k2> <k3 _type='null'/> </object>
Map<String,Object> | { k1: 'v1' k2: 123, k3: 1.23, k4: true, k5: null } | <object> <k1>v1</k1> <k2 _type='number'>123</k2> <k3 _type='number'>1.23</k3> <k4 _type='boolean'>true</k4> <k5 _type='null'/> </object>

##### Arrays

Loose collections and arrays use the element <array> for encapsulation.

Data type | JSON example | XML
--- | --- | ---
String[] | [ 'foo' null ] | <array> <string>foo</string> <null/> </array>
Number[] | [ 123, 1.23, null ] | <array> <number>123</number> <number>1.23</number> <null/> </array>
Object[] | [ 'foo', 123, 1.23, true, null ] | <array> <string>foo</string> <number>123</number> <number>1.23</number> <boolean>true</boolean> <null/> </array>
String[][] | [ ['foo', null], null, ] | <array> <array> <string>foo</string> <null/> </array> <null/> </array>
int[] | [ 123 ] | <array> <number>123</number> </array>
boolean[] | [ true ] | <array> <boolean>true</boolean> </array>
List<String> | [ 'foo' null ] | <array> <string>foo</string> <null/> </array>
List<Number> | [ 123, 1.23, null ] | <array> <number>123</number> <number>1.23</number> <null/> </array>
List<Object> | [ 'foo', 123, 1.23, true, null ] | <array> <string>foo</string> <number>123</number> <number>1.23</number> <boolean>true</boolean> <null/> </array>

##### Beans

Data type | JSON example | XML
--- | --- | ---
class MyBean { public String a; public int b; public Object c; // String value public Object d; // Integer value public MyBean2 e; public String[] f; public int[] g; } class MyBean2 { String h; } | { a: 'foo', b: 123, c: 'bar', d: 456, e: { h: 'baz' } f: ['qux'] g: [789] } | <object> <a>foo</a> <b>123</b> <c>bar</c> <d _type='number'>456</d> <e> <h>baz</h> </e> <f> <string>qux</string> </f> <g> <number>789</number> </g> </object>

##### Beans with Map properties

Data type | JSON example | XML
--- | --- | ---
class MyBean { public Map<String,String> a; public Map<String,Number> b; public Map<String,Object> c; } | { a: { k1: 'foo' }, b: { k2: 123 }, c: { k3: 'bar', k4: 456, k5: true, k6: null } } | <object> <a> <k1>foo</k1> </a> <b> <k2>123</k2> </b> <c> <k3>bar</k3> <k4 _type='number'>456</k4> <k5 _type='boolean'>true</k5> <k6 _type='null'/> </c> </object>

#### 2.22.2 - XML Serializers

The {@link org.apache.juneau.xml.XmlSerializer} class is used to serialize POJOs into XML.

The {@link org.apache.juneau.xml.XmlDocSerializer} class is the same, but serializes a <?xml?> header at the top of the file.

The XML serializers provide the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.xml.XmlSerializer}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_addBeanTypes XML_addBeanTypes}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_addNamespaceUrisToRoot XML_addNamespaceUrisToRoot}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_autoDetectNamespaces XML_autoDetectNamespaces}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_defaultNamespace XML_defaultNamespace}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_enableNamespaces XML_enableNamespaces}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_namespaces XML_namespaces}
  - {@link org.apache.juneau.xml.XmlSerializer#XML_xsNamespace XML_xsNamespace}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.xml.XmlSerializer}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_JUNEAU_NAMESPACE DEFAULT_JUNEAU_NAMESPACE}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_NS DEFAULT_NS}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_NS_SQ DEFAULT_NS_SQ}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_NS_SQ_READABLE DEFAULT_NS_SQ_READABLE}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_SQ DEFAULT_SQ}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_SQ_READABLE DEFAULT_SQ_READABLE}
  - {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_XS_NAMESPACE DEFAULT_XS_NAMESPACE}

#### 2.22.3 - XML Parsers

The {@link org.apache.juneau.xml.XmlParser} class is used to parse XML into POJOs.

The XML parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser Properties}
- {@link org.apache.juneau.xml.XmlParser}
  - {@link org.apache.juneau.xml.XmlParser#XML_eventAllocator XML_eventAllocator}
  - {@link org.apache.juneau.xml.XmlParser#XML_preserveRootElement XML_preserveRootElement}
  - {@link org.apache.juneau.xml.XmlParser#XML_reporter XML_reporter}
  - {@link org.apache.juneau.xml.XmlParser#XML_resolver XML_resolver}
  - {@link org.apache.juneau.xml.XmlParser#XML_validating XML_validating}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.xml.XmlParser}
  - {@link org.apache.juneau.xml.XmlParser#DEFAULT DEFAULT}

#### 2.22.4 - @Bean(typeName) Annotation

The {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)} annotation can be used to override the Juneau default name on bean elements. Types names serve two distinct purposes:

1. To override the element name.
2. To serve as a class identifier so that the bean class can be inferred during parsing if it cannot automatically be inferred through reflection.

##### Example

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
@Bean(typeName="X") class MyBean { public String a; public int b; } | { a: 'foo', b: 123 } | <object> <a>foo</id> <b>123</name> </object> | <X> <a>foo</id> <b>123</name> </X>

On bean properties, a _type attribute will be added if a type name is present and the bean class cannot be inferred through reflection.

In the following example, a type attribute is used on property 'b' but not property 'a' since 'b' is of type Object and therefore the bean class cannot be inferred.

##### Example

Java | Without annotation | With annotation
--- | --- | ---
class MyBean { public BeanX a = new BeanX(); public Object b = new BeanX(); } @Bean(typeName="X") class BeanX { public String fx = "foo"; } | <object> <a> <fx>foo</fx> </a> <b> <fx>foo</fx> </b> </object> | <object> <a> <fx>foo</fx> </a> <b _type='X'> <fx>foo</fx> </b> </object>

string, number, boolean, object, array, and null are reserved keywords that cannot be used as type names.

Beans with type names are often used in conjunction with the {@link org.apache.juneau.annotation.Bean#dictionary() @Bean(dictionary)} and {@link org.apache.juneau.annotation.Beanp#dictionary() @Beanp(dictionary)} annotations so that the beans can be resolved at parse time. These annotations are not necessary during serialization, but are needed during parsing in order to resolve the bean types.

The following examples show how type names are used under various circumstances.

Pay special attention to when _type attributes are and are not used.

##### Examples

Java | XML
--- | ---
@Bean(dictionary={BeanX.class}) class BeanWithArrayPropertiesWithTypeNames { public BeanX[] b1 = new BeanX[]{ new BeanX() }; public Object[] b2 = new BeanX[]{ new BeanX() }; public Object[] b3 = new Object[]{ new BeanX() }; } | <object> <b1> <X> <fx>foo</fx> </X> </b1> <b2> <X> <fx>foo</fx> </X> </b2> <b3> <X> <fx>foo</fx> </X> </b3> </object>
@Bean(dictionary={BeanX.class}) class BeanWith2dArrayPropertiesWithTypeNames { public BeanX[][] b1 = new BeanX[][]{{ new BeanX() }}; public Object[][] b2 = new BeanX[][]{{ new BeanX() }}; public Object[][] b3 = new Object[][]{{ new BeanX() }}; } | <object> <b1> <array> <X> <fx>foo</fx> </X> </array> </b1> <b2> <array> <X> <fx>foo</fx> </X> </array> </b2> <b3> <array> <X> <fx>foo</fx> </X> </array> </b3> </object>
@Bean(dictionary={BeanX.class}) class BeanWithMapPropertiesWithTypeNames { public Map<String,BeanX> b1 = new HashMap<>() {{ put("k1", new BeanX()); }}; public Map<String,Object> b2 = new HashMap<>() {{ put("k2", new BeanX()); }} } | <object> <b1> <k1> <fx>foo</fx> </k1> </b1> <b2> <k2 _type='X'> <fx>foo</fx> </k2> </b2> </object>

Bean type names are also used for resolution when abstract fields are used. The following examples show how they are used in a variety of circumstances.

Java | XML
--- | ---
@Bean(dictionary={A.class}) class BeanWithAbstractFields { public A a = new A(); public IA ia = new A(); public AA aa = new A(); public Object o = new A(); } interface IA {} abstract class AA implements IA {} @Bean(typeName="A") class A extends AA { public String fa = "foo"; } | <object> <a> <fa>foo</fa> </a> <ia _type='A'> <fa>foo</fa> </ia> <aa _type='A'> <fa>foo</fa> </aa> <o _type='A'> <fa>foo</fa> </o> </object>
@Bean(dictionary={A.class}) class BeanWithAbstractArrayFields { public A[] a = new A[]{new A()}; public IA[] ia1 = new A[]{new A()}; public IA[] ia2 = new IA[]{new A()}; public AA[] aa1 = new A[]{new A()}; public AA[] aa2 = new AA[]{new A()}; public Object[] o1 = new A[]{new A()}; public Object[] o2 = new Object[]{new A()}; } | <object> <a> <A> <fa>foo</fa> </A> </a> <ia1> <A> <fa>foo</fa> </A> </ia1> <ia2> <A> <fa>foo</fa> </A> </ia2> <aa1> <A> <fa>foo</fa> </A> </aa1> <aa2> <A> <fa>foo</fa> </A> </aa2> <o1> <A> <fa>foo</fa> </A> </o1> <o2> <A> <fa>foo</fa> </A> </o2> </object>
@Bean(dictionary={A.class}) class BeanWithAbstractMapFields { public Map<String,A> a = new HashMap<>() {{ put("k1", new A()); }}; public Map<String,AA> b = new HashMap<>() {{ put("k2", new A()); }}; public Map<String,Object> c = new HashMap<>() {{ put("k3", new A()); }}; } | <object> <a> <k1> <fa>foo</fa> </k1> </a> <b> <k2 _type='A'> <fa>foo</fa> </k2> </b> <c> <k3 _type='A'> <fa>foo</fa> </k3> </c> </object>
@Bean(dictionary={A.class}) class BeanWithAbstractMapArrayFields { public Map<String,A[]> a = new LinkedHashMap<>() {{ put("a1", new A[]{new A()}); }}; public Map<String,IA[]> ia = new LinkedHashMap<>() {{ put("ia1", new A[]{new A()}); put("ia2", new IA[]{new A()}); }}; public Map<String,AA[]> aa = new LinkedHashMap<>() {{ put("aa1", new A[]{new A()}); put("aa2", new AA[]{new A()}); }}; public Map<String,Object[]> o = newLinkedHashMap<>() {{ put("o1", new A[]{new A()}); put("o2", new AA[]{new A()}); }}; } | <object> <a> <a1> <A> <fa>foo</fa> </A> </a1> </a> <ia> <ia1> <A> <fa>foo</fa> </A> </ia1> <ia2> <A> <fa>foo</fa> </A> </ia2> </ia> <aa> <aa1> <A> <fa>foo</fa> </A> </aa1> <aa2> <A> <fa>foo</fa> </A> </aa2> </aa> <o> <o1> <A> <fa>foo</fa> </A> </o1> <o2> <A> <fa>foo</fa> </A> </o2> </o> </object>

On a side note, characters that cannot be represented in XML 1.0 are encoded using a simple encoding. Note in the examples below, some characters such as '\n', '\t', and '\r' can be represented as XML entities when used in text but not in element names. Other characters such as '\b' and '\f' cannot be encoded in XML 1.0 at all without inventing our own notation. Whitespace characters in element names are encoded as well as whitespace end characters in text.

Java | XML
--- | ---
class BeanWithSpecialCharacters { public String a = " \b\f\n\t\r "; } | <object> <a>_x0020_ _x0008__x000C_&#x000a;&#x0009;&#x000d; _x0020_</a> </object>
@Bean(typeName=" \b\f\n\t\r ") class BeanWithNamesWithSpecialCharacters { @Beanp(name=" \b\f\n\t\r ") public String a = " \b\f\n\t\r "; } | <_x0020__x0020__x0008__x000C__x000A__x0009__x000D__x0020__x0020_> <_x0020__x0020__x0008__x000C__x000A__x0009__x000D__x0020__x0020_> _x0020_ _x0008__x000C_&#x000a;&#x0009;&#x000d; _x0020_ </_x0020__x0020__x0008__x000C__x000A__x0009__x000D__x0020__x0020_> </_x0020__x0020__x0008__x000C__x000A__x0009__x000D__x0020__x0020_>

While it's true that these characters CAN be represented in XML 1.1, it's impossible to parse XML 1.1 text in Java without the XML containing an XML declaration. Unfortunately, this, and the uselessness of the {@link javax.xml.stream.XMLInputFactory#IS_REPLACING_ENTITY_REFERENCES} setting in Java forced us to make some hard design decisions that may not be the most elegant.

#### 2.22.5 - @Xml(childName) Annotation

The {@link org.apache.juneau.xml.annotation.Xml#childName() @Xml(childName)} annotation can be used to specify the name of XML child elements for bean properties of type collection or array.

##### Example

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
class MyBean { @Xml(childName="X") public String[] a; @Xml(childName="Y") public int[] b; } | { a: ['foo','bar'], b: [123,456] } | <object> <a> <string>foo</string> <string>bar</string> </a> <b> <number>123</number> <number>456</number> </b> </object> | <object> <a> <X>foo</X> <X>bar</X> </a> <b> <Y>123</Y> <Y>456</Y> </b> </object>
class MyBean { @Xml(childName="child") public int[] a; } | { a: [123,456] } | <object> <a> <string>foo</string> <string>bar</string> </a> </object> | <object> <a> <child>foo</child> <child>bar</child> </a> </object>

#### 2.22.6 - @Xml(format) Annotation

The {@link org.apache.juneau.xml.annotation.Xml#format() @Xml(format)} annotation can be used to tweak the XML format of a POJO. The value is set to an enum value of type {@link org.apache.juneau.xml.annotation.XmlFormat}. This annotation can be applied to both classes and bean properties.

The {@link org.apache.juneau.xml.annotation.XmlFormat#ATTR} format can be applied to bean properties to serialize them as XML attributes instead of elements. Note that this only supports properties of simple types (e.g. strings, numbers, booleans).

##### Example

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
class MyBean { @Xml(format=XmlFormat.ATTR) public String a; } | { a: 'foo' } | <object> <a>foo</a> </object> | <object a='foo'/>

The {@link org.apache.juneau.xml.annotation.XmlFormat#ATTRS} format can be applied to bean classes to force all bean properties to be serialized as XML attributes instead of child elements.

##### Example

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
@Xml(format=XmlFormat.ATTRS) class MyBean { public String a; public int b; } | { a: 'foo', b: 123 } | <object> <a>foo</a> <b>123</b> </object> | <object a='foo' b='123'/>

The {@link org.apache.juneau.xml.annotation.XmlFormat#ELEMENT} format can be applied to bean properties to override the {@link org.apache.juneau.xml.annotation.XmlFormat#ATTRS} format applied on the bean class.

##### Example

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
@Xml(format=XmlFormat.ATTRS) class MyBean { public String a; @Xml(format=XmlFormat.ELEMENT) public int b; } | { a: 'foo', b: 123 } | <object> <a>foo</a> <b>123</b> </object> | <object a='foo'> <b>123</b> </object>

The {@link org.apache.juneau.xml.annotation.XmlFormat#ATTRS} format can be applied to a single bean property of type Map<String,Object> to denote arbitrary XML attribute values on the element. These can be mixed with other {@link org.apache.juneau.xml.annotation.XmlFormat#ATTR} annotated properties, but there must not be an overlap in bean property names and map keys.

##### Example

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
class MyBean { @Xml(format=XmlFormat.ATTRS) public Map<String,Object> a; @Xml(format=XmlFormat.ATTR) public int b; } | { a: { k1: 'foo', k2: 123, }, b: 456 } | <object> <a> <k1>foo</k1> <k2 _type='number'>123</k2> </a> <b>456</b> </object> | <object k1='foo' k2='123' b='456'/>

The {@link org.apache.juneau.xml.annotation.XmlFormat#COLLAPSED} format can be applied to bean properties of type array/Collection. This causes the child objects to be serialized directly inside the bean element. This format must be used in conjunction with {@link org.apache.juneau.xml.annotation.Xml#childName() @Xml(childName)} to differentiate which collection the values came from if you plan on parsing the output back into beans. Note that child names must not conflict with other property names.

Data type | JSON example | Without annotation | With annotation
--- | --- | --- | ---
class MyBean { @Xml(childName="A",format=XmlFormat.COLLAPSED) public String[] a; @Xml(childName="B",format=XmlFormat.COLLAPSED) public int[] b; } | { a: ['foo','bar'], b: [123,456] } | <object> <a> <string>foo</string> <string>bar</string> </a> <b> <number>123</number> <number>456</number> </b> </object> | <object> <A>foo</A> <A>bar</A> <B>123</B> <B>456</B> </object>

The {@link org.apache.juneau.xml.annotation.XmlFormat#ELEMENTS} format can be applied to a single bean property of either a simple type or array/Collection. It allows free-form child elements to be formed. All other properties on the bean MUST be serialized as attributes.

Data type | JSON example | With annotation
--- | --- | ---
class MyBean { @Xml(format=XmlFormat.ATTR) public String a; @Xml(format=XmlFormat.ELEMENTS) public String b; } | { a: 'foo', b: 'bar' } | <object a='foo'> <string>bar</string> </object>
class MyBean { @Xml(format=XmlFormat.ATTR) public String a; @Xml(format=XmlFormat.ELEMENTS) public Object[] b; } | { a: 'foo', b: [ 'bar', 'baz', 123, true, null ] } | <object a='foo'> <string>bar</string> <string>baz</string> <number>123</number> <boolean>true</boolean> <null/> </object>

The {@link org.apache.juneau.xml.annotation.XmlFormat#MIXED} format is similar to {@link org.apache.juneau.xml.annotation.XmlFormat#ELEMENTS} except elements names on primitive types (string/number/boolean/null) are stripped from the output. This format particularly useful when combined with bean dictionaries to produce mixed content. The bean dictionary isn't used during serialization, but it is needed during parsing to resolve bean types.

The {@link org.apache.juneau.xml.annotation.XmlFormat#MIXED_PWS} format identical to {@link org.apache.juneau.xml.annotation.XmlFormat#MIXED} except whitespace characters are preserved in the output.

Data type | JSON example | Without annotations | With annotations
--- | --- | --- | ---
class MyBean { @Xml(format=XmlFormat.MIXED) @Beanp(dictionary={MyBeanX.class, MyBeanY.class}) public Object[] a; } @Bean(typeName="X") class MyBeanX { @Xml(format=XmlFormat.ATTR) public String b; } @Bean(typeName="Y") class MyBeanY { @Xml(format=XmlFormat.ATTR) public String c; } | { a: [ 'foo', { _type:'X', b:'bar' } 'baz', { _type:'Y', b:'qux' }, 'quux' ] } | <object> <a> <string>foo</string> <object> <b>bar</b> </object> <string>baz</string> <object> <b>qux</b> </object> <string>quux</string> </a> </object> | <object>foo<X b='bar'/>baz<Y c='qux'/>quux</object>

Whitespace (tabs and newlines) are not added to MIXED child nodes in readable-output mode. This helps ensures strings in the serialized output can be losslessly parsed back into their original forms when they contain whitespace characters. If the {@link javax.xml.stream.XMLInputFactory#IS_REPLACING_ENTITY_REFERENCES} setting was not useless in Java, we could support lossless readable XML for MIXED content. But as of Java 8, it still does not work.

XML suffers from other deficiencies as well that affect MIXED content. For example, <X></X> and <X/> are equivalent in XML and indistinguishable by the Java XML parsers. This makes it impossible to differentiate between an empty element and an element containing an empty string. This causes empty strings to get lost in translation. To alleviate this, we use the constructs "_xE000_" to represent an empty string, and "_x0020_" to represent leading and trailing spaces.

The examples below show how whitespace is handled under various circumstances:

Data type | XML
--- | ---
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT) public String a = null; } | <X/>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT) public String a = ""; } | <X>_xE000_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT) public String a = " "; } | <X>_x0020_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT) public String a = " "; } | <X>_x0020__x0020_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT) public String a = " foobar "; } | <X>_x0020_ foobar _x0020_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT_PWS) public String a = null; } | <X/>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT_PWS) public String a = ""; } | <X>_xE000_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT_PWS) public String a = " "; } | <X> </X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT_PWS) public String a = " "; } | <X> </X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.TEXT_PWS) public String a = " foobar "; } | <X> foobar </X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED) public String[] a = null; } | <X/>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED) public String a[] = new String[]{""}; } | <X>_xE000_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED) public String a[] = new String[]{" "}; } | <X>_x0020_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED) public String a[] = new String[]{" "}; } | <X>_x0020__x0020_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED) public String a[] = new String[]{ " foobar " }; } | <X>_x0020_ foobar _x0020_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED_PWS) public String[] a = null; } | <X/>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED_PWS) public String a[] = new String[]{""}; } | <X>_xE000_</X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED_PWS) public String a[] = new String[]{" "}; } | <X> </X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED_PWS) public String a[] = new String[]{" "}; } | <X> </X>
@Bean(typeName="X") class MyBean { @Xml(format=XmlFormat.MIXED_PWS) public String a[] = new String[]{ " foobar " }; } | <X> foobar </X>

It should be noted that when using MIXED, you are not guaranteed to parse back the exact same content since side-by-side strings in the content will end up concatenated when parsed.

The {@link org.apache.juneau.xml.annotation.XmlFormat#TEXT} format is similar to {@link org.apache.juneau.xml.annotation.XmlFormat#MIXED} except it's meant for solitary objects that get serialized as simple child text nodes. Any object that can be serialize to a String can be used. The {@link org.apache.juneau.xml.annotation.XmlFormat#TEXT_PWS} is the same except whitespace is preserved in the output.

Data type | JSON example | Without annotations | With annotations
--- | --- | --- | ---
class MyBean { @Xml(format=XmlFormat.TEXT) public String a; } | { a: 'foo' } | <object> <a>foo</a> </object> | <object>foo</object>

The {@link org.apache.juneau.xml.annotation.XmlFormat#XMLTEXT} format is similar to {@link org.apache.juneau.xml.annotation.XmlFormat#TEXT} except it's meant for strings containing XML that should be serialized as-is to the document. Any object that can be serialize to a String can be used. During parsing, the element content gets parsed with the rest of the document and then re-serialized to XML before being set as the property value. This process may not be perfect (e.g. double quotes may be replaced by single quotes, etc...).

Data type | JSON example | With TEXT annotation | With XMLTEXT annotation
--- | --- | --- | ---
class MyBean { @Xml(format=XmlFormat.XMLTEXT) public String a; } | { a: 'Some <b>XML</b> text' } | <object>Some &lt;b&gt;XML&lt;/b&gt; text</object> | <object>Some <b>XML</b> text</object>

#### 2.22.7 - Namespaces

Let's go back to the example of our original Person bean class, but add some namespace annotations:

##### Sample Beans

@Xml(prefix="per") @Bean(typeName="person") public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } @Xml(prefix="addr") @Bean(typeName="address") public class Address { // Bean properties @Xml(prefix="mail") public String street, city; @Xml(prefix="mail") public StateEnum state; @Xml(prefix="mail") public int zip; public boolean isCurrent; // Getters/setters omitted }

The namespace URLs can either be defined as part of the {@link org.apache.juneau.xml.annotation.Xml @Xml} annotation, or can be defined at the package level with the {@link org.apache.juneau.xml.annotation.XmlSchema @XmlSchema} annotation. Below shows it defined at the package level:

##### package-info.java

@XmlSchema( prefix="ab", // Default namespace xmlNs={ @XmlNs(prefix="ab", namespaceURI="http://www.apache.org/addressBook/"), @XmlNs(prefix="per", namespaceURI="http://www.apache.org/person/"), @XmlNs(prefix="addr", namespaceURI="http://www.apache.org/address/"), @XmlNs(prefix="mail", namespaceURI="http://www.apache.org/mail/") } ) package org.apache.juneau.examples.addressbook;

##### Sample Code

Person p = new Person() .name("John Smith") .birthDate("1946-08-12T00:00:00Z") .addresses( new Address() .street("100 Main Street") .city("Anywhereville") .state(NY) .zip(12345) .isCurrent(true); ); // Create a new serializer with readable output, this time with namespaces enabled. // Note that this is identical to XmlSerializer.DEFAULT_NS_SQ_READABLE. XmlSerializer s = XmlSerializer.create().ns().ws().sq().build(); String xml = s.serialize(p);

Now when we run this code, we'll see namespaces added to our output:

<per:person> <per:name>John Smith</per:name> <per:birthDate>1946-08-12T04:00:00Z</per:birthDate> <per:addresses> <addr:address> <mail:street>100 Main Street</mail:street> <mail:city>Anywhereville</mail:city> <mail:state>NY</mail:state> <mail:zip>12345</mail:zip> <addr:isCurrent>true</addr:isCurrent> </addr:address> </per:addresses> </per:person>

Enabling the {@link org.apache.juneau.xml.XmlSerializer#XML_addNamespaceUrisToRoot} setting results in the namespace URLs being added to the root node:

<per:person xmlns='http://www.apache.org/2013/Juneau' xmlns:per='http://www.apache.org/person/' xmlns:addr='http://www.apache.org/address/' xmlns:mail='http://www.apache.org/mail/' > <per:name>John Smith</per:name> <per:birthDate>1946-08-12T04:00:00Z</per:birthDate> <per:addresses> <addr:address> <mail:street>100 Main Street</mail:street> <mail:city>Anywhereville</mail:city> <mail:state>NY</mail:state> <mail:zip>12345</mail:zip> <addr:isCurrent>true</addr:isCurrent> </addr:address> </per:addresses> </per:person>

We can simplify the output by setting the default namespace on the serializer so that all the elements do not need to be prefixed:

// Create a new serializer with readable output, this time with namespaces enabled. XmlSerializer s = XmlSerializer.create().ws().sq().ns() .defaultNamespaceUri("http://www.apache.org/person/") .build();

This produces the following equivalent where the elements don't need prefixes since they're already in the default document namespace:

<person xmlns:juneau='http://www.apache.org/2013/Juneau' xmlns='http://www.apache.org/person/' xmlns:addr='http://www.apache.org/address/' xmlns:mail='http://www.apache.org/mail/' > <name>John Smith</name> <birthDate>1946-08-12T04:00:00Z</birthDate> <addresses> <addr:address> <mail:street>100 Main Street</mail:street> <mail:city>Anywhereville</mail:city> <mail:state>NY</mail:state> <mail:zip>12345</mail:zip> <addr:isCurrent>true</addr:isCurrent> </addr:address> </addresses> </person>

One important property on the XML serializer class is {@link org.apache.juneau.xml.XmlSerializer#XML_autoDetectNamespaces XML_autoDetectNamespaces}. This property tells the serializer to make a first-pass over the data structure to look for namespaces defined on classes and bean properties. In high-performance environments, you may want to consider disabling auto-detection and providing your own explicit list of namespaces to the serializer to avoid this scanning step.

The following code will produce the same output as before, but will perform slightly better since it avoids this pre-scan step.

// Create a new serializer with readable output, this time with namespaces enabled. XmlSerializer s = XmlSerializer.create() .ws() .sq() .autoDetectNamespaces(false) .namespaces("{per:'http://www.apache.org/person/'}") .build();

#### 2.22.8 - XML-Schema Support

Juneau provides the {@link org.apache.juneau.xmlschema.XmlSchemaSerializer} class for generating XML-Schema documents that describe the output generated by the {@link org.apache.juneau.xml.XmlSerializer} class. This class shares the same properties as XmlSerializer. Since the XML output differs based on settings on the XML serializer class, the XML-Schema serializer class must have the same property values as the XML serializer class it's describes. To help facilitate creating an XML Schema serializer with the same properties as the corresponding XML serializer, the {@link org.apache.juneau.xml.XmlSerializer#getSchemaSerializer()} method has been added.

XML-Schema requires a separate file for each namespace. Unfortunately, does not mesh well with the Juneau serializer architecture which serializes to single writers. To get around this limitation, the schema serializer will produce a single output, but with multiple schema documents separated by the null character ('\u0000') to make it simple to split apart.

Lets start with an example where everything is in the same namespace. We'll use the classes from before, but remove the references to namespaces. Since we have not defined a default namespace, everything is defined under the default Juneau namespace.

##### Sample Beans

@Bean(typeName="person") public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } @Bean(typeName="address") public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

The code for creating our POJO model and generating XML Schema is shown below:

// Create a new serializer with readable output. XmlSerializer s = XmlSerializer.create() .ws() .ns() .sq() .addNamespaceUrisToRoot(true) .build(); // Create the equivalent schema serializer. XmlSchemaSerializer ss = s.getSchemaSerializer(); // Get the XML Schema corresponding to the XML generated above. String xmlSchema = ss.serialize(new Person());

##### XML-Schema results

<schema xmlns='http://www.w3.org/2001/XMLSchema' targetNamespace='http://www.apache.org/2013/Juneau' elementFormDefault='qualified' xmlns:juneau='http://www.apache.org/2013/Juneau'> <element name='person' _type='juneau:org.apache.juneau.examples.addressbook.Person'/> <complexType name='org.apache.juneau.examples.addressbook.Person'> <sequence> <element name='name' _type='string' minOccurs='0'/> <element name='birthDate' _type='juneau:java.util.Calendar' minOccurs='0'/> <element name='addresses' _type='juneau:java.util.LinkedList_x003C_org.apache.juneau.examples.addressbook.Address_x003E_' minOccurs='0'/> </sequence> </complexType> <complexType name='java.util.Calendar'> <sequence> <any processContents='skip' maxOccurs='unbounded' minOccurs='0'/> </sequence> </complexType> <complexType name='java.util.LinkedList_x003C_org.apache.juneau.examples.addressbook.Address_x003E_'> <sequence> <choice minOccurs='0' maxOccurs='unbounded'> <element name='address' _type='juneau:org.apache.juneau.examples.addressbook.Address'/> <element name='null' _type='string'/> </choice> </sequence> </complexType> <complexType name='org.apache.juneau.examples.addressbook.Address'> <sequence> <element name='street' _type='string' minOccurs='0'/> <element name='city' _type='string' minOccurs='0'/> <element name='state' _type='string' minOccurs='0'/> <element name='zip' _type='integer' minOccurs='0'/> <element name='isCurrent' _type='boolean' minOccurs='0'/> </sequence> </complexType> </schema>

Now if we add in some namespaces, we'll see how multiple namespaces are handled.

##### Sample Beans with multiple namespaces

@Xml(prefix="per") @Bean(typeName="person") public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } @Xml(prefix="addr") @Bean(typeName="address") public class Address { // Bean properties @Xml(prefix="mail") public String street, city; @Xml(prefix="mail") public StateEnum state; @Xml(prefix="mail") public int zip; public boolean isCurrent; // Getters/setters omitted }

The schema consists of 4 documents separated by a '\u0000' character.

##### XML-Schema results

<schema xmlns='http://www.w3.org/2001/XMLSchema' targetNamespace='http://www.apache.org/2013/Juneau' elementFormDefault='qualified' xmlns:juneau='http://www.apache.org/2013/Juneau' xmlns:per='http://www.apache.org/person/' xmlns:addr='http://www.apache.org/address/' xmlns:mail='http://www.apache.org/mail/'> <import namespace='http://www.apache.org/person/' schemaLocation='per.xsd'/> <import namespace='http://www.apache.org/address/' schemaLocation='addr.xsd'/> <import namespace='http://www.apache.org/mail/' schemaLocation='mail.xsd'/> <complexType name='int'> <simpleContent> <extension base='integer'/> </simpleContent> </complexType> <complexType name='java.lang.String'> <simpleContent> <extension base='string'/> </simpleContent> </complexType> <complexType name='java.net.URI'> <simpleContent> <extension base='string'/> </simpleContent> </complexType> <complexType name='java.util.Calendar'> <sequence> <any processContents='skip' maxOccurs='unbounded' minOccurs='0'/> </sequence> </complexType> <complexType name='java.util.LinkedList_x003C_org.apache.juneau.examples.addressbook.Address_x003E_'> <sequence> <choice minOccurs='0' maxOccurs='unbounded'> <element name='address' _type='addr:org.apache.juneau.examples.addressbook.Address'/> <element name='null' _type='string'/> </choice> </sequence> </complexType> <complexType name='boolean'> <simpleContent> <extension base='boolean'/> </simpleContent> </complexType> </schema> [\u0000] <schema xmlns='http://www.w3.org/2001/XMLSchema' targetNamespace='http://www.apache.org/person/' elementFormDefault='qualified' attributeFormDefault='qualified' xmlns:juneau='http://www.apache.org/2013/Juneau' xmlns:per='http://www.apache.org/person/' xmlns:addr='http://www.apache.org/address/' xmlns:mail='http://www.apache.org/mail/'> <import namespace='http://www.apache.org/2013/Juneau' schemaLocation='juneau.xsd'/> <import namespace='http://www.apache.org/address/' schemaLocation='addr.xsd'/> <import namespace='http://www.apache.org/mail/' schemaLocation='mail.xsd'/> <element name='person' _type='per:org.apache.juneau.examples.addressbook.Person'/> <complexType name='org.apache.juneau.examples.addressbook.Person'> <sequence> <any minOccurs='0' maxOccurs='unbounded'/> </sequence> <attribute name='uri' _type='string'/> </complexType> <element name='name' _type='juneau:java.lang.String'/> <element name='birthDate' _type='juneau:java.util.Calendar'/> <element name='addresses' _type='juneau:java.util.LinkedList_x003C_org.apache.juneau.examples.addressbook.Address_x003E_'/> </schema> [\u0000] <schema xmlns='http://www.w3.org/2001/XMLSchema' targetNamespace='http://www.apache.org/address/' elementFormDefault='qualified' attributeFormDefault='qualified' xmlns:juneau='http://www.apache.org/2013/Juneau' xmlns:per='http://www.apache.org/person/' xmlns:addr='http://www.apache.org/address/' xmlns:mail='http://www.apache.org/mail/'> <import namespace='http://www.apache.org/2013/Juneau' schemaLocation='juneau.xsd'/> <import namespace='http://www.apache.org/person/' schemaLocation='per.xsd'/> <import namespace='http://www.apache.org/mail/' schemaLocation='mail.xsd'/> <complexType name='org.apache.juneau.examples.addressbook.Address'> <sequence> <any minOccurs='0' maxOccurs='unbounded'/> </sequence> </complexType> <element name='isCurrent' _type='juneau:boolean'/> </schema> [\u0000] <schema xmlns='http://www.w3.org/2001/XMLSchema' targetNamespace='http://www.apache.org/mail/' elementFormDefault='qualified' attributeFormDefault='qualified' xmlns:juneau='http://www.apache.org/2013/Juneau' xmlns:per='http://www.apache.org/person/' xmlns:addr='http://www.apache.org/address/' xmlns:mail='http://www.apache.org/mail/'> <import namespace='http://www.apache.org/2013/Juneau' schemaLocation='juneau.xsd'/> <import namespace='http://www.apache.org/person/' schemaLocation='per.xsd'/> <import namespace='http://www.apache.org/address/' schemaLocation='addr.xsd'/> <element name='street' _type='juneau:java.lang.String'/> <element name='city' _type='juneau:java.lang.String'/> <element name='state' _type='juneau:java.lang.String'/> <element name='zip' _type='juneau:int'/> </schema>

For convenience, the {@link org.apache.juneau.xmlschema.XmlSchemaSerializer #getValidator(SerializerSession,Object)} method is provided to create a {@link javax.xml.validation.Validator} using the input from the serialize method.

### 2.23 - HTML Details

Juneau supports converting arbitrary POJOs to and from HTML. Built on top of the existing XML parser, it also uses a STaX parser and creates POJOs directly without intermediate DOM objects.

The primary use case for HTML serialization is rendering POJOs in easy-to-read format in REST interfaces.

#### 2.23.1 - HTML Methodology

The following examples show how different data types are represented in HTML. They mirror how the data structures are represented in JSON.

##### Simple types

The representation for simple types mirror those produced by the XML serializer. Tags are added to help differentiate data types when they cannot be inferred through reflection. These tags are ignored by browsers and treated as plain text.

Data type | JSON example | HTML
--- | --- | ---
string | 'foo' | <string>foo</string>
boolean | true | <boolean>true</boolean>
integer | 123 | <number>123</number>
float | 1.23 | <number>1.23</number>
null | null | <null/>

##### Maps

Maps and beans are represented as tables.

The _type attribute is added to differentiate between objects (maps/beans) and arrays (arrays/collections).

Data type | JSON example | HTML
--- | --- | ---
Map<String,String> | { k1: 'v1' k2: null } | <table _type='object'> <tr> <td>k1</td> <td>v1</td> </tr> <tr> <td>k2</td> <td><null/></td> </tr> </table>
Map<String,Number> | { k1: 123, k2: 1.23, k3: null } | <table _type='object'> <tr> <td>k1</td> <td>123</td> </tr> <tr> <td>k2</td> <td>1.23</td> </tr> <tr> <td>k3</td> <td><null/></td> </tr> </table>
Map<String,Object> | { k1: 'v1' k2: 123, k3: 1.23, k4: true, k5: null } | <table _type='object'> <tr> <td>k1</td> <td>v1</td> </tr> <tr> <td>k2</td> <td><number>123</number></td> </tr> <tr> <td>k3</td> <td><number>1.23</number></td> </tr> <tr> <td>k4</td> <td><boolean>true</boolean></td> </tr> <tr> <td>k5</td> <td><null/></td> </tr> </table>

##### Arrays

Collections and arrays are represented as ordered lists.

Data type | JSON example | HTML
--- | --- | ---
String[] | [ 'foo' null ] | <ul> <li>foo</li> <li><null/></li> </ul>
Number[] | [ 123, 1.23, null ] | <ul> <li>123</li> <li>1.23</li> <li><null/></li> </ul>
Object[] | [ 'foo', 123, 1.23, true, null ] | <ul> <li>foo</li> <li><number>123</number></li> <li><number>1.23</number></li> <li><boolean>true</boolean></li> <li><null/></li> </ul>
String[][] | [ ['foo', null], null, ] | <ul> <li> <ul> <li>foo</li> <li><null/></li> </ul> </li> <li><null/></li> </ul>
int[] | [ 123 ] | <ul> <li>123</li> </ul>
boolean[] | [ true ] | <ul> <li>true</li> </ul>

##### Collections

Data type | JSON example | HTML
--- | --- | ---
List<String> | [ 'foo' null ] | <ul> <li>foo</li> <li><null/></li> </ul>
List<Number> | [ 123, 1.23, null ] | <ul> <li>123</li> <li>1.23</li> <li><null/></li> </ul>
List<Object> | [ 'foo', 123, 1.23, true, null ] | <ul> <li>foo</li> <li><number>123</number></li> <li><number>1.23</number></li> <li><boolean>true</boolean></li> <li><null/></li> </ul>

##### Beans

Data type | JSON example | HTML
--- | --- | ---
class MyBean { public String a; public int b; public Object c; // String value public Object d; // Integer value public MyBean2 e; public String[] f; public int[] g; } class MyBean2 { String h; } | { a: 'foo', b: 123, c: 'bar', d: 456, e: { h: 'baz' } f: ['qux'] g: [789] } | <table _type='object'> <tr> <td>a</td> <td>foo</td> </tr> <tr> <td>b</td> <td>123</td> </tr> <tr> <td>c</td> <td>bar</td> </tr> <tr> <td>d</td> <td><number>456</number></td> </tr> <tr> <td>e</td> <td> <table _type='object'> <tr> <td>h</td> <td>qux</td> </tr> </table> </td> </tr> <tr> <td>f</td> <td> <ul> <li>baz</li> </ul> </td> </tr> <tr> <td>g</td> <td> <ul> <li>789</li> </ul> </td> </tr> </table>

##### Beans with Map properties

Data type | JSON example | HTML
--- | --- | ---
class MyBean { public Map<String,String> a; public Map<String,Number> b; public Map<String,Object> c; } | { a: { k1: 'foo' }, b: { k2: 123 }, c: { k3: 'bar', k4: 456, k5: true, k6: null } } | <table _type='object'> <tr> <td>a</td> <td> <table _type='object'> <tr> <td>k1</td> <td>foo</td> </tr> </table> </td> </tr> <tr> <td>b</td> <td> <table _type='object'> <tr> <td>k2</td> <td>123</td> </tr> </table> </td> </tr> <tr> <td>c</td> <td> <table _type='object'> <tr> <td>k3</td> <td>bar</td> </tr> <tr> <td>k4</td> <td><number>456</number></td> </tr> <tr> <td>k5</td> <td><boolean>true</boolean></td> </tr> <tr> <td>k6</td> <td><null/></td> </tr> </table> </td> </tr> </table>

#### 2.23.2 - HTML Serializers

The {@link org.apache.juneau.html.HtmlSerializer} class is used to serialize POJOs into HTML.

The {@link org.apache.juneau.html.HtmlDocSerializer} class is the same, but wraps the serialized POJO inside a document template consisting of header, nav, aside, and footer sections.

The HTML serializers provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.html.HtmlSerializer}
  - {@link org.apache.juneau.html.HtmlSerializer#HTML_addBeanTypes HTML_addBeanTypes}
  - {@link org.apache.juneau.html.HtmlSerializer#HTML_addKeyValueTableHeaders HTML_addKeyValueTableHeaders}
  - {@link org.apache.juneau.html.HtmlSerializer#HTML_detectLabelParameters HTML_detectLabelParameters}
  - {@link org.apache.juneau.html.HtmlSerializer#HTML_detectLinksInStrings HTML_detectLinksInStrings}
  - {@link org.apache.juneau.html.HtmlSerializer#HTML_labelParameter HTML_labelParameter}
  - {@link org.apache.juneau.html.HtmlSerializer#HTML_uriAnchorText HTML_uriAnchorText}
- {@link org.apache.juneau.html.HtmlDocSerializer}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_aside HTMLDOC_aside}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_footer HTMLDOC_footer}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_head HTMLDOC_head}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_header HTMLDOC_header}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_nav HTMLDOC_nav}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_navlinks HTMLDOC_navlinks}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_noResultsMessage HTMLDOC_noResultsMessage}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_nowrap HTMLDOC_nowrap}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_script HTMLDOC_script}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_style HTMLDOC_style}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_stylesheet HTMLDOC_stylesheet}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_template HTMLDOC_template}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.html.HtmlSerializer}
  - {@link org.apache.juneau.html.HtmlSerializer#DEFAULT }
  - {@link org.apache.juneau.html.HtmlSerializer#DEFAULT_SQ }
  - {@link org.apache.juneau.html.HtmlSerializer#DEFAULT_SQ_READABLE }
- {@link org.apache.juneau.html.HtmlDocSerializer}
  - {@link org.apache.juneau.html.HtmlDocSerializer#DEFAULT }

#### 2.23.3 - HTML Parsers

The {@link org.apache.juneau.html.HtmlParser} class is used to parse HTML into POJOs. They can also parse the contents produced by {@link org.apache.juneau.html.HtmlDocSerializer}.

The HTML parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.html.HtmlParser}
  - {@link org.apache.juneau.html.HtmlParser#DEFAULT DEFAULT}

#### 2.23.4 - @Html Annotation

The {@link org.apache.juneau.html.annotation.Html @Html} annotation can be used to customize how POJOs are serialized to HTML on a per-class/field/method basis.

- {@link org.apache.juneau.html.annotation.Html}
  - {@link org.apache.juneau.html.annotation.Html#anchorText() anchorText}
  - {@link org.apache.juneau.html.annotation.Html#format() format}
  - {@link org.apache.juneau.html.annotation.Html#link() link}
  - {@link org.apache.juneau.html.annotation.Html#noTableHeaders() noTableHeaders}
  - {@link org.apache.juneau.html.annotation.Html#noTables() noTables}
  - {@link org.apache.juneau.html.annotation.Html#render() render}

The {@link org.apache.juneau.html.annotation.Html#link @Html(link)} annotation adds a hyperlink to a bean property when rendered as HTML.

##### Example:

public class FileSpace { // Add a hyperlink to this bean property. @Html(link="servlet:/drive/{drive}") public String getDrive() {...} }

The {@link org.apache.juneau.html.annotation.Html#anchorText @Html(anchorText)} annotation is used to specify the anchor text of a hyperlink.

##### Example:

// Produces <a href='...'>CLICK ME!</a> when serialized to HTML. public class FileSpace { // Add a hyperlink to this bean property. @Html(link="servlet:/drive/{drive}", anchorText="CLICK ME!") public String getDrive() {...} }

The {@link org.apache.juneau.html.annotation.Html#format @Html(format)} annotation is used to specify what format to use for HTML elements. For example, the HTML beans defined in the {@link org.apache.juneau.dto.html5} package use format=XML so that the beans get serialized as standard XML:

##### Example:

// Parent class of all HTML DTO beans. @Html(format=XML) public abstract class HtmlElement {...}

The {@link org.apache.juneau.html.annotation.Html#noTableHeaders @Html(noTableHeaders)} annotation is used to prevent beans from being serialized with table headers.

The {@link org.apache.juneau.html.annotation.Html#noTables @Html(noTables)} annotation is used to force beans to be serialized as trees instead of tables

#### 2.23.5 - @Html(render) Annotation

The {@link org.apache.juneau.html.annotation.Html#render @Html(render)} annotation allows for custom rendering of bean property values when serialized as HTML. Using this class, you can alter the CSS style and HTML content of the bean property.

The following example shows two render classes that customize the appearance of the pctFull and status columns in the code below:

import static org.apache.juneau.dto.html5.HtmlBuilder.*; // Our bean class public class FileSpace { private final String drive; private final long total, available; public FileSpace(String drive, long total, long available) { this.drive = drive; this.total = total; this.available = available; } @Html(link="drive/{drive}") public String getDrive() { return drive; } public long getTotal() { return total; } public long getAvailable() { return available; } @Html(render=FileSpacePctRender.class) public float getPctFull() { return ((100 * available) / total); } @Html(render=FileSpaceStatusRender.class) public FileSpaceStatus getStatus() { float pf = getPctFull(); if (pf < 80) return FileSpaceStatus.OK; if (pf < 90) return FileSpaceStatus.WARNING; return FileSpaceStatus.SEVERE; } }

// Possible values for the getStatus() method public enum FileSpaceStatus { OK, WARNING, SEVERE; }

// Custom render for getPctFull() method public class FileSpacePctRender extends HtmlRender<Float> { @Override public String getStyle(SerializerSession session, Float value) { if (value < 80) return "background-color:lightgreen;text-align:center"; if (value < 90) return "background-color:yellow;text-align:center"; return "background-color:red;text-align:center;border:;animation:color_change 0.5s infinite alternate"; } @Override public Object getContent(SerializerSession session, Float value) { if (value >= 90) return div( String.format("%.0f%%", value), style("@keyframes color_change { from { background-color: red; } to { background-color: yellow; }") ); return String.format("%.0f%%", value); } }

// Custom render for getStatus() method public class FileSpaceStatusRender extends HtmlRender<FileSpaceStatus> { @Override public String getStyle(SerializerSession session, FileSpaceStatus value) { return "text-align:center"; } @Override public Object getContent(SerializerSession session, FileSpaceStatus value) { switch (value) { case OK: return img().src(URI.create("servlet:/htdocs/ok.png")); case WARNING: return img().src(URI.create("servlet:/htdocs/warning.png")); default: return img().src(URI.create("servlet:/htdocs/severe.png")); } } }

#### 2.23.6 - HtmlDocSerializer

{@link org.apache.juneau.html.HtmlDocSerializer} is an extension of {@link org.apache.juneau.html.HtmlSerializer} that wraps serialized POJOs in a complete HTML document.

- {@link org.apache.juneau.html.HtmlDocSerializer}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_aside HTMLDOC_aside}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_footer HTMLDOC_footer}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_head HTMLDOC_head}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_header HTMLDOC_header}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_nav HTMLDOC_nav}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_navlinks HTMLDOC_navlinks}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_noResultsMessage HTMLDOC_noResultsMessage}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_nowrap HTMLDOC_nowrap}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_script HTMLDOC_script}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_style HTMLDOC_style}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_stylesheet HTMLDOC_stylesheet}
  - {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_template HTMLDOC_template}

This class is used extensively in the creation of POJO-based user interfaces in the REST API.

##### Example:

/** * Sample REST resource that prints out a simple "Hello world!" message. */ @Rest( path="/helloWorld", htmldoc=@HtmlDoc( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This page shows a resource that simply response with a 'Hello world!' message</p>", " <p>The POJO serialized is a simple String.</p>", "</div>" } ) ) public class HelloWorldResource extends BasicRestServlet {...}

The {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_template HTMLDOC_template} setting defines a template for the HTML page being generated. The default template is described next.

#### 2.23.7 - BasicHtmlDocTemplate

The {@link org.apache.juneau.html.BasicHtmlDocTemplate} class defines a default template for HTML documents created by {@link org.apache.juneau.html.HtmlDocSerializer}.

The HTML document created by this template consists of the following structure:

<html> <head> <style type='text/css'> CSS styles and links to stylesheets </style> </head> <body> <header> Page header </header> <nav> Navigation links </nav> <aside> Side-bar text </aside> <article> Contents of serialized object </article> <footer> Footer message </footer> </body> </html>

#### 2.23.8 - Custom Templates

Custom page templates can be created by implementing the {@link org.apache.juneau.html.HtmlDocTemplate} interface and associating it with your {@link org.apache.juneau.html.HtmlDocSerializer} using the {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_template HTMLDOC_template} setting.

- {@link org.apache.juneau.html.HtmlDocTemplate}
  - {@link org.apache.juneau.html.HtmlDocTemplate#writeTo(HtmlDocSerializerSession,HtmlWriter,Object) writeTo(HtmlDocSerializerSession,HtmlWriter,Object)}

The interface implementation is open-ended allowing you to define the contents of the page any way you wish.

#### 2.23.9 - HTML-Schema Support

The {@link org.apache.juneau.html.HtmlSchemaSerializer} class is the HTML-equivalent to the {@link org.apache.juneau.json.JsonSchemaSerializer} class. It's used to generate HTML versions of JSON-Schema documents that describe the output generated by the {@link org.apache.juneau.json.JsonSerializer} class.

##### Sample Beans

public class Person { // Bean properties public String name; public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

The code for creating our POJO model and generating HTML-Schema is shown below:

// Get the one of the default schema serializers. HtmlSchemaSerializer s = HtmlSchemaSerializer.DEFAULT_SIMPLE_READABLE; // Get the HTML Schema for the POJO. String htmlSchema = s.serialize(new Person()); // This also works. htmlSchema = s.serialize(Person.class);

The result is the HTML table shown below:

type | object
properties |
name |
type | string
birthDate |
type | string
addresses |
type | array
items |
type | object
properties |
street |
type | string
city |
type | string
state |
type | string
enum | AL PA NC
zip |
type | integer
format | int32
isCurrent |
type | boolean

### 2.24 - UON Details

Juneau supports converting arbitrary POJOs to and from UON strings using ultra-efficient serializers and parsers. The serializer converts POJOs directly to UON strings without the need for intermediate DOM objects using a highly-efficient state machine. Likewise, the parser creates POJOs directly from UON strings without the need for intermediate DOM objects.

Juneau uses UON (URL-Encoded Object Notation) for representing POJOs. The UON specification can be found here.

The following example shows JSON for a typical bean:

##### Sample Beans

public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

##### Sample Code

Person p = new Person() .name("John Smith") .birthDate("1946-08-12T00:00:00Z") .addresses( new Address() .street("100 Main Street") .city("Anywhereville") .state(NY) .zip(12345) .isCurrent(true); );

##### UON

( name='John+Smith', birthDate='1946-08-12T00:00:00Z', addresses=@( ( street='100 Main Street', city=Anywhereville, state=NY, zip=12345, isCurrent=true ) ) )

#### 2.24.1 - UON Methodology

##### General methodology:

Java type | JSON equivalent | UON
--- | --- | ---
Maps/beans | OBJECT | a1=(b1=x1,b2=x2) a1=(b1=(c1=x1,c2=x2))
Collections/arrays | ARRAY | a1=@(x1,x2) a1=@(@(x1,x2),@(x3,x4)) a1=@((b1=x1,b2=x2),(c1=x1,c2=x2))
Booleans | BOOLEAN | a1=true&a2=false
int/float/double/... | NUMBER | a1=123&a2=1.23e1
null | NULL | a1=null
String | STRING | a1=foobar a1='true' a1='null' a1='123' a1=' string with whitespace ' a1='string with ~'escaped~' quotes'

Refer to the UON specification for a complete set of syntax rules.

#### 2.24.2 - UON Serializers

The {@link org.apache.juneau.uon.UonSerializer} class is used to serialize POJOs into UON.

The UON serializers provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.uon.UonSerializer}
  - {@link org.apache.juneau.uon.UonSerializer#UON_addBeanTypes UON_addBeanTypes}
  - {@link org.apache.juneau.uon.UonSerializer#UON_encoding UON_encoding}
  - {@link org.apache.juneau.uon.UonSerializer#UON_paramFormat UON_paramFormat}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.uon.UonSerializer}
  - {@link org.apache.juneau.uon.UonSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.uon.UonSerializer#DEFAULT_ENCODING DEFAULT_ENCODING}
  - {@link org.apache.juneau.uon.UonSerializer#DEFAULT_READABLE DEFAULT_READABLE}

#### 2.24.3 - UON Parsers

The {@link org.apache.juneau.uon.UonParser} class is used to parse UON into POJOs.

The UON parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser Properties}
- {@link org.apache.juneau.uon.UonParser}
  - {@link org.apache.juneau.uon.UonParser#UON_decoding UON_decoding}
  - {@link org.apache.juneau.uon.UonParser#UON_validateEnd UON_validateEnd}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.uon.UonParser}
  - {@link org.apache.juneau.uon.UonParser#DEFAULT DEFAULT}
  - {@link org.apache.juneau.uon.UonParser#DEFAULT_DECODING DEFAULT_DECODING}

### 2.25 - URL-Encoding Details

Juneau supports converting arbitrary POJOs to and from URL-encoded strings using ultra-efficient serializers and parsers. The serializer converts POJOs directly to URL-encoded strings without the need for intermediate DOM objects using a highly-efficient state machine. Likewise, the parser creates POJOs directly from URL-encoded strings without the need for intermediate DOM objects.

Juneau uses UON (URL-Encoded Object Notation) for representing POJOs as URL-Encoded values in key-value pairs. The UON specification can be found here.

The following example shows JSON for a typical bean:

##### Sample Beans

public class Person { // Bean properties public String name; @Swap(TemporalCalendarSwap.IsoInstant.class) public Calendar birthDate; public List<Address> addresses; // Getters/setters omitted } public class Address { // Bean properties public String street, city; public StateEnum state; public int zip; public boolean isCurrent; // Getters/setters omitted }

##### Sample Code

Person p = new Person() .name("John Smith") .birthDate("1946-08-12T00:00:00Z") .addresses( new Address() .street("100 Main Street") .city("Anywhereville") .state(NY) .zip(12345) .isCurrent(true); );

##### URL-Encoding

name='John+Smith' &birthDate='1946-08-12T00:00:00Z' &addresses=@( ( street='100 Main Street', city=Anywhereville, state=NY, zip=12345, isCurrent=true ) )

#### 2.25.1 - URL-Encoding Methodology

##### General methodology:

Java type | JSON equivalent | UON
--- | --- | ---
Maps/beans | OBJECT | a1=(b1=x1,b2=x2) a1=(b1=(c1=x1,c2=x2))
Collections/arrays | ARRAY | a1=@(x1,x2) a1=@(@(x1,x2),@(x3,x4)) a1=@((b1=x1,b2=x2),(c1=x1,c2=x2))
Booleans | BOOLEAN | a1=true&a2=false
int/float/double/... | NUMBER | a1=123&a2=1.23e1
null | NULL | a1=null
String | STRING | a1=foobar a1='true' a1='null' a1='123' a1=' string with whitespace ' a1='string with ~'escaped~' quotes'

Refer to the UON specification for a complete set of syntax rules.

#### 2.25.2 - URL-Encoding Serializers

The {@link org.apache.juneau.urlencoding.UrlEncodingSerializer} class is used to serialize POJOs into URL-Encoding.

The URL-Encoding serializers provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.urlencoding.UrlEncodingSerializer}
  - {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#URLENC_expandedParams URLENC_expandedParams}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.urlencoding.UrlEncodingSerializer}
  - {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#DEFAULT_EXPANDED DEFAULT_EXPANDED}
  - {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#DEFAULT_PLAINTEXT DEFAULT_PLAINTEXT}
  - {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#DEFAULT_READABLE DEFAULT_READABLE}

#### 2.25.3 - URL-Encoding Parsers

The {@link org.apache.juneau.urlencoding.UrlEncodingParser} class is used to parse URL-Encoding into POJOs.

The URL-Encoding parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser Properties}
- {@link org.apache.juneau.urlencoding.UrlEncodingParser}
  - {@link org.apache.juneau.urlencoding.UrlEncodingParser#URLENC_expandedParams URLENC_expandedParams}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.urlencoding.UrlEncodingParser}
  - {@link org.apache.juneau.urlencoding.UrlEncodingParser#DEFAULT DEFAULT}

#### 2.25.4 - @UrlEncoding Annotation

The {@link org.apache.juneau.urlencoding.annotation.UrlEncoding @UrlEncoding} annotation is used to override the behavior of {@link org.apache.juneau.urlencoding.UrlEncodingSerializer} on individual bean classes or properties.

- {@link org.apache.juneau.urlencoding.annotation.UrlEncoding}
  - {@link org.apache.juneau.urlencoding.annotation.UrlEncoding#expandedParams() expandedParams}

The {@link org.apache.juneau.urlencoding.annotation.UrlEncoding#expandedParams() expandedParams} setting is used to force bean properties of type array or Collection to be expanded into multiple key/value pairings. It's identical in behavior to using the {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#URLENC_expandedParams} and {@link org.apache.juneau.urlencoding.UrlEncodingParser#URLENC_expandedParams} properties, but applies to only individual bean properties.

### 2.26 - MessagePack Details

Juneau supports converting arbitrary POJOs to and from MessagePack using ultra-efficient serializers and parsers.

MessagePack is a compact binary form of JSON. The serialization support for MessagePack mirrors that of JSON.

#### 2.26.1 - MessagePack Serializers

The {@link org.apache.juneau.msgpack.MsgPackSerializer} class is used to serialize POJOs into MessagePack.

The MessagePack serializer provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.msgpack.MsgPackSerializer}
  - {@link org.apache.juneau.msgpack.MsgPackSerializer#MSGPACK_addBeanTypes MSGPACK_addBeanTypes}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.msgpack.MsgPackSerializer}
  - {@link org.apache.juneau.msgpack.MsgPackSerializer#DEFAULT DEFAULT}

#### 2.26.2 - MessagePack Parsers

The {@link org.apache.juneau.msgpack.MsgPackParser} class is used to parse MessagePack into POJOs.

The MessagePack parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser Properties}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.msgpack.MsgPackParser}
  - {@link org.apache.juneau.msgpack.MsgPackParser#DEFAULT DEFAULT}

### 2.27 - OpenAPI Details

Juneau supports converting arbitrary POJOs to and from strings using OpenAPI-based schema rules.

The relevant classes for using OpenAPI-based serialization are:

- {@link org.apache.juneau.oapi.OpenApiSerializer} - Converts POJOs to strings.
- {@link org.apache.juneau.oapi.OpenApiParser} - Converts strings to POJOs.
- {@link org.apache.juneau.httppart.HttpPartSchema} - Defines the schema for your POJO.

The {@link org.apache.juneau.httppart.HttpPartSchema} class is used to define the formatting and validations for a POJO. It's used in conjunction with the serializer and parser to produce and consume HTTP parts based on OpenAPI rules.

Later in the rest-server and rest-client sections, we also describe how the following annotations can be applied to method parameters and class types to define the schema for various HTTP parts:

- {@link org.apache.juneau.http.annotation.Body}
- {@link org.apache.juneau.http.annotation.Header}
- {@link org.apache.juneau.http.annotation.Query}
- {@link org.apache.juneau.http.annotation.FormData}
- {@link org.apache.juneau.http.annotation.Path}
- {@link org.apache.juneau.http.annotation.Response}
- {@link org.apache.juneau.http.annotation.ResponseHeader}

#### 2.27.1 - OpenAPI Methodology

Unlike the other Juneau serializers and parsers that convert input and output directly to-and-from POJOs, the OpenAPI serializers and parsers use intermediate objects based on the type and format of the schema.

The following table shows the "natural" intermediate type of the object based on the type/format:

Type | Format | Intermediate Java Type
--- | --- | ---
string or empty | byte binary binary-spaced | byte[]
date date-time | {@link java.util.Calendar}
uon | No intermediate type. (serialized directly to/from POJO)
empty | {@link java.lang.String}
boolean | empty | {@link java.lang.Boolean}
integer | int32 | {@link java.lang.Integer}
int64 | {@link java.lang.Long}
number | float | {@link java.lang.Float}
double | {@link java.lang.Double}
array | empty | Arrays of intermediate types on this list.
uon | No intermediate type. (serialized directly to/from POJO)
object | empty | Map<String,Object>
uon | No intermediate type. (serialized directly to/from POJO)

The valid POJO types for serializing/parsing are based on the intermediate types above. As a general rule, any POJOs that are the intermediate type or transformable to or from the intermediate type are valid POJO types.

For example, the following POJO type can be transformed to and from a byte array.

// Sample POJO class convertable to and from a byte[]. public class MyPojo { // Constructor used by parser. public MyPojo(byte[] fromBytes) {...} // toX method used by serializer. public byte[] toBytes() {...} }

This example shows how that POJO can be converted to a BASE64-encoded string.

// Construct a POJO. MyPojo myPojo = ...; // Define a schema. HttpPartSchema schema = HttpPartSchema.create().type("string").format("byte").build(); // Convert POJO to BASE64-encoded string. HttpPartSerializer s = OpenApiSerializer.DEFAULT; String httpPart = s.serialize(schema, myPojo); // Convert BASE64-encoded string back into a POJO. HttpPartParser p = OpenApiParser.DEFAULT; myPojo = p.parse(schema, httpPart, MyPojo.class);

In addition to defining format, the schema also allows for validations of the serialized form.

// Construct a POJO. MyPojo myPojo = ...; // Define a schema. // Serialized string must be no smaller than 100 characters. HttpPartSchema schema = HttpPartSchema.create().type("string").format("byte").minLength(100).build(); // Convert POJO to BASE64-encoded string. HttpPartSerializer s = OpenApiSerializer.DEFAULT; String httpPart; try { httpPart = s.serialize(schema, myPojo); } catch (SchemaValidationException e) { // Oops, output too small. } // Convert BASE64-encoded string back into a POJO. HttpPartParser p = OpenApiParser.DEFAULT; try { myPojo = p.parse(schema, httpPart, MyPojo.class); } catch (SchemaValidationException e) { // Oops, input too small. }

It looks simple, but the implementation is highly sophisticated being able to serialize and parse and validate using complex schemas.

The next sections go more into depth on serializing and parsing various POJO types.

#### 2.27.2 - OpenAPI Serializers

The {@link org.apache.juneau.oapi.OpenApiSerializer} class is used to convert POJOs to HTTP parts.

Later we'll describe how to use HTTP-Part annotations to define OpenAPI schemas for serialization and parsing of HTTP parts. The following example is a preview showing an HTTP body defined as pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9"):

@RestMethod(method="POST", path="/2dLongArray") public void post2dLongArray( @Body( schema=@Schema( items=@Items( collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ) ) minLength=1, maxLength=10 ) ) Long[][] body ) {...}

Under-the-covers, this gets converted to the following schema object:

import static org.apache.juneau.httppart.HttpPartSchema.*; HttpPartSchema schema = create() .items( create() .collectionFormat("pipes") .items( create() .collectionFormat("csv") .type("integer") .format("int64") .minimum("0") .maximum("100") .minLength(1) .maxLength=(10) ) ) .build();

The following code shows how the schema above can be used to create our pipe+csv list of numbers:

// Our POJO being serialized. Long[][] input = .... // The serializer to use. HttpPartSerializer s = OpenApiSerializer.DEFAULT; // Convert POJO to a string. try { String httpPart = s.serialize(schema, input); } catch (SchemaValidationException e) { // Oops, one of the restrictions were not met. }

As a general rule, any POJO convertible to the intermediate type for the type/format of the schema can be serialized using the OpenAPI serializer. Here are the rules of POJO types allowed for various type/format combinations:

Type | Format | Valid parameter types
--- | --- | ---
string or empty | byte binary binary-spaced | byte[] (default) {@link java.io.InputStream} {@link java.io.Reader} - Read into String and then converted using {@link java.lang.String#getBytes()}. {@link java.lang.Object} - Converted to String and then converted using {@link java.lang.String#getBytes()}. Any POJO transformable to a byte[] via the following methods: public byte[] toBytes() {...} public byte[] toFoo() {...} (any method name starting with "to") Any POJO transformable to a byte[] via a {@link org.apache.juneau.transform.PojoSwap}.
date date-time | {@link java.util.Calendar} (default) {@link java.util.Date} Any POJO transformable to a {@link java.util.Calendar} via the following methods: public Calendar toCalendar() {...} public Calendar toFoo() {...} (any method name starting with "to") Any POJO transformable to a {@link java.util.Calendar} via a {@link org.apache.juneau.transform.PojoSwap}.
uon | Any {@doc PojoCategories Serializable POJO} type.
empty | {@link java.lang.String} (default) Any POJO transformable to a {@link java.lang.String} via the following methods: public String toString() {...} Any POJO transformable to a {@link java.lang.String} via a {@link org.apache.juneau.transform.PojoSwap}.
boolean | empty | {@link java.lang.Boolean} (default) boolean {@link java.lang.String} - Converted to a {@link java.lang.Boolean}. Any POJO transformable to a {@link java.lang.Boolean} via the following methods: public Boolean toBoolean() {...} public Boolean toFoo() {...} (any method name starting with "to") Any POJO transformable to a {@link java.lang.Boolean} via a {@link org.apache.juneau.transform.PojoSwap}.
integer | int32 | {@link java.lang.Integer} (default) int {@link java.lang.String} - Converted to an {@link java.lang.String}. Any POJO transformable to an {@link java.lang.Integer} via the following methods: public Integer toInteger() {...} public Integer toFoo() {...} (any method name starting with "to") Any POJO transformable to an {@link java.lang.Integer} via a {@link org.apache.juneau.transform.PojoSwap}.
int64 | {@link java.lang.Long} (default) long {@link java.lang.String} - Converted to a {@link java.lang.Long}. Any POJO transformable to a {@link java.lang.Long} via the following methods: public Long toLong() {...} public Long toFoo() {...} (any method name starting with "to") Any POJO transformable to a {@link java.lang.Long} via a {@link org.apache.juneau.transform.PojoSwap}.
number | float | {@link java.lang.Float} (default) float {@link java.lang.String} - Converted to a {@link java.lang.Float}. Any POJO transformable to a {@link java.lang.Float} via the following methods: public Float toFloat() {...} public Float toFoo() {...} (any method name starting with "to") Any POJO transformable to a {@link java.lang.Float} via a {@link org.apache.juneau.transform.PojoSwap}.
double | {@link java.lang.Double} (default) double {@link java.lang.String} - Converted to a {@link java.lang.Double}. Any POJO transformable to a {@link java.lang.Double} via the following methods: public Double toDouble() {...} public Double toFoo() {...} (any method name starting with "to") Any POJO transformable to a {@link java.lang.Double} via a {@link org.apache.juneau.transform.PojoSwap}.
array | empty | Arrays or Collections of any defaults on this list. Any POJO transformable to arrays of the default types (e.g. Integer[], Boolean[][], etc...). For example: public Boolean[][] toFoo() {...} (any method name starting with "to") Any POJO transformable to arrays of the default types via a {@link org.apache.juneau.transform.PojoSwap}
uon | Any {@doc PojoCategories Serializable POJO} type.
object | empty | Map<String,Object> (default) Beans with properties of anything on this list. Any POJO transformable to a map via a {@link org.apache.juneau.transform.PojoSwap}
uon | Any {@doc PojoCategories Serializable POJO} type.

For arrays, an example of "Any POJO transformable to arrays of the default types" is:

// Sample POJO class convertable to a Long[][]. public class MyPojo { // toX method used by serializer. public Long[][] to2dLongs() {...} }

In the example above, our POJO class can be used to create our pipe-delimited list of comma-delimited numbers:

// Our POJO being serialized. MyPojo input = .... // The serializer to use. HttpPartSerializer s = OpenApiSerializer.DEFAULT; // Convert POJO to a string. try { String httpPart = s.serialize(schema, input); } catch (SchemaValidationException e) { // Oops, one of the restrictions were not met. }

The object type is not officially part of the OpenAPI standard. However, Juneau supports serializing Maps and beans to HTTP parts using UON notation.

The following shows an example of a bean with several properties of various types.

public class MyBean { private static byte[] FOOB = "foo".getBytes(); public String f1 = "foo"; public byte[] f2 = FOOB; public byte[] f3 = FOOB; public byte[] f4 = FOOB; public Calendar f5 = parseIsoCalendar("2012-12-21T12:34:56Z"); public String f6 = "foo"; public int f7 = 1; public Long f8 = 2l; public float f9 = 1.0; public Double f10 = 1.0; public Boolean f11 = true; public Object fExtra = "1"; }

We define the following schema:

import static org.apache.juneau.httppart.HttpPartSchema.*; HttpPartSchema ps = schema("object") .property("f1", schema("string")) .property("f2", schema("string", "byte")) .property("f3", schema("string", "binary")) .property("f4", schema("string", "binary-spaced")) .property("f5", schema("string", "date-time")) .property("f6", schema("string", "uon")) .property("f7", schema("integer")) .property("f8", schema("integer", "int64")) .property("f9", schema("number")) .property("f10", schema("number", "double")) .property("f11", schema("boolean")) .additionalProperties(schema("integer")) .build();

Then we serialize our bean:

HttpPartSerializer s = OpenApiSerializer.DEFAULT; String httpPart = s.serialize(schema, new MyBean());

The results of this serialization is shown below:

( f1=foo, f2=Zm9v, f3=666F6F, f4='66 6F 6F', f5=2012-12-21T12:34:56Z, f6=foo, f7=1, f8=2, f9=1.0, f10=1.0, f11=true, fExtra=1 )

The following is an example of a bean with various array property types:

public class MyBean { private static byte[] FOOB = "foo".getBytes(); public String[] f1 = new String[]{"a,b",null}, public byte[][] f2 = new byte[][]{FOOB,null}, public byte[][] f3 = new byte[][]{FOOB,null}, public byte[][] f4 = new byte[][]{FOOB,null}, public Calendar[] f5 = new Calendar[]{parseIsoCalendar("2012-12-21T12:34:56Z"),null}, public String[] f6 = new String[]{"a","b",null}, public int[] f7 = new int[]{1,2,null}, public Integer[] f8 = new Integer[]{3,4,null}, public float[] f9 = new float[]{1f,2f,null}, public Float[] f10 = new Float[]{3f,4f,null}, public Boolean[] f11 = new Boolean[]{true,false,null}, public Object[] fExtra = new Object[]{1,"2",null}; }

For this bean, we define the following schema:

HttpPartSchema ps = schema("object") .property("f1", schema("array").items(schema("string"))) .property("f2", schema("array").items(schema("string", "byte"))) .property("f3", schema("array").items(schema("string", "binary"))) .property("f4", schema("array").items(schema("string", "binary-spaced"))) .property("f5", schema("array").items(schema("string", "date-time"))) .property("f6", schema("array").items(schema("string", "uon"))) .property("f7", schema("array").items(schema("integer"))) .property("f8", schema("array").items(schema("integer", "int64"))) .property("f9", schema("array").items(schema("number"))) .property("f10", schema("array").items(schema("number", "double"))) .property("f11", schema("array").items(schema("boolean"))) .additionalProperties(schema("array").items(schema("integer"))) .build();

Serializing this bean produces the following output:

( f1=@('a,b',null), f2=@(Zm9v,null), f4=@(2012-12-21T12:34:56Z,null), f5=@(666F6F,null), f6=@('66 6F 6F',null), f7=@(a,b,null), f8=@(1,2,null), f9=@(3,4,null), f10=@(1.0,2.0,null), f11=@(3.0,4.0,null), f12=@(true,false,null), fExtra=@(1,2,null) )

- Array properties can also use CSV/SSV/PIPES for array notation.
  Various notations can be mixed throughout.
- Schemas and POJOs can be defined arbitrarily deep.
- Schemas are optional. They can be skipped or partially defined.
- We make our best attempt to convert the input to the matching type. However, you will get SerializeExceptions if you attempt an impossible conversion. (e.g. trying to serialize the string "foo" as a boolean).

#### 2.27.3 - OpenAPI Parsers

The {@link org.apache.juneau.oapi.OpenApiParser} class is used to convert HTTP parts back into POJOs.

The following is the previous example of a schema that defines the format of a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9"):

import static org.apache.juneau.httppart.HttpPartSchema.*; HttpPartSchema schema = create() .items( create() .collectionFormat("pipes") .items( create() .collectionFormat("csv") .type("integer") .format("int64") .minimum("0") .maximum("100") .minLength(1) .maxLength=(10) ) ) .build();

The following code shows how the schema above can be used to parse our input into a POJO:

// Our input being parsed. String input = "1,2,3|4,5,6|7,8,9" // The parser to use. HttpPartParser p = OpenApiParser.DEFAULT; // Convert string to a POJO. try { Long[][] pojo = p.parse(schema, input, Long[][].class); } catch (SchemaValidationException e) { // Oops, one of the restrictions were not met. }

As a general rule, any POJO convertible from the intermediate type for the type/format of the schema can be parsed using the OpenAPI parser. Here are the rules of POJO types allowed for various type/format combinations:

Type | Format | Valid parameter types
--- | --- | ---
string or empty | byte binary binary-spaced | byte[] (default) {@link java.io.InputStream} - Returns a {@link java.io.ByteArrayInputStream}. {@link java.io.Reader} - Returns a {@link java.io.InputStreamReader} wrapped around a {@link java.io.ByteArrayInputStream}. {@link java.lang.String} - Constructed using {@link java.lang.String#String(byte[])}. {@link java.lang.Object} - Returns the default byte[]. Any POJO transformable from a byte[] (via constructors or static create methods).
date date-time | {@link java.util.Calendar} (default) {@link java.util.Date} {@link java.util.GregorianCalendar} {@link java.lang.String} - Converted using {@link java.util.Calendar#toString()}. {@link java.lang.Object} - Returns the default {@link java.util.Calendar}. Any POJO transformable from a {@link java.util.Calendar} (via constructors or static create methods).
uon | Any {@doc PojoCategories Parsable POJO} type.
empty | {@link java.lang.String} (default) {@link java.lang.Object} - Returns the default {@link java.lang.String}. Any POJO transformable from a {@link java.lang.String} (via constructors, static create methods, or swaps).
boolean | empty | {@link java.lang.Boolean} (default) boolean {@link java.lang.String} {@link java.lang.Object} - Returns the default {@link java.lang.Boolean}. Any POJO transformable from a {@link java.lang.Boolean} (via constructors, static create methods, or swaps).
integer | int32 | {@link java.lang.Integer} (default) Any subclass of {@link java.lang.Number} Any primitive number: (e.g int, float...) {@link java.lang.String} {@link java.lang.Object} - Returns the default {@link java.lang.Integer}. Any POJO transformable from an {@link java.lang.Integer} (via constructors, static create methods, or swaps).
int64 | {@link java.lang.Long} (default) Any subclass of {@link java.lang.Number} Any primitive number: (e.g int, float...) {@link java.lang.String} {@link java.lang.Object} - Returns the default {@link java.lang.Long}. Any POJO transformable from an {@link java.lang.Long} (via constructors, static create methods, or swaps).
number | float | {@link java.lang.Float} (default) Any subclass of {@link java.lang.Number} Any primitive number: (e.g int, float...) {@link java.lang.String} {@link java.lang.Object} - Returns the default {@link java.lang.Float}. Any POJO transformable from an {@link java.lang.Float} (via constructors, static create methods, or swaps).
double | {@link java.lang.Double} (default) Any subclass of {@link java.lang.Number} Any primitive number: (e.g int, float...) {@link java.lang.String} {@link java.lang.Object} - Returns the default {@link java.lang.Double}. Any POJO transformable from an {@link java.lang.Double} (via constructors, static create methods, or swaps).
array | empty | Arrays or Collections of anything on this list. Any POJO transformable from arrays of the default types (e.g. Integer[], Boolean[][], etc...).
uon | Any {@doc PojoCategories Parsable POJO} type.
object | empty | Map<String,Object> (default) Beans with properties of anything on this list. Maps with string keys.
uon | Any {@doc PojoCategories Parsable POJO} type.

Additionally, any of the type above can also be wrapped as {@link java.util.Optional Optionals}.

For arrays, an example of "Any POJO transformable from arrays of the default types" is:

// Sample POJO class convertable from a Long[][]. public class MyPojo { // Constructor used by parser. public MyPojo(Long[][] from2dLongs) {...} }

In the example above, our POJO class can be constructed from our pipe-delimited list of comma-delimited numbers:

// Our input being parsed. String input = "1,2,3|4,5,6|7,8,9" // The parser to use. HttpPartParser p = OpenApiParser.DEFAULT; // Convert string to a POJO. try { MyPojo pojo = p.parse(schema, input, MyPojo.class); } catch (SchemaValidationException e) { // Oops, one of the restrictions were not met. }

Just like serialization, the object type is not officially part of the OpenAPI standard, but Juneau supports parsing HTTP parts in UON notation to Maps and beans.

The following shows an example of a bean with several properties of various types.

public class MyBean { public String f1; public byte[] f2; public byte[] f3; public byte[] f4; public Calendar f5; public String f6; public int f7; public Long f8; public float f9; public Double f10; public Boolean f11; public Object fExtra; }

We define the following schema again:

import static org.apache.juneau.httppart.HttpPartSchema.*; HttpPartSchema ps = schema("object") .property("f1", schema("string")) .property("f2", schema("string", "byte")) .property("f3", schema("string", "binary")) .property("f4", schema("string", "binary-spaced")) .property("f5", schema("string", "date-time")) .property("f6", schema("string", "uon")) .property("f7", schema("integer")) .property("f8", schema("integer", "int64")) .property("f9", schema("number")) .property("f10", schema("number", "double")) .property("f11", schema("boolean")) .additionalProperties(schema("integer")) .build();

Then we parse our input into our POJO:

String input = "(f1=foo,f2=Zm9v,f3=666F6F,f4='66 6F 6F',f5=2012-12-21T12:34:56Z,f6=foo," + "f7=1,f8=2,f9=1.0,f10=1.0,f11=true,fExtra=1)"; HttpPartParser p = OpenApiParser.DEFAULT; MyBean b = p.parse(schema, input, MyBean.class);

Note that serializing into generic Object properties would have produced similar results:

public class MyBean { public Object f1; public Object f2; public Object f3; public Object f4; public Object f5; public Object f6; public Object f7; public Object f8; public Object f9; public Object f10; public Object f11; public Object fExtra; }

We can also parse into Maps as well:

String input = "(f1=foo,f2=Zm9v,f3=666F6F,f4='66 6F 6F',f5=2012-12-21T12:34:56Z,f6=foo," + "f7=1,f8=2,f9=1.0,f10=1.0,f11=true,fExtra=1)"; HttpPartParser p = OpenApiParser.DEFAULT; ObjectMap m = p.parse(schema, input, ObjectMap.class);

- Array properties can also use CSV/SSV/PIPES for array notation.
  Various notations can be mixed throughout.
- Schemas and POJOs can be defined arbitrarily deep.
- Schemas are optional. They can be skipped or partially defined.
- We make our best attempt to convert the output to the matching type. However, you will get ParseExceptions if you attempt an impossible conversion. (e.g. trying to parse the string "foo" into a boolean).

### 2.28 - Simple Variable Language

The org.apache.juneau.svl packages defines an API for a language called Simple Variable Language. In a nutshell, Simple Variable Language (or SVL) is text that contains variables of the form "$varName{varKey}". It is used extensively in the Config, REST and Microservice APIs.

Most variables can be recursively nested within the varKey (e.g. "$FOO{$BAR{xxx},$BAZ{xxx}}") and can return values that themselves contain more variables.

The {@link org.apache.juneau.svl.VarResolver} class is used to resolve variables. The {@link org.apache.juneau.svl.VarResolver#DEFAULT} resolver is a reusable instance of this class configured with the following basic variables:

- {@link org.apache.juneau.svl.vars.SystemPropertiesVar} - $S{key[,default]}
- {@link org.apache.juneau.svl.vars.EnvVariablesVar} - $E{key[,default]}

The following logic variables are also provided:

- {@link org.apache.juneau.svl.vars.IfVar} - $IF{arg,then[,else]}
- {@link org.apache.juneau.svl.vars.SwitchVar} - $SW{arg,pattern1:then1[,pattern2:then2...]}
- {@link org.apache.juneau.svl.vars.CoalesceVar} - $CO{arg1[,arg2...]}
- {@link org.apache.juneau.svl.vars.PatternMatchVar} - $PM{arg,pattern}
- {@link org.apache.juneau.svl.vars.PatternReplaceVar} - $PR{arg,pattern,replace}
- {@link org.apache.juneau.svl.vars.PatternExtractVar} - $PE{arg,pattern,groupIndex}
- {@link org.apache.juneau.svl.vars.NotEmptyVar} - $NE{arg}
- {@link org.apache.juneau.svl.vars.UpperCaseVar} - $UC{arg}
- {@link org.apache.juneau.svl.vars.LowerCaseVar} - $LC{arg}
- {@link org.apache.juneau.svl.vars.LenVar} - $LN{arg[,delimiter]}
- {@link org.apache.juneau.svl.vars.SubstringVar} - $ST{arg,start[,end]}

##### Example:

// Use the default variable resolver to resolve a string that contains $S (system property) variables String myProperty = VarResolver.DEFAULT.resolve("The Java home directory is $S{java.home}");

The following shows how variables can be arbitrarily nested...

// Look up a property in the following order: // 1) MYPROPERTY environment variable. // 2) 'my.property' system property if environment variable not found. // 3) 'not found' string if system property not found. String myproperty = VarResolver.DEFAULT.resolve("$E{MYPROPERTY,$S{my.property,not found}}");

#### 2.28.1 - SVL Variables 8.0.0-updated, 8.1.0-updated

Variables are defined through the {@link org.apache.juneau.svl.Var} API. The API comes with several predefined variables and is easily extensible.

The following is an example of a variable that performs URL-Encoding on strings.

// First create our var. public class UrlEncodeVar extends SimpleVar { // Must have a no-arg constructor! public UrlEncodeVar() { super("UE"); } // The method we must implement @Override public String resolve(VarResolverSession session, String key) { return URLEncoder.encode(key, "UTF-8"); } } // Next create a var resolver that extends the existing DEFAULT resolver // that supports resolving system properties. VarResolver r = VarResolver.DEFAULT .builder() .vars(UrlEncodeVar.class) .build(); // Retrieve a system property and URL-encode it if necessary. String myProperty = r.resolve("$UE{$S{my.property}}");

The following shows the class hierarchy of the {@link org.apache.juneau.svl.Var} class:

- {@link org.apache.juneau.svl.Var} - Superclass of all vars.
  - {@link org.apache.juneau.svl.SimpleVar} - Superclass of all vars that return strings.
    - {@link org.apache.juneau.svl.DefaultingVar} - Variables that define a default value if the resolve method returns null.
      - {@link org.apache.juneau.svl.MapVar} - Variables that pull values from maps.
    - {@link org.apache.juneau.svl.MultipartVar} - Variables that consist of 2 or more comma-delimited arguments.
  - {@link org.apache.juneau.svl.StreamedVar} - Superclass of all vars that stream their value to writers.

The following is the list of default variables defined in all modules:

Module | Class | Pattern
--- | --- | ---
juneau-svl | {@link org.apache.juneau.svl.vars.EnvVariablesVar} | $E{key[,default]}
{@link org.apache.juneau.svl.vars.SystemPropertiesVar} | $S{key[,default]}
{@link org.apache.juneau.svl.vars.ArgsVar} | $A{key[,default]}
{@link org.apache.juneau.svl.vars.ManifestFileVar} | $MF{key[,default]}
{@link org.apache.juneau.svl.vars.IfVar} | $IF{arg,then[,else]}
{@link org.apache.juneau.svl.vars.SwitchVar} | $SW{arg,pattern1:then1[,pattern2:then2...]}
{@link org.apache.juneau.svl.vars.CoalesceVar} | $CO{arg1[,arg2...]}
{@link org.apache.juneau.svl.vars.PatternMatchVar} | $PM{arg,pattern}
{@link org.apache.juneau.svl.vars.PatternReplaceVar} | $PR{arg,pattern,replace}
{@link org.apache.juneau.svl.vars.PatternExtractVar} | $PE{arg,pattern,groupdIndex}
{@link org.apache.juneau.svl.vars.NotEmptyVar} | $NE{arg}
{@link org.apache.juneau.svl.vars.UpperCaseVar} | $UC{arg}
{@link org.apache.juneau.svl.vars.LowerCaseVar} | $LC{arg}
{@link org.apache.juneau.svl.vars.LenVar} | $LN{arg[,delimiter]}
{@link org.apache.juneau.svl.vars.SubstringVar} | $ST{arg,start[,end]}
{@link org.apache.juneau.html.HtmlWidgetVar} | $W{name}
juneau-config | {@link org.apache.juneau.config.vars.ConfigVar} | $C{key[,default]}
juneau-rest-server | {@link org.apache.juneau.rest.vars.FileVar} | $F{path[,default]}}
{@link org.apache.juneau.rest.vars.ServletInitParamVar} | $I{name[,default]}
{@link org.apache.juneau.rest.vars.LocalizationVar} | $L{key[,args...]}
{@link org.apache.juneau.rest.vars.RequestAttributeVar} | $RA{key1[,key2...]}
{@link org.apache.juneau.rest.vars.RequestFormDataVar} | $RF{key1[,key2...]}
{@link org.apache.juneau.rest.vars.RequestHeaderVar} | $RH{key1[,key2...]}
{@link org.apache.juneau.rest.vars.RequestHeaderVar} | $RI{key}
{@link org.apache.juneau.rest.vars.RequestPathVar} | $RP{key1[,key2...]}
{@link org.apache.juneau.rest.vars.RequestQueryVar} | $RQ{key1[,key2...]}
{@link org.apache.juneau.rest.vars.RequestVar} | $R{key1[,key2...]}
{@link org.apache.juneau.rest.vars.SerializedRequestAttrVar} | $SA{contentType,key[,default]}
{@link org.apache.juneau.rest.vars.SwaggerVar} | $SS{key1[,key2...]}
{@link org.apache.juneau.rest.vars.UrlVar} | $U{uri}>
{@link org.apache.juneau.rest.vars.UrlEncodeVar} | $UE{uriPart}
{@link org.apache.juneau.rest.vars.WidgetVar} (deprecated) | $W{name}

#### 2.28.2 - VarResolvers and VarResolverSessions

The main class for performing variable resolution is {@link org.apache.juneau.svl.VarResolver}. Two methods are provided for resolving variables:

- {@link org.apache.juneau.svl.VarResolver}
  - {@link org.apache.juneau.svl.VarResolver#resolve(String) resolve(String)} - Resolves variables and returns the results as a simple string.
  - {@link org.apache.juneau.svl.VarResolver#resolveTo(String,Writer) resolveTo(String,Writer)} - Resolves variables and sends results to a writer.

Var resolvers can rely on the existence of other objects. For example, {@link org.apache.juneau.config.vars.ConfigVar} relies on the existence of a {@link org.apache.juneau.config.Config}. This is accomplished through the following:

- Context-objects - Objects set on the resolver.
- Session-objects - Objects set on the resolver session.

The following two classes are identical in behavior except for which objects they can access:

- {@link org.apache.juneau.svl.VarResolver} - Has access to context objects only.
- {@link org.apache.juneau.svl.VarResolverSession} - Has access to context and session objects.

Context and session objects are set through the following methods:

- {@link org.apache.juneau.svl.VarResolverBuilder#contextObject(String,Object)} - Context objects.
- {@link org.apache.juneau.svl.VarResolverSession#sessionObject(String,Object)} - Session objects.
- {@link org.apache.juneau.svl.VarResolver#createSession(Map)} - Session objects.

Both kinds of objects are accessible through the following method:

- {@link org.apache.juneau.svl.VarResolverSession#getSessionObject(Class, String, boolean)}

Var resolvers can be cloned and extended by using the {@link org.apache.juneau.svl.VarResolver#builder()} method. Cloning a resolver will copy it's {@link org.apache.juneau.svl.Var} class names and context objects.

##### Example:

// Create a resolver that copies the default resolver and adds $C and $A vars. VarResolver myVarResolver = VarResolver.DEFAULT .builder() .vars(ConfigVar.class, ArgsVar.class) .build();

#### 2.28.3 - VarResolver.DEFAULT 8.1.0-new

{@link org.apache.juneau.svl.VarResolver#DEFAULT} is a reusable variable resolver with default support for the following variables:

- $S{key[,default]} - {@link org.apache.juneau.svl.vars.SystemPropertiesVar}
- $E{key[,default]} - {@link org.apache.juneau.svl.vars.EnvVariablesVar}
- $A{key[,default]} - {@link org.apache.juneau.svl.vars.ArgsVar}
- $MF{key[,default]} - {@link org.apache.juneau.svl.vars.ManifestFileVar}
- $SW{stringArg,pattern:thenValue[,pattern:thenValue...]} - {@link org.apache.juneau.svl.vars.SwitchVar}
- $IF{arg,then[,else]} - {@link org.apache.juneau.svl.vars.IfVar}
- $CO{arg[,arg2...]} - {@link org.apache.juneau.svl.vars.CoalesceVar}
- $PM{arg,pattern} - {@link org.apache.juneau.svl.vars.PatternMatchVar}
- $PR{stringArg,pattern,replace}- {@link org.apache.juneau.svl.vars.PatternReplaceVar}
- $PE{arg,pattern,groupIndex} - {@link org.apache.juneau.svl.vars.PatternExtractVar}
- $UC{arg} - {@link org.apache.juneau.svl.vars.UpperCaseVar}
- $LC{arg} - {@link org.apache.juneau.svl.vars.LowerCaseVar}
- $NE{arg} - {@link org.apache.juneau.svl.vars.NotEmptyVar}
- $LN{arg[,delimiter]} - {@link org.apache.juneau.svl.vars.LenVar}
- $ST{arg,start[,end]} - {@link org.apache.juneau.svl.vars.SubstringVar}

#### 2.28.4 - Other Notes

- The escape character '\' can be used when necessary to escape the following characters: $ , { }
- WARNING: It is possible to cause {@link java.lang.StackOverflowError StackOverflowErrors} if your nested variables result in a recursive loop (e.g. the environment variable 'MYPROPERTY' has the value '$E{MYPROPERTY}'). So don't do that!
- As a general rule, this class tries to be as efficient as possible by not creating new strings when not needed.
  For example, calling the resolve method on a string that doesn't contain variables (e.g. resolver.resolve("foobar")) will simply be a no-op and return the same string.

### 2.29 - Best Practices

1. Reuse instances of serializers and parsers whenever possible.
   They are designed to be thread safe and maintain internal caches of bean metadata to increase performance.
2. The {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_detectRecursions BEANTRAVERSE_detectRecursions} option on the {@link org.apache.juneau.serializer.Serializer} class can cause a performance penalty of around 20%.
   Therefore, it's recommended that this option be used only when necessary.
3. In general, JSON serialization and parsing is about 20% faster than XML. JSON is also more compact than XML.
   MessagePack is fastest and most compact of all.
4. The RDF parsers are SLOW.
   RDF simply isn't efficient with node traversal, so creating tree structures out of RDF models is highly inefficient.
5. The {@link org.apache.juneau.parser.Parser} methods that take in {@link org.apache.juneau.ClassMeta} parameters are slightly faster than methods that take in {@link java.lang.Class} or {@link java.lang.Object} parameters, since the latter methods involve hash lookups to resolve to {@link org.apache.juneau.ClassMeta} parameters.

## 3 - juneau-marshall-rdf

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-marshall-rdf</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-marshall-rdf-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.marshall.rdf_{@property juneauVersion}.jar

The juneau-marshall-rdf library provides additional serializers and parsers for RDF. These rely on the Apache Jena library to provide support for the following languages:

- RDF/XML
- RDF/XML-Abbrev
- N-Triple
- Turtle
- N3

### 3.1 - RDF Details

Juneau supports serializing and parsing arbitrary POJOs to and from the following RDF formats:

- RDF/XML
- Abbreviated RDF/XML
- N-Triple
- Turtle
- N3

The serializers and parsers work identically to those in juneau-marshall, but are packaged separately so that you don't need to pull in the Jena dependency unless you need it.

// A simple bean public class Person { public String name = "John Smith"; public int age = 21; } // Serialize a bean to JSON, XML, or HTML Person p = new Person(); // Produces: // <rdf:RDF // xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" // xmlns:jp="http://www.apache.org/juneaubp/" // xmlns:j="http://www.apache.org/juneau/"> // <rdf:Description> // <jp:name>John Smith</jp:name> // <jp:age>21</jp:age> // </rdf:Description> // </rdf:RDF> String rdfXml = RdfSerializer.DEFAULT_XMLABBREV.serialize(p); // Produces: // @prefix jp: <http://www.apache.org/juneaubp/> . // @prefix j: <http://www.apache.org/juneau/> . // [] jp:age "21" ; // jp:name "John Smith" . String rdfN3 = N3Serializer.DEFAULT.serialize(p); // Produces: // _:A3bf53c85X3aX157cf407e2dX3aXX2dX7ffd <http://www.apache.org/juneaubp/name> "John Smith" . // _:A3bf53c85X3aX157cf407e2dX3aXX2dX7ffd <http://www.apache.org/juneaubp/age> "21" . String rdfNTriple = RdfSerializer.DEFAULT_NTRIPLE.serialize(p);

#### 3.1.1 - RDF Serializers

The {@link org.apache.juneau.jena.RdfSerializer} class is the top-level class for all Jena-based serializers. Language-specific serializers are defined as inner subclasses of the RdfSerializer class:

- {@link org.apache.juneau.jena.RdfSerializer}
  - {@link org.apache.juneau.jena.RdfXmlSerializer}
  - {@link org.apache.juneau.jena.RdfXmlAbbrevSerializer}
  - {@link org.apache.juneau.jena.N3Serializer}
  - {@link org.apache.juneau.jena.NTripleSerializer}
  - {@link org.apache.juneau.jena.TurtleSerializer}

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonSerializer Common Serializer Properties}
- {@link org.apache.juneau.jena.RdfCommon}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_embedding RDF_arp_embedding}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_err_ RDF_arp_err_}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_errorMode RDF_arp_errorMode}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_ign_ RDF_arp_ign_}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_iriRules RDF_arp_iriRules}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_warn_ RDF_arp_warn_}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_collectionFormat RDF_collectionFormat}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_juneauBpNs RDF_juneauBpNs}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_juneauNs RDF_juneauNs}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_language RDF_language}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_looseCollections RDF_looseCollections}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_abbrevBaseUri RDF_n3_abbrevBaseUri}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_indentProperty RDF_n3_indentProperty}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_minGap RDF_n3_minGap}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_objectLists RDF_n3_objectLists}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_propertyColumn RDF_n3_propertyColumn}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_subjectColumn RDF_n3_subjectColumn}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_useDoubles RDF_n3_useDoubles}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_usePropertySymbols RDF_n3_usePropertySymbols}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_useTripleQuotedStrings RDF_n3_useTripleQuotedStrings}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_widePropertyLen RDF_n3_widePropertyLen}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_allowBadUris RDF_rdfxml_allowBadUris}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_attributeQuoteChar RDF_rdfxml_attributeQuoteChar}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_blockRules RDF_rdfxml_blockRules}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_longId RDF_rdfxml_longId}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_relativeUris RDF_rdfxml_relativeUris}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_showDoctypeDeclaration RDF_rdfxml_showDoctypeDeclaration}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_showXmlDeclaration RDF_rdfxml_showXmlDeclaration}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_tab RDF_rdfxml_tab}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_xmlBase RDF_rdfxml_xmlBase}
- {@link org.apache.juneau.jena.RdfSerializer}
  - {@link org.apache.juneau.jena.RdfSerializer#RDF_addBeanTypes RDF_addBeanTypes}
  - {@link org.apache.juneau.jena.RdfSerializer#RDF_addLiteralTypes RDF_addLiteralTypes}
  - {@link org.apache.juneau.jena.RdfSerializer#RDF_addRootProperty RDF_addRootProperty}
  - {@link org.apache.juneau.jena.RdfSerializer#RDF_autoDetectNamespaces RDF_autoDetectNamespaces}
  - {@link org.apache.juneau.jena.RdfSerializer#RDF_namespaces RDF_namespaces}
  - {@link org.apache.juneau.jena.RdfSerializer#RDF_useXmlNamespaces RDF_useXmlNamespaces}

The following pre-configured serializers are provided for convenience:

- {@link org.apache.juneau.jena.RdfSerializer}
  - {@link org.apache.juneau.jena.RdfXmlSerializer}
    - {@link org.apache.juneau.jena.RdfXmlSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.RdfXmlAbbrevSerializer}
    - {@link org.apache.juneau.jena.RdfXmlAbbrevSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.N3Serializer}
    - {@link org.apache.juneau.jena.N3Serializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.NTripleSerializer}
    - {@link org.apache.juneau.jena.NTripleSerializer#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.TurtleSerializer}
    - {@link org.apache.juneau.jena.TurtleSerializer#DEFAULT DEFAULT}

Abbreviated RDF/XML is currently the most widely accepted and readable RDF syntax, so the examples shown here will use that format.

#### 3.1.2 - RDF Parsers

The {@link org.apache.juneau.jena.RdfParser} class is the top-level class for all Jena-based parsers. Language-specific parsers are defined as inner subclasses of the RdfParser class:

- {@link org.apache.juneau.jena.RdfParser}
  - {@link org.apache.juneau.jena.RdfXmlParser}
  - {@link org.apache.juneau.jena.NTripleParser}
  - {@link org.apache.juneau.jena.TurtleParser}
  - {@link org.apache.juneau.jena.N3Parser}

The RdfParser.Xml parser handles both regular and abbreviated RDF/XML.

The RDF parser provides the following settings:

- {@doc juneau-marshall.ConfigurableProperties.Common Common Properties}
- {@doc juneau-marshall.ConfigurableProperties.CommonParser Common Parser Properties}
- {@link org.apache.juneau.jena.RdfCommon}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_embedding RDF_arp_embedding}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_err_ RDF_arp_err_}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_errorMode RDF_arp_errorMode}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_ign_ RDF_arp_ign_}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_iriRules RDF_arp_iriRules}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_arp_warn_ RDF_arp_warn_}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_collectionFormat RDF_collectionFormat}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_juneauBpNs RDF_juneauBpNs}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_juneauNs RDF_juneauNs}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_language RDF_language}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_looseCollections RDF_looseCollections}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_abbrevBaseUri RDF_n3_abbrevBaseUri}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_indentProperty RDF_n3_indentProperty}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_minGap RDF_n3_minGap}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_objectLists RDF_n3_objectLists}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_propertyColumn RDF_n3_propertyColumn}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_subjectColumn RDF_n3_subjectColumn}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_useDoubles RDF_n3_useDoubles}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_usePropertySymbols RDF_n3_usePropertySymbols}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_useTripleQuotedStrings RDF_n3_useTripleQuotedStrings}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_n3_widePropertyLen RDF_n3_widePropertyLen}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_allowBadUris RDF_rdfxml_allowBadUris}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_attributeQuoteChar RDF_rdfxml_attributeQuoteChar}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_blockRules RDF_rdfxml_blockRules}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_longId RDF_rdfxml_longId}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_relativeUris RDF_rdfxml_relativeUris}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_showDoctypeDeclaration RDF_rdfxml_showDoctypeDeclaration}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_showXmlDeclaration RDF_rdfxml_showXmlDeclaration}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_tab RDF_rdfxml_tab}
  - {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_xmlBase RDF_rdfxml_xmlBase}
- {@link org.apache.juneau.jena.RdfParser}
  - {@link org.apache.juneau.jena.RdfParser#RDF_trimWhitespace RDF_trimWhitespace}

The following pre-configured parsers are provided for convenience:

- {@link org.apache.juneau.jena.RdfParser}
  - {@link org.apache.juneau.jena.RdfXmlParser}
    - {@link org.apache.juneau.jena.RdfXmlParser#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.N3Parser}
    - {@link org.apache.juneau.jena.N3Parser#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.NTripleParser}
    - {@link org.apache.juneau.jena.NTripleParser#DEFAULT DEFAULT}
  - {@link org.apache.juneau.jena.TurtleParser}
    - {@link org.apache.juneau.jena.TurtleParser#DEFAULT DEFAULT}

#### 3.1.3 - @Rdf Annotation

The {@link org.apache.juneau.jena.annotation.Rdf @Rdf} annotation is used to override the behavior of the RDF serializers and parsers on individual bean classes or properties.

- {@link org.apache.juneau.jena.annotation.Rdf}
  - {@link org.apache.juneau.jena.annotation.Rdf#beanUri() beanUri}
  - {@link org.apache.juneau.jena.annotation.Rdf#collectionFormat() collectionFormat}
  - {@link org.apache.juneau.jena.annotation.Rdf#namespace() namespace}
  - {@link org.apache.juneau.jena.annotation.Rdf#prefix() prefix}

#### 3.1.4 - Namespaces

You'll notice in the previous example that Juneau namespaces are used to represent bean property names. These are used by default when namespaces are not explicitly specified.

The juneau namespace is used for generic names for objects that don't have namespaces associated with them.

The juneaubp namespace is used on bean properties that don't have namespaces associated with them.

The easiest way to specify namespaces is through annotations. In this example, we're going to associate the prefix 'per' to our bean class and all properties of this class. We do this by adding the following annotation to our class:

@Rdf(prefix="per") public class Person {

In general, the best approach is to define the namespace URIs at the package level using a package-info.java class, like so:

// RDF namespaces used in this package @RdfSchema( prefix="ab", rdfNs={ @RdfNs(prefix="ab", namespaceURI="http://www.apache.org/addressBook/"), @RdfNs(prefix="per", namespaceURI="http://www.apache.org/person/"), @RdfNs(prefix="addr", namespaceURI="http://www.apache.org/address/"), @RdfNs(prefix="mail", namespaceURI="http://www.apache.org/mail/") } ) package org.apache.juneau.sample.addressbook; import org.apache.juneau.xml.annotation.*;

This assigns a default prefix of "ab" for all classes and properties within the project, and specifies various other prefixes used within this project.

Now when we rerun the sample code, we'll get the following:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j="http://www.apache.org/juneau/" xmlns:jp="http://www.apache.org/juneaubp/" xmlns:per="http://www.apache.org/person/"> <rdf:Description> <per:id>1</per:id> <per:name>John Smith</per:name> </rdf:Description> </rdf:RDF>

Namespace auto-detection ({@link org.apache.juneau.xml.XmlSerializer#XML_autoDetectNamespaces}) is enabled on serializers by default. This causes the serializer to make a first-pass over the data structure to look for namespaces. In high-performance environments, you may want to consider disabling auto-detection and providing an explicit list of namespaces to the serializer to avoid this scanning step.

// Create a new serializer, but manually specify the namespaces. RdfSerializer s = RdfSerializer.create() .xmlabbrev() .set(RdfProperties.RDF_rdfxml_tab, 3) .autoDetectNamespaces(false) .namespaces("{per:'http://www.apache.org/person/'}") .build();

This code change will produce the same output as before, but will perform slightly better since it doesn't have to crawl the POJO tree before serializing the result.

#### 3.1.5 - URI Properties

Bean properties of type java.net.URI or java.net.URL have special meaning to the RDF serializer. They are interpreted as resource identifiers.

In the following code, we're adding 2 new properties. The first property is annotated with @Beanp to identify that this property is the resource identifier for this bean. The second un-annotated property is interpreted as a reference to another resource.

public class Person { // Bean properties @Rdf(beanUri=true) public URI uri; public URI addressBookUri; ... // Normal constructor public Person(int id, String name, String uri, String addressBookUri) throws URISyntaxException { this.id = id; this.name = name; this.uri = new URI(uri); this.addressBookUri = new URI(addressBookUri); } }

We alter our code to pass in values for these new properties.

// Create our bean. Person p = new Person(1, "John Smith", "http://sample/addressBook/person/1", "http://sample/addressBook");

Now when we run the sample code, we get the following:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j="http://www.apache.org/juneau/" xmlns:jp="http://www.apache.org/juneaubp/" xmlns:per="http://www.apache.org/person/"> <rdf:Description rdf:about="http://sample/addressBook/person/1"> <per:addressBookUri rdf:resource="http://sample/addressBook"/> <per:id>1</per:id> <per:name>John Smith</per:name> </rdf:Description> </rdf:RDF>

The {@link org.apache.juneau.annotation.URI @URI} annotation can also be used on classes and properties to identify them as URLs when they're not instances of java.net.URI or java.net.URL (not needed if @Rdf(beanUri=true) is already specified).

The following properties would have produced the same output as before. Note that the @URI annotation is only needed on the second property.

public class Person { // Bean properties @Rdf(beanUri=true) public String uri; @URI public String addressBookUri;

Also take note of the {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriResolution}, {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriRelativity}, and and {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriContext} settings that can be specified on the serializer to resolve relative and context-root-relative URIs to fully-qualified URIs.

This can be useful if you want to keep the URI authority and context root information out of the bean logic layer.

The following code produces the same output as before, but the URIs on the beans are relative.

// Create a new serializer with readable output. RdfSerializer s = RdfSerializer.create() .xmlabbrev() .set(RdfProperties.RDF_rdfxml_tab, 3); .relativeUriBase("http://myhost/sample"); .absolutePathUriBase("http://myhost") .build(); // Create our bean. Person p = new Person(1, "John Smith", "person/1", "/"); // Serialize the bean to RDF/XML. String rdfXml = s.serialize(p);

#### 3.1.6 - Root Property

For all RDF languages, the POJO objects get broken down into simple triplets. Unfortunately, for tree-structured data like the POJOs shown above, this causes the root node of the tree to become lost. There is no easy way to identify that person/1 is the root node in our tree once in triplet form, and in some cases it's impossible.

By default, the {@link org.apache.juneau.jena.RdfParser} class handles this by scanning all the nodes and identifying the nodes without incoming references. However, this is inefficient, especially for large models. And in cases where the root node is referenced by another node in the model by URL, it's not possible to locate the root at all.

To resolve this issue, the property {@link org.apache.juneau.jena.RdfSerializer#RDF_addRootProperty} was introduced. When enabled, this adds a special root attribute to the root node to make it easy to locate by the parser.

To enable, set the RDF_addRootProperty property to true on the serializer:

// Create a new serializer. RdfSerializer s = RdfSerializer.create() .xmlabbrev() .set(RdfProperties.RDF_rdfxml_tab, 3), .addRootProperty(true) .build();

Now when we rerun the sample code, we'll see the added root attribute on the root resource.

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j="http://www.apache.org/juneau/" xmlns:jp="http://www.apache.org/juneaubp/" xmlns:per="http://www.apache.org/person/" xmlns:mail="http://www.apache.org/mail/" xmlns:addr="http://www.apache.org/address/"> <rdf:Description rdf:about="http://sample/addressBook/person/1"> <j:root>true</j:root> <per:addressBookUri rdf:resource="http://sample/addressBook"/> <per:id>1</per:id> <per:name>John Smith</per:name> <per:addresses> <rdf:Seq> <rdf:li> <rdf:Description rdf:about="http://sample/addressBook/address/1"> <addr:personUri rdf:resource="http://sample/addressBook/person/1"/> <addr:id>1</addr:id> <mail:street>100 Main Street</mail:street> <mail:city>Anywhereville</mail:city> <mail:state>NY</mail:state> <mail:zip>12345</mail:zip> <addr:isCurrent>true</addr:isCurrent> </rdf:Description> </rdf:li> </rdf:Seq> </per:addresses> </rdf:Description> </rdf:RDF>

#### 3.1.7 - Typed Literals

XML-Schema data-types can be added to non-String literals through the {@link org.apache.juneau.jena.RdfSerializer#RDF_addLiteralTypes} setting.

To enable, set the RDF_addLiteralTypes property to true on the serializer:

// Create a new serializer (revert back to namespace autodetection). RdfSerializer s = RdfSerializer.create() .xmlabbrev() .set(RdfProperties.RDF_rdfxml_tab, 3), .addLiteralTypes(true) .build();

Now when we rerun the sample code, we'll see the added root attribute on the root resource.

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j="http://www.apache.org/juneau/" xmlns:jp="http://www.apache.org/juneaubp/" xmlns:per="http://www.apache.org/person/" xmlns:mail="http://www.apache.org/mail/" xmlns:addr="http://www.apache.org/address/"> <rdf:Description rdf:about="http://sample/addressBook/person/1"> <per:addressBookUri rdf:resource="http://sample/addressBook"/> <per:id rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</per:id> <per:name>John Smith</per:name> <per:addresses> <rdf:Seq> <rdf:li> <rdf:Description rdf:about="http://sample/addressBook/address/1"> <addr:personUri rdf:resource="http://sample/addressBook/person/1"/> <addr:id rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</addr:id> <mail:street>100 Main Street</mail:street> <mail:city>Anywhereville</mail:city> <mail:state>NY</mail:state> <mail:zip rdf:datatype="http://www.w3.org/2001/XMLSchema#int">12345</mail:zip> <addr:isCurrent rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</addr:isCurrent> </rdf:Description> </rdf:li> </rdf:Seq> </per:addresses> </rdf:Description> </rdf:RDF>

## 4 - juneau-dto

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-dto</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-dto-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.dto_{@property juneauVersion}.jar

The juneau-dto library contains several predefined POJOs for generating commonly-used document types. This section describes support for these POJOs.

### 4.1 - HTML5

The Juneau HTML5 DTOs are simply beans with fluent-style setters that allow you to quickly construct HTML fragments as Java objects. These object can then be serialized to HTML using one of the existing HTML serializers, or to other languages such as JSON using the JSON serializers.

The {@link org.apache.juneau.dto.html5.HtmlBuilder} class is a utility class with predefined static methods that allow you to easily construct DTO instances in a minimal amount of code.

The following examples show how to create HTML tables.

Java code | HTML
--- | ---
import static org.apache.juneau.dto.html5.HtmlBuilder.*; Object mytable = table( tr( th("c1"), th("c2") ), tr( td("v1"), td("v2") ) ); String html = HtmlSerializer.DEFAULT.serialize(mytable); | <table> <tr> <th>c1</th> <th>c2</th> </tr> <tr> <td>v1</td> <td>v2</td> </tr> </table>
import static org.apache.juneau.dto.html5.HtmlBuilder.*; Object mydiv = div().align("center").onmouseover("alert(\"boo!\");") .children( p("Juneau supports ", b(i("mixed")), " content!") ); String html = HtmlSerializer.DEFAULT.serialize(mydiv); | <div align='center' onmouseover='alert("boo!");'> <p>Juneau supports <b><i>mixed</i></b> content!</p> </table>
import static org.apache.juneau.dto.html5.HtmlBuilder.*; Object myform = form().action("/submit").method("POST") .children( "Position (1-10000): ", input("number").name("pos").value(1), br(), "Limit (1-10000): ", input("number").name("limit").value(100), br(), button("submit", "Submit"), button("reset", "Reset") ); String html = HtmlSerializer.DEFAULT.serialize(myform); | <form action='/submit' method='POST'> Position (1-10000): <input name='pos' type='number' value='1'/><br/> Limit (1-10000): <input name='pos' type='number' value='100'/><br/> <button type='submit'>Submit</button> <button type='reset'>Reset</button> </form>

Using the HTML5 DTOs, you should be able to construct any valid HTML5 from full document bodies to any possible fragments.

The {@link org.apache.juneau.html.HtmlParser} class can be used convert these HTML documents back into POJOs.

Other serializers and parsers (e.g. {@link org.apache.juneau.json.JsonSerializer}) can be used to represent these POJOs in languages other than HTML.

##### Additional Information - org.apache.juneau.dto.html5

### 4.2 - Atom

The Juneau ATOM feed DTOs are simply beans with fluent-style setters. The following code shows a feed being created programmatically using the {@link org.apache.juneau.dto.atom.AtomBuilder} class.

import static org.apache.juneau.dto.atom.AtomBuilder.*; Feed feed = feed("tag:juneau.apache.org", "Juneau ATOM specification", "2016-01-02T03:04:05Z") .subtitle(text("html").text("Describes <em>stuff</em> about Juneau")) .links( link("alternate", "text/html", "http://juneau.apache.org").hreflang("en"), link("self", "application/atom+xml", "http://juneau.apache.org/feed.atom") ) .rights("Copyright (c) ...") .generator( generator("Juneau").uri("http://juneau.apache.org/").version("1.0") ) .entries( entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2016-01-02T03:04:05Z") .links( link"alternate", "text/html", "http://juneau.apache.org/juneau.atom"), link("enclosure", "audio/mpeg", "http://juneau.apache.org/audio/juneau_podcast.mp3").length(1337) ) .published("2016-01-02T03:04:05Z") .authors( person("Jane Smith").uri("http://juneau.apache.org/").email("janesmith@apache.org") ) .contributors( person("John Smith") ) .content( content("xhtml") .lang("en") .base("http://www.apache.org/") .text("<div><p><i>[Update: Juneau supports ATOM.]</i></p></div>") ) );

To serialize this to ATOM, use the {@link org.apache.juneau.xml.XmlSerializer} class:

##### Example with no namespaces

// Create a serializer with readable output, no namespaces yet. XmlSerializer s = XmlSerializer.create().sq().ws().build(); // Serialize to ATOM/XML String atomXml = s.serialize(feed);

##### Results

<feed> <id> tag:juneau.apache.org </id> <link href='http://juneau.apache.org/' rel='alternate' type='text/html' hreflang='en'/> <link href='http://juneau.apache.org/feed.atom' rel='self' type='application/atom+xml'/> <rights> Copyright (c) ... </rights> <title type='text'> Juneau ATOM specification </title> <updated>2016-01-02T03:04:05Z</updated> <generator uri='http://juneau.apache.org/' version='1.0'> Juneau </generator> <subtitle type='html'> Describes <em>stuff</em> about Juneau </subtitle> <entry> <author> <name>Jane Smith</name> <uri>http://juneau.apache.org/</uri> <email>janesmith@apache.org</email> </author> <contributor> <name>John Smith</name> </contributor> <id> tag:juneau.apache.org </id> <link href='http://juneau.apache.org/juneau.atom' rel='alternate' type='text/html'/> <link href='http://juneau.apache.org/audio/juneau_podcast.mp3' rel='enclosure' type='audio/mpeg' length='12345'/> <title> Juneau ATOM specification snapshot </title> <updated>2016-01-02T03:04:05Z</updated> <content base='http://www.apache.org/' lang='en' type='xhtml'> <div xmlns="http://www.w3.org/1999/xhtml" ><p><i>[Update: Juneau supports ATOM.]</i></p></div> </content> <published>2016-01-02T03:04:05Z</published> </entry> </feed>

The {@link org.apache.juneau.xml.XmlParser} class can be used convert these Atom documents back into POJOs.

Other serializers and parsers (e.g. {@link org.apache.juneau.json.JsonSerializer}) can be used to represent these POJOs in languages other than XML.

##### Additional Information - org.apache.juneau.dto.atom

### 4.3 - Swagger

The Juneau Swagger DTOs are simply beans with fluent-style setters that allow you to quickly construct Swagger documents as Java objects. These object can then be serialized to JSON using one of the existing JSON serializers, or to other languages such as XML or HTML using the other serializers.

The {@link org.apache.juneau.dto.swagger.SwaggerBuilder} class is a utility class with predefined static methods that allow you to easily construct DTO instances in a minimal amount of code.

The following is an example Swagger document from the Swagger website.

{ "swagger": "2.0", "info": { "title": "Swagger Petstore", "description": "This is a sample server Petstore server.", "version": "1.0.0", "termsOfService": "http://swagger.io/terms/", "contact": { "email": "apiteam@swagger.io" }, "license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html" } }, "host": "petstore.swagger.io", "basePath": "/v2", "tags": [ { "name": "pet", "description": "Everything about your Pets", "externalDocs": { "description": "Find out more", "url": "http://swagger.io" } } ], "schemes": [ "http" ], "paths": { "/pet": { "post": { "tags": [ "pet" ], "summary": "Add a new pet to the store", "description": "", "operationId": "addPet", "consumes": [ "application/json", "text/xml" ], "produces": [ "application/json", "text/xml" ], "parameters": [ { "in": "body", "name": "body", "description": "Pet object that needs to be added to the store", "required": true } ], "responses": { "405": { "description": "Invalid input" } } } } } }

This document can be generated by the following Java code:

static import org.apache.juneau.dto.swagger.SwaggerBuilder.*; Swagger swagger = swagger() .swagger("2.0") .info( info("Swagger Petstore", "1.0.0") .description("This is a sample server Petstore server.") .termsOfService("http://swagger.io/terms/") .contact( contact().email("apiteam@swagger.io") ) .license( license("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html") ) ) .host("petstore.swagger.io") .basePath("/v2") .tags( tag("pet").description("Everything about your Pets") .externalDocs( externalDocumentation("http://swagger.io", "http://swagger.io") ) ) .schemes("http") .path("/pet", "post", operation() .tags("pet") .summary("Add a new pet to the store") .description("") .operationId("addPet") .consumes(MediaType.JSON, MediaType.XML) .produces(MediaType.JSON, MediaType.XML) .parameters( parameterInfo("body", "body") .description("Pet object that needs to be added to the store") .required(true) ) .response(405, responseInfo("Invalid input")) ); // Serialize using JSON serializer. String swaggerJson = JsonSerializer.DEFAULT_READABLE.serialize(swagger); // Or just use toString(). String swaggerJson = swagger.toString();

Methods that take in beans and collections of beans can also take in JSON representations of those objects.

// Pass in a JSON object representation of an Info object. swagger.info("{title:'Swagger Petstore',...}");

Properties can also be accessed via the {@link org.apache.juneau.dto.swagger.SwaggerElement#get(String,Class)} and {@link org.apache.juneau.dto.swagger.SwaggerElement#set(String,Object)} methods. These methods can also be used to set and retrieve non-Swagger attributes such as "$ref" (which is not a part of the Swagger spec, but is part of the JSON Schema spec).

// Set a non-standard attribute. swagger.set("$ref", "http://foo.com"); // Retrieve a non-standard attribute. URI ref = swagger.get("$ref", URI.class);

Swagger docs can be parsed back into Swagger beans using the following code:

Swagger swagger = JsonParser.DEFAULT.parse(swaggerJson, Swagger.class);

### 4.4 - Swagger UI

The {@link org.apache.juneau.dto.swagger.ui.SwaggerUI} class is a DTO class for generating Swagger user interfaces from {@link org.apache.juneau.dto.swagger.Swagger} beans.

The PetStore example described later provides an example of auto-generated Swagger JSON:

Using {@link org.apache.juneau.dto.swagger.ui.SwaggerUI}, we're able to render that JSON as a Swagger user interface when the request is asking for HTML:

The class itself is nothing more than a POJO swap that swaps out {@link org.apache.juneau.dto.swagger.Swagger} beans with {@link org.apache.juneau.dto.html5.Div} elements:

public class SwaggerUI extends PojoSwap<Swagger,Div> { @Override public MediaType[] forMediaTypes() { // Only use this swap when the Accept type is HTML. return new MediaType[] {MediaType.HTML}; } @Override public Div swap(BeanSession beanSession, Swagger swagger) throws Exception { ... } }

The {@link org.apache.juneau.rest.BasicRestServlet} class (describe later) shows how this swap is used in the REST interface to generate the Swagger UI shown above:

@Rest( // Allow OPTIONS requests to be simulated using ?method=OPTIONS query parameter. allowedMethodParams="OPTIONS", // POJO swaps to apply to all serializers/parsers. pojoSwaps={ // Use the SwaggerUI swap when rendering Swagger beans. SwaggerUI.class }, ... ) public abstract class BasicRestServlet extends RestServlet implements BasicRestConfig { /** * [OPTIONS /*] - Show resource options. */ @RestMethod( name=OPTIONS, path="/*", summary="Swagger documentation", description="Swagger documentation for this resource.", htmldoc=@HtmlDoc( // Override the nav links for the swagger page. navlinks={ "back: servlet:/", "json: servlet:/?method=OPTIONS&Accept=text/json&plainText=true" }, // Never show aside contents of page inherited from class. aside="NONE" ) ) public Swagger getOptions(RestRequest req) { // Localized Swagger for this resource is available through the RestRequest object. return req.getSwagger(); } }

## 5 - juneau-config

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-config</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-config-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.config_{@property juneauVersion}.jar

### 5.1 - Overview

The juneau-config library contains a powerful API for creating and using INI-style config files.

##### Example configuration file:

# A set of entries [Section1] # An integer key1 = 1 # A boolean key2 = true # An array key3 = 1,2,3 # A POJO key4 = http://bar

Config files are accessed through the {@link org.apache.juneau.config.Config} class which are created through the {@link org.apache.juneau.config.ConfigBuilder} class. Builder creator methods are provided on the Config class:

// Create a Config object Config c = Config.create().name("MyConfig.cfg").build(); // Shortcut Config c = Config.create("MyConfig.cfg").build();

Once instantiated, reading values from the config are simple:

// Read values from section #1 int key1 = c.getInt("Section1/key1"); boolean key2 = c.getBoolean("Section1/key2"); int[] key3 = c.getObject("Section1/key3", int[].class); URL key4 = c.getObject("Section1/key4", URL.class);

The config language may look simple, but it is a very powerful feature with many capabilities including:

- Support for storing and retrieving any of the following data types:
  - Primitives
  - POJOs
  - Beans
  - Arrays, Maps, and Collections of anything
  - Binary data
- Transactional modifications with commit/rollback capabilities.
- A listener API.
- Filesystem watcher integration allowing changes on the file system to be reflected in real-time.
- Modifications through the Config class (e.g. add/remove/modify sections and keys, add/remove comments and whitespace, etc...) DO NOT cause loss of formatting in the file.
  All existing whitespace and comments are preserved for you!
- Value encoding for added security.
- Support for SVL variables.
- Directly populate beans from config sections.
- Accessing config sections through Java interface proxies.
- An extensible storage API allows you to write your own config storage (e.g. storage in databases or the cloud).

#### 5.1.1 - Syntax Rules

- Each config file contains zero or more sections containing zero or more entries:

  [Section1] key1 = 1 [Section2] key1 = 2

- Unicode escapes can be used in values.

  key1 = \u0070\u0075\u0062\u006c\u0069\u0063

- Comment lines start with the '#' character and can be placed on lines before sections and entries:

  # A comment about this section [Section1] # A comment about this entry key1 = 1

- Comments can also be placed on the same line as entries:

  key1 = 1 # A comment about this entry

- Values containing '#' must be escaped to prevent identification as a comment character:

  valueContainingPound = Value containing \u0023 character

  Likewise, '\' should be escaped to prevent confusion with unicode escapes.
- Values containing newlines can span multiple lines.
  Subsequent lines start with a tab character.

  multiLineValue = line 1, line 2, line 3

  When retrieved, the above translates to "line1,\nline2,\nline3".
- Leading and trailing whitespace on values are ignored.
- Whitespace is not ignored within multi-line values (except for the leading tab character on each line).
- Blank lines can be used anywhere in the file.

  # A comment line # Another comment line [Section1] ...

- Values located before any sections are considered part of the no-name section, meaning they are accessed simply by key and not section/key.

  # Top of file # Use config.getString("key1") to retrieve. key1 = val1 # The first section [Section1] # Use config.getString("Section1/key2") to retrieve. key2 = val2

- Section and key names must be at least one character long and not consist of any of the following characters:

  / \ [ ] = #

- Whitespace in section and key names is technically allowed but discouraged.

### 5.2 - Entry Types

Configuration files can contain entries for anything from primitive types up to complex hierarchies of POJOs consisting of maps, collections, and/or beans.

#### 5.2.1 - Primitive Types

The most common case for configuration values are primitives.

# A string key1 = foo # A boolean key2 = true # An integer key3 = 123 # A long key4 = 10000000000 # Doubles key5 = 6.67e−11 key6 = Infinity

The following methods are provided for accessing primitive values:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getString(String) getString(String)}
  - {@link org.apache.juneau.config.Config#getString(String,String) getString(String,String)}
  - {@link org.apache.juneau.config.Config#getBoolean(String) getBoolean(String)}
  - {@link org.apache.juneau.config.Config#getBoolean(String,boolean) getBoolean(String,boolean)}
  - {@link org.apache.juneau.config.Config#getInt(String) getInt(String)}
  - {@link org.apache.juneau.config.Config#getInt(String,int) getInt(String,int)}
  - {@link org.apache.juneau.config.Config#getLong(String) getLong(String)}
  - {@link org.apache.juneau.config.Config#getLong(String,long) getLong(String,long)}
  - {@link org.apache.juneau.config.Config#getFloat(String) getFloat(String)}
  - {@link org.apache.juneau.config.Config#getFloat(String,float) getFloat(String,long)}
  - {@link org.apache.juneau.config.Config#getDouble(String) getDouble(String)}
  - {@link org.apache.juneau.config.Config#getDouble(String,double) getDouble(String,long)}

On integers and longs, "K", "M", and "G" can be used to identify kilo, mega, and giga.

key1 = 100K # Same as 1024000 key2 = 100M # Same as 104857600

Numbers can also use hexadecimal and octal notation:

hex1 = 0x12FE hex2 = 0X12FE octal1 = 01234

Strings with newlines are treated as multi-line values that get broken into separate lines:

key1 = This is a particularly long sentence that we want to split onto separate lines.

Typically, multi-line values are started on the next line for clarity like so:

key1 = This is a particularly long sentence that we want to split onto separate lines.

#### 5.2.2 - POJOs

The following methods are provided for accessing POJO values:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getObject(String,Class) getObject(String,Class)}
  - {@link org.apache.juneau.config.Config#getObjectWithDefault(String,Object,Class) getObjectWithDefault(String,T,Class)}

In theory, any {@doc PojoCategories parsable} POJO type can be represented as a config value. However in practice, we're typically talking about the following:

- Objects convertible from Strings.
- Beans.

An example of an object convertible from a String was already shown in an example above. In that case, it was a URL which has a public constructor that takes in a String:

# A POJO key4 = http://bar

// Read values from section #1 URL key4 = c.getObject("Section1/key4", URL.class);

Beans are represented as {@doc juneau-marshall.JsonDetails.SimplifiedJson Simplified JSON} by default:

// Contact information [ContactInfo] address = { street: '123 Main Street', city: 'Anywhere', state: 'NY', zip: 12345 }

// Example bean public class Address { public String street, city; public StateEnum state; public int zip; } // Example usage Config c = Config.create("MyConfig.cfg").build(); Address myAddress = c.getObject("ContactInfo/address", Address.class);

The format for beans depends on the serializer and parser registered on the Config which is defined in the builder via the following methods:

- {@link org.apache.juneau.config.ConfigBuilder}
  - {@link org.apache.juneau.config.ConfigBuilder#serializer(Class) serializer(Class)}
  - {@link org.apache.juneau.config.ConfigBuilder#serializer(WriterSerializer) serializer(WriterSerializer)}
  - {@link org.apache.juneau.config.ConfigBuilder#parser(Class) parser(Class)}
  - {@link org.apache.juneau.config.ConfigBuilder#parser(ReaderParser) parser(ReaderParser)}

The default parser can also be overridden on the following getters:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getObject(String,Parser,Class) getObject(String,Parser,Class)}
  - {@link org.apache.juneau.config.Config#getObjectWithDefault(String,Parser,Object,Class) getObjectWithDefault(String,T,Parser,Class)}

#### 5.2.3 - Arrays

The following methods are provided for accessing arrays:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getStringArray(String) getStringArray(String)}
  - {@link org.apache.juneau.config.Config#getStringArray(String,String[]) getStringArray(String,String)}
  - {@link org.apache.juneau.config.Config#getObject(String,Class) getObject(String,Class)}
  - {@link org.apache.juneau.config.Config#getObject(String,Parser,Class) getObject(String,Parser,Class)}

The getStringArray() methods allow you to retrieve comma-delimited lists of values:

key1 = foo, bar, baz

String[] key1 = c.getStringArray("key1");

String arrays can also be represented in JSON when using the getObject() methods:

key1 = ['foo','bar','baz']

String[] key1 = c.getObject("key1", String[].class);

Primitive arrays can also be retrieved using the getObject() methods:

key1 = [1,2,3]

int[] key1 = c.getObject("key1", int[].class);

Arrays of POJOs can also be retrieved using the getObject() methods:

addresses = [ { street: '123 Main Street', city: 'Anywhere', state: 'NY', zip: 12345 }, { street: '456 Main Street', city: 'Anywhere', state: 'NY', zip: 12345 } ]

Address[] addresses = c.getObject("addresses", Address[].class);

#### 5.2.4 - Collections

The following methods are provided for accessing maps and collections:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getObject(String,Type,Type...) getObject(String,Type,Type...)}
  - {@link org.apache.juneau.config.Config#getObject(String,Parser,Type,Type...) getObject(String,Parser,Type,Type...)}
  - {@link org.apache.juneau.config.Config#getObjectWithDefault(String,Object,Type,Type...) getObjectWithDefault(String,T,Type,Type...)}
  - {@link org.apache.juneau.config.Config#getObjectWithDefault(String,Parser,Object,Type,Type...) getObjectWithDefault(String,T,Parser,Type,Type...)}

The Type,Type... arguments allow you to specify the component types for maps and collections. List class arguments can be followed by zero or one arguments representing the entry types. Map class arguments can be followed by zero or two arguments representing the key and value types. The arguments can be chained to produce any data structure consisting of maps, collections, or POJOs.

Examples are shown below:

- getObject("...", List.class)
  Produces: List<?>
- getObject("...", LinkedList.class)
  Produces: LinkedList<?>
- getObject("...", HashSet.class, Integer.class)
  Produces: HashSet<Integer>
- getObject("...", Map.class)
  Produces: Map<?,?>
- getObject("...", HashMap.class)
  Produces: HashMap<?,?>
- getObject("...", LinkedHashMap.class, String.class, MyBean.class)
  Produces: LinkedHashMap<String,MyBean>
- getObject("...", HashMap.class, Integer.class, ArrayList.class, MyBean[].class)
  Produces: LinkedHashMap<Integer,ArrayList<MyBean[]>>

##### Example:

addresses = [ { street: '123 Main Street', city: 'Anywhere', state: 'NY', zip: 12345 }, { street: '456 Main Street', city: 'Anywhere', state: 'NY', zip: 12345 } ]

List<Address> addresses = c.getObject("addresses", ArrayList.class, Address.class);

Oftentimes, it might be useful to parse into the {@link org.apache.juneau.ObjectList} and {@link org.apache.juneau.ObjectMap} classes that provide the various convenience methods for working with JSON-like data structures:

ObjectMap m = c.getObject("key1", ObjectMap.class); ObjectList l = c.getObject("key2", ObjectList.class);

#### 5.2.5 - Binary Data

The following methods are provided for accessing binary data:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getBytes(String) getBytes(String)}
  - {@link org.apache.juneau.config.Config#getBytes(String,byte[]) getBytes(String,byte[])}

Binary data can be represented in 3 formats:

- BASE-64 (default)
  Example: "Zm9vYmFycw=="
- Hexadecimal
  Example: "666F6F62617273"
- Spaced hexadecimal
  Example: "66 6F 6F 62 61 72 73"

The binary data format is controlled via the following setting:

- {@link org.apache.juneau.config.Config#CONFIG_binaryFormat}

For example:

key = Zm9vYmFycw==

byte[] bytes = c.getBytes("key");

Binary lines can be split up into separate lines for readability:

key = Zm9vYm Fycw==

Binary data line wrapping can be controlled via the following setting:

- {@link org.apache.juneau.config.Config#CONFIG_binaryLineLength}

### 5.3 - Variables

Config files can contain variables that get resolved dynamically using the previously-described {@link org.apache.juneau.svl.VarResolver} API.

##### Example:

#-------------------------- # My section #-------------------------- [MySection] # A system property locale = $S{java.locale, en_US} # An environment variable path = $E{PATH, unknown} # Another value in this config file anotherLocale = $C{MySection/locale} # Look for system property, or env var if that doesn't exist, or a default value if that doesn't exist. nested = $S{mySystemProperty,$E{MY_ENV_VAR,$C{MySection/anotherLocale}}} # A POJO with embedded variables aBean = {foo:'$S{foo}',baz:$C{MySection/anInt}}

Config c = Config.create().build(); Locale locale = cf.getObject("MySection/locale", Locale.class); String path = cf.getString("MySection/path"); int sameAsAnInt = cf.getInt("MySection/sameAsAnInt"); ABean bean = cf.getObject("MySection/aBean", ABean.class);

By default, Configs use the {@link org.apache.juneau.svl.VarResolver#DEFAULT} variable resolver which provides support for the following variables and constructs:

- {@link org.apache.juneau.svl.vars.SystemPropertiesVar} - $S{key[,default]}
- {@link org.apache.juneau.svl.vars.EnvVariablesVar} - $E{key[,default]}
- {@link org.apache.juneau.config.vars.ConfigVar} - $C{key[,default]}

The variable resolver is controlled via the following setting:

- {@link org.apache.juneau.config.Config#CONFIG_varResolver}

Additionally, the following method can be used to retrieve a Config with a different variable resolver:

- {@link org.apache.juneau.config.Config#resolving(VarResolverSession)}

#### 5.3.1 - Logic Variables

The default variable resolver also provides the following logic variables for performing simple logical operations:

- {@link org.apache.juneau.svl.vars.IfVar} - $IF{arg,then[,else]}
- {@link org.apache.juneau.svl.vars.SwitchVar} - $SW{arg,pattern1:then1[,pattern2:then2...]}
- {@link org.apache.juneau.svl.vars.CoalesceVar} - $CO{arg1[,arg2...]}
- {@link org.apache.juneau.svl.vars.PatternMatchVar} - $PM{arg,pattern}
- {@link org.apache.juneau.svl.vars.NotEmptyVar} - $NE{arg}
- {@link org.apache.juneau.svl.vars.UpperCaseVar} - $UC{arg}
- {@link org.apache.juneau.svl.vars.LowerCaseVar} - $LC{arg}

The $IF variable can be used for simple if/else logic:

# Value set to 'foo' if myBooleanProperty is true key1 = $IF{ $S{myBooleanProperty}, foo } # Value set to 'foo' if myBooleanProperty is true, 'bar' if false. key2 = $IF{ $S{myBooleanProperty}, foo, bar } # Value set to key1 value if myBooleanProperty is true, key2 value if false. key3 = $IF{ $S{myBooleanProperty}, $C{key1}, $C{key2} }

The $SW variable can be used for switch blocks based on pattern matching:

# Shell command depends on the OS shellCommand = $SW{ $LC{$S{os.name}}, *win*: bat, linux: bash, *: sh }

The $CO variable can be used for coalescing of values (finding the first non-null/empty match):

# Debug flag can be enabled by system property or environment variable. debug = $CO{ $S{debug}, $E{DEBUG}, false }

The $PM variable can be used for calculating boolean values:

# Debug flag can be enabled by system property or environment variable. isWindows = $PM{ $LC{$S{os.name}}, *win* }

### 5.4 - Encoded Entries

Encoded entries allow for sensitive information such as passwords to be obfuscated.

Encoded entries are denoted with a '*' character at the end of the key name.

For example, the following password is marked for encoding:

[MyHost] url = http://localhost:9080/foo user = me password* = {AwwJVhwUQFZEMg==}

The default encoder is {@link org.apache.juneau.config.encode.ConfigXorEncoder} which is a simple XOR+Base64 encoder.

Custom encoders can be used to provide your own encoding support by implementing the {@link org.apache.juneau.config.encode.ConfigEncoder} interface.

- {@link org.apache.juneau.config.encode.ConfigEncoder}
  - {@link org.apache.juneau.config.encode.ConfigEncoder#encode(String,String) encode(String,String)}
  - {@link org.apache.juneau.config.encode.ConfigEncoder#decode(String,String) decode(String,String)}
  - {@link org.apache.juneau.config.encode.ConfigEncoder#isEncoded(String) isEncoded(String)}

Encoders are controlled via the following setting:

- {@link org.apache.juneau.config.Config#CONFIG_encoder}

Encoded values can be set to plain-text values. The curly brackets around the value identify whether the value has been encoded or not.

Unencoded values are encoded when the file is saved using the {@link org.apache.juneau.config.Config#commit()} method. They can also be encoded immediately by calling {@link org.apache.juneau.config.Config#encodeEntries()}.

### 5.5 - Section Maps

Config sections can be retrieved in-bulk using {@link org.apache.juneau.config.Config#getSectionAsMap(String)}.

##### Example:

// Example config file [MyAddress] street = 123 Main Street city = Anywhere state = NY zip = 12345

// Example usage Config c = Config.create("MyConfig.cfg").build(); ObjectMap m = c.getSectionAsMap("MyAddress"); String street = m.getString("street"); String city = m.getString("city"); String state = m.getString("state"); int zip = m.getInt("zip");

Maps created this way are snapshot copies of the section at the time of the method call.

### 5.6 - Section Beans

Config files can also be used to directly populate beans using {@link org.apache.juneau.config.Config#getSectionAsBean(String,Class,boolean)}.

##### Example:

// Example config file [MyAddress] street = 123 Main Street city = Anywhere state = NY zip = 12345

// Example bean public class Address { public String street, city; public StateEnum state; public int zip; } // Example usage Config c = Config.create("MyConfig.cfg").build(); Address myAddress = c.getSectionAsBean("MyAddress", Address.class);

Like maps, beans created this way are snapshot copies of the section at the time of the method call.

### 5.7 - Section Interfaces

Config sections can also be accessed via interface proxies using {@link org.apache.juneau.config.Config#getSectionAsInterface(String,Class)}.

While section maps and beans retrieve copies of the configuration data at the time of the method call, section interfaces can also be use to set values in the underlying configuration.

##### Example:

// Example config file [MySection] string = foo int = 123 enum = ONE bean = {foo:'bar',baz:123} int3dArray = [[[123,null],null],null] bean1d3dListMap = {key:[[[[{foo:'bar',baz:123}]]]]}

// Example interface. // Setters are optional. public interface MyConfigInterface { String getString(); void setString(String x); int getInt(); void setInt(int x); MyEnum getEnum(); void setEnum(MyEnum x); MyBean getBean(); void setBean(MyBean x); int[][][] getInt3dArray(); void setInt3dArray(int[][][] x); Map<String,List<MyBean[][][]>> getBean1d3dListMap(); void setBean1d3dListMap(Map<String,List<MyBean[][][]>> x); } // Example usage. Config c = Config.create("MyConfig.cfg").build(); MyConfigInterface ci = c.getSectionAsInterface("MySection", MyConfigInterface.class); // Read a value. int myInt = ci.getInt(); // Write a value. ci.setBean(new MyBean()); // Commit your changes to the store. c.commit();

### 5.8 - Setting Values

The following methods allow you to add, remove, and modify entries and sections in a config file:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#set(String,Object) set(String,Object)}
  - {@link org.apache.juneau.config.Config#set(String,Object,Serializer) set(String,Object,Serializer)}
  - {@link org.apache.juneau.config.Config#set(String,Object,Serializer,ConfigMod,String,List) set(String,Object,Serializer,ConfigMod,String,List)}
  - {@link org.apache.juneau.config.Config#set(String,Object,Serializer,ConfigMod[],String,List) set(String,Object,Serializer,ConfigMod[],String,List)}
  - {@link org.apache.juneau.config.Config#set(String,String) set(String,String)}
  - {@link org.apache.juneau.config.Config#remove(String) remove(String)}
  - {@link org.apache.juneau.config.Config#setSection(String,List) setSection(String,List)}
  - {@link org.apache.juneau.config.Config#setSection(String,List,Map) setSection(String,List,Map)}
  - {@link org.apache.juneau.config.Config#removeSection(String) removeSection(String)}

// Construct the sample config file programmatically Config c = Config.create("MyConfig.cfg").build() .set("key1", 1) .set("key2", true) .set("key3", new int[]{1,2,3}) .set("key4", new URI("http://foo")) .set("Section1/key1", 2) .set("Section1/key2", false) .set("Section1/key3", new int[]{4,5,6}) .set("Section1/key4", new URI("http://bar")) .commit();

The method {@link org.apache.juneau.config.Config#set(String,Object,Serializer,ConfigMod[],String,List)} can be used for adding comments and pre-lines to entries, and specifying encoded values.

// Set an encoded value with some comments. c.set("key1", 1, null, ConfigMod.ENCODED, "Same-line comment", Arrays.asList( "# Comment 1", "", "# Comment 2" ) );

# Comment 1 # Comment 2 key1 = 1 # Same-line comment

The last 4 arguments in {@link org.apache.juneau.config.Config#set(String,Object,Serializer,ConfigMod[],String,List)} are optional in that if you pass null, the current value will not be overwritten. To unset the same-line comment, you should pass in a blank string. To remove pre-lines, you should pass in an empty list.

Sections can be added with optional pre-lines using the setSection methods:

// Set an encoded value with some comments. c.setSection("NewSection", Arrays.asList( "# Section comment 1", "", "# Section comment 2" ) );

# Section comment 1 # Section comment 2 [NewSection]

Changes made to the configuration are transactional in nature. They are kept in memory until you call the {@link org.apache.juneau.config.Config#commit()} method. Until then, you still see the modified values when you call any of the getters, but the modified values exist only in memory.

Changes can be rolled back using the {@link org.apache.juneau.config.Config#rollback()} method.

#### 5.8.1 - File System Changes

In general, external file modifications will be detected immediately in the Config object when a watcher thread is enabled (explained later). Otherwise, they are detected when a commit is performed.

The Config object maintains an in-memory record of all changes that have been applied to it through getters and setters. When the underlying file changes, the new contents are loaded and the in-memory changes are then applied to the new configuration. This provides the benefits of real-time updates of configurations while not losing any changes made in the JVM.

If the commit() method is called on the Config objects after the file system contents have been modified, we will then reload the configuration from the file system, apply the changes, and then try to save to the file system again (up to 10 times).

If the same entry is both internally and externally modified, the external modification will be overwritten (although both change events will be seen by listeners).

#### 5.8.2 - Custom Entry Serialization

Setter methods that take in a Serializer can be used to provide custom serialization of entries instead of using the predefined serializer.

// Set an XML value instead of JSON. c.set("key1", myAddress, XmlSerializer.DEFAULT_SQ_READABLE);

key1 = <address> <street>123 Main Street</street> <city>Anywhere</city> <state>NY</state> <zip>12345</zip> </address>

The value can then be retrieved using the equivalent parser:

Address myAddress = c.getObject("key1", XmlParser.DEFAULT, Address.class);

#### 5.8.3 - Setting Values in Bulk

The following methods can be used to bulk-load configuration values:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#setSection(String,List,Map) setSection(String,List,Map)}
  - {@link org.apache.juneau.config.Config#load(Map) load(Map)}
  - {@link org.apache.juneau.config.Config#load(Reader,boolean) load(Reader,boolean)}
  - {@link org.apache.juneau.config.Config#load(String,boolean) load(String,boolean)}

Changes can then be committed using the {@link org.apache.juneau.config.Config#commit()} method.

### 5.9 - Listeners

Configuration change events can be listened for using the following methods:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#addListener(ConfigEventListener) addListener(ConfigEventListener)}
  - {@link org.apache.juneau.config.Config#removeListener(ConfigEventListener) removeListener(ConfigEventListener)}

The {@link org.apache.juneau.config.event.ConfigEventListener} interface consists of the following method:

- {@link org.apache.juneau.config.event.ConfigEventListener}
  - {@link org.apache.juneau.config.event.ConfigEventListener#onConfigChange(ConfigEvents) onConfigChange(ConfigEvents)}

The {@link org.apache.juneau.config.event.ConfigEvent} class provides access to all the information about the updated entry:

- {@link org.apache.juneau.config.event.ConfigEvent}
  - {@link org.apache.juneau.config.event.ConfigEvent#getType() getType()}
  - {@link org.apache.juneau.config.event.ConfigEvent#getSection() getSection()}
  - {@link org.apache.juneau.config.event.ConfigEvent#getKey() getKey()}
  - {@link org.apache.juneau.config.event.ConfigEvent#getValue() getValue()}
  - {@link org.apache.juneau.config.event.ConfigEvent#getModifiers() getModifiers()}
  - {@link org.apache.juneau.config.event.ConfigEvent#getComment() getComment()}
  - {@link org.apache.juneau.config.event.ConfigEvent#getPreLines() getPreLines}

The listener method is triggered:

- After {@link org.apache.juneau.config.Config#commit()} is called.
- When the file changes on the file system.

In both cases, the listener is triggered after the changes have been committed.

final Config c = Config.create("MyConfig.cfg").build(); // Add a listener for changes to MySection/key1 c.addListener( new ConfigEventListener() { @Override public void onConfigChange(ConfigEvents) { for (ConfigEvent event : events) { if (event.getType() == SET_ENTRY) { String section = event.getSection(); String key = event.getKey(); if (section.equals("MySection") && key.equals("key1")) { // Get the new value from the event. String newVal = event.getValue(); // Or get the new value from the config (since the change has already been committed). newVal = c.getString("MySection/key1"); } } } } } )

### 5.10 - Serializing

The following methods are used for serializing Config objects back into INI files:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#writeTo(Writer) writeTo(Writer)}
  - {@link org.apache.juneau.config.Config#toString() toString()}

Both methods are thread safe.

The Config class implements the {@link org.apache.juneau.Writable} which means it can be returned as-is by REST methods to be serialized as INI text.

### 5.11 - Imports 8.1.0-updated

Configurations can import values from other configurations using the following syntax:

# Import values from configuration 'ParentConfig' <ParentConfig> # Our normal section [Section1] ...

A configuration can contain zero or more imports anywhere in the file. However, for clarity, imports should normally be placed in the default section of the configuration file. The resolved configuration is retrieved from the configuration store used for the child configuration.

Configuration imports can be nested arbitrarily deep.

##### Example:

# MyConfig contents <ParentConfig1>

# ParentConfig1 contents <ParentConfig2>

# ParentConfig2 contents [Foo] bar = baz

// Java code Config c = ConfigBuilder.create("MyConfig").build(); String foo = c.getString("Foo/bar"); // == "baz"

Values can be overridden by child configurations.

##### Example:

# MyConfig contents <ParentConfig1> [Foo] bar = baz

# ParentConfig1 contents <ParentConfig2> [Foo] bar = qux

# ParentConfig2 contents [Foo] bar = quux

Config c = ConfigBuilder.create("MyConfig").build(); String foo = c.getString("Foo/bar"); // == "baz"

Changes made to imported configurations are automatically reflected in the child configuration and partake in the listener API as if the entries were part of the child configuration. Only non-overridden values trigger listener events. For example, if an imported configuration defines a value for "Foo/bar" and the child configuration does not, modifications to "Foo/bar" value in the parent configuration will trigger a listener event in the child config. However, if the child configuration does also specify a value for "Foo/bar", a change to the parent "Foo/bar" will NOT trigger a listener event because the value ends up not being changed from the perspective of the child configuration.

Values can be overwritten in child configurations, but the values will only be set in that configuration and not the imported configuration.

Dynamically adding an import will cause change events to be generated for imported values.

# MyConfig contents starting empty

# ParentConfig contents [Foo] bar = baz

// Create our configuration. Config c = ConfigBuilder.create("MyConfig").build(); // Create a listener that sets a flag if "Foo/bar" is set. final boolean[] triggered = new boolean[1]; ConfigEventListener l = new ConfigEventListener() { public void onConfigChange(ConfigEvents events) { triggered[0] = events.isKeyModified("Foo", "bar")); } }; c.addListener(l); // Dynamically add an import to ParentConfig in the default section. c.setImport("", "ParentConfig"); c.commit(); // The new import statement should have triggered a config changes for imported values. assertTrue(triggered[0]);

Dynamically removing an import has the same effect as removing keys and generates REMOVE_ENTRY events.

Note that when dynamically adding or removing imports, overridden keys in the child config will be filtered from the change events.

### 5.12 - Config Stores

Configuration files are stored in entities called Stores.

The methods that need to be implemented on a store are:

- {@link org.apache.juneau.config.store.ConfigStore}
  - {@link org.apache.juneau.config.store.ConfigStore#read(String) read(String)} - Read a config file.
  - {@link org.apache.juneau.config.store.ConfigStore#write(String,String,String) write(String,String,String)} - Write a config file.
  - {@link org.apache.juneau.config.store.ConfigStore#update(String,String) update(String,String)} - Update the contents of a config file.

Read is self-explanatory:

public String read(String name) { // Return the contents of the specified configuration. }

Write is slightly trickier:

public String write(String name, String oldContents, String newContents) { // If the old contents match the current stored contents, the new contents will get stored, // and the method returns null indicating success. // If the old contents DO NOT match the current stored contents (i.e. it was modified in some way), // the new contents are NOT stored, and the method returns the current stored contents. // If the old contents are null, then just always write the new contents. }

The update method is called whenever the stored file gets modified externally:

public String update(String name, String newContents) { // Do something with the updated contents. }

Two configuration stores are provided by default:

- {@link org.apache.juneau.config.store.ConfigFileStore} - File-system storage.
- {@link org.apache.juneau.config.store.ConfigMemoryStore} - In-memory storage.

The store is defined on the Config object via the following setting:

- {@link org.apache.juneau.config.Config#CONFIG_store}

##### Example:

// Create a config with in-memory storage. Config c = Config.create("MyConfig.cfg").store(ConfigMemoryStore.DEFAULT).build();

The default store used is {@link org.apache.juneau.config.store.ConfigFileStore#DEFAULT} which defines the execution directory as the file system directory to store and retrieve files.

#### 5.12.1 - ConfigMemoryStore

The {@link org.apache.juneau.config.store.ConfigMemoryStore} class is simply an in-memory storage location for configuration files. There is no hard persistence and is used primarily for testing purposes.

However, the implementation provides a good idea on how stores work (especially the write method):

public class ConfigMemoryStore extends ConfigStore { // Some methods ommitted. private final ConcurrentHashMap<String,String> cache = new ConcurrentHashMap<>(); @Override /* ConfigStore */ public synchronized String read(String name) { return emptyIfNull(cache.get(name)); } @Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); // Success! return null; } @Override /* ConfigStore */ public synchronized ConfigMemoryStore update(String name, String newContents) { cache.put(name, newContents); super.update(name, newContents); // Trigger any listeners. return this; } }

#### 5.12.2 - ConfigFileStore

The {@link org.apache.juneau.config.store.ConfigFileStore} is the typical store used for configuration files. It provides the following configurable settings:

- {@link org.apache.juneau.config.store.ConfigFileStore}
  - {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_charset FILESTORE_charset}
  - {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_directory FILESTORE_directory}
  - {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_updateOnWrite FILESTORE_updateOnWrite}
  - {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_useWatcher FILESTORE_useWatcher}
  - {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_watcherSensitivity FILESTORE_watcherSensitivity}

##### Example:

// Create a config store with a watcher thread and high sensitivity. ConfigFileStore fs = ConfigFileStore.create().directory("configs").useWatcher().watcherSensitivity(HIGH).build(); // Create a config using the store defined above. Config c = Config.create("MyConfig.cfg").store(fs).build();

#### 5.12.3 - Custom ConfigStores

The ConfigStore API has been written to allow easy development of custom configuration storage classes.

The example below shows a starting point for an implementation based on polling a relational database. Completing it is left as an exercise:

##### Example Store Class:

public class ConfigSqlStore extends ConfigStore { // Configurable properties static final String CONFIGSQLSTORE_jdbcUrl = "ConfigSqlStore.jdbcUrl.s", CONFIGSQLSTORE_tableName = "ConfigSqlStore.tableName.s", CONFIGSQLSTORE_nameColumn = "ConfigSqlStore.nameColumn.s", CONFIGSQLSTORE_valueColumn = "ConfigSqlStore.valueColumn.s", CONFIGSQLSTORE_pollInterval = "ConfigSqlStore.pollInterval.i"; // Instance fields private final String jdbcUrl; private final String tableName, nameColumn, valueColumn; private final Timer watcher; private final ConcurrentHashMap<String,String> cache = new ConcurrentHashMap<>(); // Constructor called from builder. protected ConfigSqlStore(PropertyStore ps) { super(ps); this.jdbcUrl = getStringProperty(CONFIGSQLSTORE_jdbcUrl, "jdbc:derby:mydb"); this.tableName = getStringProperty(CONFIGSQLSTORE_tableName); this.nameColumn = getStringProperty(CONFIGSQLSTORE_nameColumn); this.valueColumn = getStringProperty(CONFIGSQLSTORE_valueColumn); int pollInterval = getStringProperty(CONFIGSQLSTORE_pollInterval, 600); // Time in seconds. TimerTask timerTask = new TimerTask() { @Override public void run() { ConfigSqlStore.this.poll(); } }; this.watcher = new Timer("MyTimer"); watcher.scheduleAtFixedRate(timerTask, 0, pollInterval * 1000); } private synchronized void poll() { // Loop through all our entries and find the latest values. for (Map.Entry<String,String> e : cache.entrySet()) { String name = e.getKey(); String cacheContents = e.getValue(); String newContents = getDatabaseValue(name); // Change detected! if (! cacheContents.equals(newContents)) update(name, newContents); } } // Reads the value from the database. protected String getDatabaseValue(String name) { // Implement me! } @Override /* ConfigStore */ public synchronized String read(String name) { String contents = cache.get(name); if (contents == null) { contents = getDatabaseValue(name); update(name, contents); } return contents; } @Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); // Success! return null; } @Override /* ConfigStore */ public synchronized ConfigSqlStore update(String name, String newContents) { cache.put(name, newContents); super.update(name, newContents); // Trigger any listeners. return this; } @Override /* Closeable */ public synchronized void close() { if (watcher != null) watcher.cancel(); } }

The purpose of the builder class is to simply set values in the {@link org.apache.juneau.PropertyStore} that's passed to the ConfigStore:

##### Example Builder Class:

public class ConfigSqlStoreBuilder extends ConfigStoreBuilder { public ConfigSqlStoreBuilder() { super(); } public ConfigSqlStoreBuilder(PropertyStore ps) { super(ps); } public ConfigSqlStoreBuilder jdbcUrl(String value) { super.set(CONFIGSQLSTORE_jdbcUrl, value); return this; } public ConfigSqlStoreBuilder tableName(String value) { super.set(CONFIGSQLSTORE_tableName, value); return this; } public ConfigSqlStoreBuilder nameColumn(String value) { super.set(CONFIGSQLSTORE_nameColumn, value); return this; } public ConfigSqlStoreBuilder valueColumn(String value) { super.set(CONFIGSQLSTORE_valueColumn, value); return this; } public ConfigSqlStoreBuilder pollInterval(int value) { super.set(CONFIGSQLSTORE_pollInterval, value); return this; } @Override /* ContextBuilder */ public ConfigFileStore build() { return new ConfigFileStore(getPropertyStore()); } }

#### 5.12.4 - ConfigStore Listeners

The ConfigStore class has the following listener methods:

- {@link org.apache.juneau.config.store.ConfigStore}
  - {@link org.apache.juneau.config.store.ConfigStore#register(String,ConfigStoreListener) register(String,ConfigStoreListener)} - Register a listener on the specified config name.
  - {@link org.apache.juneau.config.store.ConfigStore#unregister(String,ConfigStoreListener) unregister(String,ConfigStoreListener)} - Unregister a listener on the specified config name.

Note that this is a different listener than {@link org.apache.juneau.config.event.ConfigEventListener}. In this case, we're just listening for changed files:

- {@link org.apache.juneau.config.store.ConfigStoreListener}
  - {@link org.apache.juneau.config.store.ConfigStoreListener#onChange(String)} - Called when file changes. New contents are passed in.

This listener is used by the Config class to listen for changes on the file system so that it can be updated in real-time.

### 5.13 - Read-only Configs

The following settings can be used to create read-only Config objects:

- {@link org.apache.juneau.config.Config#CONFIG_readOnly}

##### Example:

// Create a read-only config Config c = Config.create("MyConfig.cfg").readOnly().build();

This causes all methods that make modifications to throw {@link java.lang.UnsupportedOperationException}.

### 5.14 - Closing Configs

In general, it's good practice to close Config if you're only creating them temporarily so that their listeners get unregistered from the underlying storage APIs.

##### Example:

// Create a transient config. Config c = Config.create("MyConfig.cfg").build(); // Do stuff with it. // Then close the config to unregister the listeners. c.close();

### 5.15 - System Default Config 8.0.0-new, 8.1.0-updated

Each JVM has a system default config. This is a configuration file that serves as the default configuration for the system. It's accessed using the following static methods:

- {@link org.apache.juneau.config.Config}
  - {@link org.apache.juneau.config.Config#getSystemDefault() getSystemDefault()}
  - {@link org.apache.juneau.config.Config#setSystemDefault(Config) setSystemDefault(Config)}

If you do not specify a system default config, one will be automatically searched for. The search is done in the following order:

1. If the system property "juneau.configFile" is set, we search for this file in first the home directory and then the classpath.
2. In the home directory:
   1. <jar-name>.cfg
   2. Any file that end with .cfg. First one matched alphabetically is used.
3. In the context classpath root package (i.e. inside the jar itself):
   1. <jar-name>.cfg
   2. juneau.cfg
   3. default.cfg
   4. application.cfg
   5. app.cfg
   6. settings.cfg
   7. application.properties

Later in the section on REST resources, we describe how to associate configurations with REST resources using the {@link org.apache.juneau.rest.annotation.Rest#config() @Rest(config)} annotation. The system default configuration can be referenced with the keyword SYSTEM_DEFAULT like so:

// Always use system default. @Rest(config="SYSTEM_DEFAULT") // Use system property if set or the system default if not. @Rest(config="$S{juneau.configFile,SYSTEM_DEFAULT}")

By default, all properties in the system default configuration are automatically set as system properties. This can be disabled by setting the system property "juneau.disableAutoSystemProps" to "true".

## 6 - juneau-rest-server

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-rest-server</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-rest-server-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.rest.server_{@property juneauVersion}.jar

The juneau-rest-server library allows you to quickly wrap POJOs and expose them as full-fledged REST resources served up in a servlet container using a bare-minimum amount of code. The primary goal for Juneau was to make it as easy as possible to implement easy-to-read and self-documenting REST resources using very little code.

One of the biggest advantages of the Juneau REST framework over similar architectures is that it hides the serialization layer from the developer. The developer can work entirely with POJOs and let the Juneau framework handle all the serialization and parsing work. The developer need never know what the Accept or Content-Type or Accept-Encoding (etc...) header values are because those details are all handled by the framework.

The API builds upon the existing JEE Servlet API. The root class, {@link org.apache.juneau.rest.RestServlet} is nothing but a specialized {@link javax.servlet.http.HttpServlet}, and the {@link org.apache.juneau.rest.RestRequest} and {@link org.apache.juneau.rest.RestResponse} classes are nothing more than specialized {@link javax.servlet.http.HttpServletRequest} and {@link javax.servlet.http.HttpServletResponse} objects. This allows maximum flexibility for the developer since you can let Juneau handle operations such as serialization, or you can revert to the existing servlet APIs to do low-level processing of requests yourself. It also means you need nothing more than a Servlet container such as Jetty to use the REST framework.

##### Features

- Serializes POJOs to JSON, XML, HTML, URL-Encoding, UON, RDF/XML, N-Triple, Turtle, N3, SOAP, or Java-serialized-object based on value of Accept header.
  No user code is required to handle these types.
  - Extensible design that provides ability to override existing content type handlers, or add the ability to handle other kinds of content types.
- Parses content of POST/PUT request bodies to POJOs.
- Automatic built-in ability to serialize POJO metadata to JSON+SCHEMA, XML+SCHEMA, or HTML+SCHEMA based on Accept header.
- Automatic negotiation of output Writer based on HTTP headers.
  - Automatic handling of Accept-Charset header for all character sets supported by the JVM.
  - Automatic handling of Accept-Encoding header with registered encoders.
- Automatic error handling.
  - Automatic 401 errors (Unauthorized) on failed guards.
  - Automatic 404 errors (Not Found) on unmatched path patterns.
  - Automatic 405 errors (Method Not Implemented) on unimplemented methods.
  - Automatic 406 errors (Not Acceptable) when no matching serializer was found to handle the Accept header.
  - Automatic 412 errors (Precondition Failed) when all matchers failed to match.
  - Automatic 415 errors (Unsupported Media Type) when no matching parser was found was found to handle the Content-Type header.
  - Automatic 500 errors on uncaught exceptions.
- Support for parsing all HTTP parts (headers, query, formData, path variables) using Swagger formatting rules and validations.
  Not limited to simple POJOs, but rather you can represent arbitrarily-complex POJOs in any HTTP part using UON notation.
- Auto-created Swagger JSON and Swagger UI available through OPTIONS requests of resources.
- Various useful debugging features that make debugging using a browser extremely simple...
  - Ability to pass HTTP header values as URL GET parameters (e.g. &Accept=text/xml).
  - Ability to pass HTTP content on PUT/POST requests as a URL GET parameter (e.g. &content=(foo=bar)).
  - Ability to simulate non-GET requests using a &method GET parameter (e.g. &method=POST).
  - Ability to force "text/plain" on response using GET parameter &plainText=true.
- Ability to implement overloaded HTTP methods through the use of the &method attribute (e.g. &method=FOO).
- Ability to match URL patterns (e.g. /foo/{fooId}/bar/{barId}) against URLs (e.g. /foo/123/bar/456/bing).
- Ability to associate guards at the resource or method levels through annotations.
  Typically useful for security, but can be used for a variety of purposes.
- Ability to associate converters at the resource or method levels through annotations.
  Typically useful for performing conversions on input and output, such as for supporting older input and output formats.

Many of the examples in this document are pulled directly from juneau-examples-rest.

### 6.1 - Hello World Example

A REST resource is simply a Java class annotated with {@link org.apache.juneau.rest.annotation.Rest}. The most common case is a class that extends {@link org.apache.juneau.rest.RestServlet}, which itself is simply an extension of {@link javax.servlet.http.HttpServlet} which allows it to be deployed as a servlet.

In this example, we define a resource called HelloWorldResource. This example is located in the juneau-examples-rest project. It's assumed the reader is familiar with defining servlets in web applications.

Like any servlet, we could define our resource in the web.xml file of the web application like so...

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.3"> <servlet> <servlet-name>HelloWorldResource</servlet-name> <servlet-class>com.foo.sample.HelloWorldResource</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorldResource</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

Our servlet code is shown below:

// Sample REST resource that prints out a simple "Hello world!" message. @Rest( path="/helloWorld", title="Hello World", description="An example of the simplest-possible resource", htmldoc=@HtmlDoc( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This page shows a resource that simply response with a 'Hello world!' message</p>", " <p>The POJO serialized is a simple String.</p>", "</div>" } ) ) public class HelloWorldResource extends BasicRestServlet { @RestMethod(name=GET, path="/*", summary="Responds with \"Hello world!\"") public String sayHello() { return "Hello world!"; } }

This is what it looks like in a browser:

http://localhost:10000/helloWorld

It doesn't much simpler than that. In this case, we're simply returning a string that will be converted to any of the supported languages (e.g. JSON, XML, HTML, ...). However, we could have returned any POJO consisting of beans, maps, collections, etc...

The {@link org.apache.juneau.rest.BasicRestServlet} class that we're using here is a subclass of {@link org.apache.juneau.rest.RestServlet} that provides default support for a variety of content types. Implementers can choose to use this class, or create their own subclass of {@link org.apache.juneau.rest.RestServlet} with their own specialized serializers and parsers.

### 6.2 - Class Hierarchy 8.1.0-updated

The class hierarchy for the REST servlet class is shown below:

- {@link javax.servlet.http.HttpServlet javax.servlet.http.HttpServlet}
  - {@link org.apache.juneau.rest.RestServlet org.apache.juneau.rest.RestServlet}
    Contains all the main logic.
    - {@link org.apache.juneau.rest.BasicRestServlet org.apache.juneau.rest.BasicRestServlet}
      Provides a default set of serializers, parsers, options page, stylesheet, and other common settings.
      - {@link org.apache.juneau.rest.BasicRestServletGroup org.apache.juneau.rest.BasicRestServletGroup}
        A default implementation for "router" pages.

For top-level resources, you'll typically extend from one of the classes above.

For child resources, you can either extend from one of the classes above, or extend from one of the following that provides identical support but does not extent from HttpServlet:

- {@link org.apache.juneau.rest.BasicRestConfig}
  - {@link org.apache.juneau.rest.BasicRest org.apache.juneau.rest.BasicRest}
    Provides a default set of serializers, parsers, options page, stylesheet, and other common settings.
    - {@link org.apache.juneau.rest.BasicRestGroup org.apache.juneau.rest.BasicRestGroup}
      A default implementation for "router" pages.

One reason to use the latter classes as your base classes is when you're implementing REST resources as @Bean-annotated Spring Beans and you don't want them to be automatically registered as top-level servlets.

The servlets with RDF support require Jena on the classpath. All other serializers and parsers do not have any external library dependencies. For this reason, we have separate servlets for supporting RDF so that you don't need Jena if you don't need to support RDF.

Everything is configured through the following classes which you will see a lot:

- {@link org.apache.juneau.rest.RestContext} - Each resource class instance has one copy that holds all of its configuration.
- {@link org.apache.juneau.rest.RestContextBuilder} - Builder for the class above.

### 6.3 - Instantiation

REST resources are deployed in one of two ways:

- Deployed in a J2EE container as a servlet.
- Deployed as a child of another REST resource.

When deployed in a J2EE container, you MUST extend from one of the servlet classes.

When deployed as a child of another resource, you MAY extend from one of the servlet classes but it's not necessary. The only requirement is that the class be annotated with @Rest and have one of the following constructors:

- public T()
- public T(RestContextBuilder)

And even that requirement is relaxed if you implement your own REST resource resolver (described later).

For example:

// Top level resource is deployed like any other servlet and must subclass from RestServlet. @Rest( path="/top", children={ ChildResource.class // Accessed via URI "/top/child" } ) public class TopLevelResource extends BasicRestServlet {...}

// Child resources can inherit from RestServlet but it's not a requirement. @Rest( path="/child" ) public class ChildResource extends WhateverYouWant {...}

That's all there is to it! There's no code scanning, module configuration/initialization classes, or anything complex like that. It's just a servlet.

#### 6.3.1 - RestServlet

The {@link org.apache.juneau.rest.RestServlet} class is the entry point for your REST resources. It extends directly from HttpServlet and is deployed like any other servlet.

When the servlet init() method is called, it triggers the code to find and process the @Rest annotations on that class and all child classes. These get constructed into a {@link org.apache.juneau.rest.RestContext} object that holds all the configuration information about your resource in a read-only object.

Most developers are not going to be using the RestServlet class itself, and instead will extend from one of the preconfigured default servlets such as {@link org.apache.juneau.rest.BasicRestServlet}. The RestServlet class by itself is not configured with any serializers and parsers, and therefore not very useful on it's own. However, the class does provide a couple of convenience methods to be aware of:

- {@link org.apache.juneau.rest.RestServlet} extends HttpServlet
  - {@link org.apache.juneau.rest.RestServlet#init(ServletConfig) init(ServletConfig)} - Can override to provide custom initialization.
  - {@link org.apache.juneau.rest.RestServlet#service(HttpServletRequest,HttpServletResponse) service(HttpServletRequest,HttpServletResponse)} - Can override to provide custom request handling.
  - {@link org.apache.juneau.rest.RestServlet#destroy() destroy()} - Can override to provide custom cleanup.
  - {@link org.apache.juneau.rest.RestServlet#getContext() getContext()} - Returns all aspects of the configuration of your resource pulled from all annotations on the class/parent-classes and methods.
  - {@link org.apache.juneau.rest.RestServlet#log(Level,String,Object...) log(Level,String,Object...)} - Convenience logging method.
  - {@link org.apache.juneau.rest.RestServlet#log(Level,Throwable,String,Object...) log(Level,Throwable,String,Object...)} - Convenience logging method.

#### 6.3.2 - BasicRestServlet 8.1.0-updated

The {@link org.apache.juneau.rest.BasicRestServlet} class is a subclass of {@link org.apache.juneau.rest.RestServlet} preconfigured with the following:

- A default set of serializers and parsers (pretty much all of them except for the RDF ones).
- Some basic HTML boilerplate for the HTML representation of your POJOs.
- Support for auto-generated Swagger documentation through OPTIONS page requests.
- Configuration of default CSS stylesheets.
- Default contents for HTML views.

The contents of the class is shown below. You should notice that very little code is being used and everything is configurable through annotations:

@Rest( // Allow OPTIONS requests to be simulated using ?method=OPTIONS query parameter. allowedMethodParams="OPTIONS", // HTML-page specific settings. htmldoc=@HtmlDoc( // Basic page navigation links. navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" } ) ) public abstract class BasicRestServlet extends RestServlet implements BasicRestConfig { /** * [OPTIONS /*] - Show resource options. * * @param req The HTTP request. * @return A bean containing the contents for the OPTIONS page. */ @RestMethod(name=OPTIONS, path="/*", summary="Swagger documentation", description="Swagger documentation for this resource.", htmldoc=@HtmlDoc( // Override the nav links for the swagger page. navlinks={ "back: servlet:/", "json: servlet:/?method=OPTIONS&Accept=text/json&plainText=true" }, // Never show aside contents of page inherited from class. aside="NONE" ) ) @JsonSchemaConfig( // Add descriptions to the following types when not specified: addDescriptionsTo="bean,collection,array,map,enum", // Add x-example to the following types: addExamplesTo="bean,collection,array,map", // Don't generate schema information on the Swagger bean itself or HTML beans. ignoreTypes="Swagger,org.apache.juneau.dto.html5.*", // Use $ref references for bean definitions to reduce duplication in Swagger. useBeanDefs="true" ) @BeanConfig( // When parsing generated beans, ignore unknown properties that may only exist as getters and not setters. ignoreUnknownBeanProperties="true", // POJO swaps to apply to all serializers/parsers on this method. pojoSwaps={ // Use the SwaggerUI swap when rendering Swagger beans. // This is a per-media-type swap that only applies to text/html requests. SwaggerUI.class } ) public Swagger getOptions(RestRequest req) { // Localized Swagger for this resource is available through the RestRequest object. return req.getSwagger(); } }

Additional annotations are pulled in from the {@link org.apache.juneau.rest.BasicRestConfig} interface which simply exists to define a common set of annotations. Notice that it has no code at all.

@Rest( // Default serializers for all Java methods in the class. serializers={ HtmlDocSerializer.class, HtmlStrippedDocSerializer.class, HtmlSchemaDocSerializer.class, JsonSerializer.class, JsonSerializer.Simple.class, JsonSchemaSerializer.class, XmlDocSerializer.class, XmlSchemaDocSerializer.class, UonSerializer.class, UrlEncodingSerializer.class, MsgPackSerializer.class, SoapXmlSerializer.class, PlainTextSerializer.class }, // Default parsers for all Java methods in the class. parsers={ JsonParser.class, JsonParser.Simple.class, XmlParser.class, HtmlParser.class, UonParser.class, UrlEncodingParser.class, MsgPackParser.class, PlainTextParser.class }, // HTML-page specific settings htmldoc=@HtmlDoc( // Default page header contents. header={ "<h1>$R{resourceTitle}</h1>", // Use @Rest(title) "<h2>$R{methodSummary,resourceDescription}</h2>", // Use either @RestMethod(summary) or @Rest(description) "$C{REST/header}" // Extra header HTML defined in external config file. }, // Basic page navigation links. navlinks={ "up: request:/.." }, // Default stylesheet to use for the page. // Can be overridden from external config file. // Default is DevOps look-and-feel (aka Depression look-and-feel). stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}", // Default contents to add to the <head> section of the HTML page. // Use it to add a favicon link to the page. head={ "<link rel='icon' href='$U{$C{REST/favicon}}'/>" }, // No default page footer contents. // Can be overridden from external config file. footer="$C{REST/footer}", // By default, table cell contents should not wrap. nowrap="true" ), // Optional external configuration file. config="$S{juneau.configFile}", // These are static files that are served up by the servlet under the specified sub-paths. // For example, "/servletPath/htdocs/javadoc.css" resolves to the file "[servlet-package]/htdocs/javadoc.css" // By default, we define static files through the external configuration file. staticFiles={"$C{REST/staticFiles}"} ) @SerializerConfig( // Enable automatic resolution of URI objects to root-relative values. uriResolution="ROOT_RELATIVE" ) public interface BasicRestConfig {}

Your top-level resource will simply extend from this class, as shown in the Hello World example from a couple sections back.

It's important to notice that the @Rest annotation is inheritable and overridable from parent class and interfaces. They'll all get merged into a single set of annotation values for the resource class.

Not shown but equally important is that all of the annotations shown have programmatic equivalents via the {@link org.apache.juneau.rest.RestContextBuilder} class which can be manipulated during servlet initialization. (As a general rule, all annotations throughout Juneau have programmatic equivalents.)

There's a lot going on in this class. But not to worry, the details will be described later.

#### 6.3.3 - BasicRest 8.1.0-new

The {@link org.apache.juneau.rest.BasicRest} class is identical to the {@link org.apache.juneau.rest.BasicRestServlet} class except that it does not extend from HttpServlet. It defines the exact same set of serializers, parsers, etc., but it cannot be deployed as a top-level servlet. It can however be used for child resources registered via the {@link org.apache.juneau.rest.annotation.Rest#children() @Rest(children)} annotation.

The code for this class is virtually identical to {@link org.apache.juneau.rest.BasicRestServlet} but lacks a parent class:

@Rest( // Allow OPTIONS requests to be simulated using ?method=OPTIONS query parameter. allowedMethodParams="OPTIONS", // HTML-page specific settings. htmldoc=@HtmlDoc( // Basic page navigation links. navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" } ) ) public abstract class BasicRest implements BasicRestConfig { /** * [OPTIONS /*] - Show resource options. * * @param req The HTTP request. * @return A bean containing the contents for the OPTIONS page. */ @RestMethod(name=OPTIONS, path="/*", summary="Swagger documentation", description="Swagger documentation for this resource.", htmldoc=@HtmlDoc( // Override the nav links for the swagger page. navlinks={ "back: servlet:/", "json: servlet:/?method=OPTIONS&Accept=text/json&plainText=true" }, // Never show aside contents of page inherited from class. aside="NONE" ) ) @JsonSchemaConfig( // Add descriptions to the following types when not specified: addDescriptionsTo="bean,collection,array,map,enum", // Add x-example to the following types: addExamplesTo="bean,collection,array,map", // Don't generate schema information on the Swagger bean itself or HTML beans. ignoreTypes="Swagger,org.apache.juneau.dto.html5.*", // Use $ref references for bean definitions to reduce duplication in Swagger. useBeanDefs="true" ) @BeanConfig( // When parsing generated beans, ignore unknown properties that may only exist as getters and not setters. ignoreUnknownBeanProperties="true", // POJO swaps to apply to all serializers/parsers on this method. pojoSwaps={ // Use the SwaggerUI swap when rendering Swagger beans. // This is a per-media-type swap that only applies to text/html requests. SwaggerUI.class } ) public Swagger getOptions(RestRequest req) { // Localized Swagger for this resource is available through the RestRequest object. return req.getSwagger(); } }

#### 6.3.4 - Children

Child Resources are REST servlets or objects that are linked to parent resources through the {@link org.apache.juneau.rest.annotation.Rest#children() @Rest(children)} annotation.

##### Example:

/** Parent Resource */ @Rest( path="/parent", children={FooResource.class} ) public MyResource extends BasicRestServlet {...}

/** Child Resource */ @Rest( path="/foo" // Path relative to parent resource. ) public FooResource {...} // Note that we don't need to extend from RestServlet.

The path of the child resource gets appended to the path of the parent resource. So in the example above, the child resource is accessed through the URL /parent/foo.

A HUGE advantage of using child resources is that they do not need to be declared in the JEE web.xml file. Initialization of and access to the child resources occurs through the parent resource. Children can be nested arbitrary deep to create complex REST interfaces with a single top-level REST servlet.

- {@link org.apache.juneau.rest.RestContext#REST_children}

#### 6.3.5 - BasicRestServletGroup 8.1.0-updated

The {@link org.apache.juneau.rest.BasicRestServletGroup} class provides a default "router" page for child resources when a parent resource is nothing more than a grouping of child resources.

The RootResources class in the Samples project is an example of a router page:

/** * Sample REST resource showing how to implement a "router" resource page. */ @Rest( path="/", title="Root resources", description="Example of a router resource page.", children={ HelloWorldResource.class, PetStoreResource.class, DtoExamples.class, ConfigResource.class, LogsResource.class, ShutdownResource.class } ) public class RootResources extends BasicRestServletGroup { // NO CODE!!! }

When you bring up this resource in a browser, you see the following that provides a list of navigable links to your child resources:

http://localhost:10000

The {@link org.apache.juneau.rest.BasicRestServletGroup} class is nothing more than a subclass of {@link org.apache.juneau.rest.BasicRestServlet} with a getChildren() method mapped to the servlet root path. The method returns a POJO with is just a linked-list of beans with name/description properties.

// The entire contents of the BasicRestServletGroup class. public class BasicRestServletGroup extends BasicRestServlet { @RestMethod(name=GET, path="/", description="Child resources") public ChildResourceDescriptions getChildren(RestRequest req) { return new ChildResourceDescriptions(this, req); } }

#### 6.3.6 - BasicRestGroup 8.1.0-new

The {@link org.apache.juneau.rest.BasicRestGroup} class is identical to the {@link org.apache.juneau.rest.BasicRestServletGroup} class except that it does not extend from HttpServlet. It defines the exact same set of serializers, parsers, etc., but it cannot be deployed as a top-level servlet. It can however be used for child resources registered via the {@link org.apache.juneau.rest.annotation.Rest#children() @Rest(children)} annotation.

// The entire contents of the BasicRestGroup class. public class BasicRestGroup extends BasicRest { @RestMethod(name=GET, path="/", description="Child resources") public ChildResourceDescriptions getChildren(RestRequest req) { return new ChildResourceDescriptions(this, req); } }

#### 6.3.7 - Resource Resolvers

By default, you can add the {@link org.apache.juneau.rest.annotation.Rest @Rest} to any class as long as it has one of the following constructors:

- public T()
- public T(RestContextBuilder)

The latter constructor can be used to get access to the {@link org.apache.juneau.rest.RestContextBuilder} object to make any configurations to the resource before it's initialized.

Resource object resolution is controlled through the following API:

- {@link org.apache.juneau.rest.RestResourceResolver}
  - {@link org.apache.juneau.rest.BasicRestResourceResolver}

This API can be extended to provide your own custom resource resolution. Later topics discuss how to use this API to instantiate resources using Spring.

- {@link org.apache.juneau.rest.RestContext#REST_resourceResolver}

#### 6.3.8 - Lifecycle Hooks

Lifecycle hooks allow you to hook into lifecycle events of the servlet/resource creation and REST calls.

For example, if you want to add an initialization method to your resource:

@Rest(...) public class MyResource { // Our database. private Map<Integer,Object> myDatabase; @RestHook(INIT) public void initMyDatabase(RestContextBuilder builder) throws Exception { myDatabase = new LinkedHashMap<>(); } }

Or if you want to intercept REST calls:

@Rest(...) public class MyResource { // Add a request attribute to all incoming requests. @RestHook(PRE_CALL) public void onPreCall(RestRequest req) { req.setAttribute("foo", "bar"); } }

The hook events can be broken down into two categories:

- Resource lifecycle events:
  - {@link org.apache.juneau.rest.annotation.HookEvent#INIT INIT} - Right before initialization.
  - {@link org.apache.juneau.rest.annotation.HookEvent#POST_INIT POST_INIT} - Right after initialization.
  - {@link org.apache.juneau.rest.annotation.HookEvent#POST_INIT_CHILD_FIRST POST_INIT_CHILD_FIRST} - Right after initialization, but run child methods first.
  - {@link org.apache.juneau.rest.annotation.HookEvent#DESTROY DESTROY} - Right before servlet destroy.
- REST call lifecycle events:
  - {@link org.apache.juneau.rest.annotation.HookEvent#START_CALL START_CALL} - At the beginning of a REST call.
  - {@link org.apache.juneau.rest.annotation.HookEvent#PRE_CALL PRE_CALL} - Right before the @RestMethod method is invoked.
  - {@link org.apache.juneau.rest.annotation.HookEvent#POST_CALL POST_CALL} - Right after the @RestMethod method is invoked.
  - {@link org.apache.juneau.rest.annotation.HookEvent#END_CALL END_CALL} - At the end of the REST call after the response has been flushed.

- {@link org.apache.juneau.rest.annotation.RestHook}

### 6.4 - @Rest 8.1.2-updated

The {@link org.apache.juneau.rest.annotation.Rest @Rest} annotation is the primary way of defining and configuring REST resource classes. The functionality of the class itself is covered in detail in the topics below.

#### 6.4.1 - Annotation Inheritance

The {@link org.apache.juneau.rest.annotation.Rest @Rest} annotation can also be used on parents and interfaces of resource classes. When multiple annotations are defined at different levels, the annotation values are combined.

This is a particularly useful feature because it allows you to define your own configured parent resource classes that can be extended by all your child resources so that they all share common settings.

##### Inheritance rules

Annotation | Inheritence Rules
--- | ---
{@link org.apache.juneau.rest.annotation.Rest#guards() guards()} | Guards on child are combined with those on parent class. Guards are executed child-to-parent in the order they appear in the annotation. Guards on methods are executed before those on classes.
{@link org.apache.juneau.rest.annotation.Rest#converters() converters()} | Converters on child are combined with those on parent class. Converters are executed child-to-parent in the order they appear in the annotation. Converters on methods are executed before those on classes.
{@link org.apache.juneau.rest.annotation.Rest#properties() properties()} | Properties on child are combined with those on parent class. Properties are applied parent-to-child in the order they appear in the annotation. Properties on methods take precedence over those on classes.
{@link org.apache.juneau.rest.annotation.Rest#serializers() serializers()} | Serializers on child override those on parent class. {@link org.apache.juneau.rest.Inherit} class can be used to inherit and augment values from parent. {@link org.apache.juneau.rest.None} class can be used to suppress inheriting from parent. Serializers on methods take precedence over those on classes.
{@link org.apache.juneau.rest.annotation.Rest#parsers() parsers()} | Parsers on child override those on parent class. {@link org.apache.juneau.rest.Inherit} class can be used to inherit and augment values from parent. {@link org.apache.juneau.rest.None} class can be used to suppress inheriting from parent. Parsers on methods take precedence over those on classes.
{@link org.apache.juneau.rest.annotation.Rest#responseHandlers() responseHandlers()} | Response handlers on child are combined with those on parent class.
{@link org.apache.juneau.rest.annotation.Rest#encoders() encoders()} | Encoders on child are combined with those on parent class.
{@link org.apache.juneau.rest.annotation.Rest#reqHeaders() reqHeaders()} | Headers on child are combined with those on parent class. Headers are applied parent-to-child in the order they appear in the annotation. Headers on methods take precedence over those on classes.
{@link org.apache.juneau.rest.annotation.Rest#resHeaders() resHeaders()} | Headers on child are combined with those on parent class. Headers are applied parent-to-child in the order they appear in the annotation.
{@link org.apache.juneau.rest.annotation.Rest#children() children()} | Children on child are combined with those on parent class. Children are list parent-to-child in the order they appear in the annotation.
{@link org.apache.juneau.rest.annotation.Rest#path() path()} | Path is searched for in child-to-parent order.
{@link org.apache.juneau.rest.annotation.Rest#title() title()} | Label is searched for in child-to-parent order.
{@link org.apache.juneau.rest.annotation.Rest#description() description()} | Description is searched for in child-to-parent order.
{@link org.apache.juneau.rest.annotation.Rest#config() config()} | Config file is searched for in child-to-parent order.
{@link org.apache.juneau.rest.annotation.Rest#staticFiles() staticFiles()} | Static files on child are combined with those on parent class. Static files are are executed child-to-parent in the order they appear in the annotation.

#### 6.4.2 - @Rest(path)8.1.0-new, 8.1.2-updated

The {@link org.apache.juneau.rest.annotation.RestResource#path() @RestResource(path)} annotation is used in the following situations:

- On child resources (resource classes attached to parents via the {@link org.apache.juneau.rest.annotation.RestResource#children() @RestResource(children)} annotation) to identify the subpath used to access the child resource relative to the parent.
- On top-level {@link org.apache.juneau.rest.RestServlet} classes deployed as Spring beans when {@link org.apache.juneau.rest.springboot.JuneauRestInitializer} is being used.

##### On child resources

The typical usage is to define a path to a child resource relative to the parent resource.

##### Example:

@RestResource( children={ ChildResource.class } ) public class TopLevelResource extends BasicRestServlet {...}

@RestResource( path="/child", children={ GrandchildResource.class } ) public class ChildResource {...}

@RestResource( path="/grandchild" ) public class GrandchildResource { @RestMethod( path="/" ) public String sayHello() { return "Hello!"; } }

In the example above, assuming the TopLevelResource servlet is deployed to path /myContext/myServlet, then the sayHello method is accessible through the URI /myContext/myServlet/child/grandchild.

Note that in this scenario, the path attribute is not defined on the top-level resource. Specifying the path on the top-level resource has no effect, but can be used for readability purposes.

##### On top-level resources deployed as Spring beans

The path can also be used on top-level resources deployed as Spring beans when used with the {@link org.apache.juneau.rest.springboot.JuneauRestInitializer} Spring Boot initializer class:

##### Example:

@SpringBootApplication @Controller public class App { // Our entry-point method. public static void main(String[] args) { new SpringApplicationBuilder(App.class) .initializers(new JuneauRestInitializer(App.class)) .run(args); } // Our top-level servlet. @Bean @JuneauRestRoot public MyResource getMyResource() { return new MyResource(); } }

@RestResource( path="/myResource" ) public class MyResource extends BasicRestServlet {...}

In this case, the servlet will get registered using the path defined on the resource class.

##### Path variables

The path can contain variables that get resolved to {@link org.apache.juneau.http.annotation.Path @Path} parameters or access through the {@link org.apache.juneau.rest.RestRequest#getPathMatch()} method.

##### Example:

@RestResource( path="/myResource/{foo}/{bar}" ) public class MyResource extends BasicRestServlet { @RestMethod( path="/{baz}" ) public void String doX(@Path String foo, @Path int bar, @Path MyPojo baz) { ... } }

Variables can be used on either top-level or child resources and can be defined on multiple levels.

All variables in the path must be specified or else the target will not resolve and a 404 will result.

When variables are used on a path of a top-level resource deployed as a Spring bean in a Spring Boot application, the first part of the URL must be a literal which will be used as the servlet path of the registered servlet.

### 6.5 - RestContext

The {@link org.apache.juneau.rest.RestContext} object is the workhorse class for all of the configuration of a single REST resource class. It's by-far the most important class in the REST API.

Every class annotated with @Rest ends up with an instance of this object. The object itself is read-only and unchangeable. It is populated through the following:

- {@link org.apache.juneau.rest.annotation.Rest} - Settings copied from the annotation during servlet initialization.
- {@link org.apache.juneau.rest.RestContextBuilder} - Builder used during servlet initialization.

The annotation should be self-explanatory at this point. The builder allows you to perform all of the same configuration as the annotation programmatically.

The {@link org.apache.juneau.rest.RestContextBuilder} class extends {@link org.apache.juneau.BeanContextBuilder} allowing you to programmatically set any properties defined on that builder class. It also implements {@link javax.servlet.ServletConfig}

To access this object, simply pass it in as a constructor argument or in an INIT hook:

// Option #1 - Pass in through constructor. public MyResource(RestContextBuilder builder) { builder .pojoSwaps(TemporalCalendarSwap.Rfc1123DateTime.class) .set(PARSER_debug, true); } // Option #2 - Use an INIT hook. @RestHook(INIT) public void init(RestContextBuilder builder) throws Exception { builder .pojoSwaps(TemporalCalendarSwap.Rfc1123DateTime.class) .set(PARSER_debug, true); }

Warning: The builder class is huge. Through it, you can configure bean/serializer/parser settings, define config files, children, resource finders, info providers, etc...

### 6.6 - @RestMethod

REST Java methods are identified on REST servlets using the {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} annotation. The annotation allows the framework to identify the available REST methods through reflection.

##### Example:

@RestMethod(name=GET, path="/") public String sayHello() { return "Hello world!"; }

When the name and/or path values are not specified, their values are inferred from the Java method name.

The HTTP method can be inferred from the Java method by starting the method name with any of the following:

- get
- put
- post
- delete
- options
- head
- trace
- patch

If path is not defined, it's inferred from the Java method name (minus the prefix above).

##### Examples:

// Method="GET", path="/foo" @RestMethod public String getFoo() {...}

// Method="DELETE", path="/foo" @RestMethod public String deleteFoo() {...}

// Method="GET", path="/foo" // "GET" is default @RestMethod public String foo() {...}

// Method="GET", path="/" @RestMethod(path="/") public String foo() {...}

// Method="GET", path="/" @RestMethod public String get() {...}

// Method="POST", path="/" @RestMethod public String post() {...}

If name and path are both specified, the Java method name can be anything.

#### 6.6.1 - Java Method Parameters

Java methods can contain any of the following parameters in any order:

- Parameters based on class types:
  - Request/response objects:
    - {@link org.apache.juneau.rest.RestRequest} - The request object.
    - {@link javax.servlet.http.HttpServletRequest} - The superclass of RestRequest.
    - {@link org.apache.juneau.rest.RestResponse} - The response object.
    - {@link javax.servlet.http.HttpServletResponse} - The superclass of RestResponse.
  - Parsed request header values:
    - {@link org.apache.juneau.http.Accept}
    - {@link org.apache.juneau.http.AcceptCharset}
    - {@link org.apache.juneau.http.AcceptEncoding}
    - {@link org.apache.juneau.http.AcceptLanguage}
    - {@link org.apache.juneau.http.Authorization}
    - {@link org.apache.juneau.http.CacheControl}
    - {@link org.apache.juneau.http.Connection}
    - {@link org.apache.juneau.http.ContentLength}
    - {@link org.apache.juneau.http.ContentType}
    - {@link org.apache.juneau.http.Date}
    - {@link org.apache.juneau.http.Expect}
    - {@link org.apache.juneau.http.From}
    - {@link org.apache.juneau.http.Host}
    - {@link org.apache.juneau.http.IfMatch}
    - {@link org.apache.juneau.http.IfModifiedSince}
    - {@link org.apache.juneau.http.IfNoneMatch}
    - {@link org.apache.juneau.http.IfRange}
    - {@link org.apache.juneau.http.IfUnmodifiedSince}
    - {@link org.apache.juneau.http.MaxForwards}
    - {@link org.apache.juneau.http.Pragma}
    - {@link org.apache.juneau.http.ProxyAuthorization}
    - {@link org.apache.juneau.http.Range}
    - {@link org.apache.juneau.http.Referer}
    - {@link org.apache.juneau.http.TE}
    - {@link org.apache.juneau.http.UserAgent}
    - {@link org.apache.juneau.http.Upgrade}
    - {@link org.apache.juneau.http.Via}
    - {@link org.apache.juneau.http.Warning}
    - {@link java.util.TimeZone}
  - Direct streams on request/response:
    - {@link java.io.InputStream}
    - {@link javax.servlet.ServletInputStream}
    - {@link java.io.Reader}
    - {@link java.io.OutputStream}
    - {@link javax.servlet.ServletOutputStream}
    - {@link java.io.Writer}
  - Localization:
    - {@link java.util.ResourceBundle} - Client-localized resource bundle.
    - {@link org.apache.juneau.utils.MessageBundle} - A resource bundle with additional features.
    - {@link java.util.Locale} - Client locale.
  - Request APIs:
    - {@link org.apache.juneau.rest.RequestHeaders} - API for accessing request headers.
    - {@link org.apache.juneau.rest.RequestQuery} - API for accessing request query parameters.
    - {@link org.apache.juneau.rest.RequestFormData} - API for accessing request form data.
    - {@link org.apache.juneau.rest.RequestPath} - API for accessing path variables.
    - {@link org.apache.juneau.rest.RequestBody} - API for accessing request body.
  - Other:
    - {@link org.apache.juneau.http.HttpMethod} - The method name matched (when using @RestMethod(name="*"))
    - {@link org.apache.juneau.rest.RestLogger} - Logger with additional features.
    - {@link org.apache.juneau.rest.RestContext} - The resource read-only context.
    - {@link org.apache.juneau.parser.Parser} - The parser matching the request content type.
    - {@link org.apache.juneau.parser.ReaderParser} - The reader parser matching the request content type.
    - {@link org.apache.juneau.parser.InputStreamParser} - The input stream parser matching the request content type.
    - {@link org.apache.juneau.dto.swagger.Swagger} - The auto-generated Swagger doc.
    - {@link org.apache.juneau.config.Config} - The external config for the resource.
    - {@link org.apache.juneau.rest.RequestProperties} - API for modifying request-time configuration properties.
- Annotated parameters:
  - {@link org.apache.juneau.http.annotation.Path} - Variables in matched URL path patterns.
  - {@link org.apache.juneau.http.annotation.FormData} - Multipart form post parameter values.
  - {@link org.apache.juneau.http.annotation.HasFormData} - Denotes whether the form data parameter exists.
  - {@link org.apache.juneau.http.annotation.Query} - Query parameters. Using this prevents the HTTP body from being processed as a URL-Encoded form post.
  - {@link org.apache.juneau.http.annotation.HasQuery} - Denotes whether the query parameter exists.
  - {@link org.apache.juneau.http.annotation.Header} - A header value.
  - {@link org.apache.juneau.http.annotation.Body} - The HTTP content parsed as a POJO.
  - {@link org.apache.juneau.rest.annotation.Method} - The HTTP method name.
  - {@link org.apache.juneau.http.annotation.Request} - HTTP request parts available through a proxy bean interface.
  - {@link org.apache.juneau.http.annotation.Response} - HTTP response parts available through a POJO.
  - {@link org.apache.juneau.http.annotation.ResponseHeader} - HTTP response header.
  - {@link org.apache.juneau.http.annotation.ResponseStatus} - HTTP response status code.

##### Example:

@RestMethod(name=GET, path="/example1/{a1}/{a2}/{a3}/*") public String doGetExample1( RestRequest req, RestResponse res, @Method String method, @Path("a1") String a1, @Path("a2") int a2, @Path("a3") UUID a3, @Query("p1") int p1, @Query("p2") String p2, @Query("p3") UUID p3, @HasQuery("p3") boolean hasP3, @Path("/*") String remainder, @Header("Accept-Language") String lang, @Header("Accept") String accept, @Header("DNT") int doNotTrack, RequestProperties properties, ResourceBundle nls ) { // Do something with all of those }

- All annotations have programmatic equivalents on the {@link org.apache.juneau.rest.RestRequest} class.

- {@link org.apache.juneau.rest.RestContext#REST_paramResolvers} - For configuring custom parameter types.

#### 6.6.2 - RestRequest

The {@link org.apache.juneau.rest.RestRequest} object is an extension of the HttpServletRequest class with various built-in convenience methods for use in building REST interfaces. It can be accessed by passing it as a parameter on your REST Java method:

@RestMethod(...) public Object myMethod(RestRequest req) {...}

There are many useful methods on this object, but the main ones are shown below:

- {@link org.apache.juneau.rest.RestRequest} extends HttpServletRequest
  - {@link org.apache.juneau.rest.RestRequest#getHeaders() getHeaders()} - HTTP request headers.
  - {@link org.apache.juneau.rest.RestRequest#getQuery() getQuery()} - Query parameters.
  - {@link org.apache.juneau.rest.RestRequest#getFormData() getFormData()} - Form-data parameters.
  - {@link org.apache.juneau.rest.RestRequest#getBody() getBody()} - HTTP request body.
  - {@link org.apache.juneau.rest.RestRequest#getPathMatch() getPathMatch()} - Path match variables.
  - {@link org.apache.juneau.rest.RestRequest#getLogger() getLogger()} - Logging.
  - {@link org.apache.juneau.rest.RestRequest#getInfoProvider() getInfoProvider()} - Swagger documentation provider.
  - {@link org.apache.juneau.rest.RestRequest#getSwagger() getSwagger()} - Generated Swagger information.
  - {@link org.apache.juneau.rest.RestRequest#getConfig() getConfig()} - External configuration API.
  - {@link org.apache.juneau.rest.RestRequest#getVarResolverSession() getVarResolverSession()} - String variable resolver.
  - {@link org.apache.juneau.rest.RestRequest#getMessageBundle() getMessageBundle()} - Localized messages.
  - {@link org.apache.juneau.rest.RestRequest#getProperties() getProperties()} - Configuration properties.
  - {@link org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String,boolean,MediaType,boolean) getClasspathReaderResource(String,boolean,MediaType,boolean)} - Various methods for retrieving static files from classpath.

#### 6.6.3 - RestResponse

The {@link org.apache.juneau.rest.RestResponse} object is an extension of the HttpServletResponse class with various built-in convenience methods for use in building REST interfaces. It can be accessed by passing it as a parameter on your REST Java method:

@RestMethod(...) public Object myMethod(RestResponse req) {...}

Some important methods on this class are:

- {@link org.apache.juneau.rest.RestResponse} extends HttpServletResponse
  - {@link org.apache.juneau.rest.RestResponse#setOutput(Object) setOutput(Object)} - Set response output programmatically.
  - {@link org.apache.juneau.rest.RestResponse#getHtmlDocBuilder() getHtmlDocBuilder()} - Set HTTP page contents programmatically.
  - {@link org.apache.juneau.rest.RestResponse#getDirectWriter(String) getDirectWriter(String)} - Direct access to underlying response writer.

#### 6.6.4 - RequestBody

The {@link org.apache.juneau.rest.RequestBody} object is the API for accessing the body of an HTTP request. It can be accessed by passing it as a parameter on your REST Java method:

@RestMethod(...) public Object myMethod(RequestBody body) {...}

##### Example:

@RestMethod(...) public void doPost(RequestBody body) { // Convert body to a linked list of Person objects. List<Person> l = body.asType(LinkedList.class, Person.class); ... }

Some important methods on this class are:

- {@link org.apache.juneau.rest.RequestBody}
  - {@link org.apache.juneau.rest.RequestBody#getReader() getReader()} - Get body as a Reader.
  - {@link org.apache.juneau.rest.RequestBody#getInputStream() getInputStream()} - Get body as an InputStream.
  - {@link org.apache.juneau.rest.RequestBody#asType(Class) asType(Class)} - Get body converted to a POJO.
  - {@link org.apache.juneau.rest.RequestBody#asType(Type,Type...) asType(Type,Type...)} - Get body converted to a map or collection of POJOs.
  - {@link org.apache.juneau.rest.RequestBody#asString() asString()} - Get body as a simple string.
  - {@link org.apache.juneau.rest.RequestBody#asHex() asHex()} - Get body as a hex-encoded string.
  - {@link org.apache.juneau.rest.RequestBody#asSpacedHex() asSpacedHex()} - Get body as spaced-hex-encoded string.

- {@link org.apache.juneau.http.annotation.Body}

#### 6.6.5 - RequestHeaders

The {@link org.apache.juneau.rest.RequestHeaders} object is the API for accessing the headers of an HTTP request. It can be accessed by passing it as a parameter on your REST Java method:

@RestMethod(...) public Object myMethod(RequestHeaders headers) {...}

##### Example:

@RestMethod(...) public Object myMethod(RequestHeaders headers) { // Add a default value. headers.addDefault("ETag", DEFAULT_UUID); // Get a header value as a POJO. UUID etag = headers.get("ETag", UUID.class); // Get a standard header. CacheControl = headers.getCacheControl(); }

Some important methods on this class are:

- {@link org.apache.juneau.rest.RequestHeaders} extends TreeMap<String,String[]>
  - {@link org.apache.juneau.rest.RequestHeaders#get(String,Class) get(String,Class)} - Get header value converted to a POJO.
  - {@link org.apache.juneau.rest.RequestHeaders#get(String,Type,Type...) get(String,Type,Type)} - Get header value converted to a map or collection of POJOs.
  - {@link org.apache.juneau.rest.RequestHeaders#getString(String,String) getString(String,String)} - Get header value as a simple string.
  - {@link org.apache.juneau.rest.RequestHeaders#getInt(String,int) getInt(String,int)} - Get header value as an integer.
  - {@link org.apache.juneau.rest.RequestHeaders#getBoolean(String,boolean) getBoolean(String,boolean)} - Get header value as a boolean.
  - {@link org.apache.juneau.rest.RequestHeaders#addDefault(String,Object) addDefault(String,Object)} - Programmatically set a default value for a header.

- {@link org.apache.juneau.http.annotation.Header}

#### 6.6.6 - RequestAttributes 8.1.0-new

The {@link org.apache.juneau.rest.RequestAttributes} object is the API for accessing the standard servlet attributes on an HTTP request (i.e. {@link javax.servlet.ServletRequest#getAttribute(String)}. It wraps the request attributes in a {@link java.util.Map} interface and provides several convenience methods.

The RequestAttributes object extends from {@link org.apache.juneau.ObjectMap} so all the convenience methods defined on that API are also available when working with request attributes:

@RestMethod(...) public Object myMethod(RequestAttributes attributes) {...}

##### Example:

@RestMethod(...) public Object myMethod(RequestAttributes attributes) { // Add a default value. attributes.putIfNotExists("Foo", 123); // Get an attribute value as a POJO. UUID etag = attributes.get("ETag", UUID.class); }

Modifications made to request attributes through the RequestAttributes bean are automatically reflected in the underlying servlet request attributes making it possible to mix the usage of both APIs.

#### 6.6.7 - RequestQuery

The {@link org.apache.juneau.rest.RequestQuery} object is the API for accessing the GET query parameters of an HTTP request. It can be accessed by passing it as a parameter on your REST Java method:

@RestMethod(...) public Object myMethod(RequestQuery query) {...}

##### Example:

@RestMethod(...) public Object myMethod(RequestQuery query) { // Get query parameters converted to various types. int p1 = query.get("p1", 0, int.class); String p2 = query.get("p2", String.class); UUID p3 = query.get("p3", UUID.class); }

An important distinction between the behavior of this object and HttpServletRequest.getParameter(String) is that the former will NOT load the body of the request on FORM POSTS and will only look at parameters found in the query string. This can be useful in cases where you're mixing GET parameters and FORM POSTS and you don't want to inadvertently read the body of the request to get a query parameter.

Some important methods on this class are:

- {@link org.apache.juneau.rest.RequestQuery} extends LinkedHashMap<String,String[]>
  - {@link org.apache.juneau.rest.RequestQuery#get(String,Class) get(String,Class)} - Get query parameter value converted to a POJO.
  - {@link org.apache.juneau.rest.RequestQuery#get(String,Type,Type...) get(String,Type,Type)} - Get query parameter value converted to a map or collection of POJOs.
  - {@link org.apache.juneau.rest.RequestQuery#getString(String,String) getString(String,String)} - Get query parameter value as a simple string.
  - {@link org.apache.juneau.rest.RequestQuery#getInt(String,int) getInt(String,int)} - Get query parameter value as an integer.
  - {@link org.apache.juneau.rest.RequestQuery#getBoolean(String,boolean) getBoolean(String,boolean)} - Get query parameter value as a boolean.
  - {@link org.apache.juneau.rest.RequestQuery#addDefault(String,Object) addDefault(String,Object)} - Programmatically set a default value for a query parameter.
  - {@link org.apache.juneau.rest.RequestQuery#getSearchArgs() getSearchArgs()} - Returns query parameter search arguments.

- {@link org.apache.juneau.http.annotation.Query}
- {@link org.apache.juneau.http.annotation.HasQuery}

#### 6.6.8 - RequestFormData

The {@link org.apache.juneau.rest.RequestFormData} object is the API for accessing the HTTP request body as form data. It can be accessed by passing it as a parameter on your REST Java method:

@RestMethod(...) public Object myMethod(RequestFormData query) {...}

##### Example:

@RestMethod(...) public Object myMethod(RequestFormData formData) { // Get query parameters converted to various types. int p1 = formData.get("p1", 0, int.class); String p2 = formData.get("p2", String.class); UUID p3 = formData.get("p3", UUID.class); }

Note that this object does NOT take GET parameters into account and only returns values found in the body of the request.

Some important methods on this class are:

- {@link org.apache.juneau.rest.RequestFormData} extends LinkedHashMap<String,String[]>
  - {@link org.apache.juneau.rest.RequestFormData#get(String,Class) get(String,Class)} - Get form-data parameter values converted to a POJO.
  - {@link org.apache.juneau.rest.RequestFormData#get(String,Type,Type...) get(String,Type,Type)} - Get form-data parameter value converted to a map or collection of POJOs.
  - {@link org.apache.juneau.rest.RequestFormData#getString(String,String) getString(String,String)} - Get form-data parameter value as a simple string.
  - {@link org.apache.juneau.rest.RequestFormData#getInt(String,int) getInt(String,int)} - Get form-data parameter value as an integer.
  - {@link org.apache.juneau.rest.RequestFormData#getBoolean(String,boolean) getBoolean(String,boolean)} - Get form-data parameter value as a boolean.
  - {@link org.apache.juneau.rest.RequestFormData#addDefault(String,Object) addDefault(String,Object)} - Programmatically set a default value for a form-data parameter.

- {@link org.apache.juneau.http.annotation.FormData}
- {@link org.apache.juneau.http.annotation.HasFormData}

#### 6.6.9 - @RestMethod(path)

The {@link org.apache.juneau.rest.annotation.RestMethod#path() @RestMethod(path)} annotation allows you to define URL path patterns to match against. These patterns can contain variables of the form "{xxx}" that can be passed in directly to the Java methods as extra parameters.

In the following example, 3 separate GET request handlers are defined with different path patterns. Note how the variables are passed in as additional arguments on the method, and how those arguments are automatically converted to the specified class type...

// Default method @RestMethod(name=GET, path="/*") public void doGetDefault() { ... } // Method with path pattern @RestMethod(name=GET, path="/xxx") public void doGetNoArgs(...) { ... } // Method with path pattern with arguments @RestMethod(name=GET, path="/xxx/{foo}/{bar}/{baz}/{bing}") public void doGetWithArgs(@Path("foo") String foo, @Path("bar") int bar, @Path("baz") MyEnum baz, @Path("bing") UUID bing) { ... }

By default, path patterns are matched using a best-match heuristic. When overlaps occur, URLs are matched from most-specific to most-general order:

// Try first @RestMethod(name=GET, path="/foo/bar") public void method1() { ... } // Try second @RestMethod(name=GET, path="/foo/{bar}") public void method2(...) { ... } // Try third @RestMethod(name=GET, path="/foo/*") public void method3(...) { ... } // Try last @RestMethod(name=GET, path="/*") public void method4(...) { ... }

The match heuristic behavior can be overridden by the {@link org.apache.juneau.rest.annotation.RestMethod#priority() @RestMethod(priority)} annotation property. However, in practice this is almost never needed.

Paths that end with "/*" will do a prefix match on the incoming URL. Any remainder after the match can be accessed through {@link org.apache.juneau.rest.RequestPath#getRemainder()} or parameters with the @Path("/*") annotation. On the other hand, paths that don't end with "/*" (e.g. "/" or "/foo") will require an exact URL match, and if any remainder exists, a 404 (not found) error will be thrown.

The following example shows the distinction.

@RestMethod(name=GET, path="/*") public void doGet(@Path("/*") String remainder) { // URL path pattern can have remainder accessible through req.getRemainder(). } @RestMethod(name=PUT, path="/") public void doPut() { // URL path pattern must match exactly and will cause a 404 error if a remainder exists. }

Annotations are provided for easy access to URL parameters with automatic conversion to any {@doc PojoCategories parsable} type. For example, the following example can process the URL "/urlWithParams?foo=foo&bar=[1,2,3]&baz=067e6162-3b6f-4ae2-a171-2470b63dff00"...

// Example GET request with access to query parameters @RestMethod(name=GET, path="/urlWithParams") public String doGetWithParams(@Query("foo") String foo, @Query("bar") int bar, @Query("baz") UUID baz) throws Exception { return "GET /urlWithParams?foo="+foo+"&bar="+bar+"&baz="+baz; }

- {@link org.apache.juneau.rest.RestContext#REST_path}
- {@link org.apache.juneau.http.annotation.Path}
- {@link org.apache.juneau.rest.RequestPath}

#### 6.6.10 - RequestPathMatch

The {@link org.apache.juneau.rest.RequestPath} object is the API for accessing the matched variables and remainder on the URL path.

@RestMethod(...) public Object myMethod(RequestPathMatch path) {...}

##### Example:

@RestMethod(..., path="/{foo}/{bar}/{baz}/*") public void doGet(RequestPathMatch path) { // Example URL: /123/qux/true/quux int foo = pm.getInt("foo"); // =123 String bar = pm.getString("bar"); // =qux boolean baz = pm.getBoolean("baz"); // =true String remainder = pm.getRemainder(); // =quux }

Some important methods on this class are:

- {@link org.apache.juneau.rest.RequestPath} extends TreeMap<String,String>
  - {@link org.apache.juneau.rest.RequestPath#get(String,Class) get(String,Class)} - Get path match variable converted to a POJO.
  - {@link org.apache.juneau.rest.RequestPath#get(String,Type,Type...) get(String,Type,Type)} - Get path match variable converted to a map or collection of POJOs.
  - {@link org.apache.juneau.rest.RequestPath#getString(String) getString(String)} - Get patch match variable as a simple string.
  - {@link org.apache.juneau.rest.RequestPath#getInt(String) getInt(String)} - Get path match variable as an integer.
  - {@link org.apache.juneau.rest.RequestPath#getBoolean(String) getBoolean(String)} - Get path match variable as a boolean.
  - {@link org.apache.juneau.rest.RequestPath#getRemainder() getRemainder()} - Get the path match remainder.

- {@link org.apache.juneau.http.annotation.Path}

#### 6.6.11 - Method Return Types

The return type can be any serializable POJO as defined in {@doc PojoCategories}. It can also be void if the method is not sending any output (e.g. a request redirect) or is setting the output using the {@link org.apache.juneau.rest.RestResponse#setOutput(Object)} method.

##### Example:

@RestMethod(name=GET) public String doGet() { return "Hello World!"; }

Out-of-the-box, besides POJOs, the following return types are handled as special cases:

- {@link java.io.InputStream}
  The contents are simply piped to the output stream returned by {@link org.apache.juneau.rest.RestResponse#getNegotiatedOutputStream()}.
  Note that you should call {@link org.apache.juneau.rest.RestResponse#setContentType(String)} to set the Content-Type header if you use this object type.
- {@link java.io.Reader}
  The contents are simply piped to the output stream returned by {@link org.apache.juneau.rest.RestResponse#getNegotiatedWriter()}.
  Note that you should call {@link org.apache.juneau.rest.RestResponse#setContentType(String)} to set the Content-Type header if you use this object type.
- {@link org.apache.juneau.Streamable}
  Interface that identifies that an object can be serialized directly to an output stream.
- {@link org.apache.juneau.Writable}
  Interface that identifies that an object can be serialized directly to a writer.
- {@link org.apache.juneau.utils.ZipFileList}
  Special interface for sending zip files as responses.

This is controlled through the following extensible API:

- {@link org.apache.juneau.rest.ResponseHandler}
  - {@link org.apache.juneau.rest.reshandlers.DefaultHandler}
  - {@link org.apache.juneau.rest.reshandlers.InputStreamHandler}
  - {@link org.apache.juneau.rest.reshandlers.ReaderHandler}

REST Java methods can generate output in any of the following ways:

- By returning a serializable POJO, or any of the following:
  {@link java.io.Reader}, {@link java.io.InputStream}, {@link org.apache.juneau.Streamable}, {@link org.apache.juneau.Writable}
- By calling {@link org.apache.juneau.rest.RestResponse#setOutput(Object)} with any of the types above.
- By accessing the {@link java.io.Writer} directly by calling {@link org.apache.juneau.rest.RestResponse#getNegotiatedWriter()} and writing the output yourself.

##### Example:

// Equivalent method 1 @RestMethod(name=GET, path="/example1/{personId}") public Person doGet1(@Path("personId") UUID personId) { Person p = getPersonById(personId); return p; } // Equivalent method 2 @RestMethod(name=GET, path="/example2/{personId}") public void doGet2(RestResponse res, @Path("personId") UUID personId) { Person p = getPersonById(personId); res.setOutput(p); } // (Sorta) Equivalent method 3 // (Ignores any converters or method-level properties) @RestMethod(name=GET, path="/example3/{personId}") public void doGet3(RestRequest req, RestResponse res, @Path("personId") UUID personId) { Person p = getPersonById(personId); String accept = req.getHeader("Accept", "text/json"); WriterSerializer s = res.getSerializerGroup().getWriterSerializer(accept); res.setContentType(s.getResponseContentType()); s.serialize(p, res.getNegotiatedWriter()); }

- {@link org.apache.juneau.rest.RestContext#REST_responseHandlers} - For configuring custom response handlers.

#### 6.6.12 - ReaderResource

The {@link org.apache.juneau.http.ReaderResource} class is a convenience object for defining thread-safe reusable character-based responses. In essence, it's a container for character data with optional response headers and support for resolving SVL variables.

The class is annotated with {@link org.apache.juneau.http.annotation.Response @Response} which allows it to be returned as responses by REST methods.

##### Example:

@RestMethod public Object sayHello(RestRequest req) { // Return a reader resource loaded from a file with support for request-time SVL variables. return ReaderResource.create() .contents(new File("helloWorld.txt")) .varResolver(req.getVarResolver()) .header("Cache-Control", "no-cache") .mediaType(TEXT_PLAIN) .build(); }

#### 6.6.13 - StreamResource

The {@link org.apache.juneau.http.StreamResource} class is the binary equivalent to the {@link org.apache.juneau.http.ReaderResource} object. In essence, it's a container for binary data with optional response headers.

The class is annotated with {@link org.apache.juneau.http.annotation.Response @Response} which allows it to be returned as responses by REST methods.

##### Example:

@RestMethod(...) public Object showPicture(RestRequest req) { // Return a stream resource loaded from a file. return StreamResource.create() .contents(new File("mypicture.png")) .header("Cache-Control", "no-cache") .mediaType(IMAGE_PNG) .build(); }

#### 6.6.14 - @RestMethod(matchers)

{@link org.apache.juneau.rest.RestMatcher RestMatchers} are used to allow multiple Java methods to be tied to the same HTTP method and path, but differentiated by some request attribute such as a specific header value.

##### Example:

// GET method that gets invoked for administrators @RestMethod(name=GET, path="/*", matchers=IsAdminMatcher.class) public Object doGetForAdmin() { ... } // GET method that gets invoked for everyone else @RestMethod(name=GET, path="/*") public Object doGetForEveryoneElse() { ... }

The interface for matchers is simple:

public class IsAdminMatcher extends RestMatcher { @Override /* RestMatcher */ public boolean matches(RestRequest req) { return req.isUserInRole("ADMINS_GROUP"); } }

- If no methods are found with a matching matcher, a 412 Precondition Failed status is returned.
- If multiple matchers are specified on the same method, ONLY ONE matcher needs to match for the method to be invoked.
- Note that you CANNOT define identical paths on different methods UNLESS you use matchers.
  That includes paths that are only different in variable names (e.g. "/foo/{bar}" and "/foo/{baz}").
  If you try to do so, a ServletException will be thrown on startup.
- Methods with matchers take precedence over methods without.
  Otherwise, methods are attempted in the order they appear in the class.

- {@link org.apache.juneau.rest.annotation.RestMethod#matchers RestMethod(matchers)}
- {@link org.apache.juneau.rest.matchers.MultipartFormDataMatcher}
- {@link org.apache.juneau.rest.matchers.UrlEncodedFormMatcher}

#### 6.6.15 - Predefined Responses

Predefined response beans are provided for all standard HTTP responses. These can be used as-is or extended to provide customized HTTP responses.

##### Examples:

@RestMethod(name="POST", path="/pets") public Ok addPet(@Body Pet pet) { addPet(Pet); // Predefined "200 OK" response bean. return new Ok(); // Could also use Ok.OK instance }

@RestMethod(name="POST", path="/pets") public SeeOther addPet(@Body Pet pet) { addPet(Pet); // Predefined "302 See Other" response bean with redirect to /pets. return new SeeOther("servlet:/pets"); }

- {@link org.apache.juneau.http.response}
  - {@link org.apache.juneau.http.response.Accepted}
  - {@link org.apache.juneau.http.response.AlreadyReported}
  - {@link org.apache.juneau.http.response.Continue}
  - {@link org.apache.juneau.http.response.Created}
  - {@link org.apache.juneau.http.response.EarlyHints}
  - {@link org.apache.juneau.http.response.Found}
  - {@link org.apache.juneau.http.response.IMUsed}
  - {@link org.apache.juneau.http.response.MovedPermanently}
  - {@link org.apache.juneau.http.response.MultipleChoices}
  - {@link org.apache.juneau.http.response.MultiStatus}
  - {@link org.apache.juneau.http.response.NoContent}
  - {@link org.apache.juneau.http.response.NonAuthoritiveInformation}
  - {@link org.apache.juneau.http.response.NotModified}
  - {@link org.apache.juneau.http.response.Ok}
  - {@link org.apache.juneau.http.response.PartialContent}
  - {@link org.apache.juneau.http.response.PermanentRedirect}
  - {@link org.apache.juneau.http.response.Processing}
  - {@link org.apache.juneau.http.response.ResetContent}
  - {@link org.apache.juneau.http.response.SeeOther}
  - {@link org.apache.juneau.http.response.SwitchingProtocols}
  - {@link org.apache.juneau.http.response.TemporaryRedirect}
  - {@link org.apache.juneau.http.response.UseProxy}

These predefined response beans are an example of {@link org.apache.juneau.http.annotation.Response @Response}-annotated objects that are describe in detail later. Without going into details, this is how the {@link org.apache.juneau.http.response.SeeOther} is defined:

@Response( code=303 // Set automatically on response, description="See Other" // Used in generated Swagger ) public class SeeOther { private final String message; private final URI location; // Constructors omitted. // Used to populate Location response header. @ResponseHeader(name="Location") public URI getLocation() { return location; } // Used during serialization. @ResponseBody public String toString() { return message; } }

The {@link org.apache.juneau.rest.helper.SeeOtherRoot} class shows how these predefined beans can be extended.

@Response( description="Redirect to servlet root" // Override description in generated Swagger. ) public class SeeOtherServletRoot extends SeeOther { public SeeOtherServletRoot() { super(URI.create("servlet:/")); } }

Note that the runtime behavior of the following code is identical to the example above. However, the important distinction is that in the previous example, the 302 response would show in the generated Swagger (since we can see the response through reflection), whereas it will NOT show up in the following example (since all we see is an Object response).

@RestMethod(name="POST", path="/pets") public Object addPet(@Body Pet pet) { addPet(Pet); // Note the Object return type. return new SeeOther("servlet:/pets"); }

#### 6.6.16 - Predefined Exceptions

Exceptions are defined for all standardized HTTP responses. These can be used to trigger HTTP errors simply by throwing an exception.

These are identical in behavior to the Predefined Responses in the previous section, except these are meant to be thrown instead of returned.

##### Example:

@RestMethod(name="GET", path="/user/login") public Ok login( @FormData("username") String username, @FormData("password") String password, ) throws Unauthorized { if (! isOK(username, password)) throw new Unauthorized("You're not welcome!"); return Ok.OK; }

- {@link org.apache.juneau.http.exception}
  - {@link org.apache.juneau.http.exception.BadRequest}
  - {@link org.apache.juneau.http.exception.Conflict}
  - {@link org.apache.juneau.http.exception.ExpectationFailed}
  - {@link org.apache.juneau.http.exception.FailedDependency}
  - {@link org.apache.juneau.http.exception.Forbidden}
  - {@link org.apache.juneau.http.exception.Gone}
  - {@link org.apache.juneau.http.exception.HttpVersionNotSupported}
  - {@link org.apache.juneau.http.exception.InsufficientStorage}
  - {@link org.apache.juneau.http.exception.InternalServerError}
  - {@link org.apache.juneau.http.exception.LengthRequired}
  - {@link org.apache.juneau.http.exception.Locked}
  - {@link org.apache.juneau.http.exception.LoopDetected}
  - {@link org.apache.juneau.http.exception.MethodNotAllowed}
  - {@link org.apache.juneau.http.exception.MisdirectedRequest}
  - {@link org.apache.juneau.http.exception.NetworkAuthenticationRequired}
  - {@link org.apache.juneau.http.exception.NotAcceptable}
  - {@link org.apache.juneau.http.exception.NotExtended}
  - {@link org.apache.juneau.http.exception.NotFound}
  - {@link org.apache.juneau.http.exception.NotImplemented}
  - {@link org.apache.juneau.http.exception.PayloadTooLarge}
  - {@link org.apache.juneau.http.exception.PreconditionFailed}
  - {@link org.apache.juneau.http.exception.PreconditionRequired}
  - {@link org.apache.juneau.http.exception.RangeNotSatisfiable}
  - {@link org.apache.juneau.http.exception.RequestHeaderFieldsTooLarge}
  - {@link org.apache.juneau.http.exception.ServiceUnavailable}
  - {@link org.apache.juneau.http.exception.TooManyRequests}
  - {@link org.apache.juneau.http.exception.Unauthorized}
  - {@link org.apache.juneau.http.exception.UnavailableForLegalReasons}
  - {@link org.apache.juneau.http.exception.UnprocessableEntity}
  - {@link org.apache.juneau.http.exception.UnsupportedMediaType}
  - {@link org.apache.juneau.http.exception.UpgradeRequired}
  - {@link org.apache.juneau.http.exception.UriTooLong}
  - {@link org.apache.juneau.http.exception.VariantAlsoNegotiates}

These exception extend from {@link java.lang.RuntimeException}, so they can optionally be specified in the thrown declaration of the method. The important distinction is that when part of the thrown declaration, they show up in the generated Swagger documentation, whereas they don't if not. This behavior can be used to define what error conditions show in your Swagger doc.

#### 6.6.17 - Predefined Helper Beans

The {@link org.apache.juneau.rest.helper} package contains several predefined beans to help when constructing REST interfaces.

- {@link org.apache.juneau.rest.helper}
  - {@link org.apache.juneau.rest.helper.BeanDescription}
  - {@link org.apache.juneau.rest.helper.ChildResourceDescriptions}
  - {@link org.apache.juneau.rest.helper.ResourceDescription}
  - {@link org.apache.juneau.rest.helper.ResourceDescriptions}
  - {@link org.apache.juneau.rest.helper.SeeOtherRoot}

##### ResourceDescription, ResourceDescrptions

The {@link org.apache.juneau.rest.helper.ResourceDescription} class is a bean with name/description properties for labeling and linking to child resources. The following examples is pulled from the REST examples:

@Resource public class PredefinedLabelsResource { @RestMethod(name=GET, path="/") public ResourceDescription[] getChildMethods() { return new ResourceDescription[] { new ResourceDescription("beanDescription", "BeanDescription"), new ResourceDescription("htmlLinks", "HtmlLink") }; } }

It get rendered as a table of name/description columns with links to child methods:

The internals of the class show it simply has two bean properties with a link annotation defined on the name property:

public class ResourceDescription { // Renders as hyperlink when serialized as HTML. @Html(link="servlet:/{name}") public String getName() {...} public String getDescription() {...} }

{@link org.apache.juneau.rest.helper.ResourceDescriptions} is a convenience class for doing the same. The example above can also be written as follows (which you'll notice is more concise):

@Resource public class PredefinedLabelsResource { @RestMethod(name=GET, path="/") public ResourceDescriptions getChildMethods() { return new ResourceDescriptions() .append("beanDescription", "BeanDescription") .append("htmlLinks", "HtmlLink"); } }

##### @HtmlLink, LinkString

The {@link org.apache.juneau.html.annotation.HtmlLink @HtmlLink} annotation can also be useful for rendering custom hyperlinks:

@RestMethod public MyLink[] htmlLinks() { return new MyLink[] { new MyLink("apache", "http://apache.org"), new MyLink("juneau", "http://juneau.apache.org") }; }

@HtmlLink(nameProperty="name", hrefProperty="href") public class MyLink { // Simple bean properties. public String name, href; public MyLink(String name, String href) { this.name = name; this.href = href; } }

The {@link org.apache.juneau.dto.LinkString LinkString} bean is a predefined @HtmlLink bean provided to simplify specifying actions. The following is equivalent to above.

@RestMethod public LinkString[] htmlLinks() { return new LinkString[] { new LinkString("apache", "http://apache.org"), new LinkString("juneau", "http://juneau.apache.org") }; }

Both examples render the following consisting of a list of hyperlinks:

In all other languages, it gets serialized as a simple bean with two properties.

##### BeanDescription

The {@link org.apache.juneau.rest.helper.BeanDescription} class provides a simple view of a bean and it's properties.

@RestMethod(name=GET, path="/beanDescription") public BeanDescription getBeanDescription() { return new BeanDescription(Person.class); }

This example renders the following:

##### ChildResourceDescriptions

The {@link org.apache.juneau.rest.helper.ChildResourceDescriptions} is a convenience bean for generating a table of child resources.

The {@link org.apache.juneau.rest.BasicRestServletGroup} class uses this to generate router pages:

@Rest public abstract class BasicRestServletGroup extends BasicRestServlet { @RestMethod(name=GET, path="/", summary="Navigation page") public ChildResourceDescriptions getChildren(RestRequest req) throws Exception { return new ChildResourceDescriptions(req); } }

Note that all it requires is a {@link org.apache.juneau.rest.RestRequest} object and it will generate a router page using reflection against the resource class.

For example, the RootResources page in the REST examples renders the child resources attached to the root resource:

The RootResources page consists of the following and extends from the {@link org.apache.juneau.rest.BasicRestServletGroup} class:

@Rest( ... children={ HelloWorldResource.class, PetStoreResource.class, DtoExamples.class, PhotosResource.class, SqlQueryResource.class, ConfigResource.class, LogsResource.class, DebugResource.class, ShutdownResource.class } ) public class RootResources extends BasicRestServletJenaGroup {}

##### SeeOtherRoot

The {@link org.apache.juneau.rest.helper.SeeOtherRoot} class can be used to redirect to the root URI of a resource class.

@RestMethod(name="POST", path="/pets") public SeeOtherRoot addPet(@Body Pet pet) { addPet(Pet); // Redirects to the servlet root URL. return SeeOtherRoot.INSTANCE; }

The runtime behavior is the same as the following:

@RestMethod(name="POST", path="/pets") public SeeOther addPet(@Body Pet pet) { addPet(Pet); // Redirects to the servlet root URL. return new SeeOther(URI.create("servlet:/")); }

One distinction is that the former defines the description "Redirect to servlet root" in the generated Swagger documentation.

### 6.7 - restRPC 8.0.0-updated

The restRPC (RPC over REST) API allows the creation of client-side remote proxy interfaces for calling methods on server-side POJOs using entirely REST.

##### Remote Interfaces

The following example shows a remote interface:

@RemoteInterface // Annotation is optional public interface IAddressBook { void init() throws Exception; List<Person> getPeople(); List<Address> getAddresses(); int createPerson(CreatePerson cp) throws Exception; Person findPerson(int id); Address findAddress(int id); Person findPersonWithAddress(int id); Person removePerson(int id); }

The requirements for a remote interface method are:

- Must be public.
- Can be called anything.
- Can have any number of {@doc PojoCategories serializable and parsable} parameters.
- Can return a {@doc PojoCategories serializable and parsable} value.
- Can throw any Throwables.

Throwables with public no-arg or single-arg-string constructors are automatically recreated on the client side when thrown on the server side.

##### Client side

Remote Interface proxies are instantiated on the client side using one of the following methods:

- {@link org.apache.juneau.rest.client.RestClient}
  - {@link org.apache.juneau.rest.client.RestClient#getRrpcInterface(Class) getRrpcInterface(Class)}
  - {@link org.apache.juneau.rest.client.RestClient#getRrpcInterface(Class,Object) getRrpcInterface(Class,Object)}
  - {@link org.apache.juneau.rest.client.RestClient#getRrpcInterface(Class,Object,Serializer,Parser) getRrpcInterface(Class,Object,Serializer,Parser)}

Since we build upon the existing RestClient API, we inherit all of it's features. For example, convenience methods for setting POJO filters and properties to customize the behavior of the serializers and parsers, and the ability to provide your own customized Apache HttpClient for handling various scenarios involving authentication and Internet proxies.

Here's an example of the above interface being used:

// Create a RestClient using JSON for serialization, and point to the server-side remote interface servlet. RestClient client = RestClient.create() .json() .rootUrl("http://localhost:10000/remote") .build(); // Create a proxy interface. IAddressBook ab = client.getRrpcInterface(IAddressBook.class); // Invoke a method on the server side and get the returned result. Person p = ab.createPerson( new Person( "John Smith", "Aug 1, 1999", new Address("My street", "My city", "My state", 12345, true) ) );

Under the covers, this method call gets converted to a REST POST.

HTTP POST http://localhost:10000/remote/org.apache.juneau.examples.addressbook.IAddressBook/createPerson(org.apache.juneau.examples.addressbook.Person) Accept: application/json Content-Type: application/json [ { "name":"John Smith", "birthDate":"Aug 1, 1999", "addresses":[ { "street":"My street", "city":"My city", "state":"My state", "zip":12345, "isCurrent":true } ] } ]

Note that the body of the request is an array. This array contains the serialized arguments of the method. The object returned by the method is then serialized as the body of the response.

##### Server side

There are two ways to expose remote interfaces on the server side:

1. Extending from {@link org.apache.juneau.rest.remote.RrpcServlet}.
2. Using a @RestMethod(name=RRPC) annotation on a Java method.

In either case, the proxy communications layer is pure REST. Therefore, in cases where the interface classes are not available on the client side, the same method calls can be made through pure REST calls. This can also aid significantly in debugging, since calls to the remote interface service can be made directly from a browser with no coding involved.

##### RrpcServlet

The {@link org.apache.juneau.rest.remote.RrpcServlet} class is a simple specialized servlet with an abstract getServiceMap() method to define the server-side POJOs:

@Rest( path="/remote" ) public class SampleRrpcServlet extends RrpcServlet { // Our server-side POJO. private AddressBook addressBook = new AddressBook(); @Override /* RrpcServlet */ protected Map<Class<?>,Object> getServiceMap() throws Exception { Map<Class<?>,Object> m = new LinkedHashMap<Class<?>,Object>(); // In this simplified example, we expose the same POJO service under two different interfaces. // One is IAddressBook which only exposes methods defined on that interface, and // the other is AddressBook itself which exposes all methods defined on the class itself (dangerous!). m.put(IAddressBook.class, addressBook); m.put(AddressBook.class, addressBook); return m; } }

##### @RestMethod(name=RRPC)

The @RestMethod(name=RRPC) approach is easier if you only have a single interface you want to expose. You simply define a Java method whose return type is an interface, and return the implementation of that interface:

// Our exposed interface. @RestMethod(name=RRPC, path="/addressbookproxy/*") public IAddressBook getProxy() { return addressBook; }

##### RrpcServlet in a browser

If you point your browser to the servlet above, you get a list of available interfaces:

http://localhost:10000/remote

Clicking the hyperlinks on each shows you the list of methods that can be invoked on that service. Note that the IAddressBook link shows that you can only invoke methods defined on that interface, whereas the AddressBook link shows ALL public methods defined on that class.

##### IAddressBook

http://localhost:10000/remote/org.apache.juneau.examples.addressbook.IAddressBook

Since AddressBook extends from LinkedList, you may notice familiar collections framework methods listed.

##### AddressBook

http://localhost:10000/remote/org.apache.juneau.examples.addressbook.AddressBook

Let's see how we can interact with this interface through nothing more than REST calls to get a better idea on how this works. We'll use the same method call as in the introduction. First, we need to create the serialized form of the arguments:

Object[] args = new Object[] { new CreatePerson("Test Person", AddressBook.toCalendar("Aug 1, 1999"), new CreateAddress("Test street", "Test city", "Test state", 12345, true)) }; String asJson = SimpleJsonSerializer.DEFAULT_READABLE.toString(args); System.err.println(asJson);

That produces the following JSON output:

[ { name: 'Test Person', birthDate: 'Aug 1, 1999', addresses: [ { street: 'Test street', city: 'Test city', state: 'Test state', zip: 12345, isCurrent: true } ] } ]

Note that in this example we're using JSON. However, various other content types can also be used such as XML, URL-Encoding, UON, or HTML. In practice however, JSON will preferred since it is often the most efficient.

Next, we can use a tool such as Poster to make the REST call. Methods are invoked by POSTing the serialized object array to the URI of the interface method. In this case, we want to POST our JSON to the following URL:

http://localhost:10000/remote/org.apache.juneau.examples.addressbook.IAddressBook/createPerson(org.apache.juneau.examples.addressbook.CreatePerson)

Make sure that we specify the Content-Type of the body as text/json. We also want the results to be returned as JSON, so we set the Accept header to text/json as well.

When we execute the POST, we should see the following successful response whose body contains the returned Person bean serialized to JSON:

From there, we could use the following code snippet to reconstruct the response object from JSON:

String response = "output from above"; Person p = JsonParser.DEFAULT.parse(response, Person.class);

If we alter our servlet to allow overloaded GET requests, we can invoke methods using nothing more than a browser...

@Rest( path="/remote", // Allow us to use method=POST from a browser. allowedMethodParams="*" ) public class SampleRrpcServlet extends RrpcServlet {

For example, to invoke the getPeople() method on our bean:

http://localhost:10000/remote/org.apache.juneau.examples.addressbook.IAddressBook/getPeople?method=POST

Here we call the findPerson(int) method to retrieve a person and get the returned POJO (in this case as HTML since that's what's in the Accept header when calling from a browser):

http://localhost:10000/remote/org.apache.juneau.examples.addressbook.IAddressBook/findPerson(int)?method=POST&body=@(3)

When specifying the POST body as a &body parameter, the method arguments should be in UON notation. See {@link org.apache.juneau.uon.UonSerializer} for more information about this encoding. Usually you can also pass in JSON if you specify &Content-Type=text/json in the URL parameters but passing in unencoded JSON in a URL may not work in all browsers. Therefore, UON is preferred.

The hyperlinks on the method names above lead you to a simple form-entry page where you can test passing parameters in UON notation as URL-encoded form posts.

##### Sample form entry page

##### Sample form entry page results

### 6.8 - OpenAPI Schema Part Parsing

Parameters annotated with any of the following are parsed using the registered {@link org.apache.juneau.oapi.OpenApiParser} and therefore support OpenAPI syntax and validation:

- {@link org.apache.juneau.http.annotation.Header}
- {@link org.apache.juneau.http.annotation.Query}
- {@link org.apache.juneau.http.annotation.FormData}
- {@link org.apache.juneau.http.annotation.Path}
- {@link org.apache.juneau.http.annotation.Body} (Content-Type must match "text/openapi")

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") in a query parameter can be converted to a 2-dimensional array of Longs:

@RestMethod(method="GET", path="/testQuery") public void testQuery( @Query( name="queryParamName", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Long[][] queryParameter ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

The following shows the same for a request body:

@RestMethod(method="POST", path="/testBody") public void testBody( @Body( parsers=OpenApiParser.class, defaultContentType="text/openapi", schema=@Schema( items=@Items( collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ) ), minLength=1, maxLength=10 ) ) Long[][] body ) {...}

The list of valid POJO types for parameters depends on type and format of the value or items/entries of the value. For example, instead of Longs in the example above, we could also define a 2-dimensional array of POJOs convertible from Longs:

@RestMethod(method="POST", path="/2dLongArray") public void testBody(@Body(...) MyPojo[][] body) {...} // POJO convertible from a Long. public class MyPojo { public MyPojo(Long input) {...} }

Or even POJOs that take in arrays of Longs[]:

@RestMethod(method="POST", path="/2dLongArray") public void testBody(@Body(...) MyPojo[] body) {...} // POJO convertible from a Long[]. public class MyPojo { public MyPojo(Long[] input) {...} }

Or even POJOs that take in the whole 2-dimensional array:

@RestMethod(method="POST", path="/2dLongArray") public void testBody(@Body(...) MyPojo body) {...} // POJO convertible from a Long[][]. public class MyPojo { public MyPojo(Long[][] input) {...} }

As you can see, the complexity of possible input types expands significantly. For more information about valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

### 6.9 - OpenAPI Schema Part Serializing

Parameters annotated with any of the following are serialized using the registered {@link org.apache.juneau.oapi.OpenApiSerializer} and therefore support OpenAPI syntax and validation:

- {@link org.apache.juneau.http.annotation.ResponseHeader}
- {@link org.apache.juneau.http.annotation.Response} (Accept must match "text/openapi")

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") in a response header can be converted to a 2-dimensional array of Longs:

@RestMethod(method="GET", path="/testResponseHeader") public void testResponseHeader( @ResponseHeader( name="My-Header", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Value<Long[][]> header ) { header.set(new Long[][]{...}); }

The following shows the same for a response body:

@RestMethod(method="GET", path="/testResponseBody") public void testResponseBody( @Response( serializers=OpenApiSerialier.class, defaultAccept="text/openapi", schema=@Schema( items=@Items( collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ) ), minLength=1, maxLength=10 ) ) Value<Long[][]> responseBody ) {...}

For more information about the valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Serializers OpenAPI Serializers}

### 6.10 - HTTP-Part Annotations

The annotations used for defining the schema for request HTTP parts are:

- {@link org.apache.juneau.http.annotation.Body}
- {@link org.apache.juneau.http.annotation.Header}
- {@link org.apache.juneau.http.annotation.FormData}
- {@link org.apache.juneau.http.annotation.Query}
- {@link org.apache.juneau.http.annotation.Path}
- {@link org.apache.juneau.http.annotation.HasFormData}
- {@link org.apache.juneau.http.annotation.HasQuery}
- {@link org.apache.juneau.http.annotation.Request}

The annotations used for defining the schema for response HTTP parts are:

- {@link org.apache.juneau.http.annotation.ResponseBody}
- {@link org.apache.juneau.http.annotation.ResponseHeader}
- {@link org.apache.juneau.http.annotation.ResponseStatus}
- {@link org.apache.juneau.http.annotation.Response}

The sub-annotations used in the annotation above are:

- {@link org.apache.juneau.jsonschema.annotation.Schema}
- {@link org.apache.juneau.jsonschema.annotation.Items}

- Annotation parameter values will be aggregated when used on POJO parent and child classes.
  Values on child classes override values on parent classes.
- Annotation parameter values will be aggregated when used on both POJOs and REST methods.
  Values on methods override values on POJO classes.

#### 6.10.1 - @Body 8.1.0-updated

The {@link org.apache.juneau.http.annotation.Body @Body} annotation is used to identify POJOs to be used as the body of an HTTP request.

- {@link org.apache.juneau.http.annotation.Body}
  - {@link org.apache.juneau.http.annotation.Body#api() api} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.Body#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.Body#example() example} - Serialized example.
  - {@link org.apache.juneau.http.annotation.Body#examples() examples} - Serialized examples per media type.
  - {@link org.apache.juneau.http.annotation.Body#required() required} - Input validation. Body must be present.
  - {@link org.apache.juneau.http.annotation.Body#schema() schema} - Swagger schema.
  - {@link org.apache.juneau.http.annotation.Body#value() value} - Free-form Swagger JSON.

##### Examples:

// Defined on parameter @RestMethod(name=POST) public void addPet(@Body Pet pet) {...}

// Defined on POJO class @RestMethod(name=POST) public void addPet(Pet pet) {...} @Body public class Pet {...}

This is functionally equivalent to the following code:

@RestMethod(name=POST) public void addPet(RestRequest req) { Person person = req.getBody().asType(Pet.class); ... }

Any of the following types can be used for the parameter or POJO class (matched in the specified order):

1. {@link java.io.Reader}
   @Body annotation is optional.
   Content-Type is ignored.
2. {@link java.io.InputStream}
   @Body annotation is optional.
   Content-Type is ignored.
3. Any {@doc PojoCategories Parsable POJO} type.
   Content-Type is required to identify correct parser.
4. Objects convertible from {@link java.io.Reader} by having one of the following non-deprecated methods:
   - public T(Reader in) {...}
   - public static T create(Reader in) {...}
   - public static T fromReader(Reader in) {...}
   Content-Type must not be present or match an existing parser so that it's not parsed as a POJO.
5. Objects convertible from {@link java.io.InputStream} by having one of the following non-deprecated methods:
   - public T(InputStream in) {...}
   - public static T create(InputStream in) {...}
   - public static T fromInputStream(InputStream in) {...}
   Content-Type must not be present or match an existing parser so that it's not parsed as a POJO.
6. Objects convertible from {@link java.lang.String} by having one of the following non-deprecated methods:
   - public T(String in) {...}
   - public static T create(String in) {...}
   - public static T fromString(String in) {...}
   - public static T parse(String in) {...}
   - public static T parseString(String in) {...}
   - public static T forName(String in) {...}
   - public static T forString(String in) {...}
   Note that this also includes all enums.
7. Any {@link java.util.Optional} of anything on this list.

The {@link org.apache.juneau.oapi.OpenApiSerializer} class can be used to serialize HTTP bodies to OpenAPI-based output.

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") can be converted to a 2-dimensional array of Longs:

// Body is a pipe-delimited list of comma-delimited lists of longs. @RestMethod( method="POST", path="/testBody", serializers=OpenApiSerializers.class, defaultAccept="text/openapi" ) public void testBody( @Body( schema=@Schema( items=@Items( collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ) ), minLength=1, maxLength=10 ) ) Long[][] body ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

For more information about valid parameter types when using OpenAPI parsing, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

The @Body annotation is also used for supplying swagger information about the body of the request. This information is used to populate the auto-generated Swagger documentation and UI.

##### Examples:

// Normal @Body( description="Pet object to add to the store", required=true, example="{name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}" )

// Free-form // Note the extra field @Body({ "description: 'Pet object to add to the store',", "required: true,", "example: {name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}," "x-extra: 'extra field'" })

{@doc DefaultRestSvlVariables} (e.g. "$L{my.localized.variable}") are supported on annotation fields.

##### Example:

// Localized @Body( description="$L{PetObjectDescription}" )

- Annotation parameter values will be aggregated when used on POJO parent and child classes.
  Values on child classes override values on parent classes.
- Annotation parameter values will be aggregated when used on both POJOs and REST methods.
  Values on methods override values on POJO classes.

If using this annotation on a Spring bean, note that you are likely to encounter issues when using on parameterized types such as `List<MyBean>`. This is due to the fact that Spring uses CGLIB to recompile classes at runtime, and CGLIB was written before generics were introduced into Java and is a virtually-unsupported library. Therefore, parameterized types will often be stripped from class definitions and replaced with unparameterized types (e.g. `List`). Under these circumstances, you are likely to get `ClassCastExceptions` when trying to access generalized `ObjectMaps` as beans. The best solution to this issue is to either specify the parameter as a bean array (e.g. `MyBean[]`) or declare the method as final so that CGLIB will not try to recompile it.

- {@link org.apache.juneau.rest.RequestBody}
- {@doc juneau-rest-server.OpenApiSchemaPartParsing}

#### 6.10.2 - @FormData 8.1.0-updated

The {@link org.apache.juneau.http.annotation.FormData @FormData} annotation is used to retrieve request form post entries.

- {@link org.apache.juneau.http.annotation.FormData}
  - {@link org.apache.juneau.http.annotation.FormData#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.FormData#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.FormData#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.FormData#api() api()} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.FormData#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.FormData#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.FormData#example() example()} - Serialized example.
  - {@link org.apache.juneau.http.annotation.FormData#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.FormData#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.FormData#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.FormData#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.FormData#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.FormData#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.FormData#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.FormData#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.FormData#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.FormData#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.FormData#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.FormData#name() name} - Form data entry name.
  - {@link org.apache.juneau.http.annotation.FormData#parser() parser} - Override the part parser.
  - {@link org.apache.juneau.http.annotation.FormData#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.FormData#required() required} - Input validation. Form data entry must be present.
  - {@link org.apache.juneau.http.annotation.FormData#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.FormData#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.
  - {@link org.apache.juneau.http.annotation.FormData#value() value} - Free-form Swagger JSON.

The most typical scenario is to simply use the value field to define form data parameter names:

##### Example:

@RestMethod(name=POST) public void doPost( @FormData("p1") int p1, @FormData("p2") String p2, @FormData("p3") UUID p3) {...}

This is functionally equivalent to the following code:

@RestMethod(name=POST) public void doPost(RestRequest req) { RequestFormData fd = req.getFormData(); int p1 = fd.get("p1", 0, int.class); String p2 = fd.get("p2", String.class); UUID p3 = fd.get("p3", UUID.class); }

The special name "*" (or blank) can be used to represent all values. When used, the data type must be a Map or bean.

##### Examples:

// Multiple values passed as a map. @RestMethod(name=POST) public void doPost(@FormData("*") Map<String,Object> map) {...}

// Same, but name "*" is inferred. @RestMethod(name=POST) public void doPost(@FormData Map<String,Object> map) {...}

// Multiple values passed as a bean. @RestMethod(name=POST) public void doPost(@FormData MyBean bean) {...}

The registered {@link org.apache.juneau.rest.RestContext#REST_partParser REST_partParser} is used to convert strings to POJOs and controls what POJO types are supported. By default, this is the {@link org.apache.juneau.oapi.OpenApiParser} which supports the standard Swagger-based rules for parsing.

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") can be converted to a 2-dimensional array of Longs:

@RestMethod(method="POST", path="/testFormData") public void testFormData( @FormData( name="formDataParamName", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Long[][] formDataParameter ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

For more information about valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

The @FormData annotation is also used for supplying swagger information about the HTTP part. This information is used to populate the auto-generated Swagger documentation and UI.

##### Examples:

// Normal @FormData( name="name", description="Pet name", required=true, example="Doggie" )

// Free-form // Note the extra field @FormData( name="name", api={ "description: 'Pet name',", "required: true,", "example: 'Doggie'," "x-extra: 'extra field'" } )

{@doc DefaultRestSvlVariables} (e.g. "$L{my.localized.variable}") are supported on annotation fields.

##### Example:

@FormData( description="$L{PetNameDescription}" )

This annotation should not be combined with the {@link org.apache.juneau.http.annotation.Body @Body} annotation or {@link org.apache.juneau.rest.RestRequest#getBody()} method for application/x-www-form-urlencoded POST posts, since it will trigger the underlying servlet API to parse the body content as key-value pairs resulting in empty content.
The {@link org.apache.juneau.http.annotation.Query @Query} annotation can be used to retrieve a URL parameter in the URL string without triggering the servlet to drain the body content.
If using this annotation on a Spring bean, note that you are likely to encounter issues when using on parameterized types such as `List<MyBean>`. This is due to the fact that Spring uses CGLIB to recompile classes at runtime, and CGLIB was written before generics were introduced into Java and is a virtually-unsupported library. Therefore, parameterized types will often be stripped from class definitions and replaced with unparameterized types (e.g. `List`). Under these circumstances, you are likely to get `ClassCastExceptions` when trying to access generalized `ObjectMaps` as beans. The best solution to this issue is to either specify the parameter as a bean array (e.g. `MyBean[]`) or declare the method as final so that CGLIB will not try to recompile it.

- {@link org.apache.juneau.rest.RequestFormData}
- {@doc juneau-rest-server.OpenApiSchemaPartParsing}

#### 6.10.3 - @HasFormData

This annotation can be used to detect the existence of a parameter when it's not set to a particular value.

- {@link org.apache.juneau.http.annotation.HasFormData}

##### Example:

@RestMethod(name=POST) public void doPost(@HasFormData("p1") boolean p1) {...}

This is functionally equivalent to the following code:

@RestMethod(name=POST) public void doPost(RestRequest req) { boolean p1 = req.hasFormData("p1"); ... }

The parameter type must be either boolean or {@link java.lang.Boolean}.

The following table shows the behavioral differences between @HasFormData and @FormData:

Body content | @HasFormData("a") | @FormData("a")
--- | --- | ---
a=foo | true | "foo"
a= | true | ""
a | true | null
b=foo | false | null

##### Important note concerning FORM posts

This annotation should not be combined with the {@link org.apache.juneau.http.annotation.Body @Body} annotation or {@link org.apache.juneau.rest.RestRequest#getBody()} method for application/x-www-form-urlencoded POST posts, since it will trigger the underlying servlet API to parse the body content as key-value pairs, resulting in empty content.

The {@link org.apache.juneau.http.annotation.HasQuery @HasQuery} annotation can be used to check for the existing of a URL parameter in the URL string without triggering the servlet to drain the body content.

#### 6.10.4 - @Query

The {@link org.apache.juneau.http.annotation.Query @Query} annotation is used to retrieve request URL query parameters. It's identical to {@link org.apache.juneau.http.annotation.FormData @FormData}, but only retrieves the parameter from the URL string, not URL-encoded form posts.

- {@link org.apache.juneau.http.annotation.Query}
  - {@link org.apache.juneau.http.annotation.Query#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.Query#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.Query#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.Query#api() api} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.Query#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.Query#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.Query#example() example} - Serialized example.
  - {@link org.apache.juneau.http.annotation.Query#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.Query#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.Query#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.Query#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.Query#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.Query#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Query#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.Query#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.Query#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Query#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.Query#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.Query#name() name} - Query parameter name.
  - {@link org.apache.juneau.http.annotation.Query#parser() parser} - Override the part parser.
  - {@link org.apache.juneau.http.annotation.Query#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.Query#required() required} - Input validation. Query parameter must be present.
  - {@link org.apache.juneau.http.annotation.Query#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.Query#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.
  - {@link org.apache.juneau.http.annotation.Query#value() value} - Free-form Swagger JSON.

Unlike {@link org.apache.juneau.http.annotation.FormData @FormData}, using this annotation does not result in the servlet reading the contents of URL-encoded form posts. Therefore, this annotation can be used in conjunction with the {@link org.apache.juneau.http.annotation.Body @Body} annotation or {@link org.apache.juneau.rest.RestRequest#getBody()} method for application/x-www-form-urlencoded POST calls.

The most typical scenario is to simply use the value field to define query parameter names:

##### Example:

@RestMethod(name=GET) public void doGet( @Query("p1") int p1, @Query("p2") String p2, @Query("p3") UUID p3) {...}

This is functionally equivalent to the following code:

@RestMethod(name=GET) public void doGet(RestRequest req) { RequestQuery q = req.getQuery(); int p1 = q.get("p1", 0, int.class); String p2 = q.get("p2", String.class); UUID p3 = q.get("p3", UUID.class); }

The special name "*" (or blank) can be used to represent all values. When used, the data type must be a Map or bean.

##### Examples:

// Multiple values passed as a map. @RestMethod(name=GET) public void doGet(@Query("*") Map<String,Object> map) {...}

// Same, but name "*" is inferred. @RestMethod(name=GET) public void doGet(@Query Map<String,Object> map) {...}

// Multiple values passed as a bean. @RestMethod(name=GET) public void doGet(@Query MyBean bean) {...}

The registered {@link org.apache.juneau.rest.RestContext#REST_partParser REST_partParser} is used to convert strings to POJOs and controls what POJO types are supported. By default, this is the {@link org.apache.juneau.oapi.OpenApiParser} which supports the standard Swagger-based rules for parsing.

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") can be converted to a 2-dimensional array of Longs:

@RestMethod(method="GET", path="/testQuery") public void testQuery( @Query( name="queryParamName", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Long[][] queryParameter ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

For more information about valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

The @Query annotation is also used for supplying swagger information about the HTTP part. This information is used to populate the auto-generated Swagger documentation and UI.

##### Examples:

// Normal @Query( name="name", description="Pet name", required=true, example="Doggie" )

// Free-form // Note the extra field @Query( name="name", api={ "description: 'Pet name',", "required: true,", "example: 'Doggie'," "x-extra: 'extra field'" } )

{@doc DefaultRestSvlVariables} (e.g. "$L{my.localized.variable}") are supported on annotation fields.

##### Example:

@Query( description="$L{PetNameDescription}" )

- {@link org.apache.juneau.rest.RequestQuery}
- {@doc juneau-rest-server.OpenApiSchemaPartParsing}

#### 6.10.5 - @HasQuery

Identical to {@link org.apache.juneau.http.annotation.HasFormData @HasFormData}, but only checks the existing of the parameter in the URL string, not URL-encoded form posts.

- {@link org.apache.juneau.http.annotation.HasQuery}

Unlike {@link org.apache.juneau.http.annotation.HasFormData @HasFormData}, using this annotation does not result in the servlet reading the contents of URL-encoded form posts. Therefore, this annotation can be used in conjunction with the {@link org.apache.juneau.http.annotation.Body @Body} annotation or {@link org.apache.juneau.rest.RestRequest#getBody()} method for application/x-www-form-urlencoded POST calls.

##### Example:

@RestMethod(name=GET) public void doGet(@HasQuery("p1") boolean p1) {...}

This is functionally equivalent to the following code:

@RestMethod(name=GET) public void doGet(RestRequest req) { boolean p1 = req.hasQuery("p1"); ... }

The parameter type must be either boolean or {@link java.lang.Boolean}.

The following table shows the behavioral differences between @HasQuery and @Query:

Query content | @HasQuery("a") | @Query("a")
--- | --- | ---
?a=foo | true | "foo"
?a= | true | ""
?a | true | null
?b=foo | false | null

#### 6.10.6 - @Header

The {@link org.apache.juneau.http.annotation.Header @Header} annotation is used to retrieve request headers.

- {@link org.apache.juneau.http.annotation.Header}
  - {@link org.apache.juneau.http.annotation.Header#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.Header#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.Header#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.Header#api() api} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.Header#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.Header#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.Header#example() example} - Serialized example.
  - {@link org.apache.juneau.http.annotation.Header#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.Header#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.Header#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.Header#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.Header#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.Header#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Header#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.Header#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.Header#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Header#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.Header#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.Header#name() name} - Header name.
  - {@link org.apache.juneau.http.annotation.Header#parser() parser} - Override the part parser.
  - {@link org.apache.juneau.http.annotation.Header#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.Header#required() required} - Input validation. Header must be present.
  - {@link org.apache.juneau.http.annotation.Header#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.Header#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.
  - {@link org.apache.juneau.http.annotation.Header#value() value} - Free-form Swagger JSON.

The most typical scenario is to simply use the value field to define header parameter names:

##### Example:

@RestMethod(name=GET) public void doGet(@Header("ETag") UUID etag) {...}

This is functionally equivalent to the following code:

@RestMethod(name=GET) public void doGet(RestRequest req) { RequestHeaders h = req.getHeaders(); UUID etag = h.get("ETag", UUID.class); }

The special name "*" (or blank) can be used to represent all values. When used, the data type must be a Map or bean.

##### Examples:

// Multiple values passed as a map. @RestMethod(name=GET) public void doGet(@Header("*") Map<String,Object> map) {...}

// Same, but name "*" is inferred. @RestMethod(name=GET) public void doGet(@Header Map<String,Object> map) {...}

// Multiple values passed as a bean. @RestMethod(name=GET) public void doGet(@Header MyBean bean) {...}

The registered {@link org.apache.juneau.rest.RestContext#REST_partParser REST_partParser} is used to convert strings to POJOs and controls what POJO types are supported. By default, this is the {@link org.apache.juneau.oapi.OpenApiParser} which supports the standard Swagger-based rules for parsing.

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") can be converted to a 2-dimensional array of Longs:

@RestMethod(method="GET", path="/testHeader") public void testHeader( @Header( name="My-Header", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Long[][] myHeader ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

For more information about valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

The @Header annotation is also used for supplying swagger information about the HTTP part. This information is used to populate the auto-generated Swagger documentation and UI.

##### Examples:

// Normal @Header( name="Pet-Name", description="Pet name", required=true, example="Doggie" )

// Free-form // Note the extra field @Header( name="Pet-Name", api={ "description: 'Pet name',", "required: true,", "example: 'Doggie'," "x-extra: 'extra field'" } )

{@doc DefaultRestSvlVariables} (e.g. "$L{my.localized.variable}") are supported on annotation fields.

##### Example:

@Header( description="$L{PetNameDescription}" )

- {@link org.apache.juneau.rest.RequestHeaders}
- {@doc juneau-rest-server.OpenApiSchemaPartParsing}

#### 6.10.7 - @Path

The {@link org.apache.juneau.http.annotation.Path @Path} annotation is used to retrieve request path parameters.

- {@link org.apache.juneau.http.annotation.Path}
  - {@link org.apache.juneau.http.annotation.Path#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.Path#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.Path#api() api} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.Path#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.Path#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.Path#example() example} - Serialized example.
  - {@link org.apache.juneau.http.annotation.Path#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.Path#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.Path#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.Path#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.Path#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.Path#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.Path#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.Path#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.Path#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.Path#name() name} - Path variable name.
  - {@link org.apache.juneau.http.annotation.Path#parser() parser} - Override the part parser.
  - {@link org.apache.juneau.http.annotation.Path#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.Path#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.Path#value() value} - Free-form Swagger JSON.

The most typical scenario is to simply use the value field to define path parameter names:

##### Example:

@RestMethod(name=GET, path="/myurl/{foo}/{bar}/{baz}/*") public void doGet( @Path("foo") String foo, @Path("bar") int bar, @Path("baz") UUID baz, @Path("/*") String remainder ) {...}

This is functionally equivalent to the following code:

@RestMethod(name=GET, path="/myurl/{foo}/{bar}/{baz}/*") public void doGet(RestRequest req) { RequestPath p = req.getPathMatch(); String foo = p.getString("foo"); int bar = p.get("bar", int.class); UUID baz = p.get("baz", UUID.class); String remainder = p.getRemainder(); }

Note that the path variable name "/*" can be used to represent the remainder of the path match.

The special name "*" (or blank) can be used to represent all values. When used, the data type must be a Map or bean.

##### Examples:

// Multiple values passed as a map. @RestMethod(name=GET, path="/{a}/{b}/{c}/*") public void doGet(@Path("*") Map<String,Object> map) {...}

// Same, but name "*" is inferred. @RestMethod(name=GET, path="/{a}/{b}/{c}/*") public void doGet(@Path Map<String,Object> map) {...}

// Multiple values passed as a bean. @RestMethod(name=GET, path="/{a}/{b}/{c}/*") public void doGet(@Path MyBean bean) {...}

The registered {@link org.apache.juneau.rest.RestContext#REST_partParser REST_partParser} is used to convert strings to POJOs and controls what POJO types are supported. By default, this is the {@link org.apache.juneau.oapi.OpenApiParser} which supports the standard Swagger-based rules for parsing.

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") can be converted to a 2-dimensional array of Longs:

@RestMethod(method="POST", path="/testPath/{pathParam}") public void testPath( @Path( name="pathParam", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Long[][] pathParameter ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

For more information about valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

The @Path annotation is also used for supplying swagger information about the HTTP part. This information is used to populate the auto-generated Swagger documentation and UI.

##### Examples:

// Normal @Path( name="name", description="Pet name", example="Doggie" )

// Free-form // Note the extra field @Path( name="name", api={ "description: 'Pet name',", "example: 'Doggie'," "x-extra: 'extra field'" } )

{@doc DefaultRestSvlVariables} (e.g. "$L{my.localized.variable}") are supported on annotation fields.

##### Example:

@Path( description="$L{PetNameDescription}" )

- {@link org.apache.juneau.rest.RequestPath}
- {@doc juneau-rest-server.OpenApiSchemaPartParsing}

#### 6.10.8 - @Request

The {@link org.apache.juneau.http.annotation.Request @Request} annotation can be applied to a parameter interface type of a @RestMethod-annotated method to identify it as an interface for retrieving HTTP parts through a bean-like interface.

- {@link org.apache.juneau.http.annotation.Request}
  - {@link org.apache.juneau.http.annotation.Request#partParser() partParser} - Override the part parser.

##### Example:

@RestMethod(path="/pets/{petId}") public void putPet(UpdatePet updatePet) {...} @Request public interface UpdatePet { @Path int getPetId(); @Query(name="verbose") boolean isDebug(); @Header("*") Map<String,Object> getAllHeaders(); @Body Pet getPet(); }

The example above is identical in behavior to specifying individual annotated parameters on the @RestMethod-annotated method:

@RestMethod(path="/pets/{petId}") public void putPet( @Path("petId") int petId, @Query("verbose") boolean debug, @Header("*") Map<String,Object> allHeaders, @Body Pet pet ) {...}

The return types of the getters must be the supported parameter types for the HTTP-part annotation used. Schema-based serialization and parsing is used just as if used as individual parameter types. Annotations used are the exact same used on REST parameters and have all the same feature support including automatic Swagger validation and documentation.

##### Example:

@Request public interface Request { // Schema-based query parameter: Pipe-delimited lists of comma-delimited lists of integers. @Query( collectionFormat="pipes" items=@Items( items=@SubItems( collectionFormat="csv" type="integer", minimum=1, maximum=100 ), maximumLength=10 ) ) int[][] getPipedCdlInts(); }

For clarity, the @Request annotation can be defined on the parameter, class, or both.

##### Example:

@RestMethod(path="/pets/{petId}") public void putPet(@Request UpdatePet updatePet) {...} @Request public interface UpdatePet {...}

#### 6.10.9 - @Response

The {@link org.apache.juneau.http.annotation.Response @Response} annotation is used to identify schema information about an HTTP response.

- {@link org.apache.juneau.http.annotation.Response}
  - {@link org.apache.juneau.http.annotation.Response#api() api} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.Response#code() code} - HTTP status code.
  - {@link org.apache.juneau.http.annotation.Response#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.Response#example() example} - Serialized example.
  - {@link org.apache.juneau.http.annotation.Response#examples() examples} - Serialized examples per media type.
  - {@link org.apache.juneau.http.annotation.Response#headers() headers} - Swagger about headers added to response.
  - {@link org.apache.juneau.http.annotation.Response#partSerializer() partSerializer} - Override the part serializer.
  - {@link org.apache.juneau.http.annotation.Response#schema() schema} - Swagger schema.
  - {@link org.apache.juneau.http.annotation.Response#value() value} - Free-form Swagger JSON.

It can be used in the following locations:

- Exception classes thrown from @RestMethod-annotated methods.
- Return type classes of @RestMethod-annotated methods.
- @RestMethod-annotated methods themselves.
- Arguments and argument-types of @RestMethod-annotated methods.

When the @Response annotation is applied to classes, the following annotations can be used on public non-static methods of the class to identify parts of a response:

- {@link org.apache.juneau.http.annotation.ResponseStatus}
- {@link org.apache.juneau.http.annotation.ResponseHeader}
- {@link org.apache.juneau.http.annotation.ResponseBody}

##### @Resource on exception classes

When applied to an exception class, this annotation defines Swagger schema and information on non-200 return types.

The following example shows the @Response annotation used to define an exception for an invalid login attempt:

// Our annotated exception. @Response( code=401, description="Invalid username or password provided" // Description show in Swagger ) public class InvalidLogin extends Exception { public InvalidLogin() { super("Invalid username or password."); // Message sent in response } } // Our REST method that throws an annotated exception. @RestMethod(name="GET", path="/user/login") public Ok login( @FormData("username") String username, @FormData("password") String password ) throws InvalidLogin { checkCredentials(username, password); return new Ok(); }

Custom exceptions can also extend from one of the predefined HTTP exceptions such as the {@link org.apache.juneau.http.exception.Unauthorized} exception:

// Our annotated exception. @Response( description="Invalid username or password provided" // Overridden from parent class ) public class InvalidLogin extends Unauthorized { public InvalidLogin() { super("Invalid username or password."); } } // Parent predefined exception class. @Response( code=401, description="Unauthorized" ) public class Unauthorized extends RestException {...}

##### @Resource on return type classes

When applied type classes returned by a Java method, this annotation defines schema and Swagger information on the body of responses.

In the example above, we're using the Ok class which is defined like so:

@Response( code=200, description="OK" ) public class Ok { @ResponseBody public String toString() { return "OK"; } }

Another example showing how a redirect can be defined:

@Response( code=307, description="Temporary Redirect" ) public class Redirect { private final URI location; public Redirect(URI location) { this.location = location; } @ResponseHeader( name="Location", format="uri" ) public URI getLocation() { return location; } @ResponseBody public String toString() { return "Temporary Redirect"; } }

// Usage @RestMethod(method=POST) public Redirect addPet(Pet pet) { // Redirect to servlet root return new Redirect(URI.create("servlet:/")); }

##### @Resource on @RestMethod-annotated methods

The @Response annotation can also be applied to the Java method itself which is effectively the same as applying it to the return type (albeit for this method only).

@RestMethod(name="GET", path="/user/login") @Response(code=200, description="OK") public Ok login( @FormData("username") String username, @FormData("password") String password ) throws InvalidLogin { checkCredentials(username, password); return new Ok(); }

The @Response annotation can be simultaneously on both the Java method and return type. When used in both locations, the annotation values are combined, but values defined on the method return annotation take precedence over the values defined on the type.

##### @Resource on @RestMethod-annotated method parameters

The @Response annotation can also be applied to the Java method parameters when the parameter type is {@link org.apache.juneau.Value} (a placeholder for objects).

@RestMethod(name="GET", path="/user/login") public void login( @FormData("username") String username, @FormData("password") String password, @Response(code=200, description="Login succeeded") Value<String> body ) throws InvalidLogin { checkCredentials(username, password); body.set("OK"); }

@Response-annotated types can also be used as value parameters:

@RestMethod(...) public void login( ... @Response Value<Ok> res ) throws InvalidLogin { ... res.set(new Ok()); }

In the above example, the @Response annotation is optional since it is inferred from the class that it's a @Response bean.

@RestMethod(name="GET", path="/user/login") public void login( ... Value<Ok> res // @Response annotation not needed. ) throws InvalidLogin { ... res.set(new Ok()); }

##### @ResponseStatus on methods of @Response-annotated types

The {@link org.apache.juneau.http.annotation.ResponseStatus @ResponseStatus} annotation can be used on the method of a @Response-annotated class to identify HTTP response statuses other than 200 (the default).

##### Example:

@Response public class AddPetSuccess { @ResponseStatus public int getStatus() { return 201; } @Override public String toString() { return "Pet was successfully added"; } }

##### @ResponseHeader on methods of @Response-annotated types

The {@link org.apache.juneau.http.annotation.ResponseHeader @ResponseHeader} annotation can be used on the method of a @Response-annotated class to identify a header to add to the response.

##### Example:

@Response public class AddPetSuccess { @ResponseHeader( name="X-PetId", type="integer", format="int32", description="ID of added pet.", example="123" ) public int getPetId() {...} }

##### @ResponseBody on methods of @Response-annotated types

The {@link org.apache.juneau.http.annotation.ResponseBody @ResponseBody} annotation can be used on the method of a @Response-annotated class to identify a POJO as the body of the HTTP response.

##### Example:

@Response public class AddPetSuccess { @ResponseBody public Pet getPet() {...} }

If a @Response class does not have a @ResponseBody-annotated method, then the response object itself is serialized in the response (typically using toString()).

##### Notes about OpenAPI part serialization

By default, POJOs representing the body of the request are serialized using the Juneau serializer matching the requesting Accept header. The {@link org.apache.juneau.oapi.OpenApiSerializer} class can be used to serialize response bodies using OpenAPI rules.

The following examples show part-schema-based serialization of response bodies:

@Rest public class ExampleResource { // Example 1 - String[] should be serialized using part serializer. @Response( serializers=OpenApiSerializer.class, defaultAccept="text/openapi" ) @RestMethod public String[] example1() { return new String[]{"foo","bar"}; } // Example 2 - Same as above. Annotation on parameter. @RestMethod public void example2( @Response( serializers=OpenApiSerializer.class, defaultAccept="text/openapi" ) Value<String[]> body ) { body.set(new String[]{"foo","bar"}); } }

The @Response(schema) annotation can be used to define the format of the output using OpenAPI-based rules.

@Rest public class ExampleResource { @Response( serializers=OpenApiSerializer.class, defaultAccept="text/openapi", schema=@Schema(collectionFormat="pipes") ) @RestMethod public String[] example1() { return new String[]{"foo","bar"}; } }

##### Swagger documentation

The attributes on this annotation are also used to populate the generated Swagger for the method. For example, in the case of the InvalidLogin example above, the following Swagger is generated:

'/user/login': { get: { responses: { 401: { description: 'Invalid username or password provided' } } } }

##### Automatic HTTP status

When the {@link org.apache.juneau.http.annotation.Response#code() @Response(code)} value is specified, the HTTP status is automatically set to that value on the response regardless of how it's used.

The following two examples are equivalent:

@RestMethod(name="GET", path="/ok") public void sendContinue( @Response(code=100) Value<String> body ) { body.set("OK"); }

@RestMethod(name="GET", path="/ok") public void sendContinue(RestResponse res) { res.setStatus(100); res.setOutput("OK"); }

- {@doc juneau-rest-server.OpenApiSchemaPartSerializing}

#### 6.10.10 - @ResponseHeader

The {@link org.apache.juneau.http.annotation.ResponseHeader @ResponseHeader} annotation can be applied to @RestMethod-annotated parameters to denote them as an HTTP response headers.

- {@link org.apache.juneau.http.annotation.ResponseHeader}
  - {@link org.apache.juneau.http.annotation.ResponseHeader#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#_enum() _enum} - Output validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#$ref() $ref} - Schema reference.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#api() api} - Free-form Swagger JSON.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#code() code} - HTTP status codes that this header applies to.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#description() description} - Description.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#example() example} - Serialized example.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#exclusiveMaximum() exclusiveMaximum} - Output validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#exclusiveMinimum() exclusiveMinimum} - Output validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#maximum() maximum} - Output validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#maxItems() maxItems} - Output validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#maxLength() maxLength} - Output validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#minimum() minimum} - Output validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#minItems() minItems} - Output validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#minLength() minLength} - Output validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#multipleOf() multipleOf} - Output validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#name() name} - Header name.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#pattern() pattern} - Output validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#serializer() serializer} - Override the part serializer.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#uniqueItems() uniqueItems} - Output validation. Collections must contain unique items only.
  - {@link org.apache.juneau.http.annotation.ResponseHeader#value() value} - Free-form Swagger JSON.

This annotation can only be applied to parameters of type {@link org.apache.juneau.Value}.

The following examples show 3 different ways of accomplishing the same task of setting an HTTP header on a response:

// Example #1 - Setting header directly on RestResponse object. @RestMethod(...) public void login(RestResponse res) { res.setHeader("X-Rate-Limit", 1000); ... } // Example #2 - Use on parameter. @RestMethod(...) public void login( @ResponseHeader( name="X-Rate-Limit", type="integer", format="int32", description="Calls per hour allowed by the user.", example="123" ) Value<Integer> rateLimit ) { rateLimit.set(1000); ... } // Example #3 - Use on type. @RestMethod(...) public void login(Value<RateLimit> rateLimit) { rateLimit.set(new RateLimit()); ... } @ResponseHeader( name="X-Rate-Limit", type="integer", format="int32", description="Calls per hour allowed by the user.", example="123" ) public class RateLimit { // OpenApiSerializer knows to look for this method based on format/type. public Integer toInteger() { return 1000; } }

##### Swagger documentation

The attributes on this annotation are also used to populate the generated Swagger for the method. For example, in the case of the X-Rate-Limit example above, the following Swagger is generated:

'/user/login': { get: { responses: { 200: { headers: { 'X-Rate-Limit': { type: 'integer', format: 'int32', description: 'Calls per hour allowed by the user.', example: '123' } } } } } }

#### 6.10.11 - @ResponseStatus

The {@link org.apache.juneau.http.annotation.ResponseStatus @ResponseStatus} annotation annotation can be applied to @RestMethod-annotated parameters to denote them as an HTTP response status codes.

- {@link org.apache.juneau.http.annotation.ResponseStatus}

This can only be applied to parameters of the {@link org.apache.juneau.Value} class with an {@link java.lang.Integer} type.

##### Examples:

// Defined on parameter. @RestMethod(name="GET", path="/user/login") public void login( @FormData("username") String username, @FormData("password") String password, @ResponseStatus Value<Integer> status ) { if (! isValid(username, password)) status.set(401); }

### 6.11 - Handling Form Posts

The best way to handle a form post is usually by using an input bean. The following is a class that takes in URL-Encoded form post of the form "aString=foo&aNumber=123&aDate=2001-07-04T15:30:45Z".

@Rest( path="/urlEncodedForm" ) public class UrlEncodedFormResource extends BasicRestServlet { /** POST request handler */ @RestMethod(name=POST, path="/") public Object doPost(@Body FormInputBean input) throws Exception { // Just mirror back the request return input; } public static class FormInputBean { public String aString; public int aNumber; @Swap(TemporalCalendarSwap.IsoLocalDateTime.class) public Calendar aDate; } }

Another possibility is to access the form parameters individually:

/** POST request handler */ @RestMethod(name=POST, path="/") public Object doPost(@FormData("aString") String aString, @FormData("aNumber") int aNumber, @FormData("aDate") Calendar aDate) throws Exception { ... }

The advantage to the form input bean is that it can handle any of the parsable types (e.g. JSON, XML...) in addition to URL-Encoding. The latter approach only supports URL-Encoding.

If you're using form input beans, DO NOT use the @FormData attribute or {@link org.apache.juneau.rest.RestRequest#getParameter(String)} method since this will cause the underlying JEE servlet to parse the HTTP body as a form post.
Your input bean will end up being null since there won't be any content left after the servlet has parsed the body of the request.
This applies to WHENEVER you use @Body or {@link org.apache.juneau.rest.RestRequest#getBody()}

### 6.12 - Handling Multi-Part Form Posts 8.0.0-updated

The Juneau framework does not natively support multipart form posts. However, it can be done in conjunction with the Apache Commons File Upload library or through the Servlet 3.0 API directly.

The following is an example that uses the File Upload library to allow files to be uploaded as multipart form posts.

##### Example:

@Rest( path="/tempDir" ) public class TempDirResource extends DirectoryResource { /** * [POST /upload] - Upload a file as a multipart form post. * Shows how to use the Apache Commons ServletFileUpload class for handling multi-part form posts. */ @RestMethod(name=POST, path="/upload", matchers=TempDirResource.MultipartFormDataMatcher.class) public Redirect uploadFile(RestRequest req) throws Exception { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iter = upload.getItemIterator(req); while (iter.hasNext()) { FileItemStream item = iter.next(); if (item.getFieldName().equals("contents")) { File f = new File(getRootDir(), item.getName()); IOPipe.create(item.openStream(), new FileOutputStream(f)).closeOut().run(); } } return new Redirect(); // Redirect to the servlet root. } /** Causes a 404 if POST isn't multipart/form-data */ public static class MultipartFormDataMatcher extends RestMatcher { @Override /* RestMatcher */ public boolean matches(RestRequest req) { String contentType = req.getContentType(); return contentType != null && contentType.startsWith("multipart/form-data"); } }

The following shows using the HttpServletRequest.getParts() method to retrieve multi-part form posts when using Jetty. This example is pulled from the PetStore application.

@RestMethod( ... ) public SeeOtherRoot uploadFile(RestRequest req) throws Exception { // Required for Jetty. MultipartConfigElement mce = new MultipartConfigElement((String)null); req.setAttribute("org.eclipse.jetty.multipartConfig", mce); String id = UUID.randomUUID().toString(); BufferedImage img = null; for (Part part : req.getParts()) { switch (part.getName()) { case "id": id = IOUtils.read(part.getInputStream()); break; case "file": img = ImageIO.read(part.getInputStream()); } } addPhoto(id, img); return new SeeOtherRoot(); // Redirect to the servlet root. }

### 6.13 - Serializers

REST resources use the {@link org.apache.juneau.serializer.Serializer} API for defining serializers for serializing response POJOs.

The servlet will pick which serializer to use by matching the request Accept header with the media types defined through the {@link org.apache.juneau.serializer.Serializer#getMediaTypeRanges()} method.

Serializers can be associated with REST servlets in the following ways:

- {@link org.apache.juneau.rest.annotation.Rest#serializers() Rest(serializers)} - Annotation on resource Java class.
- {@link org.apache.juneau.rest.annotation.RestMethod#serializers() RestMethod(serializers)} - Annotation on resource Java method.
- {@link org.apache.juneau.rest.RestContext#REST_serializers} - Programmatic.

The following are all equivalent ways of defining serializers used by a resource:

// Option #1 - Defined via annotation. @Rest(serializers={JsonSerializer.class, XmlSerializer.class}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContextBuilder builder) throws Exception { // Using method on builder. builder.serializers(JsonSerializer.class, XmlSerializer.class); // Same, but use pre-instantiated parsers. builder.serializers(JsonSerializer.DEFAULT, XmlSerializer.DEFAULT); // Same, but using property. builder.set(REST_serializers, JsonSerializer.class, XmlSerializer.class); } // Option #3 - Defined via builder passed in through init method. @RestHook(INIT) public void init(RestContextBuilder builder) throws Exception { builder.serializers(JsonSerializer.class, XmlSerializer.class); } // Override at the method level. @RestMethod(serializers={HtmlSerializer.class}) public MyPojo myMethod() { // Return a POJO to be serialized. return new MyPojo(); } }

- {@link org.apache.juneau.rest.RestContext#REST_serializers}

### 6.14 - Parsers

REST resources use the {@link org.apache.juneau.parser.Parser} API for defining parsers for parsing request body content and converting them into POJOs.

The servlet will pick which parser to use by matching the request Content-Type header with the media types defined through the {@link org.apache.juneau.parser.Parser#getMediaTypes()} method.

Parsers can be associated with REST servlets in the following ways:

- {@link org.apache.juneau.rest.annotation.Rest#parsers() Rest(parsers)} - Annotation on resource Java class.
- {@link org.apache.juneau.rest.annotation.RestMethod#parsers() RestMethod(parsers)} - Annotation on resource Java method.
- {@link org.apache.juneau.rest.RestContextBuilder#parsers(Class[])} - Programmatic.

The following are all equivalent ways of defining parsers used by a resource:

// Option #1 - Defined via annotation. @Rest(parsers={JsonParser.class, XmlParser.class}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContextBuilder builder) throws Exception { // Using method on builder. builder.parsers(JsonParser.class, XmlParser.class); // Same, but use pre-instantiated parsers. builder.parsers(JsonParser.DEFAULT, XmlParser.DEFAULT); // Same, but using property. builder.set(REST_parsers, JsonParser.class, XmlParser.class); } // Option #3 - Defined via builder passed in through init method. @RestHook(INIT) public void init(RestContextBuilder builder) throws Exception { builder.parsers(JsonParser.class, XmlParser.class); } // Override at the method level. @RestMethod(parsers={HtmlParser.class}) public Object myMethod(@Body MyPojo myPojo) { // Do something with your parsed POJO. } }

- {@link org.apache.juneau.rest.RestContext#REST_parsers}

### 6.15 - Configurable Properties 8.1.0-updated

As shown in previous sections, Juneau serializers and parsers are highly-configurable through properties. (See {@doc ConfigurableProperties})

These properties can be defined for serializers and parsers registered on a REST resource via the following:

- {@link org.apache.juneau.rest.annotation.Rest#properties() Rest(properties)}
- {@link org.apache.juneau.rest.RestContextBuilder} - Various methods on the context builder.

##### Example:

import static org.apache.juneau.BeanContext.*; import static org.apache.juneau.serializer.Serializer.*; import static org.apache.juneau.json.JsonSerializer.*; // Servlet with properties applied @Rest( properties={ // Bean properties should be sorted alphabetically. @Property(name=BEAN_sortProperties, value="true"), // Nulls should not be serialized @Property(name=SERIALIZER_trimNulls, value="true"), // Solidus characters should be escaped in JSON @Property(name=JSON_escapeSolidus, value="true") } ) public MyRestServlet extends BasicRestServlet {...}

The programmatic equivalent to this is:

// Servlet with properties applied @Rest(...) public MyRestServlet extends BasicRestServlet { public MyRestServlet(RestContextBuilder builder) { builder .sortProperties(); // Note: RestContextBuilder extends from BeanContextBuilder .set(SERIALIZER_trimNulls, true); .set(JSON_escapeSolidus, true); } }

Properties can also be overridden at the Java method level:

- {@link org.apache.juneau.rest.annotation.RestMethod#properties() RestMethod(properties)}
- {@link org.apache.juneau.rest.RequestProperties}

// GET method with method-level properties @RestMethod( name=GET, path="/*", properties={ // Bean properties should be sorted alphabetically. @Property(name=BEAN_sortProperties, value="true"), // Nulls should not be serialized @Property(name=SERIALIZER_trimNulls, value="true"), // Solidus characters should be escaped in JSON @Property(name=JSON_escapeSolidus, value="true") } public Object doGet() { ... }

- {@link org.apache.juneau.rest.annotation.Rest#flags() Rest(flags)} - Shorthand for boolean properties.
- {@link org.apache.juneau.rest.annotation.RestMethod#flags() RestMethod(flags)} - Shorthand for boolean properties.
- {@link org.apache.juneau.rest.RestContextProperties}
- {@link org.apache.juneau.rest.RestMethodProperties}

### 6.16 - Configurable Annotations 8.1.0-new

Config annotations allow you to define serializer and parser properties using specialized annotations. All configuration properties have annotation-equivalents.

The following shows the difference between the two approaches:

##### Example:

// Servlet with properties applied @Rest( properties={ @Property(name=BEAN_sortProperties, value="true"), @Property(name=SERIALIZER_trimNulls, value="true"), @Property(name=JSON_escapeSolidus, value="true") } ) public MyRestServlet extends BasicRestServlet {...}

// Servlet with config annotations applied @Rest( ... ) @BeanConfig(sortProperties="true") @SerializerConfig(trimNulls="true") @JsonConfig(escapeSolidus="true") public MyRestServlet extends BasicRestServlet {...}

Using config annotations is often cleaner and supports the same SVL variable support as those in the REST annotations.

Config annotations are defined for all serializers and parsers:

- {@link org.apache.juneau.annotation.BeanConfig BeanConfig}
- {@link org.apache.juneau.csv.annotation.CsvConfig CsvConfig}
- {@link org.apache.juneau.html.annotation.HtmlConfig HtmlConfig}
- {@link org.apache.juneau.html.annotation.HtmlDocConfig HtmlDocConfig}
- {@link org.apache.juneau.jso.annotation.JsoConfig JsoConfig}
- {@link org.apache.juneau.json.annotation.JsonConfig JsonConfig}
- {@link org.apache.juneau.jsonschema.annotation.JsonSchemaConfig JsonSchemaConfig}
- {@link org.apache.juneau.msgpack.annotation.MsgPackConfig MsgPackConfig}
- {@link org.apache.juneau.oapi.annotation.OpenApiConfig OpenApiConfig}
- {@link org.apache.juneau.parser.annotation.ParserConfig ParserConfig}
- {@link org.apache.juneau.plaintext.annotation.PlainTextConfig PlainTextConfig}
- {@link org.apache.juneau.jena.annotation.RdfConfig RdfConfig}
- {@link org.apache.juneau.serializer.annotation.SerializerConfig SerializerConfig}
- {@link org.apache.juneau.soap.annotation.SoapXmlConfig SoapXmlConfig}
- {@link org.apache.juneau.uon.annotation.UonConfig UonConfig}
- {@link org.apache.juneau.urlencoding.annotation.UrlEncodingConfig UrlEncodingConfig}
- {@link org.apache.juneau.xml.annotation.XmlConfig XmlConfig}

Config annotations can be defined at both the class and method level just like properties.

### 6.17 - Transforms 8.1.0-updated

The Juneau serializers and parsers can be configured on how to handle POJOs through the use of Transforms. (See {@doc juneau-marshall.Transforms Transforms})

Transforms are associated serializers and parsers registered on a REST resource via the following:

- {@link org.apache.juneau.annotation.BeanConfig#beanFilters() BeanConfig(beanFilters)} - On class or methods.
- {@link org.apache.juneau.annotation.BeanConfig#pojoSwaps() BeanConfig(pojoSwaps)} - On class or methods.
- {@link org.apache.juneau.rest.RestContextBuilder#beanFilters(Object...)}
- {@link org.apache.juneau.rest.RestContextBuilder#pojoSwaps(Object...)}

// Servlet with transforms applied @Rest( ... ) @BeanConfig( pojoSwaps={ // Calendars should be serialized/parsed as ISO8601 date-time strings TemporalCalendarSwap.IsoInstant.class, // Byte arrays should be serialized/parsed as BASE64-encoded strings ByteArraySwap.Base64.class }, beanFilters={ // Subclasses of MyInterface will be treated as MyInterface objects. // Bean properties not defined on that interface will be ignored. MyInterface.class } ) public MyRestServlet extends BasicRestServlet {...}

The programmatic equivalent to this is:

// Servlet with properties applied @Rest(...) public MyRestServlet extends BasicRestServlet { public MyRestServlet(RestContextBuilder builder) { builder .pojoSwaps( TemporalCalendarSwap.IsoInstant.class, ByteArraySwap.Base64.class ) .beanFilters(MyInterface.class); } }

### 6.18 - URIs

As mention earlier {@doc juneau-marshall.URIs here}, Juneau serializers have sophisticated support for transforming relative URIs to absolute form.

The following example shows a REST method that returns a list of URIs of various forms:

@Rest( uriAuthority="http://foo.com:123", uriContext="/myContext" ) public class MyResource { @RestMethod public URI[] getURIs() { return new URI[] { URI.create("http://www.apache.org/f1a"), URI.create("/f1b"), URI.create("/f1c/x/y"), URI.create("f1d"), URI.create("f1e/x/y"), URI.create(""), URI.create("context:/f2a/x"), URI.create("context:/f2b"), URI.create("context:/"), URI.create("context:/.."), URI.create("servlet:/f3a/x"), URI.create("servlet:/f3b"), URI.create("servlet:/"), URI.create("servlet:/.."), URI.create("request:/f4a/x"), URI.create("request:/f4b"), URI.create("request:/"), URI.create("request:/..") }; } }

When requested as JSON, it produces the following result:

{ f1a:'http://www.apache.org/f1a', f1b:'http://foo.com:123/f1b', f1c:'http://foo.com:123/f1c/x/y', f1d:'http://foo.com:123/myContext/myServlet/f1d', f1e:'http://foo.com:123/myContext/myServlet/f1e/x/y', f1f:'http://foo.com:123/myContext/myServlet', f2a:'http://foo.com:123/myContext/f2a/x', f2b:'http://foo.com:123/myContext/f2b', f2c:'http://foo.com:123/myContext', f2d:'http://foo.com:123', f3a:'http://foo.com:123/myContext/myServlet/f3a/x', f3b:'http://foo.com:123/myContext/myServlet/f3b', f3c:'http://foo.com:123/myContext/myServlet', f3d:'http://foo.com:123/myContext', f4a:'http://foo.com:123/myContext/myServlet/myPath/f4a/x', f4b:'http://foo.com:123/myContext/myServlet/myPath/f4b', f4c:'http://foo.com:123/myContext/myServlet/myPath', f4d:'http://foo.com:123/myContext/myServlet' }

URI resolution is controlled by the following settings:

- {@link org.apache.juneau.rest.RestContext}
  - {@link org.apache.juneau.rest.RestContext#REST_uriAuthority REST_uriAuthority}
  - {@link org.apache.juneau.rest.RestContext#REST_uriContext REST_uriContext}
  - {@link org.apache.juneau.rest.RestContext#REST_uriRelativity REST_uriRelativity}
  - {@link org.apache.juneau.rest.RestContext#REST_uriResolution REST_uriResolution}

URIs are resolved by both regular and part serializers.

### 6.19 - Guards

Guards are classes that control access to REST classes and methods.

Guards are associated with resource classes and methods via the following:

- {@link org.apache.juneau.rest.annotation.Rest#guards() Rest(guards)}
- {@link org.apache.juneau.rest.annotation.RestMethod#guards() RestMethod(guards)}
- {@link org.apache.juneau.rest.RestContextBuilder#guards(Class...)}

// Define a guard that only lets Billy make a request public BillyGuard extends RestGuard { @Override /* RestGuard */ public boolean isRequestAllowed(RestRequest req) { return req.getUserPrincipal().getName().equals("Billy"); } } // Servlet with class-level guard applied @Rest(guards=BillyGuard.class) public MyRestServlet extends BasicRestServlet { // Delete method that only Billy is allowed to call. @RestMethod(name="DELETE") public doDelete(RestRequest req, RestResponse res) throws Exception {...} }

A common use for guards is to only allow admin access to certain Java methods...

// DELETE method @RestMethod(name=DELETE, guards={AdminGuard.class}) public void doDelete(RestRequest req, RestResponse res) throws Exception {...}

public class AdminGuard extends RestGuard { @Override /* RestGuard */ public boolean isRequestAllowed(RestRequest req) { return req.getUserPrincipal().isUserInRole("ADMIN"); } }

A guard failure results in an HTTP 401 Unauthorized response. However, this can be configured by overriding the {@link org.apache.juneau.rest.RestGuard#guard(RestRequest,RestResponse)} and processing the response yourself.

public class AdminGuard extends RestGuard { @Override /* RestGuard */ public boolean guard(RestRequest req, RestResponse res) throws RestException { if (! isOkay(req)) throw new RestException(SC_FORBIDDEN, "Access denied!!!"); return true; } }

When guards are associated at the class-level, it's equivalent to associating guards on all Java methods on the servlet. If multiple guards are present, ALL guards must pass.

- {@link org.apache.juneau.rest.RestContext#REST_guards}

### 6.20 - Role guards 8.1.0-new

Specialized guards are provided for controlling access to servlet classes and methods based on user roles. These are controlled via annotations on the REST class and methods:

- {@link org.apache.juneau.rest.annotation.Rest}
  - {@link org.apache.juneau.rest.annotation.Rest#roleGuard() roleGuard()}
  - {@link org.apache.juneau.rest.annotation.Rest#rolesDeclared() rolesDeclared()}
- {@link org.apache.juneau.rest.annotation.RestMethod}
  - {@link org.apache.juneau.rest.annotation.RestMethod#roleGuard() roleGuard()}
  - {@link org.apache.juneau.rest.annotation.RestMethod#rolesDeclared() rolesDeclared()}

The roleGuard() annotation is an expression that defines whether a user with specified roles are allowed to access methods.

##### Example:

// Only admin users or users with both read/write and special access // can run any methods on this class. @Rest( path="/foo", roleGuard="ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)" ) public class MyResource extends RestServlet { ... }

The syntax allows for any of the following:

- "foo" - Single arguments.
- "foo,bar,baz" - Multiple OR'ed arguments.
- "foo | bar | baz" - Multiple OR'ed arguments, pipe syntax.
- "foo || bar || baz" - Multiple OR'ed arguments, Java-OR syntax.
- "fo*" - Patterns including '*' and '?'.
- "fo* & *oo" - Multiple AND'ed arguments, ampersand syntax.
- "fo* && *oo" - Multiple AND'ed arguments, Java-AND syntax.
- "fo* || (*oo || bar)" - Parenthesis.

If patterns are used, you must specify the list of declared roles using the rolesDeclared() annotations. This declares the list of all possible user roles and is needed because the servlet API does not provide this capability.

##### Example:

@Rest( rolesDeclared="ROLE_ADMIN,ROLE_READ_WRITE,ROLE_READ_ONLY,ROLE_SPECIAL", roleGuard="ROLE_ADMIN || (*WRITE* && *SPECIAL*)" ) public class MyResource extends RestServlet { ... }

### 6.21 - Converters

Converters can be thought of as "post-processors" for POJOs before they get passed to the serializers.

Converters are associated with resource classes and methods via the following:

- {@link org.apache.juneau.rest.annotation.Rest#converters() Rest(converters)}
- {@link org.apache.juneau.rest.annotation.RestMethod#converters() RestMethod(converters)}
- {@link org.apache.juneau.rest.RestContextBuilder#converters(Class...)}

##### Example:

// Associate the Traversable converter to all Java REST methods in this servlet @Rest(converters=Traversable.class) public MyRestServlet extends BasicRestServlet { ... }

They can also be defined at the method level:

// GET person request handler. // Traversable conversion enabled to allow nodes in returned POJO tree to be addressed. // Queryable conversion enabled to allow returned POJO to be searched/viewed/sorted. @RestMethod( name=GET, path="/people/{id}/*", converters={Traversable.class,Queryable.class} ) public Person getPerson(@Path("id") int id) { return findPerson(id); }

The following converter is used to provide support for addressing child nodes in a POJO tree with URL path remainders. In this code, the 3rd parameter is the object that was returned by the Java method. The converter uses the {@link org.apache.juneau.utils.PojoRest} wrapper class to address nodes in the tree.

/** * Converter for enablement of PojoRest support on response objects returned by a @RestMethod method. * When enabled, objects in a POJO tree returned by the REST method can be addressed through additional URL path information. */ public class Traversable implements RestConverter { @Override /* RestConverter */ public Object convert(RestRequest req, Object o) throws RestException { if (o == null) return null; String pathRemainder = req.getPathMatch().getRemainder(); if (pathRemainder != null) { try { // Use the PojoRest class to traverse our POJO model. PojoRest p = new PojoRest(o); o = p.get(pathRemainder); } catch (PojoRestException e) { throw new RestException(e.getStatus(), e); } catch (Exception e) { throw new RestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e); } } return o; } }

Juneau defines the following converters out-of-the-box:

- {@link org.apache.juneau.rest.RestConverter}
  - {@link org.apache.juneau.rest.converters.Queryable}
    Provides query parameters that can be used to transform the response (i.e. search/view/sort the POJO response before being serialized).
  - {@link org.apache.juneau.rest.converters.Traversable}
    Allows nodes in the POJO response tree to be individually accessed through additional path info on the request.
  - {@link org.apache.juneau.rest.converters.Introspectable}
    Allows method calls to be made on the response POJO, and for the result of that method call to be serialized as the response.

- {@link org.apache.juneau.rest.RestContext#REST_converters}

### 6.22 - Messages

The {@link org.apache.juneau.rest.annotation.Rest#messages @Rest(messages)} annotation is used to associate a resource bundle with a servlet class.

// Servlet with associated resource bundle @Rest(messages="nls/MyMessages") public MyRestServlet extends BasicRestServlet { // Returns the localized greeting from the "greeting" key in MyMessages.properties @RestMethod(name=GET, path="/") public String printLocalizedGreeting(RestRequest req) { return req.getMessage("greeting"); }

The resource bundle can also be passed into the method by simply specifying a parameter of type {@link java.util.ResourceBundle} or {@link org.apache.juneau.utils.MessageBundle}:

@RestMethod(name=GET) public String printLocalizedGreeting(MessageBundle messages) { return messages.getString("greeting"); }

If a resource bundle is shared by multiple servlets, the label and description can be prefixed by the class name:

#-------------------------------------------------------------------------------- # Contents of MyMessages.properties #-------------------------------------------------------------------------------- greeting = Hello!

#-------------------------------------------------------------------------------- # Contents of shared MyMessages.properties #-------------------------------------------------------------------------------- MyRestServlet.greeting = Hello!

- {@link org.apache.juneau.rest.RestContext#REST_messages}

### 6.23 - Encoders

The {@link org.apache.juneau.rest.annotation.Rest#encoders @Rest(encoders)} annotation can be used to associate character encoders with a servlet class. Encoders can be used to enable various kinds of compression (e.g. "gzip") on requests and responses based on the request Accept-Encoding and Content-Encoding headers.

##### Example:

// Servlet with automated support for GZIP compression @Rest(encoders={GzipEncoder.class}) public MyRestServlet extends BasicRestServlet { ... }

Juneau defines the following encoders out-of-the-box:

- {@link org.apache.juneau.encoders.Encoder}
  - {@link org.apache.juneau.encoders.GzipEncoder}
  - {@link org.apache.juneau.encoders.IdentityEncoder}

- {@link org.apache.juneau.rest.RestContext#REST_encoders}

### 6.24 - SVL Variables

In the previous examples, there were several cases where embedded variables were contained within annotation values:

@Rest( title="$L{my.label}" )

Variables take the form $X{contents} where X can consist of zero or more ASCII characters and contents can be virtually anything. This is called Simple Variable Language, or SVL, and is defined here: {@doc juneau-marshall.SimpleVariableLanguage Simple Variable Language}.

##### Features

- Variables can be nested arbitrarily deep (e.g. "$X{$Y{foo}}").
- Variables can contain arguments (e.g. "$L{my.label,arg1,arg2}").
- Variables are recursively resolved.
  i.e., if a variable results to a value with another variable in it, that variable will also be resolved (restricted for security reasons on some variables).

Variables are configured on resources via the following API:

- {@link org.apache.juneau.rest.RestContextBuilder#vars(Class[])}

##### Example:

// Defined a variable that simply wrapps all strings inside [] brackets. // e.g. "$BRACKET{foobar}" -> "[foobar]" public class BracketVar extends SimpleVar { public BracketVar() { super("BRACKET"); } @Override /* Var */ public String resolve(VarResolverSession session, String arg) { return '[' + arg + ']'; } } // Register it with our resource. @Rest(...) public class MyResource { public MyResource(RestContextBuilder builder) { builder.vars(BracketVar.class); } }

The methods involved with variables are:

- {@link org.apache.juneau.rest.RestContext#getVarResolver()}
- {@link org.apache.juneau.rest.RestRequest#getVarResolverSession()}
- {@link org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String,boolean)}

There are two distinct groups of variables:

- Initialization-time variables
  These are variables that can be used in many of the annotations in {@link org.apache.juneau.rest.annotation.Rest @Rest}.
  The {@link org.apache.juneau.rest.RestContext#getVarResolver()} method returns initialization-time variables only.
- Request-time variables
  These are variables that are available during HTTP-requests and can be used on annotation such as {@link org.apache.juneau.rest.annotation.HtmlDoc @HtmlDoc}.
  {@link org.apache.juneau.rest.RestRequest#getVarResolverSession()} method returns initialization and request-time variables.

The following is the default list of supported variables.

##### Default REST SVL Variables:

Module | Class | Pattern | Initialization time | Request time | Examples
--- | --- | --- | --- | --- | ---
juneau-svl | {@link org.apache.juneau.svl.vars.EnvVariablesVar} | $E{key[,default]} | yes | yes | $E{PATH}
{@link org.apache.juneau.svl.vars.SystemPropertiesVar} | $S{key[,default]} | yes | yes | $S{java.home}
{@link org.apache.juneau.svl.vars.ArgsVar} | $A{key[,default]} | yes | yes | $A{foo,null}
{@link org.apache.juneau.svl.vars.ManifestFileVar} | $MF{key[,default]} | yes | yes | $MF{Main-Class}
{@link org.apache.juneau.svl.vars.IfVar} | $IF{arg,then[,else]} | yes | yes | $IF{$S{my.boolean.property},foo,bar}
{@link org.apache.juneau.svl.vars.SwitchVar} | $SW{arg,p1:then1[,p2:then2...]} | yes | yes | $SW{$P{os.name},*win*:Windows,*:Something else}
{@link org.apache.juneau.svl.vars.CoalesceVar} | $CO{arg1[,arg2...]} | yes | yes | $CO{$S{my.property},$E{my.property},n/a}
{@link org.apache.juneau.svl.vars.PatternMatchVar} | $PM{arg,pattern} | yes | yes | $PM{$P{os.name},*win*}
{@link org.apache.juneau.svl.vars.NotEmptyVar} | $NE{arg} | yes | yes | $NE{$S{foo}}
{@link org.apache.juneau.svl.vars.UpperCaseVar} | $UC{arg} | yes | yes | $UC{$S{foo}}
{@link org.apache.juneau.svl.vars.LowerCaseVar} | $LC{arg} | yes | yes | $LC{$S{foo}}
juneau-config | {@link org.apache.juneau.config.vars.ConfigVar} | $C{key[,default]} | yes | yes | $C{REST/staticFiles}
juneau-rest-server | {@link org.apache.juneau.rest.vars.FileVar} | $F{path[,default]}} | yes | yes | $F{resources/MyAsideMessage.html, Oops not found!}
{@link org.apache.juneau.rest.vars.ServletInitParamVar} | $I{name[,default]} | yes | yes | $I{my.param}
{@link org.apache.juneau.rest.vars.LocalizationVar} | $L{key[,args...]} | no | yes | $L{MyMessage,foo,bar}
{@link org.apache.juneau.rest.vars.RequestAttributeVar} | $RA{key1[,key2...]} | no | yes | $RA{attrName}
{@link org.apache.juneau.rest.vars.RequestFormDataVar} | $RF{key1[,key2...]} | no | yes | $RF{paramName}
{@link org.apache.juneau.rest.vars.RequestHeaderVar} | $RH{key1[,key2...]} | no | yes | $RH{Header-Name}
{@link org.apache.juneau.rest.vars.RequestPathVar} | $RP{key1[,key2...]} | no | yes | $RP{pathVAr}
{@link org.apache.juneau.rest.vars.RequestQueryVar} | $RQ{key1[,key2...]} | no | yes | $RQ{paramName}
{@link org.apache.juneau.rest.vars.RequestVar} | $R{key1[,key2...]} | no | yes | $R{contextPath}
{@link org.apache.juneau.rest.vars.RestInfoVar} | $RI{key} | no | yes | $RI{externalDocs}
{@link org.apache.juneau.rest.vars.SerializedRequestAttrVar} | $SA{contentType,key[,default]} | no | yes | $SA{application/json,$RA{foo}}
{@link org.apache.juneau.rest.vars.UrlVar} | $U{uri}> | no | yes | $U{servlet:/foo}
{@link org.apache.juneau.rest.vars.UrlEncodeVar} | $UE{uriPart} | yes | yes | $U{servlet:/foo?bar=$UE{$RA{bar}}
{@link org.apache.juneau.rest.vars.WidgetVar} | $W{name} | no | yes | $W{MenuItemWidget}

### 6.25 - Configuration Files

The Server API provides methods for associating configuration files with REST servlets so that configuration properties can be defined in external files.

In recap, the Configuration API provides support for INI-style configuration files with embedded string variables:

##### Example:

#-------------------------- # Examples #-------------------------- [MyProperties] path = $E{PATH} javaHome = $S{java.home} customMessage = Java home is $C{MyProperties/javaHome} and the environment path is $C{MyProperties/path}.

These properties are then accessible through the {@link org.apache.juneau.config.Config} class.

Config c = Config.create("myconfig.cfg").build(); String path = c.getString("MyProperties/path"); File javaHome = c.getObject("MyProperties/javaHome", File.class); String customMessage = c.getString("MyProperties/customMessage");

Configuration files are associated with REST resources through the following:

- {@link org.apache.juneau.rest.annotation.Rest#config() Rest(config)}

##### Example:

@Rest( // Config file is located at ./config_dir/myconfig.cfg config="config_dir/myconfig.cfg", ... ) public class MyResource {...}

The annotation itself can contain string variables. For example, the Microservice API {@link org.apache.juneau.rest.BasicRestServlet} class defines the location of the config file as a system property "juneau.configFile":

@Rest( // Config file location is defined as a system property config="$S{juneau.configFile}", ... ) public class MyResource {...}

Once a config file has been associated with a REST resource, it can be accessed through the {@link org.apache.juneau.rest.RestContextBuilder#getConfig()} method.

A common usage is to use this method to initialize fields in your servlet.

@Rest( // Config file is located at ./config_dir/myconfig.cfg config="config_dir/myconfig.cfg", ... ) public class MyResource { private final String path; private final File javaHome; public MyResource(RestContextBuilder builder) { Config c = builder.getConfig(); path = c.getString("MyProperties/path"); javaHome = c.getObject(File.class, "MyProperties/javaHome"); }

Another common usage is to refer to config properties through $C variables in your annotations:

@Rest( // Get stylesheet from myconfig.cfg, but default to devops.css if it's not specified htmldoc=@HtmlDoc( stylesheet="$C{MyServlet/stylesheet,servlet:/styles/devops.css}", ) ... ) public class MyResource {...}

It's even possible to reference request-level variables in your config file if you use {@link org.apache.juneau.rest.RestRequest#getConfig()} to access the config file:

#------------------------------------- # Contents of config_dir/myconfig.cfg #------------------------------------- [HelloWorldResource] message = Hello $RQ{person}!

/** * Sample REST resource that prints out a simple "Hello world!" message. */ @Rest( config="config_dir/myconfig.cfg", ... ) public class HelloWorldResource extends BasicRestServlet { /** * GET request handler. * Specify the GET parameter "?person=X" for a specialized message! */ @RestMethod(name=GET, path="/") public String sayHello(RestRequest req) { return req.getConfig().getString("HelloWorldResource/message"); } }

You can even add resource bundles into the mix:

#------------------------------------- # Contents of config_dir/myconfig.cfg #------------------------------------- [HelloWorldResource] message = $L{localizedMessage,$RQ{person}}

#------------------------------------------- # Contents of HelloWorldResource.properties #------------------------------------------- localizedMessage = Hello {0}!

/** * Sample REST resource that prints out a simple "Hello world!" message. */ @Rest( messages="HelloWorldResources", config="config_dir/myconfig.cfg", ... ) public class HelloWorldResource extends BasicRestServlet { /** * GET request handler. * Specify the GET parameter "?person=X" for a specialized message! */ @RestMethod(name=GET, path="/") public String sayHello(RestRequest req) { return req.getConfig().getString("HelloWorldResource/message"); } }

- {@doc juneau-config}

### 6.26 - Static files

The {@link org.apache.juneau.rest.annotation.Rest#staticFiles @Rest(staticFiles)} annotation is used to define paths and locations of statically-served files such as images or HTML documents.

The value is a JSON map of paths to packages/directories located on either the classpath or working directory.

##### Example:

package com.foo.mypackage; @Rest( path="/myresource", staticFiles={"htdocs:docs"} ) public class MyResource extends BasicRestServlet {...}

Static files are found by calling {@link java.lang.Class#getResource(String)} up the class hierarchy. If not found, then an attempt is made to find the class in the Java working directory.

In the example above, given a GET request to /myresource/htdocs/foobar.html, the servlet will attempt to find the foobar.html file in the following ordered locations:

1. com.foo.mypackage.docs package.
2. [working-dir]/docs directory.

- Mappings are cumulative from parent to child.
  Child resources can override mappings made on parent resources.
- The media type on the response is determined by the {@link org.apache.juneau.rest.RestContext#getMediaTypeForName(String)} method.

- {@link org.apache.juneau.rest.RestContext#REST_staticFiles}

### 6.27 - Client Versioning

Client version headers are used to support backwards compatibility for breaking REST interface changes. Using them, you're able to return different responses based on which client is making a request.

The APIs involved with defining client version headers are:

- {@link org.apache.juneau.rest.annotation.Rest#clientVersionHeader() Rest(clientVersionHeader)}
- {@link org.apache.juneau.rest.RestContextBuilder#clientVersionHeader(String)}
- {@link org.apache.juneau.rest.annotation.RestMethod#clientVersion() RestMethod(clientVersion)}

##### Example:

// Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(clientVersionHeader="Client-Version") public class MyResource { // Call this method if Client-Version is at least 2.0. // Note that this also matches 2.0.1. @RestMethod(name=GET, path="/foobar", clientVersion="2.0") public Object method1() { ... } // Call this method if Client-Version is at least 1.1, but less than 2.0. @RestMethod(name=GET, path="/foobar", clientVersion="[1.1,2.0)") public Object method2() { ... } // Call this method if Client-Version is less than 1.1. @RestMethod(name=GET, path="/foobar", clientVersion="[0,1.1)") public Object method3() { ... }

- {@link org.apache.juneau.rest.RestContext#REST_clientVersionHeader}

### 6.28 - RestInfoProvider

The {@link org.apache.juneau.rest.RestInfoProvider} class is used to find the title and description for your resource and also generate the Swagger documentation. It can be overridden to provide your own custom Swagger documentation.

The methods on this interface are:

- {@link org.apache.juneau.rest.RestInfoProvider}
  - {@link org.apache.juneau.rest.RestInfoProvider#getSwagger(RestRequest) getSwagger(RestRequest)}
  - {@link org.apache.juneau.rest.RestInfoProvider#getSiteName(RestRequest) getSiteName(RestRequest)}
  - {@link org.apache.juneau.rest.RestInfoProvider#getTitle(RestRequest) getTitle(RestRequest)}
  - {@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest) getDescription(RestRequest)}
  - {@link org.apache.juneau.rest.RestInfoProvider#getMethodSummary(Method,RestRequest) getMethodSummary(Method,RestRequest)}
  - {@link org.apache.juneau.rest.RestInfoProvider#getMethodDescription(Method,RestRequest) getMethodDescription(Method,RestRequest)}

The info provider in turn supplies the information returned by the following methods:

- {@link org.apache.juneau.rest.RestRequest}
  - {@link org.apache.juneau.rest.RestRequest#getSwagger() getSwagger()}
  - {@link org.apache.juneau.rest.RestRequest#getSiteName() getSiteName()}
  - {@link org.apache.juneau.rest.RestRequest#getResourceTitle() getResourceTitle()}
  - {@link org.apache.juneau.rest.RestRequest#getResourceDescription() getResourceDescription()}
  - {@link org.apache.juneau.rest.RestRequest#getMethodSummary() getMethodSummary()}
  - {@link org.apache.juneau.rest.RestRequest#getMethodDescription() getMethodDescription()}

Info providers are registered through the following property:

- {@link org.apache.juneau.rest.RestContext#REST_infoProvider}

While you can implement this interface from scratch, you may want to instead consider extending from the BasicRestInfoProvider class described next.

#### 6.28.1 - BasicRestInfoProvider

The {@link org.apache.juneau.rest.BasicRestInfoProvider} class is the default implementation of the {@link org.apache.juneau.rest.RestInfoProvider} interface.

It finds and collects information gathered from the following locations:

- Localized JSON Swagger files in the classpath.
- Reflection.
- Annotations.
- Properties files.

The class itself is designed to be extended if you wish to rely mostly on the default behavior, but tweak certain aspects.

### 6.29 - Swagger

One of the most useful features of Juneau is the ability to generate Swagger-based OPTIONS pages for self-documenting designs (i.e. REST interfaces that document themselves).

As described previously, the PetStore example provides an example of auto-generated Swagger JSON:

Using {@link org.apache.juneau.dto.swagger.ui.SwaggerUI}, we're able to render that JSON as a Swagger user interface:

#### 6.29.1 - BasicRestServlet 8.1.0-updated

Any subclass of {@link org.apache.juneau.rest.BasicRestServlet} gets an auto-generated Swagger UI when performing an OPTIONS request with Accept:text/html.

The underlying mechanics are simple. The {@link org.apache.juneau.rest.BasicRestServlet#getOptions(RestRequest)} method returns a {@link org.apache.juneau.dto.swagger.Swagger} bean consisting of information gathered from annotations and other sources. Then that bean is swapped for a {@link org.apache.juneau.dto.swagger.ui.SwaggerUI} bean when rendered as HTML.

Here's the class that defines the behavior:

@Rest( // Allow OPTIONS requests to be simulated using ?method=OPTIONS query parameter. allowedMethodParams="OPTIONS", ... ) public abstract class BasicRestServlet extends RestServlet implements BasicRestConfig { /** * [OPTIONS /*] - Show resource options. * * @param req The HTTP request. * @return A bean containing the contents for the OPTIONS page. */ @RestMethod(name=OPTIONS, path="/*", summary="Swagger documentation", description="Swagger documentation for this resource.", htmldoc=@HtmlDoc( // Override the nav links for the swagger page. navlinks={ "back: servlet:/", "json: servlet:/?method=OPTIONS&Accept=text/json&plainText=true" }, // Never show aside contents of page inherited from class. aside="NONE" ) ) @JsonSchemaConfig( // Add descriptions to the following types when not specified: addDescriptionsTo="bean,collection,array,map,enum", // Add x-example to the following types: addExamplesTo="bean,collection,array,map", // Don't generate schema information on the Swagger bean itself or HTML beans. ignoreTypes="Swagger,org.apache.juneau.dto.html5.*", // Use $ref references for bean definitions to reduce duplication in Swagger. useBeanDefs="true" ) @BeanConfig( // When parsing generated beans, ignore unknown properties that may only exist as getters and not setters. ignoreUnknownBeanProperties="true", // POJO swaps to apply to all serializers/parsers on this method. pojoSwaps={ // Use the SwaggerUI swap when rendering Swagger beans. // This is a per-media-type swap that only applies to text/html requests. SwaggerUI.class } ) public Swagger getOptions(RestRequest req) { // Localized Swagger for this resource is available through the RestRequest object. return req.getSwagger(); } }

Note that to have your resource create Swagger UI, you must either extend from {@link org.apache.juneau.rest.BasicRestServlet} or provide your own @RestMethod-annotated method that returns a {@link org.apache.juneau.dto.swagger.Swagger} object and a {@link org.apache.juneau.dto.swagger.ui.SwaggerUI} swap.

#### 6.29.2 - Basic Swagger Info

Let's look at the various parts of the Petstore application Swagger UI to see how they are defined.

The top part of the page shows general information about the REST interface:

The information is pulled from the {@link org.apache.juneau.rest.annotation.Rest#swagger() @Rest(swagger)} annotation.

##### org.apache.juneau.examples.rest.petstore.PetStoreResource

@Rest( path="/petstore", title="Petstore application", ... swagger=@ResourceSwagger("$F{PetStoreResource.json}"), ... ) public class PetStoreResource extends BasicRestServletJena {...}

In this particular case, the Swagger is pulled in from a localized Swagger JSON file located in the org.apache.juneau.examples.rest.petstore package using the {@link org.apache.juneau.rest.vars.FileVar $F} variable.

##### PetStoreResource.json

{ "swagger": "2.0", "info": { "version": "1.0.0", "title": "Swagger Petstore", "termsOfService": "You are on your own.", "contact": { "name": "Juneau Development Team", "email": "dev@juneau.apache.org", "url": "http://juneau.apache.org" }, "license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html" } }, "externalDocs": { "description": "Find out more about Juneau", "url": "http://juneau.apache.org" }, ... }

Note that the {@link org.apache.juneau.rest.vars.FileVar $F} variable allows for request-locale-sensitive name matching so that you can provide localized Swagger information.

The {@link org.apache.juneau.rest.vars.FileVar $F} variable simply expands to a string to fill the {@link org.apache.juneau.rest.annotation.ResourceSwagger#value() @ResourceSwagger(value)} annotation. You could equivalently embed JSON directly into your annotation like so:

@Rest( path="/petstore", title="Petstore application", ... swagger=@ResourceSwagger( // Raw Simplified JSON. // Values are concatenated. "{", "swagger: '2.0',", "version: '1.0.0',", ... "}" ), ... ) public class PetStoreResource extends BasicRestServletJena {...}

However, a more typical (and less error-prone) scenario is to define all of your Swagger as annotations:

@Rest( path="/petstore", title="Petstore application", ... swagger=@ResourceSwagger( version="1.0.0", title="Swagger Petstore", termsOfService="You are on your own.", contact=@Contact( name="Juneau Development Team", email="dev@juneau.apache.org", url="http://juneau.apache.org" ), license=@License( name="Apache 2.0", url="http://www.apache.org/licenses/LICENSE-2.0.html" ), externalDocs=@ExternalDocs( description="Find out more about Juneau", url="http://juneau.apache.org" ) ), ... ) public class PetStoreResource extends BasicRestServletJena {...}

All annotations support {@doc DefaultRestSvlVariables SVL variables}, so you could for example pull localized strings from resource bundles using {@link org.apache.juneau.rest.vars.LocalizationVar $L} variables.

@Rest( path="/petstore", title="Petstore application", messages="nls/MyMessages", ... swagger=@ResourceSwagger( version="1.0.0", title="$L{myTitle}", termsOfService="$L{myTermsOfService}", contact=@Contact( name="$L{myTeam}", email="dev@juneau.apache.org", url="http://juneau.apache.org" ), license=@License( name="Apache 2.0", url="http://www.apache.org/licenses/LICENSE-2.0.html" ), externalDocs=@ExternalDocs( description="$L{myExternalDocsDescription}", url="http://juneau.apache.org" ) ), ... ) public class PetStoreResource extends BasicRestServletJena {...}

A third option is to define your Swagger information in your {@link org.apache.juneau.rest.annotation.Rest#messages @Rest(messages)} resource bundle using predefined Swagger keywords:

PetStoreResource.version = 1.0.0 PetStoreResource.title = Swagger Petstore PetStoreResource.termsOfService = You are on your own. PetStoreResource.contact = {name:'Juneau Development Team', email:'dev@juneau.apache.org',...} PetStoreResource.license = {name:'Apache 2.0',...} PetStoreResource.externalDocs = {description:'Find out more about Juneau',...}

Information defined in multiple locations are merged into a single set of data. When the same information is provided in multiple locations, the following order-of-precedence is used:

1. Java annotations
2. Resource bundle
3. Swagger JSON file

#### 6.29.3 - Tags

Tags allow you to group operations into general categories. In the user interface, these can be expanded/collapsed by clicking on the tag sections. In the example below, the pet and store tag sections are collapsed and the user section is not:

Tags are also defined in the @ResourceSwagger annotation

##### PetStoreResource.json

"tags": [ { "name": "pet", "description": "Everything about your Pets", "externalDocs": { "description": "Find out more", "url": "http://juneau.apache.org" } }, { "name": "store", "description": "Access to Petstore orders" }, { "name": "user", "description": "Operations about user", "externalDocs": { "description": "Find out more about our store", "url": "http://juneau.apache.org" } } ],

The annotation-only approach is shown here:

##### org.apache.juneau.examples.rest.petstore.PetStoreResource

swagger=@ResourceSwagger( ... tags={ @Tag( name="pet", description="Everything about your Pets", externalDocs=@ExternalDocs( description="Find out more", url="http://juneau.apache.org" ) ), @Tag( name="store", description="Access to Petstore orders" ), @Tag( name="user", description="Operations about user", externalDocs=@ExternalDocs( description="Find out more about our store", url="http://juneau.apache.org" ) ) } ),

Tags are associated with operations using the {@link org.apache.juneau.rest.annotation.MethodSwagger#tags() @MethodSwagger(tags)} annotation:

##### GET /user operation

@RestMethod( name=GET, path="/user", summary="Petstore users", swagger=@MethodSwagger( tags="user" ) ) public Collection<User> getUsers() throws NotAcceptable {...}

Operations can be mapped to multiple tags.

Tags are optional. Operations not mapped to tags are listed in the UI before tagged operations.

For example, the getTopPage() method in PetStoreResource is not tagged, as well as the getOptions() method inherited from BaseRestServlet, so these show up at the top of the page:

#### 6.29.4 - Operations

@RestMethod-annotated methods automatically get rendered as Swagger operations:

The following shows the annotations defined on the GET /pet operation:

##### PetStoreResource.getPets()

@RestMethod( name=GET, path="/pet", summary="All pets in the store", swagger=@MethodSwagger( tags="pet", ... ), ... ) public Collection<Pet> getPets() throws NotAcceptable { return store.getPets(); }

Methods marked as deprecated will show up as deprecated in the Swagger UI:

##### PetStoreResource.findPetsByTag()

@RestMethod( name=GET, path="/pet/findByTags", summary="Finds Pets by tags", ... ) @Deprecated public Collection<Pet> findPetsByTags(...) { ... }

#### 6.29.5 - Parameters

Expanding operations shows you a list of parameters:

Parameter information can be defined in a couple of ways. The typical way is through annotations on parameters being passed to your @RestMethod-annotated method, like so:

@RestMethod( ... ) public Collection<Pet> getPets( @Query( name="s", description={ "Search.", "Key/value pairs representing column names and search tokens.", "'*' and '?' can be used as meta-characters in string fields.", "'>', '>=', '<', and '<=' can be used as limits on numeric and date fields.", "Date fields can be matched with partial dates (e.g. '2018' to match any date in the year 2018)." }, type="array", collectionFormat="csv", example="Bill*,birthDate>2000" ) String[] s, @Query( name="v", description={ "View.", "Column names to display." }, type="array", collectionFormat="csv", example="name,birthDate" ) String[] v, ... ) throws NotAcceptable { ... }

Note: The type and collectionFormat values above are optional and auto-detected based on the parameter class type if omitted. They're included here for clarity. The examples will be explained in the next section.

Another option is to specify your parameter information in the parameters annotation as free-form Simple JSON. In the case of the PetStoreResource.getPets() method, we pull this information from a static field defined in the {@link org.apache.juneau.rest.converters.Queryable} class:

##### PetStoreResource.getPets()

@RestMethod( name=GET, path="/pet", summary="All pets in the store", swagger=@MethodSwagger( tags="pet", parameters={ Queryable.SWAGGER_PARAMS } ), ... converters={Queryable.class} ) public Collection<Pet> getPets() throws NotAcceptable { return store.getPets(); }

##### Queryable

public class Queryable implements RestConverter { public static final String SWAGGER_PARAMS="" + "{" + "in:'query'," + "name:'s'," + "description:'" + "Search.\n" + "Key/value pairs representing column names and search tokens.\n" + "\\'*\\' and \\'?\\' can be used as meta-characters in string fields.\n" + "\\'>\\', \\'>=\\', \\'<\\', and \\'<=\\' can be used as limits on numeric and date fields.\n" + "Date fields can be matched with partial dates (e.g. \\'2018\\' to match any date in the year 2018)." + "'," + "type:'array'," + "collectionFormat:'csv'," + "x-examples:{example:'?s=Bill*,birthDate>2000'}" + "}," + "{" + "in:'query'," + "name:'v'," + "description:'" + "View.\n" + "Column names to display." + "'," + "type:'array'," + "collectionFormat:'csv'," + "x-examples:{example:'?v=name,birthDate'}" + "}," ... ; }

This information could have also been defined in the Swagger JSON for the resource as well.

The parameter section contains information about the request body as well for PUT and POST methods, as shown here:

The definition of this method is shown here:

@RestMethod( summary="Add a new pet to the store", swagger=@MethodSwagger( tags="pet" ) ) public Ok postPet( @Body(description="Pet object to add to the store") PetCreate pet ) throws IdConflict, NotAcceptable, UnsupportedMediaType { store.create(pet); return OK; }

Note that the schema information on the body parameter is automatically detected if not provided.

#### 6.29.6 - Parameter Examples 8.1.0-updated

The model select box in the parameters can be expanded to show examples:

The examples for query/form-data/path/header parameters can be defined using the example attribute on your annotated parameters as shown here:

@RestMethod( ... ) public Collection<Pet> getPets( @Query( name="s", description={ "Search.", "Key/value pairs representing column names and search tokens.", "'*' and '?' can be used as meta-characters in string fields.", "'>', '>=', '<', and '<=' can be used as limits on numeric and date fields.", "Date fields can be matched with partial dates (e.g. '2018' to match any date in the year 2018)." }, type="array", collectionFormat="csv", example="Bill*,birthDate>2000" ) ... ) throws NotAcceptable { ... }

This value gets converted to an x-examples attribute in your parameter information:

{ "swagger": "2.0", "paths": { "/pet": { "get": { "operationId": "getPets", "summary": "All pets in the store", "parameters": [ { "in": "query", "name": "s", ... "x-examples": { "example": "?s=Bill*,birthDate>2000" } }, ...

Examples for request bodies includes all supported Content-Type values:

These are based on the parsers registered on your servlet or method.

Selecting any of the content types shows you a representative example for the POJO:

There are several options for defining examples for request bodies:

- {@link org.apache.juneau.http.annotation.Body#example() @Body(example)} annotation.
- {@link org.apache.juneau.http.annotation.Body#examples() @Body(examples)} annotation.
- Defining an "x-examples" field in the inherited Swagger JSON body field (classpath file or @ResourceSwagger(value)/@MethodSwagger(value)).
- Defining an "x-examples" field in the Swagger Schema Object for the body (including referenced "$ref" schemas).
- Allowing Juneau to auto-generate a code example.

When using {@link org.apache.juneau.http.annotation.Body#example() @Body(example)}, you specify a Simple JSON representation of your POJO. The Swagger generator will then convert that JSON into a POJO using the registered serializers on the REST method to produce examples for all supported language types.

##### Example:

// A JSON representation of a PetCreate object. @Body( example="{name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}" )

The {@link org.apache.juneau.http.annotation.Body#examples() @Body(examples)} annotation allows you to specify raw output values per media type. This field allows you to override the behavior and show examples for only specified media types or different examples for different media types.

##### Example:

// A JSON representation of a PetCreate object. @Body( examples={ "'application/json':'{name:\\'Doggie\\',species:\\'Dog\\'}',", "'text/uon':'(name:Doggie,species=Dog)'" } )

The Swagger generator uses these to create an x-examples entry in your generated Swagger:

"/pet": { "post": { "operationId": "postPet", "summary": "Add a new pet to the store", "parameters": [ { "in": "body", "description": "Pet object to add to the store", "required": true, "schema": { "$ref": "#/definitions/PetCreate" }, "x-examples": { "application/json": "{\n\t\"name\": \"Doggie\",\n\t\"species\": \"Dog\",\n\t\"price\": 9.99,\n\t\"tags\": [\n...", "application/json+simple": "{\n\tname: 'Doggie',\n\tspecies: 'Dog',\n\tprice: 9.99,\n\ttags: [\n\t\t'friendly...", "text/xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<object>\n\t<name>Doggie</name&...", "text/html+stripped": "<table>\n\t<tr>\n\t\t<td>name</td>\n\t\t<td>Doggie</t...", "text/uon": "(\n\tname=Doggie,\n\tspecies=Dog,\n\tprice=9.99,\n\ttags=@(\n\t\tfriendly,\n\t\tcute\n\t)\n)", "application/x-www-form-urlencoded": "name=Doggie\n&species=Dog\n&price=9.99\n&tags=@(\n\tfriendly,\n\tcute\n)", "text/openapi": "(\n\tname=Doggie,\n\tspecies=Dog,\n\tprice=9.99,\n\ttags=@(\n\t\tfriendly,\n\t\tcute\n\t)\n)", "octal/msgpack": "84 A4 6E 61 6D 65 A6 44 6F 67 67 69 65 A7 73 70 65 63 69 65 73 A3 44 6F 67 A5 70 72 69 63 6...", "text/plain": "{name:'Doggie',species:'Dog',price:9.99,tags:['friendly','cute']}", "text/xml+rdf": "<rdf:RDF\n xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n xmlns:j=\"ht...", "text/turtle": "@prefix jp: <http://www.apache.org/juneaubp/> .\n@prefix j: <http://www.a...", "text/n-triple": "_:A59722791X3aX165d321a2b4X3aXX2dX7fca <http://www.apache.org/juneaubp/name> \"Doggie...", "text/n3": "@prefix jp: <http://www.apache.org/juneaubp/> .\n@prefix j: <http://www.apach..." } } ],

Another option is to define these directly in your resource Swagger JSON file, or via {@link org.apache.juneau.rest.annotation.Rest#swagger() @Rest(swagger)}/{@link org.apache.juneau.rest.annotation.RestMethod#swagger() @RestMethod(swagger)}.

Juneau also supports auto-generation of JSON-Schema directly from POJO classes. By default, the generated swagger uses to the {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_addExamplesTo JSONSCHEMA_addExamplesTo} setting to automatically add examples to beans, collections, arrays, and maps:

public abstract class BasicRestServlet extends RestServlet implements BasicRestConfig { @RestMethod(name=OPTIONS, path="/*", ... ) @JsonSchemaConfig( // Add x-example to the following types: addExamplesTo="bean,collection,array,map", ... ) public Swagger getOptions(RestRequest req) {...}

Examples can be defined via static methods, fields, and annotations on the classes themselves.

##### Examples:

// Annotation on class. @Example("{name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}") public class PetCreate { ... }

// Annotation on static method. public class PetCreate { @Example public static PetCreate sample() { return new PetCreate("Doggie", 9.99f, "Dog", new String[] {"friendly","cute"}); } }

// Static method with specific name 'example'. public class PetCreate { public static PetCreate example() { return new PetCreate("Doggie", 9.99f, "Dog", new String[] {"friendly","cute"}); } }

// Static field. public class PetCreate { @Example public static PetCreate EXAMPLE = new PetCreate("Doggie", 9.99f, "Dog", new String[] {"friendly","cute"}); }

Examples can also be specified via generic properties as well using the {@link org.apache.juneau.BeanContext#BEAN_examples} property or {@link org.apache.juneau.annotation.BeanConfig#examples() @BeanConfig(examples)} annotation at either the class or method level.

##### Example:

// Examples defined at class level. @Rest(...) @BeanConfig( examples="{PetCreate: {name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}}" )

- {@link org.apache.juneau.annotation.Example}
- {@link org.apache.juneau.BeanContext}
  - {@link org.apache.juneau.BeanContext#BEAN_examples BEAN_examples}
- {@link org.apache.juneau.jsonschema.JsonSchemaGenerator}
  - {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_addExamplesTo JSONSCHEMA_addExamplesTo}
  - {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_allowNestedExamples JSONSCHEMA_allowNestedExamples}

#### 6.29.7 - Responses

Under the input parameters are listed the possible responses for the resource:

The 200 response is determined by the return type on the method, in this case a collection of Pet objects:

@RestMethod( name=GET, path="/pet", summary="All pets in the store", ... ) public Collection<Pet> getPets() throws NotAcceptable { return store.getPets(); }

Note that additional responses can be specified by throwing exceptions annotated with the {@link org.apache.juneau.http.annotation.Response @Response} annotation such as this one:

@Response(code=406, description="Not Acceptable") public class NotAcceptable extends RestException {...}

Like input parameters, the Swagger for responses can be define in multiple locations such as:

- {@link org.apache.juneau.http.annotation.Response @Response} annotated classes, methods, and parameters.
- {@link org.apache.juneau.rest.annotation.Rest#swagger() @Rest(swagger)} / {@link org.apache.juneau.rest.annotation.RestMethod#swagger() @RestMethod(swagger)} annotations.

- {@doc juneau-rest-server.HttpPartAnnotations.Response}
- {@doc juneau-rest-server.HttpPartAnnotations.ResponseHeader}
- {@doc juneau-rest-server.HttpPartAnnotations.ResponseStatus}

#### 6.29.8 - Response Examples

The model select box in the responses can be expanded to show examples:

##### PetStoreResource.getPet()

Examples are provided for any supported Accept type based on the serializers defined on your servlet/method.

##### application/json+simple

##### text/uon

Examples are pulled from the examples attribute in the response object of the generated Swagger JSON:

"/pet/{petId}": { "get": { "operationId": "getPet", "summary": "Find pet by ID", "description": "Returns a single pet", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Pet" }, "examples": { "text/html+stripped": "<table>\n\t<tr>\n\t\t<td>id</td>\n\t\t<td>\t\t\t<a href=\"...", "text/html+schema": "<html>\n\t<head>\n\t\t<link rel='icon' href='$U{servlet:/htdocs/cat.png}'/>...", "application/json": "{\n\t\"id\": 123,\n\t\"species\": {\n\t\t\"name\": \"Dog\",\n\t\t\"id\": 123\n\t},\n\t\"name\...", "application/json+simple": "{\n\tid: 123,\n\tspecies: {\n\t\tname: 'Dog',\n\t\tid: 123\n\t},\n\tname: 'Doggie',\n\...", "application/json+schema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"id\": {\n\t\t\t\"type\": \"inte...", "text/xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Pet>\n\t<id>123</id>\n\t<spec...", "text/xml+schema": "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.apache.org/...", "text/uon": "(\n\tid=123,\n\tspecies=(\n\t\tname=Dog,\n\t\tid=123\n\t),\n\tname=Doggie,\n\ttags=@(\n\t\t(\n\t\t\tn...", "application/x-www-form-urlencoded": "id=123\n&species=(\n\tname=Dog,\n\tid=123\n)\n&name=Doggie\n&tags=@(\n\t(\n\...", "text/openapi": "(\n\tid=123,\n\tspecies=(\n\t\tname=Dog,\n\t\tid=123\n\t),\n\tname=Doggie,\n\ttags=@(\n\t\t(\n\t\...", "octal/msgpack": "86 A2 69 64 7B A7 73 70 65 63 69 65 73 82 A4 6E 61 6D 65 A3 44 6F 67 A2 69 64 7B A4 6E 61 6D 65 ...", "text/xml+soap": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Envelope soap=\"http://www.w3.org/2003/05/...", "text/plain": "{id:123,species:{name:'Dog',id:123},name:'Doggie',tags:[{name:'MyTag',id:123}],price:0.0,status:'AV...", "text/xml+rdf": "<rdf:RDF\n xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n xmlns:j=\"http://...", "text/xml+rdf+abbrev": "<rdf:RDF\n xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n xmlns:j=\"...", "text/turtle": "@prefix jp: <http://www.apache.org/juneaubp/> .\n@prefix j: <http://www.apache...", "text/n-triple": "_:A720f0f4fX3aX165d4974933X3aXX2dX7f93 <http://www.apache.org/juneaubp/name> \"Dog\" .\n_:...", "text/n3": "@prefix jp: <http://www.apache.org/juneaubp/> .\n@prefix j: <http://www.apache.org..."

There are several options for defining examples for response bodies:

- {@link org.apache.juneau.http.annotation.Response#example() @Response(example)} annotation.
- {@link org.apache.juneau.http.annotation.Response#examples() @Response(examples)} annotation.
- Defining an "examples" field in the inherited Swagger JSON response object (classpath file or @ResourceSwagger(value)/@MethodSwagger(value)).
- Defining an "examples" field in the Swagger Schema Object for the response object (including referenced "$ref" schemas).
- Allowing Juneau to auto-generate a code example.

The {@link org.apache.juneau.http.annotation.Response#example @Response(example)} annotation can be used on either your @RestMethod-annotated method or return class to define the example of the body.

// A JSON representation of a Pet object. @Response( example="{name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}" )

This is a Simple JSON representation of the body that is converted to a POJO and then serialized to all the registered serializers on the REST method to produce examples for all supported language types. These values are then used to automatically populate the examples field.

Direct per-media-type examples can also be defined using the {@link org.apache.juneau.http.annotation.Response#examples @Response(examples)} annotation:

// A JSON representation of a PetCreate object. @Response( examples={ "'application/json':'{name:\\'Doggie\\',species:\\'Dog\\'}',", "'text/uon':'(name:Doggie,species=Dog)'" } )

Juneau also supports auto-generation of JSON-Schema directly from POJO classes. By default, the generated swagger uses to the {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_addExamplesTo JSONSCHEMA_addExamplesTo} setting to automatically add examples to beans, collections, arrays, and maps:

In particular, examples can be defined via static methods, fields, and annotations on the classes themselves.

// Annotation on class. @Example("{name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}") public class PetCreate { ... }

// Annotation on static method. public class PetCreate { @Example public static PetCreate sample() { return new PetCreate("Doggie", 9.99f, "Dog", new String[] {"friendly","cute"}); } }

// Static method with specific name 'example'. public class PetCreate { public static PetCreate example() { return new PetCreate("Doggie", 9.99f, "Dog", new String[] {"friendly","cute"}); } }

// Static field. public class PetCreate { @Example public static PetCreate EXAMPLE = new PetCreate("Doggie", 9.99f, "Dog", new String[] {"friendly","cute"}); }

Examples can also be specified via generic properties as well using the {@link org.apache.juneau.BeanContext#BEAN_examples} property or {@link org.apache.juneau.annotation.BeanConfig#examples @BeanConfig(examples)} annotation at either the class or method level.

// Examples defined at class level. @Rest(...) @BeanConfig( examples="{PetCreate: {name:'Doggie',price:9.99,species:'Dog',tags:['friendly','cute']}}" )

Response headers are also rendered in the Swagger UI:

These can be auto-generated from {@link org.apache.juneau.http.annotation.ResponseHeader @ResponseHeader} annotations defined on either method parameters or type classes. The example above shows one of each:

@RestMethod( name=GET, path="/user/login", summary="Logs user into the system", swagger=@MethodSwagger( tags="user" ) ) public Ok login( @Query( name="username", description="The username for login", required=true, example="myuser" ) String username, @Query( name="password", description="The password for login in clear text", required=true, example="abc123" ) String password, @ResponseHeader( name="X-Rate-Limit", type="integer", format="int32", description="Calls per hour allowed by the user.", example="123" ) Value<Integer> rateLimit, Value<ExpiresAfter> expiresAfter, RestRequest req, RestResponse res ) throws InvalidLogin, NotAcceptable { if (! store.isValid(username, password)) throw new InvalidLogin(); Date d = new Date(System.currentTimeMillis() + 30 * 60 * 1000); req.getSession().setAttribute("login-expires", d); rateLimit.set(1000); expiresAfter.set(new ExpiresAfter(d)); return OK; }

@ResponseHeader( name="X-Expires-After", type="string", format="date-time", description="Date in UTC when token expires", example="2012-10-21" ) public static class ExpiresAfter { private final Calendar c; public ExpiresAfter(Date d) { this.c = new GregorianCalendar(); c.setTime(d); } public Calendar toCalendar() { return c; } }

#### 6.29.9 - Models

The {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_useBeanDefs} setting can be used to reduce the size of your generated Swagger JSON files by creating model definitions for beans and referencing those definitions through $ref attributes.

By default, this flag is enabled when extending from {@link org.apache.juneau.rest.BasicRestServlet}:

public abstract class BasicRestServlet extends RestServlet implements BasicRestConfig { @RestMethod(name=OPTIONS, path="/*", ... flags={ // Use $ref references for bean definitions to reduce duplication in Swagger. JSONSCHEMA_useBeanDefs } ) public Swagger getOptions(RestRequest req) {...}

In the Swagger UI, this causes bean definitions to show up in the Models section at the bottom of the page:

##### Models section

##### Models section with Order bean expanded

In the generated Swagger JSON, embedded schema information for beans will be replaced with references such as the one shown below for the Order bean:

{ "swagger": "2.0", "paths": { "/store/order": { "get": { "operationId": "getOrders", "summary": "Petstore orders", "responses": { "200": { "description": "OK", "schema": { "description": "java.util.Collection<org.apache.juneau.examples.rest.petstore.Order>", "type": "array", "items": { "$ref": "#/definitions/Order" } }, ... ... ... ... ... }, "definitions": { "Order": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "petId": { "type": "integer", "format": "int64" }, "shipDate": { "type": "string" }, "status": { "type": "string", "enum": [ "PLACED", "APPROVED", "DELIVERED" ] } }, "description": "org.apache.juneau.examples.rest.petstore.Order", "example": { "id": 123, "petId": 456, "shipDate": "2012-12-21", "status": "APPROVED" } }, ... }

Note that this does not affect how the information is rendered for that bean in the Swagger UI:

#### 6.29.10 - SwaggerUI.css

The look-and-feel of the Swagger UI is controlled via a single CSS file: SwaggerUI.css.

In the microservice template, this file is located in the files/htdocs/styles directory. It's a simple straightforward file consisting of less than 350 lines. This file can be modified to change the look-and-feel of your Swagger UI.

### 6.30 - REST method execution statistics 8.1.3-new

@RestResource annotated classes get automated timing and error statistic information for all @RestMethod and @RestHook annotated methods on the class.

The statistics are made available via the subpath /stats as shown below in the HelloWorldResource example:

The default REST configuration provides a link to the stats in the navlinks section of the page:

The exception hash shown is the same hash that is shown in the log file and provides a quick way of locating the exception in the logs.

Programmatic access to the statistics are provided via the following methods:

- {@link org.apache.juneau.rest.RestContext}
  - {@link org.apache.juneau.rest.RestContext#getStats() getStats()}
  - {@link org.apache.juneau.rest.RestContext#getMethodExecStats() getMethodExecStats()}
  - {@link org.apache.juneau.rest.RestContext#getMethodExecStatsReport() getMethodExecStatsReport()}

### 6.31 - @HtmlDocConfig 8.1.0-updated

The {@link org.apache.juneau.html.annotation.HtmlDocConfig @HtmlDocConfig} annotation is used to customize the HTML view of your serialized POJOs. It's used in the following locations:

- {@link org.apache.juneau.rest.annotation.Rest @Rest}-annotated classes.
- {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}-annotated methods.

The annotation itself is just a convenience for setting configuration properties set on the {@link org.apache.juneau.html.HtmlDocSerializer} class. For example, the following two pieces of code are equivalent:

// Title defined via property. @Rest( properties={ @Property(name=HTMLDOC_title, value="My Resource Page") } ) // Title defined via @HtmlDoc annotation. @Rest() @HtmlDocConfig( title="My Resource Page" )

The purpose of these annotation is to populate the HTML document view which by default consists of the following structure:

<html> <head> <style type='text/css'> CSS styles and links to stylesheets </style> </head> <body> <header> Page header </header> <nav> Navigation links </nav> <aside> Side-bar text </aside> <article> Contents of serialized object </article> <footer> Footer message </footer> </body> </html>

The outline above is controlled by the {@link org.apache.juneau.html.HtmlDocTemplate} interface which can be overridden via the {@link org.apache.juneau.rest.annotation.HtmlDoc#template @HtmlDoc(template)} annotation.

The HelloWorldResource class was an example of the @HtmlDoc annotation in use:

/** * Sample REST resource that prints out a simple "Hello world!" message. */ @Rest( path="/helloWorld" ) @HtmlDocConfig( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This page shows a resource that simply response with a 'Hello world!' message</p>", " <p>The POJO serialized is a simple String.</p>", "</div>" } ) public class HelloWorldResource extends BasicRestServlet {...}

SVL variables can be used in any of these annotations:

@Rest( path="/helloWorld", // Register a config file. config="MyConfig.cfg" ) @HtmlDocConfig( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS", // Add a nav link to view the source code for this class. "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, aside={ // Localize our messages. "<div style='max-width:400px' class='text'>", " <p>$L{localizedMessage1}</p>", " <p>$L{localizedMessage2}</p>", "</div>" } ) public class HelloWorldResource extends BasicRestServlet {...}

#### 6.31.1 - User Interfaces (UI) vs. Developer Interfaces (DI)

An important distinction needs to be made about the HTML representations produced by the REST API. These should not be considered User Interfaces, but rather Developer Interfaces.

UIs should hide the end-user from the underlying architecture. The audience generally consists of non-technical people not interested in how the UI works.

DIs, on the other hand, should NOT hide the end-user from the underlying architecture. Instead, it's a thin veneer over the REST interface with the following goals:

- Make it easy for the developer to explore and understand the REST API.
- Make it easy for the developer to debug the REST API using simple tools (hopefully just a browser).

As a result, the following guidelines are recommended:

- Use titles/descriptions/asides to describe why the REST interface exists. A developer knowing little about it should be able to access it with a browser and quickly understand what it is and how to use it.
- Don't hide the raw data! The HTML view should simply be considered an easier-to-read representation of the data normally rendered in JSON or some other format.
- Limit your use of Javascript! You can use it sparingly if you want to implement something simple like a pull-down menu to simplify some debug task, but remember that your audience cares more about interacting with your service programmatically using REST. Remember that the HTML is just icing on the cake.
- Don't use it to implement a Web 2.0 interface! If you want a Web 2.0 UI, implement it separately ON TOP OF this REST interface. The architecture is flexible enough that you could in theory pull in and use jQuery, React, Angular, or any number of sophisticated Javascript UI frameworks. Resist the urge to do so.

#### 6.31.2 - Widgets

The {@link org.apache.juneau.rest.widget.Widget} class allows you to add arbitrary HTML, CSS, and Javascript to HTML pages.
They are registered in the following locations:

- {@link org.apache.juneau.rest.annotation.HtmlDoc#widgets() HtmlDoc(widgets)}
- {@link org.apache.juneau.rest.RestContextBuilder#widgets(Class...)}
- {@link org.apache.juneau.rest.RestContextBuilder#widgets(Widget...)}
- {@link org.apache.juneau.rest.RestContext#REST_widgets}

##### Example:

@RestMethod( widgets={ MyWidget.class } htmldoc=@HtmlDoc( navlinks={ "$W{MyWidget}" }, aside={ "Check out this widget: $W{MyWidget}" } ) )

The Widget class is composed of the following methods:

- {@link org.apache.juneau.rest.widget.Widget}
  - {@link org.apache.juneau.rest.widget.Widget#getHtml(RestRequest,RestResponse) getHtml(RestRequest,RestResponse)}
  - {@link org.apache.juneau.rest.widget.Widget#getStyle(RestRequest,RestResponse) getStyle(RestRequest,RestResponse)}
  - {@link org.apache.juneau.rest.widget.Widget#getScript(RestRequest,RestResponse) getScript(RestRequest,RestResponse)}

The HTML content returned by the {@link org.apache.juneau.rest.widget.Widget#getHtml(RestRequest,RestResponse) getHtml(RestRequest,RestResponse)} method is added wherever the "$W{...}" variable is used.

The CSS returned by {@link org.apache.juneau.rest.widget.Widget#getScript(RestRequest,RestResponse) getScript(RestRequest,RestResponse)} is added to the style section in the page header.

The Javascript returned by {@link org.apache.juneau.rest.widget.Widget#getScript(RestRequest,RestResponse) getScript(RestRequest,RestResponse)} is added to the script section in the page header.

The following examples shows how to associate a widget with a REST method and then have it rendered in the links and aside section of the page. It shows an example of a widget that renders an image located in the htdocs static files directory in your classpath (see {@link org.apache.juneau.rest.annotation.Rest#staticFiles() @Rest(staticFiles)}):

public class MyWidget extends Widget { @Override /* Widget */ public String getHtml(RestRequest req) throws Exception { UriResolver r = req.getUriResolver(); // API used for resolving URIs. return "<img class='myimage' onclick='myalert(this)' src='"+r.resolve("servlet:/htdocs/myimage.png")+"'>"; } @Override /* Widget */ public String getScript(RestRequest req) throws Exception { return "" + "\n function myalert(imageElement) {" + "\n alert('cool!');" + "\n }"; } @Override /* Widget */ public String getStyle(RestRequest req) throws Exception { return "" + "\n .myimage {" + "\n border: 10px solid red;" + "\n }"; } }

The Widget class also defines the following two convenience methods for loading Javascript and CSS files from the classpath or file system.

- {@link org.apache.juneau.rest.widget.Widget}
  - {@link org.apache.juneau.rest.widget.Widget#getClasspathResourceAsString(String) getClasspathResourceAsString(String)}
  - {@link org.apache.juneau.rest.widget.Widget#getClasspathResourceAsString(String,Locale) getClasspathResourceAsString(String,Locale)}

##### Example:

public class MyWidget extends Widget { ... @Override /* Widget */ public String getScript(RestRequest req) throws Exception { return getClasspathResourceAsString("MyWidget.js"); } @Override /* Widget */ public String getStyle(RestRequest req) throws Exception { return getClasspathResourceAsString("MyWidget.css"); } }

- {@link org.apache.juneau.rest.RestContext#REST_widgets}

#### 6.31.3 - Predefined Widgets

The {@link org.apache.juneau.rest.widget} package contains predefined reusable widgets.

- {@link org.apache.juneau.rest.widget}
  - {@link org.apache.juneau.rest.widget.Widget}
    - {@link org.apache.juneau.rest.widget.MenuItemWidget}
      - {@link org.apache.juneau.rest.widget.ContentTypeMenuItem}
      - {@link org.apache.juneau.rest.widget.QueryMenuItem}
      - {@link org.apache.juneau.rest.widget.ThemeMenuItem}
    - {@link org.apache.juneau.rest.widget.PoweredByJuneau}
  - {@link org.apache.juneau.rest.widget.Tooltip}

##### MenuItemWidget

{@link org.apache.juneau.rest.widget.MenuItemWidget} is an abstract class for rendering menu items with drop-downs. It defines some simple CSS and Javascript for enabling drop-down menus in the nav section of the page (although nothing keeps you from using it in an arbitrary location in the page).

The script specifies a "menuClick(element)" function that toggles the visibility of the next sibling of the element.

Subclasses implement the following two methods:

- {@link org.apache.juneau.rest.widget.MenuItemWidget}
  - {@link org.apache.juneau.rest.widget.MenuItemWidget#getLabel(RestRequest,RestResponse) getLabel(RestRequest,RestResponse)} - The menu item label.
  - {@link org.apache.juneau.rest.widget.MenuItemWidget#getContent(RestRequest,RestResponse) getContent(RestRequest,RestResponse)} - The menu item content.

For example, to render a link that brings up a simple dialog in a div tag:

@Override public String getLabel() { return "my-menu-item"; }; @Override public Div getLabel() { return Html5Builder.div("Surprise!").style("color:red"); };

The HTML content returned by the {@link org.apache.juneau.rest.widget.MenuItemWidget#getHtml(RestRequest,RestResponse) getHtml(RestRequest,RestResponse)} method is added where the "$W{...}" is referenced in the page.

##### ContentTypeMenuItem

{@link org.apache.juneau.rest.widget.ContentTypeMenuItem} is a predefined Widget that returns back a list of hyperlinks for rendering the contents of a page in a variety of content types.

The variable it resolves is "$W{ContentTypeMenuItem}".

An example of this widget can be found in the PetStoreResource in the examples that provides a drop-down menu item for rendering all other supported content types in plain text:

@RestMethod( name=GET, path="/", widgets={ ContentTypeMenuItem.class, }, htmldoc=@HtmlDoc( navlinks={ "up: ...", "options: ...", "$W{QueryMenuItem}", "$W{ContentTypeMenuItem}", "$W{ThemeMenuItem}", "source: ..." } ) ) public Collection<Pet> getPets() {

It renders the following popup-box:

##### QueryMenuItem

{@link org.apache.juneau.rest.widget.QueryMenuItem} is a predefined Widget that returns a menu-item drop-down form for entering search/view/sort arguments.

The variable it resolves is "$W{QueryMenuItem}".

This widget is designed to be used in conjunction with the {@link org.apache.juneau.rest.converters.Queryable} converter, although implementations can process the query parameters themselves if they wish to do so by using the {@link org.apache.juneau.rest.RequestQuery#getSearchArgs()} method to retrieve the arguments and process the data themselves.

An example of this widget can be found in the PetStoreResource in the examples that provides search/view/sort capabilities against the collection of POJOs:

@RestMethod( name=GET, path="/", widgets={ QueryMenuItem.class, }, htmldoc=@HtmlDoc( navlinks={ "up: ...", "options: ...", "$W{QueryMenuItem}", "$W{ContentTypeMenuItem}", "$W{ThemeMenuItem}", "source: ..." } ), converters=Queryable.class ) public Collection<Pet> getPets() {

It renders the following popup-box:

Tooltips are provided by hovering over the field names.

When submitted, the form submits a GET request against the current URI with special GET search API query parameters. (e.g. "?s=column1=Foo*&v=column1,column2&o=column1,column2-&p=100&l=100"). The {@link org.apache.juneau.rest.converters.Queryable} class knows how to perform these filters against collections of POJOs.

##### ThemeMenuItem

{@link org.apache.juneau.rest.widget.ThemeMenuItem} is a predefined Widget that returns back a list of hyperlinks for rendering the contents of a page in the various default styles.

The variable it resolves is "$W{ThemeMenuItem}".

An example of this widget can be found in the PetStoreResource in the examples that provides a drop-down menu item for rendering all other supported content types in plain text:

@RestMethod( name=GET, path="/", widgets={ ThemeMenuItem.class, }, htmldoc=@HtmlDoc( navlinks={ "up: ...", "options: ...", "$W{QueryMenuItem}", "$W{ContentTypeMenuItem}", "$W{ThemeMenuItem}", "source: ..." } ) ) public Collection<Pet> getPets() {

##### PoweredByJuneau

{@link org.apache.juneau.rest.widget.PoweredByJuneau} is a predefined Widget that places a powered-by-Juneau message on a page.

The variable it resolves is "$W{PoweredByJuneau}".

It produces a simple Apache Juneau icon floating on the right. Typically it's used in the footer of the page, as shown below in the AddressBookResource from the examples:

@Rest( path="/addressBook", widgets={ PoweredByJuneau.class }, htmldoc=@HtmlDoc( footer="$W{PoweredByJuneau}" )

It renders the following image:

##### Tooltip

{@link org.apache.juneau.rest.widget.Tooltip} is a predefined template for adding tooltips to HTML5 bean constructs, typically in menu item widgets.

The following examples shows how tooltips can be added to a menu item widget.

public class MyFormMenuItem extends MenuItemWidget { @Override public String getLabel(RestRequest req) throws Exception { return "myform"; } @Override public Object getContent(RestRequest req) throws Exception { return div( form().id("form").action("servlet:/form").method(POST).children( table( tr( th("Field 1:"), td(input().name("field1").type("text")), td(new Tooltip("(?)", "This is field #1!", br(), "(e.g. '", code("Foo"), "')")) ), tr( th("Field 2:"), td(input().name("field2").type("text")), td(new Tooltip("(?)", "This is field #2!", br(), "(e.g. '", code("Bar"), "')")) ) ) ) ); } }

#### 6.31.4 - UI Customization

The HTML views of POJOs can somewhat be considered a rudimentary User Interface. In reality, a better term for them would be a Developer Interface as they're meant to be used primarily by developers and not end users. Despite that distinction, it is possible to 'brand' the HTML page to whatever you desire.

The sample root page below includes some default branding for Juneau and Apache:

http://localhost:10000/helloWorld

The Juneau REST framework does not provide specific branding support (i.e. there is no concept of a brand icon). Instead, it just uses the existing open-ended API for defining branding via annotations on your REST classes.

@Rest( ... // HTML-page specific settings htmldoc=@HtmlDoc( // Default page header contents. header={ "<h1>$R{resourceTitle}</h1>", // Use @Rest(title) "<h2>$R{methodSummary,resourceDescription}</h2>", // Use either @RestMethod(summary) or @Rest(description) "$C{REST/header}" // Extra header HTML defined in external config file. }, // Default stylesheet to use for the page. // Can be overridden from external config file. // Default is DevOps look-and-feel (aka Depression look-and-feel). stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}", // Default contents to add to the <head> section of the HTML page. // Use it to add a favicon link to the page. head={ "<link rel='icon' href='$U{$C{REST/favicon}}'/>" }, // No default page footer contents. // Can be overridden from external config file. footer="$C{REST/footer}" ), // Optional external configuration file. config="$S{juneau.configFile}", // These are static files that are served up by the servlet under the specified sub-paths. // For example, "/servletPath/htdocs/javadoc.css" resolves to the file "[servlet-package]/htdocs/javadoc.css" // By default, we define static files through the external configuration file. staticFiles="$C{REST/staticFiles}" ) public interface BasicRestConfig {}

@Rest( ... htmldoc=@HtmlDoc( htmldoc=@HtmlDoc( // Basic page navigation links. navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" } ) ), ... ) public abstract class BasicRestServlet extends RestServlet implements BasicRestConfig {...}

@Rest public abstract class BasicRestServletGroup extends BasicRestServlet {...}

@Rest( htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, ThemeMenuItem.class }, navlinks={ "options: ?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{ThemeMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This is an example of a 'router' page that serves as a jumping-off point to child resources.</p>", " <p>Resources can be nested arbitrarily deep through router pages.</p>", " <p>Note the <span class='link'>options</span> link provided that lets you see the generated swagger doc for this page.</p>", " <p>Also note the <span class='link'>sources</span> link on these pages to view the source code for the page.</p>", " <p>All content on pages in the UI are serialized POJOs. In this case, it's a serialized array of beans with 2 properties, 'name' and 'description'.</p>", " <p>Other features (such as this aside) are added through annotations.</p>", "</div>" } ), ... ) public class RootResources extends BasicRestServletGroup {...}

The default annotation values use {@link org.apache.juneau.config.vars.ConfigVar $C} variables to pull in values from an optional external configuration file such as the one shown below:

#======================================================================================================================= # REST settings #======================================================================================================================= [REST] staticFiles = htdocs:files/htdocs # Stylesheet to use for HTML views. theme = servlet:/htdocs/themes/devops.css headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a>

The take-away here is that the "User Interface" is open-ended, lets you define pretty much anything you want through arbitrary HTML, and allows you either hardcode your interface inside annotations or pull them in via string variables from other places such as external config files.

- {@doc juneau-microservice-jetty.UiCustomization}

#### 6.31.5 - Stylesheets 8.1.0-updated

The sample root page renders in the default "devops" look-and-feel:

http://localhost:10000

The sample root page provides a dropdown widget to try out the other default look-and-feels:

For example, the "light" look-and-feel:

http://localhost:10000/?stylesheet=styles%2Flight.css

And the "dark" look-and-feel:

http://localhost:10000/?stylesheet=styles%2Fdark.css

The stylesheet URL is controlled by the {@link org.apache.juneau.html.annotation.HtmlDocConfig#stylesheet() @HtmlDocConfig(stylesheet)} annotation. The {@link org.apache.juneau.rest.BasicRestServlet} class defines the stylesheet served up as a static file:

@Rest( htmldoc=@HtmlDoc( stylesheet="$C{REST/stylesheet,servlet:/styles/devops.css}", ), staticFiles={"styles:styles"} ) public abstract class BasicRestServlet extends RestServlet {...}

The "$C{REST/stylesheet,servlet:/styles/devops.css}" variable says to use the URI defined in your servlet's config file, if there is one, and to default to serving up the file org/apache/juneau/rest/styles/devops.css.

To provide your own stylesheet, simply override the stylesheet attribute and point to a different file:

@Rest( htmldoc=@HtmlDoc( stylesheet="servlet:/my-styles/my-style.css}", ), staticFiles={"my-styles:my-styles"} ) public class MyResourceBaseClass extends BasicRestServlet {...}

You can try out different stylesheets by passing in a stylesheet attribute in the request URL. The example above show this in use.

In case you're curious about how the menu item works, it's defined via a widget:

@Rest( htmldoc=@HtmlDoc( widgets={ PoweredByApache.class, ContentTypeMenuItem.class, StyleMenuItem.class }, navlinks={ "options: ?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, ) public class RootResources extends BasicRestServletJenaGroup {...}

The StyleMenuItem is a widget that extends from {@link org.apache.juneau.rest.widget.MenuItemWidget}, a specialized widget for creating pop-up menus. In the case of StyleMenuItem, it's simply returning a list of links wrapped in a div tag:

import static org.apache.juneau.dto.html5.HtmlBuilder.*; public class StyleMenuItem extends MenuItemWidget { private static final String[] BUILT_IN_STYLES = {"devops", "light", "original", "dark"}; @Override /* Widget */ public String getLabel(RestRequest req) { return "styles"; } @Override /* MenuItemWidget */ public Div getContent(RestRequest req) throws Exception { Div div = div(); for (String s : BUILT_IN_STYLES) { java.net.URI uri = req.getUri(true, new AMap<String,String>().append("stylesheet", "styles/"+s+".css")); div.children(a(uri, s), br()); } return div; } }

### 6.32 - Default Headers

The following annotations are provided for specifying default header values for requests and responses:

- {@link org.apache.juneau.rest.annotation.Rest#reqHeaders() Rest(reqHeaders)}
  Defines default headers on request when the client doesn't specify them.
- {@link org.apache.juneau.rest.annotation.Rest#resHeaders() Rest(resHeaders)}
  Appends the specified headers if they weren't already set programmatically.

##### Example:

// Servlet with default headers @Rest( // Assume "text/json" Accept value when Accept not specified reqHeaders={"Accept: text/json"}, // Add a version header attribute to all responses resHeaders={"X-Version: 1.0"} ) public MyRestServlet extends BasicRestServlet { ... }

Default headers can also be specified programmatically by overriding the following methods:

- {@link org.apache.juneau.rest.RestContextBuilder}
  - {@link org.apache.juneau.rest.RestContextBuilder#reqHeaders(String[])}
  - {@link org.apache.juneau.rest.RestContextBuilder#resHeaders(String[])}

### 6.33 - Logging / Debugging 8.1.0-new

The REST APIs provides support for fine-tuned control of logging for HTTP requests and responses.

The APIs involved are:

- {@link org.apache.juneau.rest.annotation.Rest}
  - {@link org.apache.juneau.rest.annotation.Rest#logging() logging()} - Class-level logging configuration and rules.
  - {@link org.apache.juneau.rest.annotation.Rest#debug() debug()} - Enable debug mode.
- {@link org.apache.juneau.rest.annotation.RestMethod}
  - {@link org.apache.juneau.rest.annotation.RestMethod#logging() logging()} - Class-level logging configuration.
  - {@link org.apache.juneau.rest.annotation.RestMethod#debug() debug()} - Enable debug mode.
- {@link org.apache.juneau.rest.RestContext}
  - {@link org.apache.juneau.rest.RestContext#REST_callLoggerConfig REST_callLoggerConfig} - Underlying configuration property for {@link org.apache.juneau.rest.annotation.Rest#logging() @Rest(logging)}.
  - {@link org.apache.juneau.rest.RestContext#REST_debug REST_debug} - Underlying configuration property for {@link org.apache.juneau.rest.annotation.Rest#debug() @Rest(debug)}.
- {@link org.apache.juneau.rest.annotation.Logging} - Annotation for {@link org.apache.juneau.rest.annotation.Rest#logging() @Rest(logging)} and {@link org.apache.juneau.rest.annotation.RestMethod#logging() @RestMethod(logging)}
  - {@link org.apache.juneau.rest.annotation.Logging#level() level()} - The logging level.
  - {@link org.apache.juneau.rest.annotation.Logging#rules() rules()} - The logging rules.
  - {@link org.apache.juneau.rest.annotation.Logging#useStackTraceHashing() useStackTraceHashing()} - Enables de-duplication of logged stack traces and replacement with hash IDs.
  - {@link org.apache.juneau.rest.annotation.Logging#stackTraceHashingTimeout() stackTraceHashingTimeout()} - Controls how frequently hashed stack traces are re-logged.
  - {@link org.apache.juneau.rest.annotation.Logging#disabled() disabled()} - Disables logging completely or per-request.
- {@link org.apache.juneau.rest.annotation.LoggingRule} - Annotation for {@link org.apache.juneau.rest.annotation.Logging#rules() @Logging(rules)}
  - {@link org.apache.juneau.rest.annotation.LoggingRule#level() level()} - The logging level.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#codes() codes()} - Status code patterns and ranges to match against.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#exceptions() exceptions()} - Exception class names and patterns to match against.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#debugOnly() debugOnly()} - Match only if debug is set on the request.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#req() req()} - The level of request detail.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#res() res()} - The level of response detail.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#verbose() verbose()} - Shortcut for LONG request and response detail.
  - {@link org.apache.juneau.rest.annotation.LoggingRule#disabled() disabled()} - Disables logging completely or per-request.

##### Request/response details

The amount of detail on requests and responses is controlled via the {@link org.apache.juneau.rest.annotation.LoggingRule#req() @LoggingRule(req)} and {@link org.apache.juneau.rest.annotation.LoggingRule#res() @LoggingRule(res)} annotations:

- "short" - Results in simple one-line log lines containing the HTTP method + url + response code.
- "medium" - Also includes headers and body length information (if debug enabled).
- "large" - Dumps the entire request/response bodies (if debug enabled).

The following code shows the output produced using the "short" setting:

@Rest( logging=@Logging( level="info", rules={ @LoggingRule(codes"500-", level="warning", req="short", res="short") } ) ) public static class MyRestClass { @RestMethod(method="POST", path="foo") public String myRestMethod(RestRequest req, RestResponse res) throws Exception { res.setStatus(500); res.setHeader("Foo", "bar"); res.setException(new StringIndexOutOfBoundsException()); // Could also throw. return req.getBody().asString(); } } static MockRest MY_REST = MockRest.build(MyRestClass.class, null); @Test public void test() throws Exception { MY_REST.post("/foo?foo=bar", "Foo").header("Foo", "bar").execute().assertStatus(500); }

The log output produced from the code above looks like this:

WARNING: [500] HTTP POST /foo java.lang.StringIndexOutOfBoundsException at org.apache.juneau.rest.annotation.RestResourceLoggingTest$MyRestClass.myRestMethod(RestResourceLoggingTest.java:672) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) ...

In comparison, using "long" formatting adds information about headers and body.

@Rest( debug="true", // Needed to capture request/response bodies for logging. logging=@Logging( level="info", rules={ @LoggingRule(codes"500-", level="warning", req="long", res="long") } ) )

Request/response bodies are only cached for logging if debugging is enabled via the debug="true" flag.

The log file now contains the following with shows the contents of the request and response bodies in both UTF-8 and spaced-hex:

WARNING: === HTTP Request (incoming) =================================================== [500] HTTP POST /foo?foo=bar Request length: 3 bytes Response code: 500 Response length: 3 bytes Exec time: 20ms ---Request Headers--- Foo: bar ---Response Headers--- Foo: bar Content-Type: text/plain ---Request Body UTF-8--- Foo ---Request Body Hex--- 46 6F 6F ---Response Body UTF-8--- Foo ---Response Body Hex--- 46 6F 6F === END =================================================================== java.lang.StringIndexOutOfBoundsException at org.apache.juneau.rest.annotation.RestResourceLoggingTest$MyRestClass.myRestMethod(RestResourceLoggingTest.java:672) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) ...

##### Rule matching

Logging rules can match against status codes, exception class names, and the debug flag.
The following shows various examples of logging rule matches.

@Rest( logging=@Logging( rules={ // Individual status codes. @LoggingRule(codes="300", ...) // Ranges of status codes. @LoggingRule(codes="400-499", ...) @LoggingRule(codes=">=500", ...) // All codes. @LoggingRule(codes="*", ...) // Full class names of exceptions. @LoggingRule(exceptions="java.lang.StringIndexOutOfBoundsException", ...) // Exception class name patterns. @LoggingRule(exceptions="String*Exception *Foo*Exception", ...) // Match when debug enabled only. @LoggingRule(codes="*", debugOnly="true", ...) } ) )

Rules are matched in the order listed on the annotation. Rules on methods are matched before rules on classes. Rules on child methods/classes are matched before rules on parent classes.

##### Debug mode

The debug mode setting allows HTTP request/response bodies to be cached in memory for logging purposes:

@Rest( debug="true" )

The possible values for the debug setting are (case-insensitive):

- "true" - Debug mode enabled.
- "false" (default) - Debug mode disabled.
- "per-request" - Debug mode is enabled only on requests containing an X-Debug: true header.

Note that caching HTTP bodies in memory can produce significant performance penalties, so use the setting wisely.
In particular, do not leave this setting enabled on production instances since it can easily lead to denial-of-service attacks.

Servlet code can check the debug setting via the {@link org.apache.juneau.rest.RestRequest#isDebug()} method allowing it to be used for custom purposes.

Debug mode can also be enabled on a request by calling the {@link org.apache.juneau.rest.RestRequest#setDebug(Boolean)} or {@link org.apache.juneau.rest.RestResponse#setDebug(Boolean)} methods. Note however that you must be sure not to have already consumed the request or started writing the response before calling this method.

##### No-trace (disabled) mode

The {@link org.apache.juneau.rest.annotation.Logging#disabled() @Logging(disabled)} and {@link org.apache.juneau.rest.annotation.LoggingRule#disabled() @LoggingRule(disabled)} annotations can be used to disable logging entirely or on a per-request basis:

@Rest( logging=@Logging( disabled="true" rules={ @LoggingRule( codes"500-", disabled="false" ) } ) )

The possible values for the disabled setting are (case-insensitive):

- "true" - Logging disabled.
- "false" (default) - Logging not disabled.
- "per-request" - Logging is disabled only on requests containing a X-NoTrace: true header.

Disabled logging is particularly useful when running testcases that are expected to throw exceptions or cause other errors and you don't want these errors logged.

Disabled logging can also be set on a request by calling the {@link org.apache.juneau.rest.RestRequest#setNoTrace(Boolean)} or {@link org.apache.juneau.rest.RestResponse#setNoTrace(Boolean)} methods.

##### Stacktrace hashing

The {@link org.apache.juneau.rest.annotation.Logging#useStackTraceHashing() @Logging(useStackTraceHashing)} setting can be used to eliminate duplicate stacktraces in your log file by logging them once and then logging identifying hash IDs.

In the example below, we're causing two exceptions but only logging the first one:

@Rest( logging=@Logging( useStackTraceHashing="true", rules={ @LoggingRule(codes">=500", level="warning", req="short", res="short") } ) ) public static class MyRestClass { @RestMethod(method="POST", path="foo") public String myRestMethod(RestRequest req, RestResponse res) throws Exception { res.setHeader("Foo", "bar"); // Equivalent to throwing an exception. res.setStatus(500); res.setException(new StringIndexOutOfBoundsException()); return req.getBody().asString(); } } static MockRest MY_REST = MockRest.build(MyRestClass.class, null); @Test public void test() throws Exception { MY_REST.post("/foo?foo=bar", "Foo").header("Foo", "bar").execute().assertStatus(500); MY_REST.post("/foo?foo=bar", "Foo").header("Foo", "bar").execute().assertStatus(500); }

The log file will show a 4 byte hash ID "9b85cc96" and count ".1" as shown below:

Jul 11, 2019 3:38:48 PM org.apache.juneau.rest.BasicRestCallLogger log WARNING: [500,9b85cc96.1] HTTP POST /foo java.lang.StringIndexOutOfBoundsException at org.apache.juneau.rest.annotation.RestResourceLoggingTest$MyRestClass.myRestMethod(RestResourceLoggingTest.java:671) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) ... WARNING: [500,9b85cc96.2] HTTP POST /foo

The {@link org.apache.juneau.rest.annotation.Logging#stackTraceHashingTimeout() @Logging(stackTraceHashingTimeout)} setting can be used to periodically log the stacktrace to the log file again.

### 6.34 - HTTP Status Codes

By default, a 200 (OK) status is automatically set as the HTTP status when a Java method executes successfully.

Other status codes can be generated by throwing a {@link org.apache.juneau.rest.RestException} with a specific HTTP status code, or calling {@link javax.servlet.http.HttpServletResponse#setStatus(int)}.

Non-OK (200) status codes are automatically triggered by the following conditions:

Code | Description | When triggered
--- | --- | ---
401 | Unauthorized | A {@link org.apache.juneau.rest.RestGuard guard} prevented the method from being executed
404 | Not Found | No matching path patterns were found on any method
405 | Method Not Implemented | A path pattern matched, but no Java methods were found for the HTTP method
406 | Not Acceptable | A path pattern matched, but no Java methods were found with a matching serializer for the Accept on the request
412 | Precondition Failed | A path pattern matched, but no Java methods were found that were not rejected by {@link org.apache.juneau.rest.RestMatcher matchers}
415 | Unsupported Media Type | A path pattern matched, but no Java methods were found with a matching parser for the Content-Type on the request
500 | Internal Server Error | The Java method threw an exception other than {@link org.apache.juneau.rest.RestException}

### 6.35 - Overloading HTTP Methods

Through the use of the built-in "method" GET parameter, you can implement requests beyond the basic REST http method types.

For example, the URL "/sample/foo?method=BAR" will cause the following method to be invoked...

@RestMethod(name="BAR") public void doBar(RestRequest req, RestResponse res) { // Handle BAR requests }

To support overloaded methods, the {@link org.apache.juneau.rest.annotation.Rest#allowedMethodParams() @Rest(allowedMethodParams)} setting must be enabled on your servlet.

@Rest( // Allow &method parameter on BAR requests allowedMethodParams="BAR" )

### 6.36 - Built-in Parameters

The following URL parameters have special meaning and can be passed in through the URL of the request:

GET Parameter | Description
--- | ---
&plainText=true | Response will always be Content-Type: text/plain and the returned text will be human-readable ({@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_useWhitespace WSERIALIZER_useWhitespace} enabled). Useful for debugging.
&debug=true | Request body content will be dumped to log file.
&noTrace=true | If an error occurs, don't log the stack trace to the log file. Useful for automated JUnit testcases testing error states to prevent the log file from filling up with useless stack traces.
&method=X | Overload the HTTP method as a GET parameter (e.g "POST"). Must be enabled via {@link org.apache.juneau.rest.annotation.Rest#allowedMethodParams() @Rest(allowedMethodParams)} setting.
&Header-Name=headerValue | Specify a header value as a GET parameter. Must be enabled via {@link org.apache.juneau.rest.annotation.Rest#allowedHeaderParams() @Rest(allowedHeaderParams)} setting.
&body=X | Pass in the HTTP body content on PUT and POST methods as a UON-encoded GET parameter. Must be enabled via {@link org.apache.juneau.rest.annotation.Rest#allowBodyParam() @Rest(allowBodyParam)} setting.
&x-response-headers=X | Pass-through headers to the response. Must be a UON-encoded map of key-value pairs.

### 6.37 - Custom Serializers and Parsers

A very easy-to-use API is provided for defining your own serializers and parsers at both the servlet and method levels.

The following examples show a custom serializer and parser defined at the method level. It's the PhotosResource class pulled from the Samples project. It shows an example of defining a serializer and parser to handle images.

/** * Sample resource that allows images to be uploaded and retrieved. */ @Rest( path="/photos", messages="nls/PhotosResource", title="Photo REST service", description="Use a tool like Poster to upload and retrieve jpeg and png images.", htmldoc=@HtmlDoc( navlinks={ "options: ?method=OPTIONS" } ) ) public class PhotosResource extends BasicRestServlet { // Our cache of photos private Map<Integer,Photo> photos = new TreeMap<Integer,Photo>(); /** Bean class for storing photos */ public static class Photo { private int id; BufferedImage image; Photo(int id, BufferedImage image) { this.id = id; this.image = image; } public URI getURI() throws URISyntaxException { return new URI("photos/"+id); } public int getID() { return id; } } /** GET request handler for list of all photos */ @RestMethod(name=GET, path="/") public Collection<Photo> getAllPhotos(RestRequest req, RestResponse res) throws Exception { res.setPageTitle("Photo REST service"); res.setPageText("Use a tool like Poster to upload and retrieve jpeg and png images."); return photos.values(); } /** GET request handler for single photo */ @RestMethod(name=GET, path="/{id}", serializers=ImageSerializer.class) public BufferedImage getPhoto(RestRequest req, @Path("id") int id) throws Exception { Photo p = photos.get(id); if (p == null) throw new RestException(SC_NOT_FOUND, "Photo not found"); return p.image; } /** PUT request handler */ @RestMethod(name=PUT, path="/{id}", parsers=ImageParser.class) public String addPhoto(RestRequest req, @Path("id") int id, @Body BufferedImage image) throws Exception { photos.put(id, new Photo(id, image)); return "OK"; } /** POST request handler */ @RestMethod(name=POST, path="/", parsers=ImageParser.class) public Photo setPhoto(RestRequest req, @Body BufferedImage image) throws Exception { int id = photos.size(); Photo p = new Photo(id, image); photos.put(id, p); return p; } /** DELETE request handler */ @RestMethod(name=DELETE, path="/{id}") public String deletePhoto(RestRequest req, @Path("id") int id) throws Exception { Photo p = photos.remove(id); if (p == null) throw new RestException(SC_NOT_FOUND, "Photo not found"); return "OK"; } /** OPTIONS request handler */ @RestMethod(name=OPTIONS, path="/*") public Swagger getOptions(RestRequest req) { return req.getSwagger(); } /** Serializer for converting images to byte streams */ @Produces("image/png,image/jpeg") public static class ImageSerializer extends OutputStreamSerializer { @Override /* Serializer */ public void serialize(Object o, OutputStream out, SerializerSession session) throws IOException, SerializeException { RenderedImage image = (RenderedImage)o; String mediaType = ctx.getMediaType(); ImageIO.write(image, mediaType.substring(mediaType.indexOf('/')+1), out); } } /** Parser for converting byte streams to images */ @Consumes("image/png,image/jpeg") public static class ImageParser extends InputStreamParser { @Override /* Parser */ public <T> T parse(InputStream in, ClassMeta<T> type, ParserSession session) throws ParseException, IOException { BufferedImage image = ImageIO.read(in); return (T)image; } } }

### 6.38 - Using with OSGi

Since REST servlets are basically just HttpServlets, incorporating them into an OSGi environment is pretty straightforward.

The following code shows how to register your REST servlets in an OSGi Activator:

package org.apache.juneau.examples.rest; import org.osgi.framework.*; import org.osgi.service.http.*; import org.osgi.util.tracker.*; import org.apache.juneau.rest.samples.*; /** * Activator class used when running samples as a bundle in an OSGi environment. */ public class Activator implements BundleActivator, ServiceTrackerCustomizer { private ServiceTracker httpServiceTracker; private BundleContext context; @Override /* BundleActivator */ public void start(BundleContext context) throws Exception { this.context = context; httpServiceTracker = new ServiceTracker(context, HttpService.class.getName(), this); httpServiceTracker.open(); } @Override /* BundleActivator */ public void stop(BundleContext context) throws Exception { httpServiceTracker.close(); } @Override /* ServiceTrackerCustomizer */ public Object addingService(ServiceReference reference) { Object service = context.getService(reference); if (service instanceof HttpService) { HttpService s = (HttpService)service; try { s.registerServlet("/sample", new MyRestServlet(), null, null); } catch (Exception e) { throw new RuntimeException(e); } } return service; } @Override /* ServiceTrackerCustomizer */ public void modifiedService(ServiceReference reference, Object service) { } @Override /* ServiceTrackerCustomizer */ public void removedService(ServiceReference reference, Object service) { } }

### 6.39 - Using with Spring and Injection frameworks

The Juneau REST server API is compatible with dependency injection frameworks such as Spring.

The important class is the {@link org.apache.juneau.rest.RestResourceResolver} class which is used to resolve child servlet/resource implementation classes inside parent contexts. In other words, it's used for resolving {@link org.apache.juneau.rest.annotation.Rest#children() @Rest(children)} instances.

The general approach starts with defining a resolver that uses the Spring application context for resolution:

public class SpringRestResourceResolver extends RestResourceResolverSimple { private final ApplicationContext appContext; public SpringRestResourceResolver(ApplicationContext appContext) { this.appContext = appContext; } @Override /* RestResourceResolverSimple */ public Object resolve(Class<?> resourceType, RestContextBuilder builder) throws Exception { Object resource = appContext.getBean(type); // If Spring can't resolve it, use default resolution (just look for no-arg constructor). if (resource == null) { resource = super.resolve(resourceType, builder); } return resource; } }

Next, define the Spring configuration to return our resolver:

@Configuration public abstract class MySpringConfiguration { @Autowired private static ApplicationContext appContext; public static ApplicationContext getAppContext(){ return appContext; } public static void setAppContext(ApplicationContext appContext){ MySpringConfiguration.appContext = appContext; } @Bean public RestResourceResolver restResourceResolver(ApplicationContext appContext) { return new SpringRestResourceResolver(appContext); } }

Finally, define your Root resource with a constructor that takes in our rest resource resolver and sets it on the config object during initialization.

@Rest( children={ ... } ) public class Root extends BasicRestServletGroup { private final RestResourceResolver resolver; @Inject public Root(RestResourceResolver resolver) { this.resolver = resolver; } @RestHook(INIT) public void initSpring(RestContextBuilder builder) throws Exception { builder.setResourceResolver(resolver); } }

After that, just define constructors on your child resources to take in Spring beans:

@Rest( path="/child" ) public class MyChildResource extends BasicRestServlet { private final Bean1 bean1; private final Bean2 bean2; private final Bean3 bean3; @Inject public MyChildResource(Bean1 bean1, Bean2 bean2, Bean3 bean3) { this.bean1 = bean1; this.bean2 = bean2; this.bean3 = bean3; }

### 6.40 - Using HTTP/2 features

Juneau is built as a veneer on top of the Servlet API, allowing you to use low-level Servlet APIs whenever needed. This allows you to take advantage of the newest HTTP/2 features implemented in the new Servlet 4.0 specification.

### 6.41 - Other Notes

- Subclasses can use either {@link javax.servlet.http.HttpServlet#init(ServletConfig)} or {@link javax.servlet.http.HttpServlet#init()} for initialization just like any other servlet.
- The X-Response-Headers header can be used to pass through header values into the response. The value should be a URL-encoded map of key-value pairs. For example, to add a "Refresh: 1" header to the response to auto-refresh a page, the following parameter can be specified: "/sample?X-Response-Headers={Refresh=1}"

## 7 - juneau-rest-server-jaxrs

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-rest-server-jaxrs</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-rest-server-jaxrs-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.rest.server_{@property juneauVersion}.jar

The juneau-rest-server-jaxrs library provides an implementation of a MessageBodyReader and MessageBodyWriter to allow any of the Juneau serializers and parsers to be used in a JAX/RS environment.

### 7.1 - Juneau JAX-RS Provider

The Juneau framework contains the juneau-rest-server-jaxrs bundle for performing simple integration of Juneau serializers and parsers in JAX-RS compliant environments.

It should be noted that although some of the functionality of the Juneau Server API is provided through the JAX-RS integration components, it is not nearly as flexible as using the {@link org.apache.juneau.rest.RestServlet} class directly.

What you can do with the Juneau JAX-RS provider classes:

- Use existing Juneau serializers and parsers for converting streams to POJOs and vis-versa.
- Use annotations to specify filters and properties using the {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} and {@link org.apache.juneau.rest.jaxrs.JuneauProvider} annotations.

What you can't do with the Juneau JAX-RS provider classes:

- Specify or override serializers/parsers at the Java class and method levels.
  JAX-RS does not provide the capability to use different providers for the same media types at the class or method levels.
- Specify or override filters and properties at the Java class level.
- Default stylesheets for the {@link org.apache.juneau.html.HtmlDocSerializer} class.
  It will produce HTML, but it won't contain any styles applied.
- The ability to specify HTTP method, headers, and content using GET parameters.
  These make debugging REST interfaces using only a browser possible.
- Class or method level encoding.
- Class or method level guards.
- Class or method level converters.

The Juneau JAX-RS provider API consists of the following classes:

- {@link org.apache.juneau.rest.jaxrs.BaseProvider} - The base provider class that implements the JAX-RS MessageBodyReader and MessageBodyWriter interfaces.
- {@link org.apache.juneau.rest.jaxrs.JuneauProvider} - Annotation that is applied to subclasses of BaseProvider to specify the serializers/parsers associated with a provider, and optionally filters and properties to apply to those serializers and parsers.
- {@link org.apache.juneau.rest.jaxrs.BasicProvider} - A default provider that provides the same level of media type support as the {@link org.apache.juneau.rest.BasicRestServlet} class.

For the most part, when using these components, you'll either use the existing BasicProvider, or define your own by subclassing BaseProvider.

## 8 - juneau-rest-server-springboot 8.0.0-new

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-rest-server-springboot</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-rest-server-springboot-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.rest.server.springboot_{@property juneauVersion}.jar

The juneau-rest-server-springboot library provides classes to make it easy to integrate Juneau REST resources with Spring and Spring Boot.

### 8.1 - Overview 8.0.0-new

The Juneau integration component for Spring Boot consists of the following classes:

- {@link org.apache.juneau.rest.springboot.annotation.JuneauRestRoot}
- {@link org.apache.juneau.rest.springboot.JuneauRestInitializer}
- {@link org.apache.juneau.rest.springboot.SpringRestResourceResolver}

A typical Spring Boot application can use the {@link org.apache.juneau.rest.springboot.JuneauRestInitializer} to find and register Juneau REST servlets via the {@link org.apache.juneau.rest.springboot.annotation.JuneauRestRoot} annotation.

##### Example:

@SpringBootApplication @Controller public class App { public static void main(String[] args) { new SpringApplicationBuilder(App.class) .initializers(new JuneauRestInitializer(App.class)) .run(args); } /** Our root resource */ @Bean @JuneauRestRoot public RootResource getRootResource() { return new RootResource(); // A subclass of RestServlet. } }

The initializer will search for Spring beans annotated with the @JuneauRestRoot annotation identifying it as a top-level servlet to be deployed in the Spring Boot web container.

Another option is to use the @JuneauRestRoot annotation on your Spring Boot source class like so:

@SpringBootApplication @Controller @JuneauRestRoot(servlets=RootResource.class) public class App { public static void main(String[] args) { new SpringApplicationBuilder(App.class) .initializers(new JuneauRestInitializer(App.class)) .run(args); } }

The root servlets are given an instance of {@link org.apache.juneau.rest.springboot.SpringRestResourceResolver} which allows for child resources to be defined as injectable Spring beans.

The {@doc juneau-examples-rest-springboot} section describes how the Examples REST application is deployed using Spring Boot and quickly deployable as an online application using Heroku.

### 8.2 - Child Resources 8.1.0-new

When using the @JuneauRestRoot annotation, servlet are given an instance of {@link org.apache.juneau.rest.springboot.SpringRestResourceResolver}. The resource resolver gets passed down through the children hierarchy, allowing child resources to be defined as injectable Spring beans.

##### Example:

@Configuration public class AppConfiguration { @Bean @JuneauRestRoot public RootResource getRootResource() { return new RootResource(); } @Bean public ChildResource getChildResource() { return new ChildResource(); } @Bean public GrandChildResource getGrandChildResource() { return new GrandChildResource(); } }

The root resource class must extend from HttpServlet so that it can be registered as a normal servlet using the Spring Boot architecture. The {@link org.apache.juneau.rest.BasicRestServletGroup} class is our router class that extends from HttpServlet:

@Rest( path="/root", children={ ChildResource.class } ) public class RootResource extends BasicRestServletGroup { // No code needed. }

Because Spring Boot will automatically register any beans that extend from HttpServlet, we DON'T want the child classes to extend from HttpServlet. Instead, we extend from {@link org.apache.juneau.rest.BasicRestGroup} and {@link org.apache.juneau.rest.BasicRest} instead:

@Rest( path="/child", children={ GrandChildResource.class } ) public class ChildResource extends BasicRestGroup { // No code needed. }

@Rest( path="/grandchild" ) public class GrandChildResource extends BasicRest { // Injectable bean }

## 9 - juneau-rest-client

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-rest-client</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-rest-client-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.rest.client_{@property juneauVersion}.jar

The REST client API provides the ability to access remote REST interfaces and transparently convert the input and output to and from POJOs using any of the provided serializers and parsers.

Built upon the Apache HttpClient libraries, it extends that API and provides specialized APIs for working with REST interfaces while maintaining all the functionality available in the HttpClient API.

// Create a reusable JSON client. try (RestClient client = RestClient.create().json().build()) { // The address of the root resource. String url = "http://localhost:10000/addressBook"; // Do a REST GET against a remote REST interface and convert // the response to an unstructured ObjectMap object. ObjectMap m1 = client.doGet(url).getResponse(ObjectMap.class); // Same as above, except parse the JSON as a bean. AddressBook a2 = client.doGet(url).getResponse(AddressBook.class); } try (RestClient client = RestClient.create().serializer(XmlSerializer.class).parser(XmlSerializer.class).build()) { // Add a person to the address book. // Use XML as the transport medium. Person p = new Person("Joe Smith", 21); int returnCode = client.doPost(url + "/entries", p).run(); }

Juneau provides an HTTP client API that makes it extremely simple to connect to remote REST interfaces and seemlessly send and receive serialized POJOs in requests and responses.

##### Features

- Converts POJOs directly to HTTP request message bodies using {@link org.apache.juneau.serializer.Serializer} classes.
- Converts HTTP response message bodies directly to POJOs using {@link org.apache.juneau.parser.Parser} classes.
- Serializes and parses HTTP request and response parts (query/form-data parameters, headers, path variables) using OpenAPI marshalling and validation.
- Exposes the full functionality of the Apache HttpClient API by exposing all methods defined on the {@link org.apache.http.impl.client.HttpClientBuilder} class.

The client API is designed to work as a thin layer on top of the proven Apache HttpClient API. By leveraging the HttpClient library, details such as SSL certificate negotiation, proxies, encoding, etc... are all handled in Apache code.

The Juneau client API prereq's Apache HttpClient 4.5+. At a minimum, the following jars are required:

- httpclient-4.5.jar
- httpcore-4.4.1.jar
- httpmime-4.5.jar

##### Example:

// Examples below use the Juneau Address Book resource example // Create a reusable client with JSON support try (RestClient client = RestClient.create().json().build()) { // GET request, ignoring output try { int rc = client.doGet("http://localhost:10000/addressBook").run(); // Succeeded! } catch (RestCallException e) { // Failed! System.err.println( String.format("status=%s, message=%s", e.getResponseStatus(), e.getResponseMessage()) ); } // Remaining examples ignore thrown exceptions. // GET request, secure, ignoring output client.doGet("https://localhost:9443/sample/addressBook").run(); // GET request, getting output as a String. No POJO parsing is performed. // Note that when calling one of the getX() methods, you don't need to call connect() or disconnect(), since // it's automatically called for you. String output = client.doGet("http://localhost:10000/addressBook") .getResponseAsString(); // GET request, getting output as a Reader Reader r = client.doGet("http://localhost:10000/addressBook") .getReader(); // GET request, getting output as an untyped map // Input must be an object (e.g. "{...}") ObjectMap m = client.doGet("http://localhost:10000/addressBook/0") .getResponse(ObjectMap.class); // GET request, getting output as an untyped list // Input must be an array (e.g. "[...]") ObjectList l = client.doGet("http://localhost:10000/addressBook") .getResponse(ObjectList.class); // GET request, getting output as a parsed bean // Input must be an object (e.g. "{...}") // Note that you don't have to do any casting! Person p = client.doGet("http://localhost:10000/addressBook/0") .getResponse(Person.class); // GET request, getting output as a parsed bean // Input must be an array of objects (e.g. "[{...},{...}]") Person[] pa = client.doGet("http://localhost:10000/addressBook") .getResponse(Person[].class); // Same as above, except as a List<Person> List<Person> pl = client.doGet("http://localhost:10000/addressBook") .getResponse(List.class, Person.class); // GET request, getting output as a parsed string // Input must be a string (e.g. "<string>foo</string>" or "'foo'") String name = client.doGet("http://localhost:10000/addressBook/0/name") .getResponse(String.class); // GET request, getting output as a parsed number // Input must be a number (e.g. "<number>123</number>" or "123") int age = client.doGet("http://localhost:10000/addressBook/0/age") .getResponse(Integer.class); // GET request, getting output as a parsed boolean // Input must be a boolean (e.g. "<boolean>true</boolean>" or "true") boolean isCurrent = client.doGet("http://localhost:10000/addressBook/0/addresses/0/isCurrent") .getResponse(Boolean.class); } // GET request, getting a filtered object try (RestClient client = RestClient.create().pojoSwaps(TemporalCalendarSwap.IsoInstant.class).build()) { Calendar birthDate = client.doGet("http://localhost:10000/addressBook/0/birthDate") .getResponse(GregorianCalendar.class); // PUT request on regular field String newName = "John Smith"; int rc = client.doPut("http://localhost:10000/addressBook/0/name", newName).run(); // PUT request on filtered field Calendar newBirthDate = new GregorianCalendar(1, 2, 3, 4, 5, 6); rc = client.doPut("http://localhost:10000/addressBook/0/birthDate", newBirthDate).run(); // POST of a new entry to a list Address newAddress = new Address("101 Main St", "Anywhere", "NY", 12121, false); rc = client.doPost("http://localhost:10000/addressBook/0/addresses", newAddress).run(); }

- The {@link org.apache.juneau.rest.client.RestClient} class exposes all the builder methods on the Apache HttpClient {@link org.apache.http.impl.client.HttpClientBuilder} class.
  Use these methods to provide any customized HTTP client behavior.

### 9.1 - REST Proxies

The juneau-rest-client library can also be used to define interface proxies against 3rd-party REST interfaces. This is an extremely powerful feature that allows you to quickly define easy-to-use interfaces against virtually any REST interface.

Remote resources are instantiated using one of the following methods:

- {@link org.apache.juneau.rest.client.RestClient}
  - {@link org.apache.juneau.rest.client.RestClient#getRemote(Class) getRemote(Class)}
  - {@link org.apache.juneau.rest.client.RestClient#getRemote(Class,Object) getRemote(Class,Object)}
  - {@link org.apache.juneau.rest.client.RestClient#getRemote(Class,Object,Serializer,Parser) getRemote(Class,Object,Serializer,Parser)}

Annotations are used on the interface and interface methods to specify how to convert input and output to HTTP headers, query parameters, form post parameters, or request/response bodies.

- {@link org.apache.juneau.http.remote}
  - {@link org.apache.juneau.http.remote.Remote}
  - {@link org.apache.juneau.http.remote.RemoteMethod}
- {@link org.apache.juneau.http.annotation}
  - {@link org.apache.juneau.http.annotation.Body}
  - {@link org.apache.juneau.http.annotation.Header}
  - {@link org.apache.juneau.http.annotation.FormData}
  - {@link org.apache.juneau.http.annotation.Query}
  - {@link org.apache.juneau.http.annotation.Path}
  - {@link org.apache.juneau.http.annotation.Request}
  - {@link org.apache.juneau.http.annotation.Response}

##### Example:

@Remote(path="/petstore") public interface PetStore { @RemoteMethod(httpMethod=POST, path="/pets") String addPet( @Body CreatePet pet, @Header("E-Tag") UUID etag, @Query("debug") boolean debug ); }

// Use a RestClient with default Simple JSON support. try (RestClient client = RestClient.create().simpleJson().build()) { PetStore store = client.getRemote(PetStore.class, "http://localhost:10000"); CreatePet pet = new CreatePet("Fluffy", 9.99); String response = store.createPet(pet, UUID.randomUUID(), true); }

The call above translates to the following REST call:

POST http://localhost:10000/petstore/pets?debug=true HTTP/1.1 Accept: application/json Content-Type: application/json E-Tag: 475588d4-0b27-4f56-9296-cc683251d314 { name: 'Fluffy', price: 9.99 }

#### 9.1.1 - @Remote 8.1.2-updated

The {@link org.apache.juneau.http.remote.Remote @Remote} annotation is used on your interface class to identify it as a REST proxy interface.

- {@link org.apache.juneau.http.remote.Remote}
  - {@link org.apache.juneau.http.remote.Remote#path path}

The @Remote annotation is optional, but often included for code readability.

##### @Remote(path)

The {@link org.apache.juneau.http.remote.Remote#path @Remote(path)} annotation is used to define the HTTP path of the REST service.

The path can be an absolute path to your REST service.

##### Example:

@Remote(path="http://localhost:10000/petstore") public interface PetStore {...}

PetStore p = client.getRemote(PetStore.class);

When a relative path is specified, it's relative to the root-url defined on the RestClient used to instantiate the interface.

##### Example:

@Remote(path="/petstore") public interface PetStore {...}

RestClient client = RestClient.create().json().rootUrl("http://localhost:10000").build(); PetStore p = client.getRemote(PetStore.class);

When no path is specified, the root-url defined on the RestClient is used.

##### Example:

@Remote public interface PetStore {...}

RestClient client = RestClient.create().json().rootUrl("http://localhost:10000/petstore").build(); PetStore p = client.getRemote(PetStore.class);

#### 9.1.2 - @RemoteMethod

The {@link org.apache.juneau.http.remote.RemoteMethod @RemoteMethod} annotation is applied to methods of @Remote-annotated interfaces to identify REST endpoints.

- {@link org.apache.juneau.http.remote.RemoteMethod}
  - {@link org.apache.juneau.http.remote.RemoteMethod#method method}
  - {@link org.apache.juneau.http.remote.RemoteMethod#path path}
  - {@link org.apache.juneau.http.remote.RemoteMethod#returns returns}

##### @RemoteMethod(method/path)

The HTTP method and path are mapped to a Java method using the method and path annotations.

##### Example:

@Remote public interface PetStore { // GET /pets/{petId} @RemoteMethod(method="GET", path="/pets/{petId}") Pet getPet(@Path("petId") int id); }

The Java method name can be anything.

##### Inferred method/path

In such cases, method and path annotations are optional if you follow certain naming conventions on your method that identify the method and path.

For example, the getPet method below defaults to GET /pet:

@Remote public interface PetStore { // GET /pet @RemoteMethod Pet getPet(...); }

In such cases, the @RemoteMethod annotation is optional.

Method names matching the following pattern are assumed to be implying the HTTP method name:

(get|put|post|delete|options|head|connect|trace|patch).*

do(?i)(get|put|post|delete|options|head|connect|trace|patch)

##### Examples:

Java method name | Inferred HTTP method | Inferred HTTP path
--- | --- | ---
getPet() | GET | /pet
get() | GET | /
postPet() | POST | /pet
fooPet() | [default] | /fooPet
doGet() | GET | /
doGET() | GET | /
doFoo() | [default] | /doFoo

##### @RemoteMethod(returns)

The return type of the Java methods of can be any of the following:

- void - Don't parse any response.
  Note that the method will still throw a runtime exception if an error HTTP status is returned.
- Any {@doc PojoCategories parsable} POJO - The body of the response will be converted to the POJO using the parser defined on the RestClient based on the Content-Type of the response.
- Any {@link org.apache.juneau.http.annotation.Response @Response}-annotated type. (described later)
- HttpResponse - Returns the raw HttpResponse returned by the inner HttpClient.
- {@link java.io.Reader} - Returns access to the raw reader of the response.
- {@link java.io.InputStream} - Returns access to the raw input stream of the response.

If you're only interested in the HTTP status code of the response, you can use the {@link org.apache.juneau.http.remote.RemoteMethod#returns() returns} annotation with a value of {@link org.apache.juneau.http.remote.RemoteReturn#STATUS STATUS}:

##### Example:

@Remote public interface PetStore { // POST /pets // Returns HTTP status code. @RemoteMethod(returns=STATUS) int postPets(...); }

If your RestClient does not have a parser associated with it, then the value is converted directly from a String using the rules defined in {@doc PojosConveribleToStrings}.

#### 9.1.3 - @Body

The {@link org.apache.juneau.http.annotation.Body @Body} annotation can be applied to arguments of @RemoteMethod-annotated methods to denote that they are the HTTP body of the request.

- {@link org.apache.juneau.http.annotation.Body}
  - {@link org.apache.juneau.http.annotation.Body#required() required} - Input validation. Body must be present.
  - {@link org.apache.juneau.http.annotation.Body#schema() schema} - Swagger schema.

##### Examples:

// Used on parameter @Remote(path="/petstore") public interface PetStore { @RemoteMethod(path="/pets") String addPet(@Body Pet pet); }

// Used on class @Remote(path="/petstore") public interface PetStore { @RemoteMethod(path="/pets") String addPet(Pet pet); } @Body public class Pet {...}

The argument can be any of the following types:

- Any serializable POJO - Converted to output using the {@link org.apache.juneau.serializer.Serializer} registered with the RestClient.
  Content-Type is set to that of the Serializer.
- {@link java.io.Reader} - Raw contents of {@code Reader} will be serialized to remote resource.
  Content-Type is set to "text/plain".
- {@link java.io.InputStream} - Raw contents of {@code InputStream} will be serialized to remote resource.
  Content-Type is set to "application/octet-stream".
- NameValuePairs - Converted to a URL-encoded FORM post.
  Content-Type is set to "aplication/x-www-form-urlencoded".
- HttpEntity - Bypass Juneau serialization and pass HttpEntity directly to HttpClient.

OpenAPI schema based serialization can be used by using the {@link org.apache.juneau.oapi.OpenApiSerializer} class.

@RemoteMethod(path="/comma-delimited-pipe-delimited-ints") String addCommaDelimitedPipeDelimitedInts( @Body( serializer=OpenApiSerializer.class, schema=@Schema( type="array", collectionFormat="pipes", items=@Items( type="array" items=@SubItems( type="int32", // Auto-validates on client side! minimum="0", maximum="64" ) ) ) ) int[][] input );

See {@doc juneau-marshall.OpenApiDetails.Serializers} for information about supported data types in OpenAPI serialization.

If your RestClient class does not have a serializer associated with it, the body will automatically be serialized to a string using the rules defined in {@doc PojosConveribleToStrings}.

#### 9.1.4 - @FormData

The {@link org.apache.juneau.http.annotation.FormData @FormData} annotation can be applied to arguments of @RemoteMethod-annotated methods to denote that they are form-data parameters on the request.

- {@link org.apache.juneau.http.annotation.FormData}
  - {@link org.apache.juneau.http.annotation.FormData#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.FormData#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.FormData#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.FormData#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.FormData#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.FormData#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.FormData#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.FormData#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.FormData#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.FormData#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.FormData#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.FormData#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.FormData#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.FormData#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.FormData#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.FormData#name() name} - Form data entry name.
  - {@link org.apache.juneau.http.annotation.FormData#pattern() pattern}- Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.FormData#required() required}- Input validation. Form data entry must be present.
  - {@link org.apache.juneau.http.annotation.FormData#serializer() serializer}- Override the part serializer.
  - {@link org.apache.juneau.http.annotation.FormData#skipIfEmpty() skipIfEmpty}- Don't add if value is null or empty.
  - {@link org.apache.juneau.http.annotation.FormData#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.FormData#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.

##### Example:

@Remote(path="/myproxy") public interface MyProxy { // Explicit names specified for form data parameters. @RemoteMethod String postParameters( @FormData("foo") String foo, @FormData("bar") MyPojo pojo ); // Multiple values pulled from a NameValuePairs object. // Name "*" is inferred. @RemoteMethod String postNameValuePairs(@FormData NameValuePairs nameValuePairs); // Multiple values pulled from a Map. @RemoteMethod String postMap(@FormData Map<String,Object> map); // Multiple values pulled from a bean. @RemoteMethod String postBean(@FormData MyBean bean); // An entire form-data HTTP body as a String. @RemoteMethod String postString(@FormData String string); // An entire form-data HTTP body as a Reader. @RemoteMethod String postReader(@FormData Reader reader); }

Single-part arguments (i.e. those with name != "*") can be any of the following types:

- Any serializable POJO - Converted to a string using the {@link org.apache.juneau.httppart.HttpPartSerializer} registered with the RestClient ({@link org.apache.juneau.oapi.OpenApiSerializer} by default) or associated via the {@link org.apache.juneau.http.annotation.FormData#serializer() @FormData(serializer)} annotation.

Multi-part arguments (i.e. those with name == "*" or empty) can be any of the following types:

- {@link java.io.Reader} - Raw contents of {@code Reader} will be serialized to remote resource.
- {@link java.io.InputStream} - Raw contents of {@code InputStream} will be serialized to remote resource.
- NameValuePairs - Converted to a URL-encoded FORM post.
- Map - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).
- Bean - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).
- CharSequence - Used directly as am "application/x-www-form-urlencoded" entity.

See the link below for information about supported data types in OpenAPI serialization.

- {@doc juneau-marshall.OpenApiDetails.Serializers}

#### 9.1.5 - @Query

The {@link org.apache.juneau.http.annotation.Query @Query} annotation can be applied to arguments of @RemoteMethod-annotated methods to denote that they are query parameters on the request.

- {@link org.apache.juneau.http.annotation.Query}
  - {@link org.apache.juneau.http.annotation.Query#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.Query#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.Query#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.Query#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.Query#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.Query#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.Query#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.Query#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.Query#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.Query#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Query#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.Query#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.Query#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Query#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.Query#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.Query#name() name} - Query parameter name.
  - {@link org.apache.juneau.http.annotation.Query#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.Query#required() required} - Input validation. Query parameter must be present.
  - {@link org.apache.juneau.http.annotation.Query#serializer() serializer} - Override the part serializer.
  - {@link org.apache.juneau.http.annotation.Query#skipIfEmpty() skipIfEmpty}- Don't add if value is null or empty.
  - {@link org.apache.juneau.http.annotation.Query#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.Query#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.

##### Example:

@Remote(path="/myproxy") public interface MyProxy { // Explicit names specified for query parameters. @RemoteMethod String parameters( @Query("foo") String foo, @Query("bar") MyPojo pojo); // Multiple values pulled from a NameValuePairs object. // Same as @Query("*"). @RemoteMethod String nameValuePairs(@Query NameValuePairs nameValuePairs); // Multiple values pulled from a Map. // Same as @Query("*"). @RemoteMethod String map(@Query Map<String,Object> map); // Multiple values pulled from a bean. // Same as @Query("*"). @RemoteMethod String bean(@Query MyBean myBean); // An entire query string as a String. // Same as @Query("*"). @RemoteMethod String string(@Query String string); // An entire query string as a Reader. // Same as @Query("*"). @RemoteMethod String reader(@Query Reader reader); }

Single-part arguments (i.e. those with name != "*") can be any of the following types:

- Any serializable POJO - Converted to a string using the {@link org.apache.juneau.httppart.HttpPartSerializer} registered with the RestClient ({@link org.apache.juneau.oapi.OpenApiSerializer} by default) or associated via the {@link org.apache.juneau.http.annotation.Query#serializer() @Query(serializer)} annotation.

Multi-part arguments (i.e. those with name == "*" or empty) can be any of the following types:

- {@link java.io.Reader} - Raw contents of {@code Reader} will be serialized directly a query string.
- NameValuePairs - Serialized as individual query parameters.
- Map - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).
- Bean - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).
- CharSequence - Serialized directly a query string.

See the link below for information about supported data types in OpenAPI serialization.

- {@doc juneau-marshall.OpenApiDetails.Serializers}

#### 9.1.6 - @Header

The {@link org.apache.juneau.http.annotation.Header @Header} annotation can be applied to arguments of @RemoteMethod-annotated methods to denote that they are header parameters on the request.

- {@link org.apache.juneau.http.annotation.Header}
  - {@link org.apache.juneau.http.annotation.Header#_default() _default} - Default value if not present.
  - {@link org.apache.juneau.http.annotation.Header#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.Header#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.Header#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.Header#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.Header#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.Header#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.Header#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.Header#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.Header#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Header#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.Header#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.Header#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link org.apache.juneau.http.annotation.Header#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.Header#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.Header#name() name} - Header name.
  - {@link org.apache.juneau.http.annotation.Header#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.Header#required() required} - Input validation. Header must be present.
  - {@link org.apache.juneau.http.annotation.Header#serializer() serializer} - Override the part serializer.
  - {@link org.apache.juneau.http.annotation.Header#skipIfEmpty() skipIfEmpty} - Don't add if value is null or empty.
  - {@link org.apache.juneau.http.annotation.Header#type() type} - The schema type.
  - {@link org.apache.juneau.http.annotation.Header#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.

##### Example:

@Remote(path="/myproxy") public interface MyProxy { // Explicit names specified for HTTP headers. // pojo will be converted to UON notation (unless plain-text parts enabled). @RemoteMethod(path="/mymethod1") String myProxyMethod1(@Header("Foo") String foo, @Header("Bar") MyPojo pojo); // Multiple values pulled from a NameValuePairs object. // Same as @Header("*"). @RemoteMethod(path="/mymethod2") String myProxyMethod2(@Header NameValuePairs nameValuePairs); // Multiple values pulled from a Map. // Same as @Header("*"). @RemoteMethod(path="/mymethod3") String myProxyMethod3(@Header Map<String,Object> map); // Multiple values pulled from a bean. // Same as @Header("*"). @RemoteMethod(path="/mymethod4") String myProxyMethod4(@Header MyBean myBean); }

Single-part arguments (i.e. those with name != "*") can be any of the following types:

- Any serializable POJO - Converted to a string using the {@link org.apache.juneau.httppart.HttpPartSerializer} registered with the RestClient ({@link org.apache.juneau.oapi.OpenApiSerializer} by default) or associated via the {@link org.apache.juneau.http.annotation.Header#serializer() @Header(serializer)} annotation.

Multi-part arguments (i.e. those with name == "*" or empty) can be any of the following types:

- NameValuePairs - Serialized as individual headers.
- Map - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).
- Bean - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).

See the link below for information about supported data types in OpenAPI serialization.

- {@doc juneau-marshall.OpenApiDetails.Serializers}

#### 9.1.7 - @Path

The {@link org.apache.juneau.http.annotation.Path @Path} annotation can be applied to arguments of @RemoteMethod-annotated methods to denote that they are path parameters on the request.

- {@link org.apache.juneau.http.annotation.Path}
  - {@link org.apache.juneau.http.annotation.Path#_enum() _enum} - Input validation. Must match one of the values.
  - {@link org.apache.juneau.http.annotation.Path#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link org.apache.juneau.http.annotation.Path#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link org.apache.juneau.http.annotation.Path#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link org.apache.juneau.http.annotation.Path#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link org.apache.juneau.http.annotation.Path#format() format} - The schema type format.
  - {@link org.apache.juneau.http.annotation.Path#items() items} - The schema of items in a collection.
  - {@link org.apache.juneau.http.annotation.Path#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link org.apache.juneau.http.annotation.Path#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link org.apache.juneau.http.annotation.Path#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link org.apache.juneau.http.annotation.Path#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link org.apache.juneau.http.annotation.Path#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link org.apache.juneau.http.annotation.Path#name() name} - Path variable name.
  - {@link org.apache.juneau.http.annotation.Path#pattern() pattern} - Input validation. Must match regular expression.
  - {@link org.apache.juneau.http.annotation.Path#serializer() serializer} - Override the part serializer.
  - {@link org.apache.juneau.http.annotation.Path#type() type} - The schema type.

##### Example:

@Remote(path="/myproxy") public interface MyProxy { // Explicit names specified for path parameters. // pojo will be converted to UON notation (unless plain-text parts enabled). @RemoteMethod(path="/mymethod1/{foo}/{bar}") String myProxyMethod1(@Path("foo") String foo, @Path("bar") MyPojo pojo); // Multiple values pulled from a NameValuePairs object. // Same as @Path("*"). @RemoteMethod(path="/mymethod2/{foo}/{bar}/{baz}") String myProxyMethod2(@Path NameValuePairs nameValuePairs); // Multiple values pulled from a Map. // Same as @Path("*"). @RemoteMethod(path="/mymethod3/{foo}/{bar}/{baz}") String myProxyMethod3(@Path Map<String,Object> map); // Multiple values pulled from a bean. // Same as @Path("*"). @RemoteMethod(path="/mymethod4/{foo}/{bar}/{baz}") String myProxyMethod4(@Path MyBean myBean); }

Single-part arguments (i.e. those with name != "*") can be any of the following types:

- Any serializable POJO - Converted to a string using the {@link org.apache.juneau.httppart.HttpPartSerializer} registered with the RestClient ({@link org.apache.juneau.oapi.OpenApiSerializer} by default) or associated via the {@link org.apache.juneau.http.annotation.Path#serializer() @Path(serializer)} annotation.

Multi-part arguments (i.e. those with name == "*" or empty) can be any of the following types:

- NameValuePairs - Serialized as individual query parameters.
- Map - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).
- Bean - Converted to key-value pairs.
  Values serialized using the registered {@link org.apache.juneau.httppart.HttpPartSerializer} ({@link org.apache.juneau.oapi.OpenApiSerializer} by default).

See the link below for information about supported data types in OpenAPI serialization.

- {@doc juneau-marshall.OpenApiDetails.Serializers}

#### 9.1.8 - @Request

The {@link org.apache.juneau.http.annotation.Request @Request} annotation can be applied to a type of a @RemoteMethod-annotated method to identify it as a bean for setting HTTP parts through a bean-like interface.

- {@link org.apache.juneau.http.annotation.Request}
  - {@link org.apache.juneau.http.annotation.Request#partSerializer() partSerializer} - Override the part serializer.

##### Example:

@Remote(path="/petstore") public interface PetStore { @RemoteMethod String postPet(CreatePetRequest bean); }

@Request public class CreatePetRequest { private CreatePet pet; public CreatePetRequest(String name, float price) { this.pet = new CreatePet(name, price); } @Body public CreatePet getBody() { return this.pet; } @Query public Map<String,Object> getQueryParams() { return new ObjectMap().append("debug", true); } @Header("E-Tag") public static UUID getUUID() { return UUID.generatedUUID(); } }

PetStore store = restClient.getRemote(PetStore.class, "http://localhost:10000"); CreatePetRequest requestBean = new CreatePetRequest("Fluffy", 9.99); String response = store.postPet(requestBean);

The @Request annotation can be applied to either the class or argument.

The annotated methods must be no-arg and public. They can be named anything.

Any of the following annotations can be used on the methods:

- {@link org.apache.juneau.http.annotation.Body}
- {@link org.apache.juneau.http.annotation.Header}
- {@link org.apache.juneau.http.annotation.FormData}
- {@link org.apache.juneau.http.annotation.Query}
- {@link org.apache.juneau.http.annotation.Path}

The behavior and functionality of all of the annotations are the same as if they were used on method arguments directly. This means full support for OpenAPI serialization and validation.

Annotations on methods are inherited from parent classes and interfaces. For example, the request bean above could have defined annotations in an interface to keep them clear from the implementation:

@Request public interface CreatePetRequest { @Body CreatePet getBody(); @Query Map<String,Object> getQueryParams(); @Header("E-Tag") UUID getUUID(); }

public class CreatePetRequestImpl implements CreatePetRequest { public CreatePetRequestImpl(String name, float price) {...} @Override public CreatePet getBody() { return this.pet; } @Override public Map<String,Object> getQueryParams() { return new ObjectMap().append("debug", true); } @Override public UUID getUUID() { return UUID.generateUUID(); } }

#### 9.1.9 - @Response

The {@link org.apache.juneau.http.annotation.Response @Response} annotation can be applied to types returned by @RemoteMethod-annotated methods.

- {@link org.apache.juneau.http.annotation.Response}
  - {@link org.apache.juneau.http.annotation.Response#partParser() partParser} - Override the part parser.

The @Response annotation can be used to define interfaces for retrieving response parts using a bean-like proxy.

##### Example:

@Remote public interface PetStore { @RemoteMethod CreatePetResponse postPet(...); }

@Response public interface CreatePetResponse { @ResponseBody Pet getBody(); @ResponseHeader("E-Tag") UUID getUUID(); @ResponseStatus int getStatus(); }

PetStore store = restClient.getRemote(PetStore.class, "http://localhost:10000"); CreatePetResponse response = store.postPet(...); Pet pet = response.getBody(); UUID uuid = response.getUUID(); int status = response.getStatus();

The annotated methods must be no-arg. They can be named anything.

Any of the following annotations can be used on the methods:

- {@link org.apache.juneau.http.annotation.ResponseBody}
- {@link org.apache.juneau.http.annotation.ResponseHeader}
- {@link org.apache.juneau.http.annotation.ResponseStatus}

The behavior and functionality of all of the annotations are the same as if they were used on method arguments directly. This means full support for OpenAPI serialization and validation.

#### 9.1.10 - Dual-purpose (end-to-end) interfaces 8.0.0-new

A common coding practice is to use the same Java interface to define both your server and client side REST interfaces. The advantage to this approach is that changes that you make to your REST interface can be reflected in both places at the same time, reducing the chances for compatibility mistakes.

What makes this possible is that method-level annotations such as @RestMethod and parameter-level annotations such as @Query are inherited from parent classes. This normally isn't possible, but the framework will spider up the parent hierarchy of classes to find method and parameter level annotations defined on overridden methods.

The general approach is to define your {@link org.apache.juneau.http.remote.Remote @Remote}-annotated interface first. The following example is pulled from the PetStore app:

@Remote(path="/petstore") public interface PetStore { @RemoteMethod(method=GET, path="/pet") public Collection<Pet> getPets() throws NotAcceptable; @RemoteMethod(method=DELETE, path="/pet/{petId}") public Ok deletePet( @Header( name="api_key", description="Security API key", required=true, example="foobar" ) String apiKey, @Path( name="petId", description="Pet id to delete", example="123" ) long petId ) throws IdNotFound, NotAcceptable; ...

Next you define the implementation of your interface as a normal Juneau REST resource:

@Rest( path="/petstore", title="Petstore application", ... ) public class PetStoreResource extends BasicRestJena implements PetStore { ... @Override /* PetStore */ @RestMethod( name=GET, path="/pet", summary="All pets in the store", ... ) public Collection<Pet> getPets() throws NotAcceptable { return store.getPets(); } @Override /* PetStore */ @RestMethod( name=DELETE, path="/pet/{petId}", summary="Deletes a pet", ... ) public Ok deletePet(String apiKey, long petId) throws IdNotFound, NotAcceptable { store.removePet(petId); return OK; }

Then use the interface as a remote resource like so:

try (RestClient rc = RestClient.create().json().rootUrl("http://localhost:10000").build()) { PetStore ps = rc.getRemote(PetStore.class); for (Pet x : ps.getPets()) { ps.deletePet("my-special-key", x.getId()); System.err.println("Deleted pet: id=" + x.getId()); } }

In the example above, we chose to add the @RestMethod annotation to the implementation class. However, they could have been added to the interface instead.

Note how we didn't need to use the @Header and @Path annotations in our implementation since the annotations were inherited from the interface.

### 9.2 - SSL Support

The simplest way to enable SSL support in the client is to use the {@link org.apache.juneau.rest.client.RestClientBuilder#enableLaxSSL()} method.

##### Example:

// Create a client that ignores self-signed or otherwise invalid certificates. RestClient rc = RestClient.create().enableLaxSSL().build();

A more typical scenario using default cert and hostname verification is shown here:

RestClient rc = RestClient.create().enableSSL().sslProtocols("TLSv1.2").build();

The following convenience methods are provided in the builder class for specifying SSL parameters:

- {@link org.apache.juneau.rest.client.RestClientBuilder}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#sslProtocols(String...) sslProtocols(String...)}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#cipherSuites(String...) cipherSuites(String...)}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#hostnameVerifier(HostnameVerifier) hostnameVerifier(HostnameVerifier)}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#keyManagers(KeyManager...) keyManagers(KeyManager...)}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#trustManagers(TrustManager...)}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#secureRandom(SecureRandom)}

SSL support can also be enabled by passing in your own connection manager using {@link org.apache.juneau.rest.client.RestClientBuilder#httpClientConnectionManager(HttpClientConnectionManager)}.

### 9.3 - Authentication

The Juneau REST client itself does not implement any support for authentication. Instead, it delegates it to the underlying Apache HTTP Client interface.

The following sections show how some common authentication mechanisms can be set up using HTTP Client APIs.

#### 9.3.1 - BASIC Authentication

The {@link org.apache.juneau.rest.client.RestClientBuilder#basicAuth(String,int,String,String)} method can be used to quickly enable BASIC authentication support.

##### Example:

// Create a client that performs BASIC authentication using the specified user/pw. RestClient restClient = RestClient.create() .basicAuth(HOST, PORT, USER, PW) .build();

This is functionally equivalent to the following:

RestClientBuilder builder = RestClient.create(); AuthScope scope = new AuthScope(HOST, PORT); Credentials up = new UsernamePasswordCredentials(USER, PW); CredentialsProvider p = new BasicCredentialsProvider(); p.setCredentials(scope, up); builder.setDefaultCredentialsProvider(p);

#### 9.3.2 - FORM-based Authentication

The {@link org.apache.juneau.rest.client.RestClientBuilder} class does not itself provide FORM-based authentication since there is no standard way of providing such support. Typically, to perform FORM-based or other types of authentication, you'll want to create your own subclass of {@link org.apache.juneau.rest.client.RestClientBuilder} and override the {@link org.apache.juneau.rest.client.RestClientBuilder#createHttpClient()} method to provide an authenticated client.

The following example shows how the JazzRestClient class provides FORM-based authentication support.

/** * Constructor. */ public JazzRestClientBuilder(URI jazzUri, String user, String pw) throws IOException { ... } /** * Override the createHttpClient() method to return an authenticated client. */ @Override /* RestClientBuilder */ protected CloseableHttpClient createHttpClient() throws Exception { CloseableHttpClient client = super.createHttpClient(); formBasedAuthenticate(client); visitAuthenticatedURL(client); return client; } /* * Performs form-based authentication against the Jazz server. */ private void formBasedAuthenticate(HttpClient client) throws IOException { URI uri2 = jazzUri.resolve("j_security_check"); HttpPost request = new HttpPost(uri2); request.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build()); // Charset must explicitly be set to UTF-8 to handle user/pw with non-ascii characters. request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); NameValuePairs params = new NameValuePairs() .append(new BasicNameValuePair("j_username"", user)) .append(new BasicNameValuePair("j_password", pw)); request.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(request); try { int rc = response.getStatusLine().getStatusCode(); Header authMsg = response.getFirstHeader("X-com-ibm-team-repository-web-auth-msg"); if (authMsg != null) throw new IOException(authMsg.getValue()); // The form auth request should always respond with a 200 ok or 302 redirect code if (rc == SC_MOVED_TEMPORARILY) { if (response.getFirstHeader("Location").getValue().matches("^.*/auth/authfailed.*$")) throw new IOException("Invalid credentials."); } else if (rc != SC_OK) { throw new IOException("Unexpected HTTP status: " + rc); } } finally { EntityUtils.consume(response.getEntity()); } } /* * This is needed for Tomcat because it responds with SC_BAD_REQUEST when the j_security_check URL is visited before an * authenticated URL has been visited. This same URL must also be visited after authenticating with j_security_check * otherwise tomcat will not consider the session authenticated */ private int visitAuthenticatedURL(HttpClient httpClient) throws IOException { HttpGet authenticatedURL = new HttpGet(jazzUri.resolve("authenticated/identity")); HttpResponse response = httpClient.execute(authenticatedURL); try { return response.getStatusLine().getStatusCode(); } finally { EntityUtils.consume(response.getEntity()); } }

#### 9.3.3 - OIDC Authentication

The following example shows how the JazzRestClient class provides OIDC authentication support.

/** * Constructor. */ public JazzRestClientBuilder(URI jazzUri, String user, String pw) throws IOException { ... } /** * Override the createHttpClient() method to return an authenticated client. */ @Override /* RestClientBuilder */ protected CloseableHttpClient createHttpClient() throws Exception { CloseableHttpClient client = super.createHttpClient(); oidcAuthenticate(client); return client; } private void oidcAuthenticate(HttpClient client) throws IOException { HttpGet request = new HttpGet(jazzUri); request.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build()); // Charset must explicitly be set to UTF-8 to handle user/pw with non-ascii characters. request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); HttpResponse response = client.execute(request); try { int code = response.getStatusLine().getStatusCode(); // Already authenticated if (code == SC_OK) return; if (code != SC_UNAUTHORIZED) throw new RestCallException("Unexpected response during OIDC authentication: " + response.getStatusLine()); // x-jsa-authorization-redirect String redirectUri = getHeader(response, "X-JSA-AUTHORIZATION-REDIRECT"); if (redirectUri == null) throw new RestCallException("Expected a redirect URI during OIDC authentication: " + response.getStatusLine()); // Handle Bearer Challenge HttpGet method = new HttpGet(redirectUri + "&prompt=none"); addDefaultOidcHeaders(method); response = client.execute(method); code = response.getStatusLine().getStatusCode(); if (code != SC_OK) throw new RestCallException("Unexpected response during OIDC authentication phase 2: " + response.getStatusLine()); String loginRequired = getHeader(response, "X-JSA-LOGIN-REQUIRED"); if (! "true".equals(loginRequired)) throw new RestCallException("X-JSA-LOGIN-REQUIRED header not found on response during OIDC authentication phase 2: " + response.getStatusLine()); method = new HttpGet(redirectUri + "&prompt=none"); addDefaultOidcHeaders(method); response = client.execute(method); code = response.getStatusLine().getStatusCode(); if (code != SC_OK) throw new RestCallException("Unexpected response during OIDC authentication phase 3: " + response.getStatusLine()); // Handle JAS Challenge method = new HttpGet(redirectUri); addDefaultOidcHeaders(method); response = client.execute(method); code = response.getStatusLine().getStatusCode(); if (code != SC_OK) throw new RestCallException("Unexpected response during OIDC authentication phase 4: " + response.getStatusLine()); cookie = getHeader(response, "Set-Cookie"); Header[] defaultHeaders = new Header[] { new BasicHeader("User-Agent", "Jazz Native Client"), new BasicHeader("X-com-ibm-team-configuration-versions", "com.ibm.team.rtc=6.0.0,com.ibm.team.jazz.foundation=6.0"), new BasicHeader("Accept", "text/json"), new BasicHeader("Authorization", "Basic " + StringUtils.base64EncodeToString(user + ":" + pw)), new BasicHeader("Cookie", cookie) }; setDefaultHeaders(Arrays.asList(defaultHeaders)); } finally { EntityUtils.consume(response.getEntity()); } } private void addDefaultOidcHeaders(HttpRequestBase method) { method.addHeader("User-Agent", "Jazz Native Client"); method.addHeader("X-com-ibm-team-configuration-versions", "com.ibm.team.rtc=6.0.0,com.ibm.team.jazz.foundation=6.0"); method.addHeader("Accept", "text/json"); if (cookie != null) { method.addHeader("Authorization", "Basic " + StringUtils.base64EncodeToString(user + ":" + pw)); method.addHeader("Cookie", cookie); } }

### 9.4 - Using Response Patterns

One issue with REST (and HTTP in general) is that the HTTP response code must be set as a header before the body of the request is sent. This can be problematic when REST calls invoke long-running processes, pipes the results through the connection, and then fails after an HTTP 200 has already been sent.

One common solution is to serialize some text at the end to indicate whether the long-running process succeeded (e.g. "FAILED" or "SUCCEEDED").

The {@link org.apache.juneau.rest.client.RestClient} class has convenience methods for scanning the response without interfering with the other methods used for retrieving output.

The following example shows how the {@link org.apache.juneau.rest.client.RestCall#successPattern(String)} method can be used to look for a SUCCESS message in the output:

##### Example:

// Throw a RestCallException if SUCCESS is not found in the output. restClient.doPost(URL) .successPattern("SUCCESS") .run();

The {@link org.apache.juneau.rest.client.RestCall#failurePattern(String)} method does the opposite. It throws an exception if a failure message is detected.

##### Example:

// Throw a RestCallException if FAILURE or ERROR is found in the output. restClient.doPost(URL) .failurePattern("FAILURE|ERROR") .run();

These convenience methods are specialized methods that use the {@link org.apache.juneau.rest.client.RestCall#responsePattern(ResponsePattern)} method which uses regular expression matching against the response body. This method can be used to search for arbitrary patterns in the response body.

The following example shows how to use a response pattern finder to find and capture patterns for "x=number" and "y=string" from a response body.

##### Example:

final List<Number> xList = new ArrayList<Number>(); final List<String> yList = new ArrayList<String>(); String responseText = restClient.doGet(URL) .responsePattern( new ResponsePattern("x=(\\d+)") { @Override public void onMatch(RestCall restCall, Matcher m) throws RestCallException { xList.add(Integer.parseInt(m.group(1))); } @Override public void onNoMatch(RestCall restCall) throws RestCallException { throw new RestCallException("No X's found!"); } } ) .responsePattern( new ResponsePattern("y=(\\S+)") { @Override public void onMatch(RestCall restCall, Matcher m) throws RestCallException { yList.add(m.group(1)); } @Override public void onNoMatch(RestCall restCall) throws RestCallException { throw new RestCallException("No Y's found!"); } } ) .getResponseAsString();

Using response patterns does not affect the functionality of any of the other methods used to retrieve the response such as {@link org.apache.juneau.rest.client.RestCall#getResponseAsString()} or {@link org.apache.juneau.rest.client.RestCall#getResponse(Class)}. HOWEVER, if you want to retrieve the entire text of the response from inside the match methods, use {@link org.apache.juneau.rest.client.RestCall#getCapturedResponse()} since this method will not absorb the response for those other methods.

### 9.5 - Piping Response Output

The {@link org.apache.juneau.rest.client.RestCall} class provides various convenience pipeTo() methods to pipe output to output streams and writers.

If you want to pipe output without any intermediate buffering, you can use the {@link org.apache.juneau.rest.client.RestCall#byLines()} method. This will cause the output to be piped and flushed after every line. This can be useful if you want to display the results in real-time from a long running process producing output on a REST call.

##### Example:

// Pipe output from REST call to System.out in real-time. restClient.doPost(URL).byLines().pipeTo(new PrintWriter(System.out)).run();

### 9.6 - Debugging

Use the {@link org.apache.juneau.rest.client.RestClientBuilder#debug()} method to enable logging for HTTP requests made from the client.

Under-the-covers, this is simply a shortcut for adding the {@link org.apache.juneau.rest.client.RestCallLogger#DEFAULT} interceptor to the client. This causes the following output to be generated by the Java org.apache.juneau.rest.client logger at WARNING level:

=== HTTP Call (outgoing) ======================================================= === REQUEST === POST http://localhost:10000/testUrl HTTP/1.1 ---request headers--- Debug: true No-Trace: true Accept: application/json ---request entity--- Content-Type: application/json ---request content--- {"foo":"bar","baz":123} === RESPONSE === HTTP/1.1 200 OK ---response headers--- Content-Type: application/json;charset=utf-8 Content-Length: 21 Server: Jetty(8.1.0.v20120127) ---response content--- {"message":"OK then"} === END ========================================================================

This setting also causes a Debug: true header value to trigger logging of the request on the server side as well.

=== HTTP Request (incoming) ==================================================== HTTP POST /testUrl ---Headers--- Host: localhost:10000 Transfer-Encoding: chunked Accept: application/json Content-Type: application/json User-Agent: Apache-HttpClient/4.5 (Java/1.6.0_65) Connection: keep-alive Debug: true Accept-Encoding: gzip,deflate ---Default Servlet Headers--- ---Body--- {"foo":"bar","baz":123} === END ========================================================================

### 9.7 - Logging

Use the {@link org.apache.juneau.rest.client.RestClientBuilder#logTo(Level,Logger)} and {@link org.apache.juneau.rest.client.RestCall#logTo(Level,Logger)} methods to log HTTP calls. These methods will cause the HTTP request and response headers and body to be logged to the specified logger.

##### Example:

// Log the HTTP request/response to the specified logger. int rc = restClient.doGet(URL).logTo(INFO, getLogger()).run();

The method call is ignored if the logger level is below the specified level.

Customized logging can be handled by sub-classing the {@link org.apache.juneau.rest.client.RestCallLogger} class and using the {@link org.apache.juneau.rest.client.RestCall#interceptor(RestCallInterceptor)} method.

### 9.8 - Interceptors

The {@link org.apache.juneau.rest.client.RestClientBuilder#interceptors(RestCallInterceptor...)} and {@link org.apache.juneau.rest.client.RestCall#interceptor(RestCallInterceptor)} methods can be used to intercept responses during specific connection lifecycle events.

The {@link org.apache.juneau.rest.client.RestCallLogger} class is an example of an interceptor that uses the various lifecycle methods to log HTTP requests.

/** * Specialized interceptor for logging calls to a log file. */ public class RestCallLogger extends RestCallInterceptor { private Level level; private Logger log; /** * Constructor. * * @param level The log level to log messages at. * @param log The logger to log to. */ protected RestCallLogger(Level level, Logger log) { this.level = level; this.log = log; } @Override /* RestCallInterceptor */ public void onInit(RestCall restCall) { if (log.isLoggable(level)) restCall.captureResponse(); } @Override /* RestCallInterceptor */ public void onConnect(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res) { // Do nothing. } @Override /* RestCallInterceptor */ public void onRetry(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res) { if (log.isLoggable(level)) log.log(level, MessageFormat.format("Call to {0} returned {1}. Will retry.", req.getRequestLine().getUri(), statusCode)); } @Override /* RestCallInterceptor */ public void onClose(RestCall restCall) throws RestCallException { try { if (log.isLoggable(level)) { String output = restCall.getCapturedResponse(); StringBuilder sb = new StringBuilder(); HttpUriRequest req = restCall.getRequest(); HttpResponse res = restCall.getResponse(); if (req != null) { sb.append("\n=== HTTP Call (outgoing) ========================================================="); sb.append("\n=== REQUEST ===\n").append(req); sb.append("\n---request headers---"); for (Header h : req.getAllHeaders()) sb.append("\n").append(h); if (req instanceof HttpEntityEnclosingRequestBase) { sb.append("\n---request entity---"); HttpEntityEnclosingRequestBase req2 = (HttpEntityEnclosingRequestBase)req; HttpEntity e = req2.getEntity(); if (e == null) sb.append("\nEntity is null"); else { if (e.getContentType() != null) sb.append("\n").append(e.getContentType()); if (e.getContentEncoding() != null) sb.append("\n").append(e.getContentEncoding()); if (e.isRepeatable()) { try { sb.append("\n---request content---\n").append(EntityUtils.toString(e)); } catch (Exception ex) { throw new RuntimeException(ex); } } } } } if (res != null) { sb.append("\n=== RESPONSE ===\n").append(res.getStatusLine()); sb.append("\n---response headers---"); for (Header h : res.getAllHeaders()) sb.append("\n").append(h); sb.append("\n---response content---\n").append(output); sb.append("\n=== END ========================================================================"); } log.log(level, sb.toString()); } } catch (IOException e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); } } }

### 9.9 - Other Useful Methods

The {@link org.apache.juneau.rest.client.RestClientBuilder#rootUrl(Object)} method can be used to specify a root URL on all requests so that you don't have to use absolute paths on individual calls.

// Create a rest client with a root URL RestClient rc = RestClient.create().rootUrl("http://localhost:9080/foobar").build(); String r = rc.doGet("/baz").getResponseAsString(); // Gets "http://localhost:9080/foobar/baz"

The {@link org.apache.juneau.rest.client.RestClientBuilder#set(String,Object)} method can be used to set serializer and parser properties. For example, if you're parsing a response into POJOs and you want to ignore fields that aren't on the POJOs, you can use the {@link org.apache.juneau.BeanContext#BEAN_ignoreUnknownBeanProperties} property.

// Create a rest client that ignores unknown fields in the response RestClient rc = RestClient.create() .set(BEAN_ignoreUnknownBeanProperties, true) // or .ignoreUnknownBeanProperties(true) .build(); MyPojo myPojo = rc.doGet(URL).getResponse(MyPojo.class);

The {@link org.apache.juneau.rest.client.RestCall#retryable(int,long,RetryOn)} method can be used to automatically retry requests on failures. This can be particularly useful if you're attempting to connect to a REST resource that may be in the process of still initializing.

// Create a rest call that retries every 10 seconds for up to 30 minutes as long as a connection fails // or a 400+ is received. restClient.doGet(URL) .retryable(180, 10000, RetryOn.DEFAULT) .run();

## 10 - juneau-rest-mock 8.1.0-new

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-rest-mock</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-rest-mock-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.rest.mock_{@property juneauVersion}.jar

The juneau-rest-mock module contains convenience APIs for performing serverless unit testing of your REST APIs. Each of the APIs provide the ability to fully test your server and client REST interfaces without the need for a running servlet container.

The API consists of the following classes:

- {@link org.apache.juneau.rest.mock2}
  - {@link org.apache.juneau.rest.mock2.MockRest} - API for unit testing {@link org.apache.juneau.rest.annotation.Rest @Rest}-annotated classes.
  - {@link org.apache.juneau.rest.mock2.MockRemote} - API for unit testing {@link org.apache.juneau.http.remote.Remote @Remote}-annotated classes.

### 10.1 - MockRest 8.1.0-new

The {@link org.apache.juneau.rest.mock2.MockRest} class is used for performing serverless unit testing of {@link org.apache.juneau.rest.annotation.Rest @Rest}-annotated classes. These include both parent resource classes that extend from {@link org.apache.juneau.rest.RestServlet} and child resources that do not.

The API consists of the following classes:

- {@link org.apache.juneau.rest.mock2}
  - {@link org.apache.juneau.rest.mock2.MockRest}
    The API for instantiating mocks of REST resource classes.
  - {@link org.apache.juneau.rest.mock2.MockServletRequest}
    An implementation of {@link javax.servlet.http.HttpServletRequest} with additional convenience methods for building requests.
  - {@link org.apache.juneau.rest.mock2.MockServletResponse}
    An implementation of {@link javax.servlet.http.HttpServletRequest} with additional convenience methods for testing responses.

The following shows a simple example of invoking a PUT method on a simple REST interface and asserting the correct status code and response body:

public class MockTest { // Our REST resource to test. @Rest( serializers=SimpleJsonSerializer.class, parsers=JsonParser.class ) public static class EchoRest { @RestMethod( name=PUT, path="/echo" ) public String echo(@Body String body) { return body; } } // Our JUnit test. @Test public void testEcho() throws Exception { MockRest mr = MockRest.build(EchoRest.class); mr .put("/echo", "'foo'") .execute() .assertStatus(200) .assertBody("'foo'"); } }

Breaking apart the fluent method call above will help you understand how this works.

@Test public void testEcho() throws Exception { // Instantiate our mock. MockRest mr = MockRest.build(EchoRest.class); // Create a request. MockServletRequest req = mr.put("/echo", "'foo'"); // Execute it (by calling RestCallHandler.service(...) and then returning the response object). MockServletResponse res = req.execute(); // Run assertion tests on the results. res.assertStatus(200); res.assertBody("'foo'"); }

The concept of the design is simple. The {@link org.apache.juneau.rest.mock2.MockRest} class is used to create instances of {@link org.apache.juneau.rest.mock2.MockServletRequest} and {@link org.apache.juneau.rest.mock2.MockServletResponse} which are passed directly to the call handler on the resource class {@link org.apache.juneau.rest.RestCallHandler#service(HttpServletRequest,HttpServletResponse)}. In effect, you're fully testing your REST API as if it were running in a live servlet container, yet not actually having to run in a servlet container.

The create(Object) method can take in either Class objects or pre-instantiated beans. The latter is particularly useful for testing Spring beans.

By default, the {@link org.apache.juneau.rest.mock2.MockRest} class specifies the following request headers:

Accept: application/json+simple Content-Type: application/json

The reason for using "application/json+simple" as the default is that it significantly simplifies testing by allowing you to compare response content with simple Java strings without having to escape lots of quotes:

// Using Simple JSON mr.assertBody("{foo:'bar':baz:123}"); // Using normal JSON mr.assertBody("{\"foo\":\"bar\",\"baz\":123}");

Other media types headers can be specified via any of the following methods:

- {@link org.apache.juneau.rest.mock2.MockRest#build(Object,Marshall) build(Object,Marshall)} - Use media types defined on a marshall.
- {@link org.apache.juneau.rest.mock2.MockRest#build(Object,Serializer,Parser) build(Object,Serializer,Parser)} - Use media types defined on a serializer and parser.
- {@link org.apache.juneau.rest.mock2.MockRest.Builder#accept(String) accept(String)} - Explicitly set the Accept header.
- {@link org.apache.juneau.rest.mock2.MockRest.Builder#contentType(String) contentType(String)} - Explicitly set the Content-Type header.

Various other convenience methods for common media types are also provided.

The following examples are functionally equivalent for specifying XML serialization:

MockRest mr; mr = MockRest.build(EchoRest.class, Xml.DEFAULT); mr = MockRest.build(EchoRest.class, XmlSerializer.DEFAULT, XmlParser.DEFAULT); mr = MockRest.create(EchoRest.class).marshall(Xml.DEFAULT).build(); mr = MockRest.create(EchoRest.class).serializer(XmlSerializer.DEFAULT).parser(XmlParser.DEFAULT).build(); mr = MockRest.create(EchoRest.class).accept("text/xml").contentType("text/xml").build(); mr = MockRest.create(EchoRest.class).xml().build();

The {@link org.apache.juneau.rest.mock2.MockRest} class provides the following methods for creating requests:

- {@link org.apache.juneau.rest.mock2.MockRest}
  - {@link org.apache.juneau.rest.mock2.MockRest#request(String,String) request(String,String)}
  - {@link org.apache.juneau.rest.mock2.MockRest#request(String,String,Object) request(String,String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockRest#get(String) get(String)}
  - {@link org.apache.juneau.rest.mock2.MockRest#put(String,Object) put(String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockRest#post(String,Object) post(String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockRest#delete(String) delete(String)}
  - {@link org.apache.juneau.rest.mock2.MockRest#patch(String,Object) patch(String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockRest#options(String) options(String)}

For HTTP methods that pass a request body (i.e. PUT,POST PATCH), the body object can be any of the following types:

- byte[]
- {@link java.io.Reader}
- {@link java.io.InputStream}
- {@link java.lang.CharSequence}

All other body object types are converted to strings using the toString() method.

A common tactic is to override a bean's toString() method to return Simple JSON so that instances can be passed to the methods above.

public class MyBean { ... @Override public String toString() { SimpleJson.DEFAULT.toString(this); } }

The {@link org.apache.juneau.rest.mock2.MockServletRequest} class provides default implementations for all the methods defined on the {@link javax.servlet.http.HttpServletRequest} in addition to many convenience methods.

The following fluent convenience methods are provided for setting common Accept and Content-Type headers.

- {@link org.apache.juneau.rest.mock2.MockServletRequest}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#json() json()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#xml() xml()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#html() html()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#plainText() plainText()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#msgpack() msgpack()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#uon() uon()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#urlEnc() urlEnc()}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#yaml() yaml()}

The following fluent convenience methods are provided for building up your request.

- {@link org.apache.juneau.rest.mock2.MockServletRequest}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#header(String,Object) header(String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#query(String,Object) query(String,Object}}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#formData(String,Object) formData(String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#attribute(String,Object) attribute(String,Object)}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#body(Object) body(Object)}

Fluent setters are provided for all common request headers:

- {@link org.apache.juneau.rest.mock2.MockServletRequest}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#accept(Object) accept(Object)}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#acceptCharset(Object) acceptCharset(Object)}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#acceptEncoding(Object) acceptEncoding(Object)}
  - {@link org.apache.juneau.rest.mock2.MockServletRequest#acceptLanguage(Object) acceptLanguage(Object)}
  - ...

The {@link org.apache.juneau.rest.mock2.MockServletResponse} class provides default implementations for all the methods defined on the {@link javax.servlet.http.HttpServletResponse} in addition to many convenience methods.

- {@link org.apache.juneau.rest.mock2.MockServletResponse}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#getBody() getBody()}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#getBodyAsString() getBodyAsString()}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertStatus(int) assertStatus(int)}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertBody(String) assertBody(String)}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertBodyContains(String...) assertBodyContains(String...)}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertBodyMatches(String) assertBodyMatches(String)}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertBodyMatchesRE(String) assertBodyMatchesRE(String)}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertHeader(String,String) assertHeader(String,String)}
  - {@link org.apache.juneau.rest.mock2.MockServletResponse#assertHeaderContains(String,String...) assertHeaderContains(String,String...)}

The {@link org.apache.juneau.rest.mock2.MockRest} class has a debug mode that will cause your HTTP requests and responses to be sent to the console:

MockRest mr = MockRest .create(MyRest.class) .debug() .simpleJson() .build();

### 10.2 - MockRemote 8.1.0-new, 8.1.2-updated

The {@link org.apache.juneau.rest.mock2.MockRemote} class is used for serverless unit testing of {@link org.apache.juneau.http.remote.Remote @Remote}-annotated classes.

The {@link org.apache.juneau.rest.mock2.MockRemote} API requires a {@link org.apache.juneau.rest.annotation.Rest @Rest}-annotated class to be used as an underlying mocked resource to process the request and return a response.

##### Example:

// Our remote resource to test. @Remote public interface MyRemoteInterface { @RemoteMethod(httpMethod="GET", path="/echoQuery") public int echoQuery(@Query(name="id") int id); } // Our mocked-up REST interface to test against. @Rest public class MyRest { @RestMethod(name=GET, path="/echoQuery") public int echoQuery(@Query("id") String id) { return id; } } @Test public void testProxy() { MyRemoteInterface mri = MockRemote.build(MyRemoteInterface.class, MyRest.class); assertEquals(123, mri.echoQuery(123)); }

It looks simple, but there's a lot going on here.

Remote resource interfaces are normally created through the {@link org.apache.juneau.rest.client.RestClient#getRemote(Class)} method. The {@link org.apache.juneau.rest.mock2.MockRemote} will create a {@link org.apache.juneau.rest.client.RestClient} using a specialized HttpClientConnectionManager designed to transform client-side HttpRequest/HttpResponse objects into server-side {@link org.apache.juneau.rest.mock2.MockServletRequest}/{@link org.apache.juneau.rest.mock2.MockServletResponse} objects and then pass those to the {@link org.apache.juneau.rest.mock2.MockRest} object described in the previous section.

All aspects of the client and server side code are tested, yet no servlet container is required. The actual over-the-wire serialization is the only aspect being bypassed.

By default, the {@link org.apache.juneau.rest.mock2.MockRemote} class uses JSON marshalling. This can be overridden via any of the following methods:

- {@link org.apache.juneau.rest.mock2.MockRemote#build(Class,Object,Marshall)}
- {@link org.apache.juneau.rest.mock2.MockRemote#build(Class,Object,Serializer,Parser)}
- {@link org.apache.juneau.rest.mock2.MockRemote#create(Class,Object,Marshall)}
- {@link org.apache.juneau.rest.mock2.MockRemote#create(Class,Object,Serializer,Parser)}

The {@link org.apache.juneau.rest.mock2.MockRemote} class has a debug mode that will cause your HTTP requests and responses to be sent to the console on both the client and server sides:

@Test public void testProxy() { MyRemoteInterface mri = MockRemote .create(MyRemoteInterface.class, MyRest.class) .debug() .build(); assertEquals(123, mri.echoQuery(123)); }

## 11 - juneau-microservice-core 8.0.0-new, 8.1.2-deprecated

The Juneau Microservice libraries are likely to be removed in Juneau 9.0 due to the popularity of the Spring Boot framework for creating microservices and the ability for Juneau to be used within Spring Boot.

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-microservice-core</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-microservice-core-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.microservice.core_{@property juneauVersion}.jar

Juneau Microservice is an API for creating stand-alone executable jars with automatic support for Juneau configurations and console commands.

Features include:

- A builder-based API for defining and starting microservices.
- An extensible API that allows you to hook into various lifecycle events.
- Simple-to-use APIs for accessing manifest file entries, command-line arguments, and external configuration file properties.

### 11.1 - Microservice Overview 8.0.0-new, 8.1.2-deprecated

The Microservice API consists of a base class for defining executable microservices.

Features include:

- A builder-based API for defining and starting microservices.
- An extensible API that allows you to hook into various lifecycle events.
- Simple-to-use APIs for accessing manifest file entries, command-line arguments, and external configuration file properties.

The Microservice API consists of the following packages and classes:

- {@link org.apache.juneau.microservice}
  - {@link org.apache.juneau.microservice.Microservice} - The base microservice class.
  - {@link org.apache.juneau.microservice.MicroserviceBuilder} - Builder for the microservice class.
  - {@link org.apache.juneau.microservice.MicroserviceListener} - Interface for hooking into lifecyle events of the microservice.
    - {@link org.apache.juneau.microservice.BasicMicroserviceListener} - Adapter for MicroserviceListener class.
- {@link org.apache.juneau.microservice.console}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand} - Abstract class for defining console commands.

By itself the Microservice API doesn't provided much functionality, but it does provide the basis for the {@doc juneau-microservice-jetty Jetty Microservice} described later.

The most-basic creation of a microservice from an entry-point method is shown below:

public class App { public static void main(String[] args) { Microservice .create() // Create builder. .args(args) // Pass in args. .build() // Create microservice. .start() // Start microservice. ; } }

### 11.2 - Lifecycle Methods 8.0.0-new, 8.1.2-deprecated

The lifecycle methods of the {@link org.apache.juneau.microservice.Microservice} class consists of the following:

- {@link org.apache.juneau.microservice.Microservice}
  - {@link org.apache.juneau.microservice.Microservice#start() start()}
  - {@link org.apache.juneau.microservice.Microservice#startConsole() startConsole()}
  - {@link org.apache.juneau.microservice.Microservice#join() join()}
  - {@link org.apache.juneau.microservice.Microservice#stop() stop()}
  - {@link org.apache.juneau.microservice.Microservice#stopConsole() stopConsole()}
  - {@link org.apache.juneau.microservice.Microservice#exit() exit()}
  - {@link org.apache.juneau.microservice.Microservice#kill() kill()}

A typical implementation of an app with lifecycle methods might look like the following:

public class App { private static final Microservice MICROSERVICE; public static void main(String[] args) { MICROSERVICE = Microservice .create() // Create builder. .args(args) // Pass in args. .build() // Create microservice. .start() // Start microservice. .startConsole() // Start console. .join() // Join thread. ; } public static void restart() { MICROSERVICE.stop().start(); } public static void exit() { MICROSERVICE.exit(); } }

If your application consists of a single microservice, you can use the {@link org.apache.juneau.microservice.Microservice#getInstance()} method from anywhere in your code:

public class App { public static void main(String[] args) { Microservice .create() // Create builder. .args(args) // Pass in args. .build() // Create microservice. .start() // Start microservice. .startConsole() // Start console. .join() // Join thread. ; } public static void restart() { Microservice.getInstance().stop().start(); } public static void exit() { Microservice.getInstance().exit(); } }

The {@link org.apache.juneau.microservice.Microservice#startConsole()} and {@link org.apache.juneau.microservice.Microservice#stopConsole()} control the lifecycle of the console commands. Typically you'll want to control these separately from the app so that you can easily restart your application from the console without affecting the console itself.

The lifecycle methods on the {@link org.apache.juneau.microservice.Microservice} class are purposely left non-final so that subclasses can override them to provide customized behavior.

### 11.3 - Args 8.0.0-new, 8.1.2-deprecated

Command-line arguments can be associated with a microservice using the {@link org.apache.juneau.microservice.MicroserviceBuilder#args(String...)} method.

##### Example:

public static void main(String[] args) { Microservice .create() // Create builder. .args(args) // Pass in args. .build() // Create microservice. .start() // Start microservice. .join() // Join thread. ; }

When specified, the arguments can be retrieved using the {@link org.apache.juneau.microservice.Microservice#getArgs()} method which provides an API for easily accessing command-line arguments using common notation:

Args a = Microservice.getInstance().getArgs(); // One main argument // a1 String a1 = a.getArg(0); // "a1" String a2 = a.getArg(1); // null // Two main arguments // a1 a2 String a1 = a.getArg(0); // "a1" String a2 = a.getArg(1); // "a2" // One main argument and one optional argument with no value // a1 -a2 String a1 = a.getArg(0); boolean hasA2 = a.hasArg("a2"); // true boolean hasA3 = a.hasArg("a3"); // false // One main argument and one optional argument with one value // a1 -a2 v2 String a1 = a.getArg(0); String a2 = a.getArg("a2"); // "v2" String a3 = a.getArg("a3"); // null // One main argument and one optional argument with two values // a1 -a2 v2a v2b String a1 = a.getArg(0); List<String> a2 = a.getArgs("a2"); // Contains ["v2a","v2b"] List<String> a3 = a.getArgs("a3"); // Empty list // Same as previous, except specify optional argument name multiple times // a1 -a2 v2a -a2 v2b String a1 = a.getArg(0); List<String> a2 = a.getArgs("a2"); // Contains ["v2a","v2b"]

Specifying the command-line arguments also makes them available through {@link org.apache.juneau.svl.vars.ArgsVar $A} SVL variables. These can be used in the configuration file and throughout various Juneau annotations.

##### Example:

// $A used in variable resolver. VarResolver vr = Microservice.getInstance().getVarResolver(); System.out.println(vr.resolve("Arg #1 is set to $A{1}"));

// $A used in annotation. @Rest( title="$A{title}", ... )

### 11.4 - Manifest 8.0.0-new, 8.1.2-deprecated

The {@link org.apache.juneau.microservice.MicroserviceBuilder#manifest(Object)} method can be used to specify the contents or location of of the main manifest file of the executable jar.

If you do not specify the location/contents of the manifest file, the microservice will attempt to resolve it through the following methods:

1. Looking on the file system for a file at "META-INF/MANIFEST.MF". This is primarily to allow for running microservices from within eclipse workspaces where the manifest file is located in the project root.
2. Using the class loader for this class to find the file at the URL "META-INF/MANIFEST.MF".

If you do manually specify the manifest file, you can pass in any of the following types:

- {@link org.apache.juneau.utils.ManifestFile} - A pre-parsed manifest file.
- {@link java.util.jar.Manifest} - A pre-parsed manifest file.
- {@link java.io.Reader} - Containing the raw contents of the manifest.
- {@link java.io.InputStream} - Containing the raw contents of the manifest.
- {@link java.io.File} - File containing the raw contents of the manifest.
- {@link java.lang.String} - Path to file containing the raw contents of the manifest.
- {@link java.lang.Class} - Finds and loads the manifest file of the jar file that the specified class is contained within.

The manifest file can be retrieved using the the {@link org.apache.juneau.microservice.Microservice#getManifest()} method which provides an API for accessing manifest file entries. This method returns an instance of {@link org.apache.juneau.utils.ManifestFile} which extends from {@link org.apache.juneau.ObjectMap} allowing you to retrieve entries as any data types supported by that class.

##### Example:

ManifestFile mf = Microservice.getInstance().getManifest(); String mainClass = mf.getString("Main-Class"); int myInt = mf.getInt("My-Int", 123); boolean myBoolean = mf.getBoolean("My-Boolean");

The manifest is also used for the {@link org.apache.juneau.svl.vars.ManifestFileVar $MF} SVL variable.

##### Examples:

// $MF used in variable resolver. VarResolver vr = Microservice.getInstance().getVarResolver(); System.out.println(vr.resolve("The main class is $MF{Main-Class}"));

// $MF used in annotation. @Rest( title="$MF{Application-Title}", ... )

### 11.5 - Config 8.0.0-new, 8.1.2-deprecated

The following methods can be used to define the configuration for your microservice using the powerful Config API:

- {@link org.apache.juneau.microservice.MicroserviceBuilder}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#config(Config) config(Config)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#configName(String) configName(String)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#configStore(ConfigStore) configStore(ConfigStore)}

If you do not specify any of this information, we attempt to resolve it through the following methods:

1. Resolve file first in working directory, then in classpath, using the following names:
   1. The "configFile" argument in the command line arguments passed in through the constructor.
   2. The value of the Main-Config entry in the manifest file.
   3. A config file in the same location and with the same name as the executable jar file. (e.g. "java -jar myjar.jar" will look for "myjar.cfg").
2. Resolve any "*.cfg" file that can be found in the working directory.
3. Resolve any of the following files in the classpath:
   1. juneau.cfg
   2. default.cfg
   3. application.cfg
   4. app.cfg
   5. settings.cfg

If no configuration file is found, and empty in-memory configuration is used.

The {@link org.apache.juneau.microservice.MicroserviceBuilder#configName(String) configName(String)} method allows you to explicitly specify the name of the external configuration file location for your microservice.

Microservice .create() .config("my-files/MyMicroservice.cfg") .build() .start() ;

By default, we try to find the file on the file system and then the classpath. If located on the file system, then the configuration is writeable and the microservice can automatically listen for and react to changes in the configuration file on the file system. If located on the classpath, then the configuration can still react to modifications made to it through the Config API, but the changes cannot be persisted since the location prevents the file from being modified.

The {@link org.apache.juneau.microservice.MicroserviceBuilder#configStore(ConfigStore) configStore(ConfigStore)} method can be used to explicitly specify a configuration store. This can include your own custom configuration store, such as one that's implemented in a relational database.

Microservice .create() .configStore(new MyConfigSqlStore()) .configName("MyConfig") .build() .start() ;

The {@link org.apache.juneau.microservice.MicroserviceBuilder#config(Config) config(Config)} method can be used to explicitly specify a {@link org.apache.juneau.config.Config} file as the microservice configuration. When this method is used, the above two methods are bypassed entirely.

Config config = getMyOwnConfig(); Microservice .create() .config(config) .build() .start() ;

Once the configuration is resolved, it is made as the system default configuration available through the {@link org.apache.juneau.config.Config#getSystemDefault()}. This in turn allows it to be used by REST resources that reference the system default configuration via the "SYSTEM_DEFAULT" such as those implementing the {@link org.apache.juneau.rest.BasicRestConfig} interface.

##### BasicRestConfig.java

@Rest( config="$S{juneau.configFile,SYSTEM_DEFAULT}" ... )

The {@link org.apache.juneau.microservice.Microservice#getConfig()} method can be used to get access to the configuration.

Config c = Microservice.getInstance().getConfig(); File logDir = c.getObject("Logging/logDir", File.class); boolean append = c.getBoolean("Logging/append"); String format = c.getString("Logging/format", "[{date} {level}] {msg}%n"); long limit = c.getLong("Logging/limit"); Map<String,Level> levels = c.getObject("Logging/levels", Map.class, String.class, Level.class);

Changes to the configuration file can trigger notifications that can be used to restart your microservice or make various other on-the-fly changes. This can be accomplished by either overriding the {@link org.apache.juneau.microservice.Microservice#onConfigChange(ConfigEvents)} or implementing a listener and using the {@link org.apache.juneau.microservice.MicroserviceListener#onConfigChange(Microservice,ConfigEvents)} methods. These will be described in detail later.

- {@doc juneau-config}

### 11.6 - System properties 8.0.0-new, 8.1.2-deprecated

As a convenience, the SystemProperties section of your configuration file can be used to define system properties to set during initialization of your microservice:

#======================================================================================================================= # System properties #----------------------------------------------------------------------------------------------------------------------- # These are arbitrary system properties that are set during startup. #======================================================================================================================= [SystemProperties] # Configure Jetty for StdErrLog Logging # org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog # Configure Jetty to log using java-util logging org.eclipse.jetty.util.log.class = org.apache.juneau.microservice.jetty.JettyLogger # Jetty logging level # Possible values: ALL, DEBUG, INFO, WARN, OFF org.eclipse.jetty.LEVEL = WARN derby.stream.error.file = $C{Logging/logDir}/derby-errors.log

### 11.7 - VarResolver 8.0.0-new, 8.1.2-deprecated

The Microservice API incorporates the {@doc juneau-marshall.SimpleVariableLanguage Simple Variable Language} API.

The variable resolver can be augmented through the following methods:

- {@link org.apache.juneau.microservice.MicroserviceBuilder}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#vars(Class...) vars(Class...)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#varContext(String, Object) varContext(String,Object)}

A typical usage pattern is shown below:

// $A used in variable resolver. VarResolver vr = Microservice.getInstance().getVarResolver(); System.out.println(vr.resolve("Main class is set to $MF{Main-Class, unknown}"));

The variable resolver becomes much more powerful when used in REST resource annotations which will be described latter in {@doc juneau-microservice-jetty}

By default, support for the following variables are provided:

- $S{key[,default]} - {@link org.apache.juneau.svl.vars.SystemPropertiesVar}
- $E{key[,default]} - {@link org.apache.juneau.svl.vars.EnvVariablesVar}
- $A{key[,default]} - {@link org.apache.juneau.svl.vars.ArgsVar}
- $C{key[,default]} - {@link org.apache.juneau.config.vars.ConfigVar}
- $MF{key[,default]} - {@link org.apache.juneau.svl.vars.ManifestFileVar}
- $IF{arg,then[,else]} - {@link org.apache.juneau.svl.vars.IfVar}
- $SW{arg,pattern1:then1[,pattern2:then2...]} - {@link org.apache.juneau.svl.vars.SwitchVar}
- $CO{arg[,arg2...]} - {@link org.apache.juneau.svl.vars.CoalesceVar}
- $PM{arg,pattern} - {@link org.apache.juneau.svl.vars.PatternMatchVar}
- $UC{arg} - {@link org.apache.juneau.svl.vars.UpperCaseVar}
- $LC{arg} - {@link org.apache.juneau.svl.vars.LowerCaseVar}
- $NE{arg} - {@link org.apache.juneau.svl.vars.NotEmptyVar}

### 11.8 - Console Commands 8.0.0-new, 8.1.2-deprecated

The Microservice API provides support for simple console commands.

public static void main(String[] args) { Microservice .create() .args(args) .build() .start() .startConsole() // Start console. .join() ; }

When started, the console renders the following output:

Running class 'Microservice' using config file 'my-microservice.cfg'. List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help >

The builder methods for controlling the console are as follows:

- {@link org.apache.juneau.microservice.MicroserviceBuilder}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#consoleEnabled(boolean) consoleEnabled(boolean)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#consoleCommands(ConsoleCommand...) consoleCommands(ConsoleCommand...)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#consoleCommands(Class...) consoleCommands(Class...)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#console(Scanner,PrintWriter) console(Scanner,PrintWriter)}

By default, the supported commands are pulled from the configuration file:

#======================================================================================================================= # Console settings #======================================================================================================================= [Console] enabled = true # List of available console commands. # These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via # the console. # When listed here, the implementations must provide a no-arg constructor. # They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method. commands = org.apache.juneau.microservice.console.ExitCommand, org.apache.juneau.microservice.console.RestartCommand, org.apache.juneau.microservice.console.HelpCommand

New commands can be added by adding them to the configuration file, or programmatically using the {@link org.apache.juneau.microservice.MicroserviceBuilder#consoleCommands(ConsoleCommand...) consoleCommands(ConsoleCommand...)} builder method.

The API for defining console commands is shown below:

- {@link org.apache.juneau.microservice.console.ConsoleCommand}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand#execute(Scanner,PrintWriter,Args) execute(Scanner,PrintWriter,Args)}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand#getDescription() getDescription()}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand#getExamples() getExamples()}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand#getInfo() getInfo()}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand#getName() getName()}
  - {@link org.apache.juneau.microservice.console.ConsoleCommand#getSynopsis() getSynopsis()}

By default, the console input and output are taken from {@link java.lang.System.in} and {@link java.lang.System.out}. These can be overridden using the {@link org.apache.juneau.microservice.MicroserviceBuilder#console(Scanner,PrintWriter) console(Scanner,PrintWriter)} method.

### 11.9 - Logging 8.0.0-new, 8.1.2-deprecated

The Microservice API provides build-in but configurable and overridable support for logging.

The method for configuring logging is as follows:

- {@link org.apache.juneau.microservice.MicroserviceBuilder}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#logConfig(LogConfig) logConfig(LogConfig)}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#logger(Logger) logger(Logger)}

If not specified, the logging configuration is pulled in from the configuration file:

#======================================================================================================================= # Logger settings #----------------------------------------------------------------------------------------------------------------------- # See FileHandler Java class for details. #======================================================================================================================= [Logging] # The directory where to create the log file. # Default is "." logDir = logs # The name of the log file to create for the main logger. # The logDir and logFile make up the pattern that's passed to the FileHandler # constructor. # If value is not specified, then logging to a file will not be set up. logFile = microservice.%g.log # Whether to append to the existing log file or create a new one. append = false # The SimpleDateFormat format to use for dates. dateFormat = yyyy.MM.dd hh:mm:ss # The log message format. # The value can contain any of the following variables: # {date} - The date, formatted per dateFormat. # {class} - The class name. # {method} - The method name. # {logger} - The logger name. # {level} - The log level name. # {msg} - The log message. # {threadid} - The thread ID. # {exception} - The localized exception message. format = [{date} {level}] {msg}%n # The maximum log file size. # Suffixes available for numbers. # See Config.getInt(String,int) for details. limit = 1M # Max number of log files. count = 5 # Default log levels. # Format is lax-JSON. # Keys are logger names. # Values are serialized Level POJOs (SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST) levels = { '': 'WARNING', org.apache.juneau: 'WARNING', org.eclipse.jetty: 'WARNING' } # Only print unique stack traces once and then refer to them by a simple 8 character hash identifier. # Useful for preventing log files from filling up with duplicate stack traces. useStackTraceHashes = true # The default level for the console logger. # Values are serialized Level POJOs (SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST) consoleLevel = WARNING # The default level for the file logger. # Values are serialized Level POJOs (SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST) fileLevel = INFO

The logging configuration can also be defined programmatically through the following API:

- {@link org.apache.juneau.microservice.LogConfig}
  - {@link org.apache.juneau.microservice.LogConfig#create() create()}
  - {@link org.apache.juneau.microservice.LogConfig#append() append()}
  - {@link org.apache.juneau.microservice.LogConfig#consoleLevel(Level) consoleLevel(Level)}
  - {@link org.apache.juneau.microservice.LogConfig#count(int) count(int)}
  - {@link org.apache.juneau.microservice.LogConfig#fileLevel(Level) fileLevel(Level)}
  - {@link org.apache.juneau.microservice.LogConfig#formatter(Formatter) formatter(Formatter)}
  - {@link org.apache.juneau.microservice.LogConfig#level(String,Level) level(String,Level)}
  - {@link org.apache.juneau.microservice.LogConfig#levels(Map) levels(Map)}
  - {@link org.apache.juneau.microservice.LogConfig#limit(int) limit(int)}
  - {@link org.apache.juneau.microservice.LogConfig#logDir(String) logDir(String)}
  - {@link org.apache.juneau.microservice.LogConfig#logFile(String) logFile(String)}

##### Example:

public static void main(String[] args) { LogConfig logConfig = LogConfig .create() .append(true) .consoleLevel(FINE) .level("org.mylogger", FINER) .logDir("my-log-files"); Microservice .create() .args(args) .logConfig(logConfig) .build() .start() .join() ; }

If you wish to bypass the default logging configuration entirely, you can pass in your own logger via the {@link org.apache.juneau.microservice.MicroserviceBuilder#logger(Logger)} method.

In addition to configuring the built-in Java logging framework, the following convenience methods are also provided on the {@link org.apache.juneau.microservice.Microservice} class for logging.

- {@link org.apache.juneau.microservice.Microservice}
  - {@link org.apache.juneau.microservice.Microservice#getLogger() getLogger()}
  - {@link org.apache.juneau.microservice.Microservice#out(MessageBundle,String,Object...) out(MessageBundle,String,Object...)}
  - {@link org.apache.juneau.microservice.Microservice#err(MessageBundle,String,Object...) err(MessageBundle,String,Object...)}

### 11.10 - Listeners 8.0.0-new, 8.1.2-deprecated

As mentioned previously, the lifecycle methods for the {@link org.apache.juneau.microservice.Microservice} class are explicitly defined as non-final so that they can be overridden by subclasses.

In addition to this support, an interface for defining event listeners for your microservice:

- {@link org.apache.juneau.microservice.MicroserviceBuilder}
  - {@link org.apache.juneau.microservice.MicroserviceBuilder#listener(MicroserviceListener) listener(MicroserviceListener)}
- {@link org.apache.juneau.microservice.MicroserviceListener}
  - {@link org.apache.juneau.microservice.MicroserviceListener#onStart(Microservice) onStart(Microservice)}
  - {@link org.apache.juneau.microservice.MicroserviceListener#onStop(Microservice) onStop(Microservice)}
  - {@link org.apache.juneau.microservice.MicroserviceListener#onConfigChange(Microservice,ConfigEvents) onConfigChange(Microservice,ConfigEvents)}
- {@link org.apache.juneau.microservice.BasicMicroserviceListener}

This listener API can be used for listening for and reacting to configuration changes on the file system.

public class MyMicroserviceListener extends BasicMicroserviceListener { @Override /* MicroserviceListener */ public void onConfigChange(Microservice microservice, ConfigEvents events) { // Restart the microservice if anything was modified in one of our sections if (events.isSectionChanged("MySection")) microservice.stop().start(); } }

Note that the {@link org.apache.juneau.microservice.Microservice#onConfigChange(ConfigEvents)} method can also be overridden to react to configuration changes as well:

public class MyMicroservice extends Microservice { @Override /* MicroserviceListener */ public void onConfigChange(ConfigEvents events) { // Restart the microservice if anything was modified in one of our sections if (events.isSectionChanged("MySection")) this.stop().start(); } }

## 12 - juneau-microservice-jetty 8.0.0-new, 8.1.2-deprecated

The Juneau Microservice libraries are likely to be removed in Juneau 9.0 due to the popularity of the Spring Boot framework for creating microservices and the ability for Juneau to be used within Spring Boot.

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-microservice-jetty</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-microservice-jetty-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.microservice.jetty_{@property juneauVersion}.jar

Juneau Microservice Jetty is an API for creating stand-alone executable jars that can be used to start lightweight configurable REST interfaces with all the power of the Juneau REST server and client APIs.

### 12.1 - Overview 8.0.0-new, 8.1.2-deprecated

The Jetty Microservice API consists of a combination of the Juneau Core, Server, and Client APIs and an embedded Eclipse Jetty Servlet Container.

The API builds upon the {@doc juneau-microservice-core Core Microservice} classes to produce easy-to-create and easy-to-use microservices in a standard Java 1.8+ environment.

The juneau-microservice-jetty library consists of the following classes:

- {@link org.apache.juneau.microservice.jetty}
  - {@link org.apache.juneau.microservice.jetty.JettyMicroservice} - The Jetty microservice class.
  - {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder} - Builder for the microservice class.
  - {@link org.apache.juneau.microservice.jetty.JettyMicroserviceListener} - Interface for hooking into lifecyle events of the microservice.
    - {@link org.apache.juneau.microservice.jetty.BasicJettyMicroserviceListener} - Adapter for JettyMicroserviceListener class.
  - {@link org.apache.juneau.microservice.jetty.JettyServerFactory} - Interface for defining custom Jetty servers.
    - {@link org.apache.juneau.microservice.jetty.BasicJettyServerFactory} - Adapter for JettyServerFactory class.

The most-basic creation of a Jetty microservice from an entry-point method is shown below:

public class App { public static void main(String[] args) { JettyMicroservice .create() // Create builder. .args(args) // Pass in args. .servlets(RootResource.class) // A Juneau RestServlet class. .build() // Create microservice. .start() // Start microservice. ; } }

### 12.2 - Lifecycle Methods 8.0.0-new, 8.1.2-deprecated

To review, the {@link org.apache.juneau.microservice.Microservice} class contains the following lifecycle methods:

- {@link org.apache.juneau.microservice.Microservice}
  - {@link org.apache.juneau.microservice.Microservice#start() start()}
  - {@link org.apache.juneau.microservice.Microservice#startConsole() startConsole()}
  - {@link org.apache.juneau.microservice.Microservice#join() join()}
  - {@link org.apache.juneau.microservice.Microservice#stop() stop()}
  - {@link org.apache.juneau.microservice.Microservice#stopConsole() stopConsole()}
  - {@link org.apache.juneau.microservice.Microservice#exit() exit()}
  - {@link org.apache.juneau.microservice.Microservice#kill() kill()}

The {@link org.apache.juneau.microservice.jetty.JettyMicroservice} class which extends from {@link org.apache.juneau.microservice.Microservice} provides the following additional lifecycle methods:

- {@link org.apache.juneau.microservice.jetty.JettyMicroservice}
  - {@link org.apache.juneau.microservice.jetty.JettyMicroservice#createServer() createServer()}
  - {@link org.apache.juneau.microservice.jetty.JettyMicroservice#startServer() startServer()}
  - {@link org.apache.juneau.microservice.jetty.JettyMicroservice#destroyServer() destroyServer()}

The additional lifecycle methods are typically not called directly, but are exposed to allow subclasses to provide customized behavior for these events. For this reason, these methods are left as non-final so that they can be overridden.

A typical implementation of an app with lifecycle methods might look like the following:

public class App { private static final JettyMicroservice MICROSERVICE; public static void main(String[] args) { MICROSERVICE = JettyMicroservice .create() // Create builder. .args(args) // Pass in args. .servlets(RootResource.class) // A Juneau RestServlet class. .build() // Create microservice. .start() // Start microservice. .startConsole() // Start console. .join() // Join thread. ; } public static void restart() { MICROSERVICE.stop().start(); } public static void exit() { MICROSERVICE.exit(); } }

Similar to {@link org.apache.juneau.microservice.Microservice#getInstance()}, the {@link org.apache.juneau.microservice.jetty.JettyMicroservice#getInstance()} also allows easy access to the microservice:

public class App { public static void main(String[] args) { JettyMicroservice .create() // Create builder. .args(args) // Pass in args. .servlets(RootResource.class) // A Juneau RestServlet class. .build() // Create microservice. .start() // Start microservice. .startConsole() // Start console. .join() // Join thread. ; } public static void restart() { JettyMicroservice.getInstance().stop().start(); } public static void exit() { JettyMicroservice.getInstance().exit(); } }

### 12.3 - Resource Classes 8.0.0-new, 8.1.2-deprecated

This section describes how to define a top-level REST resource page and deploy it in our microservice. The example is a router page that serves as a jumping off page to child resources.

@Rest( path="/*", title="My Microservice", description="Top-level resources page", htmldoc=@HtmlDoc( navlinks={ "options: servlet:/?method=OPTIONS" } ), children={ HelloWorldResource.class, ConfigResource.class, LogsResource.class } ) public class RootResources extends BasicRestServletJenaGroup { // No code! }

When deployed, it looks like this in a browser:

http://localhost:10000

- The title and description annotations define the titles on the page.
  These can be globalized using $L{...} variables, or by defining specially-named properties in the properties file for the resource.
- In this case, the path annotation defines the context root of your application since it was not specified in the manifest or config file.
  Therefore, this resource is mapped to http://localhost:10000.
- The children annotation make up the list of child resources.
  These child resources can be anything that extends from Servlet, although usually they will be subclasses of {@link org.apache.juneau.rest.BasicRestServlet} or other resource groups.

If you click the helloWorld link in your application, you'll get a simple hello world message:

http://localhost:10000/helloWorld

...which is generated by this class...

@Rest( path="/helloWorld", title="Hello World example", description="Simplest possible REST resource" ) public class HelloWorldResource extends BasicRestServlet { @RestMethod(name=GET, path="/*") public String sayHello() { return "Hello world!"; } }

The most-common case for deploying the top-level resource is to use the {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder#servlet(Class)} method:

public class App { public static void main(String[] args) { JettyMicroservice .create() .args(args) .servlet(RootResources.class) // Our root resource. .build() .start() ; } }

However, there are multiple ways of deploying top-level resources:

- {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder#servlet(Class)} - Using the builder. Several methods provided.
- {@link org.apache.juneau.microservice.jetty.JettyMicroservice#addServlet(Servlet,String)} - After the Jetty container has been started.
- As a configuration variable "Jetty/servlets".

  #======================================================================================================================= # Jetty settings #======================================================================================================================= [Jetty] # Subclasses of RestServlet servlets = org.apache.juneau.examples.rest.RootResources

- As a configuration variable "Jetty/servletMap".

  #======================================================================================================================= # Jetty settings #======================================================================================================================= [Jetty] # Any servlets and their path specs servletMap = { '/*': 'org.apache.juneau.examples.rest.RootResources' }

- Directly in the jetty.xml file.

  <Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> ... <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> <Set name="contextPath">/</Set> <Call name="addServlet"> <Arg>org.apache.juneau.rest.test.Root</Arg> <Arg>/*</Arg> </Call> <Set name="sessionHandler"> <New class="org.eclipse.jetty.server.session.SessionHandler" /> </Set> </New> ...

### 12.4 - Predefined Resource Classes 8.0.0-new, 8.1.2-deprecated

The following predefined resource classes are also provided for easy inclusion into your microservice:

- {@link org.apache.juneau.microservice.resources.ConfigResource} - View and modify the external INI config file.
- {@link org.apache.juneau.microservice.resources.DirectoryResource} - View and modify file system directories.
- {@link org.apache.juneau.microservice.resources.LogsResource} - View and control generated log files.
- {@link org.apache.juneau.microservice.resources.SampleRootResource} - A sample root resource class to get started from.
- {@link org.apache.juneau.microservice.resources.ShutdownResource} - Shutdown and/or restart the JVM.

### 12.5 - Config 8.0.0-new, 8.1.2-deprecated

In {@doc juneau-microservice-core.Config}, we described how to associate a configuration file with your microservice. In this section we describe how that configuration can be used to customize the behavior or your REST resource classes.

The most common usage for the configuration file is to reference values using the {@link org.apache.juneau.config.vars.ConfigVar $C} variable in annotations. For example, the {@link org.apache.juneau.rest.BasicRestConfig} interface that defines the annotations that control the look-and-feel of classes that extend from {@link org.apache.juneau.rest.BasicRestServlet} use several $C variables to externalize values:

@Rest( ... // HTML-page specific settings htmldoc=@HtmlDoc( // Default page header contents. header={ "<h1>$R{resourceTitle}</h1>", // Use @Rest(title) "<h2>$R{methodSummary,resourceDescription}</h2>", // Use either @RestMethod(summary) or @Rest(description) "$C{REST/header}" // Extra header HTML defined in external config file. }, // Default stylesheet to use for the page. // Can be overridden from external config file. // Default is DevOps look-and-feel (aka Depression look-and-feel). stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}", // Default contents to add to the <head> section of the HTML page. // Use it to add a favicon link to the page. head={ "<link rel='icon' href='$U{$C{REST/favicon}}'/>" }, // No default page footer contents. // Can be overridden from external config file. footer="$C{REST/footer}", ... ), // These are static files that are served up by the servlet under the specified sub-paths. // For example, "/servletPath/htdocs/javadoc.css" resolves to the file "[servlet-package]/htdocs/javadoc.css" // By default, we define static files through the external configuration file. staticFiles="$C{REST/staticFiles}" ) public interface BasicRestConfig {}

These values in turn are pulled from the external configuration file shown below. Note that the configuration file can also contain $C variables.

#======================================================================================================================= # REST settings #======================================================================================================================= [REST] # Mappings to folders containing static files. # Can be in the working directory or in the classpath. staticFiles = htdocs:files/htdocs # Stylesheet to use for HTML views. theme = servlet:/htdocs/themes/devops.css headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a>

Configuration files can also be accessed programmatically. There are 3 primary ways of getting access to the config file:

- {@link org.apache.juneau.microservice.Microservice#getConfig()}

  Any {@doc DefaultRestSvlVariables initialization-time variables} can be used.

- {@link org.apache.juneau.rest.RestContext#getConfig()}

  Any {@doc DefaultRestSvlVariables initialization-time variables} can be used.

  ##### Example usage:

  #---------------------------------- # Configuration for MyHelloResource #---------------------------------- [MyHelloResource] greeting = Hello world!

  #--------------------------------- # Contents of MyHelloResource.java #--------------------------------- @Rest(...) public class MyHelloResource extends BasicRestServlet { private String greeting; // Or access config file in servlet init method. @Override /* Servlet */ public void init() { Config c = getContext().getConfig(); this.greeting = c.getString("MyHelloResource/greeting"); } }

  Additional user-defined variables at the servlet level can be defined by adding a {@link org.apache.juneau.rest.annotation.HookEvent#INIT} hook method and using the {@link org.apache.juneau.rest.RestContextBuilder#vars(Class...)} method.

- {@link org.apache.juneau.rest.RestRequest#getConfig()} - An instance method to access it from inside a REST method.

  Any {@doc DefaultRestSvlVariables initialization-time or request-time variables} can be used.

  ##### Example usage:

  #---------------------------------- # Configuration for MyHelloResource #---------------------------------- [MyHelloResource] greeting = Hello $RP{person}! // $RP is RequestPathVar localizedGreeting = $L{HelloMessage,$RP{person}} // $L is LocalizationVar with args

  #--------------------------------- # Contents of MyHelloResource.java #--------------------------------- @Rest( path="/hello", messages="nls/Messages", ... ) public class MyHelloResource extends BasicRestServlet { /** Standard hello message. */ @RestMethod(name=GET, path="/{person}") public String sayHello(RestRequest req) { return req.getConfig().getString("MyHelloResource/greeting"); } /** Hello message in users language. */ @RestMethod(name=GET, path="/localized/{person}") public String sayLocalizedHello(RestRequest req) { return req.getConfig().getString("MyHelloResource/localizedGreeting"); } }

  #--------------------------------------- # Contents of nls/Messages_en.properties #--------------------------------------- MyHelloResource.HelloMessage = Hello {0}!

  Additional user-defined variables can be defined at this level by overriding the {@link org.apache.juneau.rest.RestContextBuilder#vars(Class...)} method.

That sayLocalizedHello() example might need some explanation since there's a lot going on there. Here's what happens when an HTTP call is made to GET /hello/localized/Bob:

1. The HTTP call matches the /hello path on the MyHelloResource class.
2. The HTTP call matches the /localized/{person} path on the sayLocalizedHello() method.
3. The request attribute person gets assigned the value "Bob".
4. The call to req.getConfig().getString("MyHelloResource/localizedGreeting") finds the value "$L{HelloMessage,$RP{person}}".
5. The arguments in the $L{} variable get resolved, resulting in "$L{HelloMessage,Bob}".
6. The $L{} variable gets resolved to the message "Hello {0}!" in the localized properties file of the servlet based on the Accept-Language header on the request.
7. The arguments get replaced in the message resulting in "Hello Bob!".
8. The resulting message "Hello Bob!" is returned as a POJO to be serialized to whatever content type was specified on the Accept header on the request.

This particular example is needlessly complex, but it gives an idea of how variables can be used recursively to produce sophisticated results

- {@doc juneau-config}

### 12.6 - Jetty.xml file 8.0.0-new, 8.1.2-deprecated

The Jetty microservice comes with a bare-bones jetty.xml file which can be modified to suite any needs.

The jetty.xml can be located in either the "." or "files" working directory or classpath. It can also be specified in any of the following ways:

- Using the {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder#jettyXml(Object,boolean)} method to specify the location or contents of the file.
- Specifying the location using a Jetty-Config value in the MANIFEST.MF file.

  Jetty-Config: files/jetty.xml

- Specifying the location using the "Jetty/jettyXml" configuration value.

  #======================================================================================================================= # Jetty settings #======================================================================================================================= [Jetty] # Path of the jetty.xml file used to configure the Jetty server. config = files/jetty.xml

SVL variables in the jetty.xml file are automatically resolved by the microservice. This allows you to reference values in your configuration file from the jetty.xml file.

The HTTP port used is controlled via the following:

- The {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder#ports(int...)} method.

  JettyMicroservice .create() .args(args) .servlets(RootResource.class) .port(1000,2000,0,0,0) // Try port 1000, then 2000, then 3 random ports. .build() .start()

- The "Jetty/ports" configuration property.

  #======================================================================================================================= # Jetty settings #======================================================================================================================= [Jetty] # Port to use for the jetty server. # You can specify multiple ports. The first available will be used. '0' indicates to try a random port. port = 1000,2000,0,0,0

The first available port is then made available through the system property "availablePort" so that it can be referenced in our jetty.xml file.

<Set name="connectors"> <Array type="org.eclipse.jetty.server.Connector"> <Item> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg> <Ref refid="ExampleServer" /> </Arg> <Set name="port">$S{availablePort,8080}</Set> </New> </Item> </Array> </Set>

The {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder#jettyServerFactory(JettyServerFactory)} method is also provided to use your own customized Jetty server.

### 12.7 - UI Customization 8.0.0-new, 8.1.2-deprecated

The Microservice project contains a files/htdocs folder with predefined stylesheets and images.

These files can be used to tailor the look-and-feel of your microservice.

http://localhost:10000/helloWorld

The REST configuration section of your microservice configuration file can be used to tailor the header and footer on the pages:

#======================================================================================================================= # REST settings #======================================================================================================================= [REST] staticFiles = htdocs:files/htdocs # Stylesheet to use for HTML views. theme = servlet:/htdocs/themes/devops.css headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a>

The {@link org.apache.juneau.rest.BasicRestConfig} interface (which defines the default settings for {@link org.apache.juneau.rest.BasicRestServlet} pulls in this information using {@link org.apache.juneau.config.vars.ConfigVar $C} and {@link org.apache.juneau.rest.vars.UrlVar $U} variables:

@Rest( ... // HTML-page specific settings htmldoc=@HtmlDoc( // Default page header contents. header={ "<h1>$R{resourceTitle}</h1>", // Use @Rest(title) "<h2>$R{methodSummary,resourceDescription}</h2>", // Use either @RestMethod(summary) or @Rest(description) "$C{REST/header}" // Extra header HTML defined in external config file. }, // Default stylesheet to use for the page. // Can be overridden from external config file. // Default is DevOps look-and-feel (aka Depression look-and-feel). stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}", // Default contents to add to the <head> section of the HTML page. // Use it to add a favicon link to the page. head={ "<link rel='icon' href='$U{$C{REST/favicon}}'/>" }, // No default page footer contents. // Can be overridden from external config file. footer="$C{REST/footer}" ), // Optional external configuration file. config="$S{juneau.configFile}", // These are static files that are served up by the servlet under the specified sub-paths. // For example, "/servletPath/htdocs/javadoc.css" resolves to the file "[servlet-package]/htdocs/javadoc.css" // By default, we define static files through the external configuration file. staticFiles="$C{REST/staticFiles}" ) public interface BasicRestConfig {}

Note that the files/htdocs directory is mapped to "servlet:/htdocs" using the staticFiles setting. This allows those files to be served up through the servlet through the URL "/[servlet-path]/htdocs"

The theme files are externally accessible and can be modified to produce any look-and-feel you desire. The microservice still works without the files directory. An embedded devops.css is included in the jar as a default spreadsheet.

If you're testing out changes in the theme stylesheets, you may want to set the following system property that prevents caching of those files so that you don't need to restart the microservice each time a change is made:

#======================================================================================================================= # System properties #----------------------------------------------------------------------------------------------------------------------- # These are arbitrary system properties that are set during startup. #======================================================================================================================= [SystemProperties] # Disable classpath resource caching. # Useful if you're attached using a debugger and you're modifying classpath resources while running. RestContext.useClasspathResourceCaching.b = false

### 12.8 - Extending JettyMicroservice 8.0.0-new, 8.1.2-deprecated

This example shows how the {@link org.apache.juneau.microservice.jetty.JettyMicroservice} class can be extended to implement lifecycle listener methods or override existing methods. We'll create a new class com.foo.MyJettyMicroservice.

/** * Sample subclass of a JettyMicroservice that provides customized behavior. */ public class MyJettyMicroservice extends JettyMicroservice { public static void main(String[] args) throws Exception { JettyMicroserviceBuilder builder = JettyMicroservice.create(); new MyJettyMicroservice(builder).start().join(); } public MyJettyMicroservice(JettyMicroserviceBuilder builder) throws Exception { super(builder); } // Customized code here.

Optionally, you can extend the {@link org.apache.juneau.microservice.jetty.JettyMicroserviceBuilder} class as well:

public class MyJettyMicroserviceBuilder extends JettyMicroserviceBuilder { int extraField; /** * Constructor (required). */ protected MyJettyMicroserviceBuilder() {} /** * Copy constructor (required). * * @param copyFrom The builder to copy settings from. */ protected MyJettyMicroserviceBuilder(MyJettyMicroserviceBuilder copyFrom) { super(copyFrom); } // Additional setters public MyJettyMicroserviceBuilder extraField(int extraField) { this.extraField = extraField; return this; } // Overridden methods @Override /* JettyMicroserviceBuilder */ public MyJettyMicroserviceBuilder copy() { return new MyJettyMicroserviceBuilder(this); } @Override /* JettyMicroserviceBuilder */ public MyJettyMicroserviceBuilder ports(int...ports) { super.ports(ports); return this; } @Override /* JettyMicroserviceBuilder */ public MyJettyMicroserviceBuilder servlet(Class<? extends RestServlet> c) throws InstantiationException, IllegalAccessException { super.servlet(c); return this; } ... }

## 13 - my-jetty-microservice 8.0.0-new, 8.1.2-deprecated

The Juneau Microservice libraries are likely to be removed in Juneau 9.0 due to the popularity of the Spring Boot framework for creating microservices and the ability for Juneau to be used within Spring Boot.

##### Starter Project Zip

my-jetty-microservice-{@property juneauVersion}.zip

The my-jetty-microservice.zip file is a predefined starter Eclipse project for developing REST microservices using the {@doc juneau-microservice-jetty juneau-microservice-jetty} package.

It includes a combination of the Juneau Core, Server, and Client APIs and all libraries needed to execute in a Java 1.8+ environment.

### 13.1 - Installing in Eclipse 8.0.0-updated, 8.1.2-deprecated

Follow these instructions to create a new template project in Eclipse.

1. Download the my-jetty-microservice-{@property juneauVersion}.zip file from the downloads page (located in the binaries) and import it into your workspace as an existing project:
2. Select the archive file and import the project:
3. In your workspace, you should now see the following project:

The important elements in this project are:

- App.java - The entry point.
  This class creates and starts our microservice:

  public class App { public static void main(String[] args) throws Exception { JettyMicroservice .create() .args(args) .servlet(RootResources.class) .build() .start() .startConsole() .join(); } }

- RootResources.java - The top-level REST resource.
  This class routes HTTP requests to child resources:

  @Rest( path="/", title="My Microservice", description="Top-level resources page", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, StyleMenuItem.class }, navlinks={ "options: servlet:/?method=OPTIONS" } ), children={ HelloWorldResource.class, ConfigResource.class, LogsResource.class } ) public class RootResources extends BasicRestServletJenaGroup { // No code }

- my-jetty-microservice.cfg - The external configuration file.
  Contains various useful settings.
  Can be used for your own resource configurations.

  #======================================================================================================================= # Basic configuration file for REST microservices # Subprojects can use this as a starting point. #======================================================================================================================= #======================================================================================================================= # Jetty settings #======================================================================================================================= [Jetty] # Path of the jetty.xml file used to configure the Jetty server. config = jetty.xml # Resolve Juneau variables in the jetty.xml file. resolveVars = true # Port to use for the jetty server. # You can specify multiple ports. The first available will be used. '0' indicates to try a random port. # The resulting available port gets set as the system property "availablePort" which can be referenced in the # jetty.xml file as "$S{availablePort}" (assuming resolveVars is enabled). port = 10000,0,0,0 # Optionally specify your servlets here: #servlets = org.apache.juneau.microservice.sample.RootResources #======================================================================================================================= # REST settings #======================================================================================================================= [REST] # Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @Rest-annotated # classes. These are static files that are served up by the servlet under the specified sub-paths. # For example, given the following setting... # staticFiles = htdocs:my-docs,styles/my-styles # ...the URI "/servletPath/htdocs/javadoc.css" resolves to the path "/my-docs/javadoc.css". # This path can be relative to the working directory, classpath root, or package of your resource class. # Used by the BasicRestConfig interface that defines the following value: # staticFiles="$C{REST/staticFiles}" staticFiles = htdocs:htdocs # Stylesheet to use for HTML views. # Used by the BasicRestConfig interface that defines the following value: # stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}" theme = servlet:/htdocs/themes/devops.css # Various look-and-feel settings used in the BasicRestConfig interface. headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a> #======================================================================================================================= # Console settings #======================================================================================================================= [Console] enabled = true # List of available console commands. # These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via # the console. # When listed here, the implementations must provide a no-arg constructor. # They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method. commands = org.apache.juneau.microservice.console.ExitCommand, org.apache.juneau.microservice.console.RestartCommand, org.apache.juneau.microservice.console.HelpCommand, org.apache.juneau.microservice.console.ConfigCommand #======================================================================================================================= # Logger settings #----------------------------------------------------------------------------------------------------------------------- # See FileHandler Java class for details. #======================================================================================================================= [Logging] ... #======================================================================================================================= # System properties #----------------------------------------------------------------------------------------------------------------------- # These are arbitrary system properties that are set during startup. #======================================================================================================================= [SystemProperties] # Configure Jetty for StdErrLog Logging # org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog # Configure Jetty to log using java-util logging org.eclipse.jetty.util.log.class = org.apache.juneau.microservice.jetty.JettyLogger # Jetty logging level # Possible values: ALL, DEBUG, INFO, WARN, OFF org.eclipse.jetty.LEVEL = WARN derby.stream.error.file = $C{Logging/logDir}/derby-errors.log

- jetty.xml - The Jetty configuration file.
  A bare-bones config file that can be extended to use any Jetty features.

  <Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> <Set name="connectors"> <Array type="org.eclipse.jetty.server.Connector"> <Item> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg> <Ref refid="ExampleServer"/> </Arg> <Set name="port">$S{availablePort,8080}</Set> </New> </Item> </Array> </Set> <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> <Set name="contextPath">/</Set> <!-- Optionally specify your servlets here --> <!--Call name="addServlet"> <Arg>org.apache.juneau.microservice.sample.RootResources</Arg> <Arg>/*</Arg> </Call--> <Set name="sessionHandler"> <New class="org.eclipse.jetty.server.session.SessionHandler"/> </Set> </New> <Set name="handler"> <New class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <Ref refid="context"/> </Item> <Item> <New class="org.eclipse.jetty.server.handler.DefaultHandler"/> </Item> </Array> </Set> </New> </Set> <Set name="requestLog"> <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog"> <Set name="filename"><Property name="jetty.logs" default="$C{Logging/logDir,logs}"/>/jetty-requests.log</Set> <Set name="filenameDateFormat">yyyy_MM_dd</Set> <Set name="LogTimeZone">GMT</Set> <Set name="retainDays">90</Set> <Set name="append">false</Set> <Set name="LogLatency">true</Set> </New> </Set> <Get name="ThreadPool"> <Set name="minThreads" type="int">10</Set> <Set name="maxThreads" type="int">100</Set> <Set name="idleTimeout" type="int">60000</Set> <Set name="detailedDump">true</Set> </Get> </Configure>

At this point, you're ready to start the microservice from your workspace.

### 13.2 - Running in Eclipse 8.0.0-updated, 8.1.2-deprecated

The my-jetty-microservice.launch file is already provided to allow you to quickly start your new microservice.

Go to Run -> Run Configurations -> Java Application -> my-jetty-microservice and click Run. In your console view, you should see the following output:

Running class 'JettyMicroservice' using config file 'my-jetty-microservice.cfg'. Server started on port 10000 List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help >

Now open your browser and point to http://localhost:10000. You should see the following:

http://localhost:10000

You can enter the command exit to shut it down.

### 13.3 - Building and Running from Command-Line 8.0.0-updated, 8.1.2-deprecated

The pom.xml file is a basic Maven build script for creating your microservice as an executable uber-jar.

The easiest way to build your microservice is to run the following from the project root.

mvn clean install

Your target directory should now contain the following files:

- my-jetty-microservice-1.0.jar
- my-jetty-microservice.cfg

To start from a command line, run the following command from inside your target directory:

java -jar my-jetty-microservice-1.0.jar

You should see the following console output:

Running class 'JettyMicroservice' using config file 'my-jetty-microservice.cfg'. Server started on port 10000 List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help >

If you get this error message: `java.net.BindException: Address already in use`, then this microservice is already running elsewhere and so it cannot bind to port 10000.

## 14 - my-springboot-microservice 8.0.0-new

##### Starter Project Zip

my-springboot-microservice-{@property juneauVersion}.zip

The my-springboot-microservice.zip file is a predefined starter Eclipse project for developing REST microservices using the {@doc juneau-rest-server-springboot juneau-rest-server-springboot} package with Spring Boot.

It includes a combination of the Juneau Core, Server, and Client APIs and all libraries needed to execute in a Java 1.8+ environment.

One significant difference is that we are not using the Juneau {@link org.apache.juneau.microservice.Microservice} API for our application but instead using the existing Spring Boot API.

### 14.1 - Installing in Eclipse 8.0.0-new

Follow these instructions to create a new template project in Eclipse.

1. Download the my-springboot-microservice-{@property juneauVersion}.zip file from the downloads page (located in the binaries) and import it into your workspace as an existing project:
2. Select the archive file and import the project:
3. In your workspace, you should now see the following project:

The important elements in this project are:

- App.java - The entry point.
  This class creates and starts our microservice.
  Note that we're using the existing Spring Boot application logic for the microservice and we're retrieving our root resource as a spring bean.
  Only the top-level resource needs to be annotated with {@link org.apache.juneau.rest.springboot.annotation.JuneauRestRoot @JuneauRestRoot}

  @SpringBootApplication @Controller public class App { public static void main(String[] args) { new SpringApplicationBuilder(App.class) .initializers(new JuneauRestInitializer(App.class)) .run(args); } @Bean @JuneauRestRoot public RootResources getRootResources() { return new RootResources(); } }

- RootResources.java - The top-level REST resource.
  This class routes HTTP requests to child resources.
  This is identical to the Jetty example.

  @Rest( path="/", title="My Microservice", description="Top-level resources page", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, StyleMenuItem.class }, navlinks={ "options: servlet:/?method=OPTIONS" } ), children={ HelloWorldResource.class, ConfigResource.class, LogsResource.class } ) public class RootResources extends BasicRestServletJenaGroup { // No code }

- juneau.cfg - The configuration file.
  Contains various useful settings.
  Can be used for your own resource configurations.
  Note that the Jetty configuration is not present.
  Also it's located in the classpath so that our microservice can be built as a single executable jar.

  #======================================================================================================================= # Basic configuration file for REST microservices # Subprojects can use this as a starting point. #======================================================================================================================= #======================================================================================================================= # REST settings #======================================================================================================================= [REST] # Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @Rest-annotated # classes. These are static files that are served up by the servlet under the specified sub-paths. # For example, given the following setting... # staticFiles = htdocs:my-docs,styles/my-styles # ...the URI "/servletPath/htdocs/javadoc.css" resolves to the path "/my-docs/javadoc.css". # This path can be relative to the working directory, classpath root, or package of your resource class. # Used by the BasicRestConfig interface that defines the following value: # staticFiles="$C{REST/staticFiles}" staticFiles = htdocs:htdocs # Stylesheet to use for HTML views. # Used by the BasicRestConfig interface that defines the following value: # stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}" theme = servlet:/htdocs/themes/devops.css # Various look-and-feel settings used in the BasicRestConfig interface. headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a>

At this point, you're ready to start the microservice from your workspace.

### 14.2 - Running in Eclipse 8.0.0-new

The my-springboot-microservice.launch file is already provided to allow you to quickly start your new microservice.

Go to Run -> Run Configurations -> Java Application -> my-springboot-microservice and click Run. In your console view, you should see the following output:

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) ... INFO: Tomcat started on port(s): 8080 (http) with context path '' Dec 21, 2012 12:30:00 AM org.springframework.boot.StartupInfoLogger logStarted INFO: Started App in 1.999 seconds (JVM running for 2.999)

Now open your browser and point to http://localhost:5000. You should see the following:

http://localhost:5000

### 14.3 - Building and Running from Command-Line 8.0.0-new

The pom.xml file is a basic Maven build script for creating your microservice as an executable uber-jar.

The easiest way to build your microservice is to run the following from the project root.

mvn clean install

Your target directory should now contain the following files:

- my-springboot-microservice-1.0.jar

To start from a command line, run the following command from inside your target directory:

java -jar my-springboot-microservice-1.0.jar

You should see the following console output:

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) ... INFO: Tomcat started on port(s): 8080 (http) with context path '' Dec 21, 2012 12:30:00 AM org.springframework.boot.StartupInfoLogger logStarted INFO: Started App in 1.999 seconds (JVM running for 2.999)

## 15 - juneau-examples-core 8.0.0-updated

##### Archive File

juneau-examples-core-{@property juneauVersion}.zip

The juneau-examples-core project contains various code examples for using the core APIs.

### 15.1 - Installing in Eclipse 8.0.0-new

Follow these instructions to import the Juneau project into Eclipse.

1. Download the juneau-examples-core-{@property juneauVersion}.zip file from the downloads page (located in the binaries) and import it into your workspace as an existing project:
2. Select the archive file and import the project:
3. In your workspace, you should now see the following project:

### 15.2 - Examples 8.0.0-new

The following shows the core examples provided:

- {@link org.apache.juneau.examples.core.json}
  - {@link org.apache.juneau.examples.core.json.JsonSimpleExample} - JsonSerializer and JsonParser usage on serialize and deserialize simple Pojo bean.
  - {@link org.apache.juneau.examples.core.json.JsonComplexExample} - JsonSerializer and JsonParser usage on serialize and deserialize complex Pojo bean.
  - {@link org.apache.juneau.examples.core.json.JsonConfigurationExample} - Json Serializers configured using properties defined in JsonSerializer class.
- {@link org.apache.juneau.examples.core.xml}
  - {@link org.apache.juneau.examples.core.xml.XmlSimpleExample} - XmlSerializer and XmlParser usage on serialize and deserialize simple Pojo bean.
  - {@link org.apache.juneau.examples.core.xml.XmlComplexExample} - XmlSerializer and XmlParser usage on serialize and deserialize complex Pojo bean.
  - {@link org.apache.juneau.examples.core.xml.XmlConfigurationExample} - XmlSerializers configured using properties defined in XmlSerializer class.
- {@link org.apache.juneau.examples.core.dto}
  - {@link org.apache.juneau.examples.core.dto.DtoExample} - Usage of core dto module.
- {@link org.apache.juneau.examples.core.rdf}
  - {@link org.apache.juneau.examples.core.rdf.RdfExample} - RdfXmlSerializer usage on serialize simple Pojo bean.
  - {@link org.apache.juneau.examples.core.rdf.RdfComplexExample} - RdfXmlSerializer usage on serialize complex Pojo bean.
- {@link org.apache.juneau.examples.core.html}
  - {@link org.apache.juneau.examples.core.html.HtmlSimpleExample} - HtmlSerializer usage on serialize and deserialize simple Pojo bean.
  - {@link org.apache.juneau.examples.core.html.HtmlComplexExample} - HtmlSerializer usage on serialize and deserialize complex Pojo bean.
- {@link org.apache.juneau.examples.core.uon}
  - {@link org.apache.juneau.examples.core.uon.UONExample} - UonSerializer usage on serialize and deserialize simple Pojo bean.
  - {@link org.apache.juneau.examples.core.uon.UONComplexExample} - UonSerializer usage on serialize and deserialize complex Pojo bean.
- {@link org.apache.juneau.examples.core.svl}
  - {@link org.apache.juneau.examples.core.svl.SvlExample} - Usage of Svl module in juneau.

## 16 - juneau-examples-rest 8.0.0-updated

##### Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-examples-rest</artifactId> <version>{@property juneauVersion}</version> </dependency>

##### Java Library

juneau-examples-rest-{@property juneauVersion}.jar

##### OSGi Module

org.apache.juneau.examples.rest_{@property juneauVersion}.jar

The juneau-examples-rest project includes various examples of REST resources written using Juneau.

Note: These examples can be deployed as buildable Eclipse projects using Jetty or Spring Boot using instructions in the following sections:

- {@doc juneau-examples-rest-jetty}
- {@doc juneau-examples-rest-springboot}

### 16.1 - RootResources 8.0.0-updated, 8.1.0-updated

The RootResources class is the main page for the REST microservice. It serves as the jumping-off point for the other resources.

The class hierarchy for this class is:

- {@link org.apache.juneau.rest.RestServlet} - Contains all the REST servlet logic.
  - {@link org.apache.juneau.rest.BasicRestServlet} - Defines default serializers and parsers, and OPTIONs page logic.
    - {@link org.apache.juneau.rest.BasicRestServletGroup} - Specialized subclass for grouping other resources.
      - {@link org.apache.juneau.rest.BasicRestServletJenaGroup} - Group resource with added RDF support.
        - RootResources

Pointing a browser to the resource shows the following:

http://localhost:10000

The RootResources class can also be defined as a servlet in a web.xml file:

<web-app version='3.0'> <servlet> <servlet-name>RootResources</servlet-name> <servlet-class>org.apache.juneau.examples.rest.RootResources</servlet-class> </servlet> <servlet-mapping> <servlet-name>RootResources</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

The RootResources class consists entirely of annotations:

##### RootResources.java

/** * Sample REST resource showing how to implement a "router" resource page. */ @Rest( path="/", title="Root resources", description="Example of a router resource page.", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, StyleMenuItem.class }, navlinks={ "options: ?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This is an example of a 'router' page that serves as a jumping-off point to child resources.</p>", " <p>Resources can be nested arbitrarily deep through router pages.</p>", " <p>Note the <span class='link'>options</span> link provided that lets you see the generated swagger doc for this page.</p>", " <p>Also note the <span class='link'>sources</span> link on these pages to view the source code for the page.</p>", " <p>All content on pages in the UI are serialized POJOs. In this case, it's a serialized array of beans with 2 properties, 'name' and 'description'.</p>", " <p>Other features (such as this aside) are added through annotations.</p>", "</div>" } ), children={ HelloWorldResource.class, PetStoreResource.class, DtoExamples.class, ConfigResource.class, LogsResource.class, DebugResource.class, ShutdownResource.class } ) @SerializerConfig( // For testing purposes, we want to use single quotes in all the serializers so it's easier to do simple // String comparisons. quoteChar="'" ) public class RootResources extends BasicRestServletJenaGroup { // No code! }

The children annotation defines the child resources of this router resource. These are resources whose paths are direct descendants to the parent resource.

Child resources must be annotated with the {@link org.apache.juneau.rest.annotation.Rest#path() @Rest(path)} annotation to identify the subpath of the child. Children CAN extend from {@link org.apache.juneau.rest.BasicRestServlet} but it is not a requirement.

Note that these router pages can be arbitrarily nested deep. You can define many levels of router pages for arbitrarily hierarchical REST interfaces.

Let's step back and describe what's going on here:

During servlet initialization of the RootResources object, the toolkit looks for the @Rest(children) annotation. If it finds it, it instantiates instances of each class and recursively performs servlet initialization on them. It then associates the child resource with the parent by the name specified by the @Rest(path) annotation on the child class.

When a request for the child URL (/helloWorld) is received, the RootResources servlet gets the request and sees that the URL remainder matches one of its child resources. It then forwards the request to the child resource for processing. The request passed to the child resource is the same as if the child resource had been deployed independently (e.g. path-info, resource-URI, and so forth).

### 16.2 - HelloWorldResource 8.0.0-updated

The HelloWorldResource class is a simple resource that prints a "Hello world!" message.

##### HelloWorldResource.java

/** * Sample REST resource that prints out a simple "Hello world!" message. */ @Rest( title="Hello World", description="An example of the simplest-possible resource", path="/helloWorld", htmldoc=@HtmlDoc( aside={ "<div style='max-width:400px' class='text'>", " <p>This page shows a resource that simply response with a 'Hello world!' message</p>", " <p>The POJO serialized is a simple String.</p>", "</div>" } ) ) public class HelloWorldResource implements BasicRestConfig { /** GET request handler */ @RestMethod(name=GET, path="/*", summary="Responds with \"Hello world!\"") public String sayHello() { return "Hello world!"; } }

Notice that in this case we're not extending from {@link org.apache.juneau.rest.RestServlet}. We are however implementing {@link org.apache.juneau.rest.BasicRestConfig} which is a no-op interface that defines a default @Rest annotation with all the serializers, parsers, and configuration defined on the {@link org.apache.juneau.rest.BasicRestServlet} class.

The only difference between implementing BasicRestConfig and extending from BasicRestServlet is that the latter provides the following additional features:

- A default OPTIONS method.
- It can be deployed like any servlet.

All other examples in this project extend from BasicRestServlet so that they provide automatic OPTIONS page support.

Pointing a browser to the resource shows the following:

http://localhost:10000/helloWorld

Using the special &Accept=text/json and &plainText=true parameters allows us to see this page rendered as JSON:

http://localhost:10000/helloWorld?Accept=text/json&plainText=true

### 16.3 - DtoExamples 8.0.0-new, 8.1.0-updated

The DtoExamples resource is a resource group for demonstrating various DTO examples.

The AtomFeedResource class shows examples of the following:

- Using the {@doc org.apache.juneau.dto.atom#TOC ATOM Feed DTO} API.

Pointing a browser to the resource shows the following:

http://localhost:10000/atom

True ATOM feeds require using an Accept:text/xml header:

http://localhost:10000/atom?Accept=text/xml&plainText=true

Other languages, such as JSON are also supported:

http://localhost:10000/atom?Accept=text/json&plainText=true

##### AtomFeedResource.java

/** * Sample resource that shows how to generate ATOM feeds. */ @Rest( path="/atom", title="Sample ATOM feed resource", description="Sample resource that shows how to render ATOM feeds", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, StyleMenuItem.class }, navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" } ), encoders=GzipEncoder.class ) @SerializerConfig(quoteChar="'") @RdfConfig(rdfxml_tab="5", addRootProperty="true") public class AtomFeedResource extends BasicRestServletJena { private Feed feed; // The root resource object @Override /* Servlet */ public void init() { try { feed = feed("tag:juneau.sample.com,2013:1", "Juneau ATOM specification", "2013-05-08T12:29:29Z") .subtitle(text("html").text("A <em>lot</em> of effort went into making this effortless")) .links( link("alternate", "text/html", "http://www.sample.com/").hreflang("en"), link("self", "application/atom+xml", "http://www.sample.com/feed.atom") ) .generator( generator("Juneau").uri("http://juneau.apache.org/").version("1.0") ) .entries( entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2013-05-08T12:29:29Z") .links( link("alternate", "text/html", "http://www.sample.com/2012/05/08/juneau.atom"), link("enclosure", "audio/mpeg", "http://www.sample.com/audio/juneau_podcast.mp3").length(1337) ) .published("2013-05-08T12:29:29Z") .authors( person("James Bognar").uri(new URI("http://www.sample.com/")).email("jamesbognar@apache.org") ) .contributors( person("Barry M. Caceres") ) .content( content("xhtml") .lang("en") .base("http://www.apache.org/") .text("<div><p>[Update: Juneau supports ATOM.]</p></div>") ) ); } catch (Exception e) { throw new RuntimeException(e); } } /** * GET request handler */ @RestMethod(name=GET, path="/") public Feed getFeed() throws Exception { return feed; } /** * PUT request handler. * Replaces the feed with the specified content, and then mirrors it as the response. */ @RestMethod(name=PUT, path="/") public Feed setFeed(@Body Feed feed) throws Exception { this.feed = feed; return feed; } }

The JsonSchemaResource class shows examples of the following:

- Using the {@link org.apache.juneau.dto.jsonschema JSON Schema DTO} API.

The resource consists of a pre-initialized {@link org.apache.juneau.dto.jsonschema.JsonSchema} object. Pointing a browser to the resource shows the following:

http://localhost:10000/jsonSchema

For true JSON-Schema, you need to specify the header Accept: text/json:

http://localhost:10000/jsonSchema?Accept=text/json&plainText=true

##### JsonSchemaResource.java

/** * Sample resource that shows how to serialize JSON-Schema documents. */ @Rest( path="/jsonSchema", messages="nls/JsonSchemaResource", title="Sample JSON-Schema document", description="Sample resource that shows how to generate JSON-Schema documents", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, StyleMenuItem.class }, navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, aside={ "<div style='min-width:200px' class='text'>", " <p>Shows how to produce JSON-Schema documents in a variety of languages using the JSON-Schema DTOs.</p>", "</div>" } ) ) public class JsonSchemaResource extends BasicRestServletJena { private static final long serialVersionUID = 1L; private JsonSchema schema; // The schema document @Override /* Servlet */ public void init() { try { schema = new JsonSchema() .setId("http://example.com/sample-schema#") .setSchemaVersionUri("http://json-schema.org/draft-04/schema#") .setTitle("Example Schema") .setType(JsonType.OBJECT) .addProperties( new JsonSchemaProperty("firstName", JsonType.STRING), new JsonSchemaProperty("lastName", JsonType.STRING), new JsonSchemaProperty("age", JsonType.INTEGER) .setDescription("Age in years") .setMinimum(0) ) .addRequired("firstName", "lastName"); } catch (Exception e) { throw new RuntimeException(e); } } /** GET request handler */ @RestMethod(name=GET, path="/") public JsonSchema getSchema() throws Exception { return schema; } /** * PUT request handler. * Replaces the schema document with the specified content, and then mirrors it as the response. */ @RestMethod(name=PUT, path="/") public JsonSchema setSchema(@Body JsonSchema schema) throws Exception { this.schema = schema; return schema; } }

### 16.4 - ConfigResource

The {@link org.apache.juneau.microservice.resources.ConfigResource} class is a predefined reusable resource. It provides a REST interface for reading and altering the microservice config file.

Pointing a browser to the resource shows the following:

http://localhost:10000/config

An edit page is provided for altering the raw config file:

http://localhost:10000/config/edit

The {@link org.apache.juneau.config.Config} class is a serializable POJO, which makes the resource relatively straightforward to implement.

##### ConfigResource.java

/** * Shows contents of the microservice configuration file. */ @Rest( path="/config", title="Configuration", description="Contents of configuration file.", htmldoc=@HtmlDoc( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS", "edit: servlet:/edit" } ) ) public class ConfigResource extends BasicRestServlet { @RestMethod(name=GET, path="/", description="Show contents of config file.") public ObjectMap getConfig() throws Exception { return getServletConfig().getConfig().asMap(); } @RestMethod(name=GET, path="/edit", description="Edit config file.") public Form getConfigEditForm(RestRequest req) throws Exception { return form().id("form").action("servlet:/").method("POST").enctype("application/x-www-form-urlencoded").children( div()._class("data").children( table( tr(td().style("text-align:right").children(button("submit","Submit"),button("reset","Reset"))), tr(th().child("Contents")), tr(th().child( textarea().name("contents").rows(40).cols(120).style("white-space:pre;word-wrap:normal;overflow-x:scroll;font-family:monospace;") .text(getServletConfig().getConfig().toString())) ) ) ) ); } @RestMethod(name=GET, path="/{section}", description="Show config file section.", swagger={ "parameters:[", "{name:'section',in:'path',description:'Section name.'}", "]" } ) public ObjectMap getConfigSection(@Path("section") String section) throws Exception { return getSection(section); } @RestMethod(name=GET, path="/{section}/{key}", description="Show config file entry.", swagger={ "parameters:[", "{name:'section',in:'path',description:'Section name.'},", "{name:'key',in:'path',description:'Entry name.'}", "]" } ) public String getConfigEntry(@Path("section") String section, @Path("key") String key) throws Exception { return getSection(section).getString(key); } @RestMethod(name=POST, path="/", description="Sets contents of config file from a FORM post.", swagger={ "parameters:[", "{name:'contents',in:'formData',description:'New contents in INI file format.'}", "]" } ) public Config setConfigContentsFormPost(@FormData("contents") String contents) throws Exception { return setConfigContents(new StringReader(contents)); } @RestMethod(name=PUT, path="/", description="Sets contents of config file.", swagger={ "parameters:[", "{in:'body',description:'New contents in INI file format.'}", "]" } ) public Config setConfigContents(@Body Reader contents) throws Exception { return getServletConfig().getConfig().load(contents, true).asMap(); } @RestMethod(name=PUT, path="/{section}", description="Add or overwrite a config file section.", swagger={ "parameters:[", "{name:'section',in:'path',description:'Section name.'}", "{in:'body',description:'New contents for section as a simple map with string keys and values.'}", "]" } ) public ObjectMap setConfigSection(@Path("section") String section, @Body Map<String,String> contents) throws Exception { getServletConfig().getConfig().setSection(section, contents); return getSection(section); } @RestMethod(name=PUT, path="/{section}/{key}", description="Add or overwrite a config file entry.", swagger={ "parameters:[", "{name:'section',in:'path',description:'Section name.'}", "{name:'key',in:'path',description:'Entry name.'}", "{in:'body',description:'New value as a string.'}", "]" } ) public String setConfigSection(@Path("section") String section, @Path("key") String key, @Body String value) throws Exception { getServletConfig().getConfig().put(section, key, value, false); return getSection(section).getString(key); } private ObjectMap getSection(String name) { ObjectMap m = getServletConfig().getConfig().getSectionMap(name); if (m == null) throw new RestException(SC_NOT_FOUND, "Section not found."); return m; } }

### 16.5 - LogsResource

The {@link org.apache.juneau.microservice.resources.LogsResource} class is a reusable predefined resource. It provides a REST interface for the log files generated by the microservice.

Pointing a browser to the resource shows the following:

http://localhost:10000/logs

## 17 - juneau-examples-rest-jetty 8.0.0-new, 8.1.2-deprecated

The Juneau Microservice libraries are likely to be removed in Juneau 9.0 due to the popularity of the Spring Boot framework for creating microservices and the ability for Juneau to be used within Spring Boot.

##### Starter Project Zip

juneau-examples-rest-jetty-{@property juneauVersion}.zip

The juneau-examples-rest-jetty project includes everything you need create a Samples REST microservice in an Eclipse workspace and build it as an executable jar.

### 17.1 - Installing in Eclipse 8.0.0-new,8.1.2-deprecated

Follow these instructions to import the REST examples project using Jetty into Eclipse.

1. Download the juneau-examples-rest-jetty-{@property juneauVersion}.zip file from the downloads page (located in the binaries) and import it into your workspace as an existing project:
2. Select the archive file and import the project:
3. In your workspace, you should now see the following project:

The important elements in this project are:

- App.java - The entry point.
  This class creates and starts our microservice:

  public class App { public static void main(String[] args) throws Exception { JettyMicroservice .create() .args(args) .servlet(RootResources.class) .build() .start() .startConsole() .join(); } }

- RootResources.java - The top-level REST resource.
  This class routes HTTP requests to child resources:

  @Rest( path="/*", title="Root resources", description="Example of a router resource page.", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, ThemeMenuItem.class }, navlinks={ "options: ?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{ThemeMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This is an example of a 'router' page that serves as a jumping-off point to child resources.</p>", " <p>Resources can be nested arbitrarily deep through router pages.</p>", " <p>Note the <span class='link'>options</span> link provided that lets you see the generated swagger doc for this page.</p>", " <p>Also note the <span class='link'>sources</span> link on these pages to view the source code for the page.</p>", " <p>All content on pages in the UI are serialized POJOs. In this case, it's a serialized array of beans with 2 properties, 'name' and 'description'.</p>", " <p>Other features (such as this aside) are added through annotations.</p>", "</div>" } ), children={ HelloWorldResource.class, PetStoreResource.class, DtoExamples.class, ConfigResource.class, LogsResource.class, ShutdownResource.class } ) @SerializerConfig( // For testing purposes, we want to use single quotes in all the serializers so it's easier to do simple // String comparisons. quoteChar="'" ) public class RootResources extends BasicRestServletJenaGroup { // No code }

- juneau-examples-rest-jetty.cfg - The external configuration file.
  Contains various useful settings.
  Can be used for your own resource configurations.

  #======================================================================================================================= # Basic configuration file for REST microservices # Subprojects can use this as a starting point. #======================================================================================================================= #======================================================================================================================= # Jetty settings #======================================================================================================================= [Jetty] # Path of the jetty.xml file used to configure the Jetty server. config = jetty.xml # Resolve Juneau variables in the jetty.xml file. resolveVars = true # Port to use for the jetty server. # You can specify multiple ports. The first available will be used. '0' indicates to try a random port. # The resulting available port gets set as the system property "availablePort" which can be referenced in the # jetty.xml file as "$S{availablePort}" (assuming resolveVars is enabled). port = 10000,0,0,0 # Optionally specify your servlets here: #servlets = org.apache.juneau.microservice.sample.RootResources #======================================================================================================================= # REST settings #======================================================================================================================= [REST] # Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @Rest-annotated # classes. These are static files that are served up by the servlet under the specified sub-paths. # For example, given the following setting... # staticFiles = htdocs:my-docs,styles/my-styles # ...the URI "/servletPath/htdocs/javadoc.css" resolves to the path "/my-docs/javadoc.css". # This path can be relative to the working directory, classpath root, or package of your resource class. # Used by the BasicRestConfig interface that defines the following value: # staticFiles="$C{REST/staticFiles}" staticFiles = htdocs:htdocs # Stylesheet to use for HTML views. # Used by the BasicRestConfig interface that defines the following value: # stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}" theme = servlet:/htdocs/themes/devops.css # Various look-and-feel settings used in the BasicRestConfig interface. headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a> #======================================================================================================================= # Console settings #======================================================================================================================= [Console] enabled = true # List of available console commands. # These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via # the console. # When listed here, the implementations must provide a no-arg constructor. # They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method. commands = org.apache.juneau.microservice.console.ExitCommand, org.apache.juneau.microservice.console.RestartCommand, org.apache.juneau.microservice.console.HelpCommand, org.apache.juneau.microservice.console.ConfigCommand #======================================================================================================================= # Logger settings #----------------------------------------------------------------------------------------------------------------------- # See FileHandler Java class for details. #======================================================================================================================= [Logging] ... #======================================================================================================================= # System properties #----------------------------------------------------------------------------------------------------------------------- # These are arbitrary system properties that are set during startup. #======================================================================================================================= [SystemProperties] # Configure Jetty for StdErrLog Logging # org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog # Configure Jetty to log using java-util logging org.eclipse.jetty.util.log.class = org.apache.juneau.microservice.jetty.JettyLogger # Jetty logging level # Possible values: ALL, DEBUG, INFO, WARN, OFF org.eclipse.jetty.LEVEL = WARN derby.stream.error.file = $C{Logging/logDir}/derby-errors.log

- jetty.xml - The Jetty configuration file.
  A bare-bones config file that can be extended to use any Jetty features.

  <Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> <Set name="connectors"> <Array type="org.eclipse.jetty.server.Connector"> <Item> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg> <Ref refid="ExampleServer"/> </Arg> <Set name="port">$S{availablePort,8080}</Set> </New> </Item> </Array> </Set> <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> <Set name="contextPath">/</Set> <!-- Optionally specify your servlets here --> <!--Call name="addServlet"> <Arg>org.apache.juneau.microservice.sample.RootResources</Arg> <Arg>/*</Arg> </Call--> <Set name="sessionHandler"> <New class="org.eclipse.jetty.server.session.SessionHandler"/> </Set> </New> <Set name="handler"> <New class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <Ref refid="context"/> </Item> <Item> <New class="org.eclipse.jetty.server.handler.DefaultHandler"/> </Item> </Array> </Set> </New> </Set> <Set name="requestLog"> <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog"> <Set name="filename"><Property name="jetty.logs" default="$C{Logging/logDir,logs}"/>/jetty-requests.log</Set> <Set name="filenameDateFormat">yyyy_MM_dd</Set> <Set name="LogTimeZone">GMT</Set> <Set name="retainDays">90</Set> <Set name="append">false</Set> <Set name="LogLatency">true</Set> </New> </Set> <Get name="ThreadPool"> <Set name="minThreads" type="int">10</Set> <Set name="maxThreads" type="int">100</Set> <Set name="idleTimeout" type="int">60000</Set> <Set name="detailedDump">true</Set> </Get> </Configure>

At this point, you're ready to start the microservice from your workspace.

### 17.2 - Running in Eclipse 8.0.0-new,8.1.2-deprecated

The juneau-examples-rest-jetty.launch file is already provided to allow you to quickly start your new microservice.

Go to Run -> Run Configurations -> Java Application -> juneau-examples-rest-jetty and click Run. In your console view, you should see the following output:

Running class 'JettyMicroservice' using config file 'juneau-examples-rest-jetty.cfg'. Server started on port 10000 List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help >

Now open your browser and point to http://localhost:10000. You should see the following:

http://localhost:10000

You can enter the command exit to shut it down.

### 17.3 - Building and Running from Command-Line 8.0.0-new,8.1.2-deprecated

The pom.xml file is a basic Maven build script for creating the examples microservice as an executable uber-jar.

The easiest way to build the microservice is to run the following from the project root.

mvn clean install

Your target directory should now contain the following files:

- juneau-examples-rest-jetty-1.0.jar
- juneau-examples-rest-jetty.cfg

To start from a command line, run the following command from inside your target directory:

java -jar juneau-examples-rest-jetty-1.0.jar

You should see the following console output:

Running class 'JettyMicroservice' using config file 'juneau-examples-rest-jetty.cfg'. Server started on port 10000 List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help >

If you get this error message: `java.net.BindException: Address already in use`, then this microservice is already running elsewhere and so it cannot bind to port 10000.

## 18 - juneau-examples-rest-springboot 8.0.0-new

##### Starter Project Zip

juneau-examples-rest-springboot-{@property juneauVersion}.zip

The juneau-examples-rest-springboot library contains the same examples as juneau-examples-rest but also includes the following:

- A starter class for invoking the examples using Spring Boot.
- A resource resolver for resolving REST resources as injectable beans.
- A POM that extends from spring-boot-starter-parent that allows you to build a fully-shaded executable jar.
- Configuration files for deploying the microservice to Heroku.

### 18.1 - Installing in Eclipse 8.0.0-new

Follow these instructions to import the REST examples project using Spring Boot into Eclipse.

1. Download the juneau-examples-rest-springboot-{@property juneauVersion}.zip file from the downloads page (located in the binaries) and import it into your workspace as an existing project:
2. Select the archive file and import the project:
3. In your workspace, you should now see the following project:

The important elements in this project are:

- App.java - The entry point.
  This class creates and starts our microservice.
  Note that we're using the existing Spring Boot application logic for the microservice and we're retrieving our root resource as a spring bean.
  Only the top-level resource needs to be annotated with {@link org.apache.juneau.rest.springboot.annotation.JuneauRestRoot @JuneauRestRoot}

  @SpringBootApplication @Controller public class App { public static void main(String[] args) { new SpringApplicationBuilder(App.class) .initializers(new JuneauRestInitializer(App.class)) .run(args); } @Bean @JuneauRestRoot public RootResources getRootResources() { return new RootResources(); } }

- RootResources.java - The top-level REST resource.
  This class routes HTTP requests to child resources:

  @Rest( path="/*", title="Root resources", description="Example of a router resource page.", htmldoc=@HtmlDoc( widgets={ ContentTypeMenuItem.class, ThemeMenuItem.class }, navlinks={ "options: ?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{ThemeMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" }, aside={ "<div style='max-width:400px' class='text'>", " <p>This is an example of a 'router' page that serves as a jumping-off point to child resources.</p>", " <p>Resources can be nested arbitrarily deep through router pages.</p>", " <p>Note the <span class='link'>options</span> link provided that lets you see the generated swagger doc for this page.</p>", " <p>Also note the <span class='link'>sources</span> link on these pages to view the source code for the page.</p>", " <p>All content on pages in the UI are serialized POJOs. In this case, it's a serialized array of beans with 2 properties, 'name' and 'description'.</p>", " <p>Other features (such as this aside) are added through annotations.</p>", "</div>" } ), children={ HelloWorldResource.class, PetStoreResource.class, DtoExamples.class, ConfigResource.class, LogsResource.class, ShutdownResource.class } ) @SerializerConfig( // For testing purposes, we want to use single quotes in all the serializers so it's easier to do simple // String comparisons. quoteChar="'" ) public class RootResources extends BasicRestServletJenaGroup { // No code }

- juneau.cfg - The configuration file.
  Contains various useful settings.
  Can be used for your own resource configurations.
  Note that the Jetty configuration is not present.
  Also it's located in the classpath so that our microservice can be built as a single executable jar.

  #======================================================================================================================= # Basic configuration file for REST microservices # Subprojects can use this as a starting point. #======================================================================================================================= #======================================================================================================================= # REST settings #======================================================================================================================= [REST] # URL mappings to static files in the working directory or classpath. staticFiles = htdocs:files/htdocs # Stylesheet to use for HTML views. theme = servlet:/htdocs/themes/devops.css headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org favicon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'> <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> </a> footer = <a href='$U{$C{REST/footerLink}}'> <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> </a>

At this point, you're ready to start the microservice from your workspace.

### 18.2 - Running in Eclipse 8.0.0-new

The juneau-examples-rest-springboot.launch file is already provided to allow you to quickly start your new microservice.

Go to Run -> Run Configurations -> Java Application -> juneau-examples-rest-springboot and click Run. In your console view, you should see the following output:

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) ... INFO: Tomcat started on port(s): 8080 (http) with context path '' Dec 21, 2012 12:30:00 AM org.springframework.boot.StartupInfoLogger logStarted INFO: Started App in 1.999 seconds (JVM running for 2.999)

Now open your browser and point to http://localhost:5000. You should see the following:

http://localhost:5000

### 18.3 - Building and Running from Command-Line 8.0.0-new

The pom.xml file is a basic Maven build script for creating your microservice as an executable uber-jar.

The easiest way to build your microservice is to run the following from the project root.

mvn clean install

Your target directory should now contain the following files:

- juneau-examples-rest-springboot-1.0.jar

To start from a command line, run the following command from inside your target directory:

java -jar juneau-examples-rest-springboot-1.0.jar

You should see the following console output:

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) ... INFO: Tomcat started on port(s): 8080 (http) with context path '' Dec 21, 2012 12:30:00 AM org.springframework.boot.StartupInfoLogger logStarted INFO: Started App in 1.999 seconds (JVM running for 2.999)

### 18.4 - Deploying to Heroku 8.0.0-new

Heroku is a platform-as-a-service that allows applications to be quickly hosted in the cloud. The juneau-examples-rest-springboot project contains additional metadata files for quickly deploying and running the examples in Heroku using free services.

- app.json
  This class provides basic metadata information to Heroku about our application.

  { "name": "Start on Heroku: Juneau REST Examples", "description": "Deployable REST examples to Heroku." }

- Procfile
  This class tells Heroku how to deploy our application using the Web dyno.

  web: java -jar target/juneau-examples-rest-springboot-8.0.0-SNAPSHOT.jar

- settings.xml
  This is an optional Maven settings file that points to both the main Maven repo in addition to the Apache snapshots repo if you happen to be using a snapshot version of Juneau.

You'll need to sign up for an account on Heroku. Afterwards, you can go to the apps page to create a new application:

https://dashboard.heroku.com/apps

Click the New button to create a new app, give it a unique name:

https://dashboard.heroku.com/new-app

After clicking the Create app button, you should see this page:

https://dashboard.heroku.com/apps/juneau-examples-rest/deploy/heroku-git

For this example, we'll use the Heroku Git option for deploying our application. Follow the instructions for installing the Heroku CLI and logging into Heroku:

https://dashboard.heroku.com/apps/juneau-examples-rest/deploy/heroku-git

Next, run the following commands to cd into our Eclipse project and initialize it as a local git repo:

$ cd juneau-examples-rest-springboot/ $ git init

##### Output

$ cd juneau-examples-rest-springboot/ $ git init Initialized empty Git repository in /.../juneau-examples-rest-springboot/.git/

Next, run the following command to link our project to the Heroku app:

$ heroku git:remote -a juneau-examples-rest

##### Output

$ heroku git:remote -a juneau-examples-rest set git remote heroku to https://git.heroku.com/juneau-examples-rest.git

Next, run the following commands to add our files to the git repo and push to the Heroku master branch:

$ git add . $ git commit -am "Initial deploy" $ git push heroku master

##### Output

$ git add . master (root-commit) 7c94cb9] Initial deploy 123 files changed, 11986 insertions(+) Counting objects: 127, done. $ git commit -am "Initial deploy" $ git push heroku master Delta compression using up to 8 threads. Compressing objects: 100% (113/113), done. Writing objects: 100% (127/127), 363.91 KiB | 21.41 MiB/s, done. ... remote: -----> Compressing... remote: Done: 85.9M remote: -----> Launching... remote: Released v3 remote: https://juneau-examples-rest.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/juneau-examples-rest.git * [new branch] master -> master

If no errors were shown, then our application should now be live. You can click on the Open app button to open the examples application in a browser:

If everything worked, your browser should now be loaded with our example REST app:

https://juneau-examples-rest.herokuapp.com

## 19 - Glossaries 8.1.3-new

### 19.1 - Configurable Properties Glossary 8.1.3-new

The following is a list of all properties defined throughout Juneau:

Context | ID | Description | Data type
--- | --- | --- | ---
{@link org.apache.juneau.BeanContext} | {@link org.apache.juneau.BeanContext#BEAN_annotations BEAN_annotations} | Annotations. | List<{@link java.lang.annotation.Annotation}>
| {@link org.apache.juneau.BeanContext#BEAN_beanClassVisibility BEAN_beanClassVisibility} | Minimum bean class visibility. | {@link org.apache.juneau.Visibility}
| {@link org.apache.juneau.BeanContext#BEAN_beanConstructorVisibility BEAN_beanConstructorVisibility} | Minimum bean constructor visibility. | {@link org.apache.juneau.Visibility}
| {@link org.apache.juneau.BeanContext#BEAN_beanDictionary BEAN_beanDictionary} | Bean dictionary. | List<Class>
| {@link org.apache.juneau.BeanContext#BEAN_beanFieldVisibility BEAN_beanFieldVisibility} | Minimum bean field visibility. | {@link org.apache.juneau.Visibility}
| {@link org.apache.juneau.BeanContext#BEAN_beanFilters BEAN_beanFilters} | Bean filters. | List<Class>
| {@link org.apache.juneau.BeanContext#BEAN_beanMapPutReturnsOldValue BEAN_beanMapPutReturnsOldValue} | BeanMap.put() returns old property value. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_beanMethodVisibility BEAN_beanMethodVisibility} | Minimum bean method visibility. | {@link org.apache.juneau.Visibility}
| {@link org.apache.juneau.BeanContext#BEAN_beanTypePropertyName BEAN_beanTypePropertyName} | Bean type property name. | String
| {@link org.apache.juneau.BeanContext#BEAN_beansRequireDefaultConstructor BEAN_beansRequireDefaultConstructor} | Beans require no-arg constructors. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_beansRequireSerializable BEAN_beansRequireSerializable} | Beans require Serializable interface. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_beansRequireSettersForGetters BEAN_beansRequireSettersForGetters} | Beans require setters for getters. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_beansRequireSomeProperties BEAN_beansRequireSomeProperties} | Beans require at least one property. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_bpi BEAN_bpi} | Bean property includes. | Map<String,String>
| {@link org.apache.juneau.BeanContext#BEAN_bpro BEAN_bpro} | Read-only bean properties. | Map<String,String>
| {@link org.apache.juneau.BeanContext#BEAN_bpwo BEAN_bpwo} | Write-only bean properties. | Map<String,String>
| {@link org.apache.juneau.BeanContext#BEAN_bpx BEAN_bpx} | Bean property excludes. | Map<String,String>
| {@link org.apache.juneau.BeanContext#BEAN_debug BEAN_debug} | Debug mode. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_examples BEAN_examples} | POJO examples. | Map<String,Object>
| {@link org.apache.juneau.BeanContext#BEAN_fluentSetters BEAN_fluentSetters} | Find fluent setters. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_ignoreInvocationExceptionsOnGetters BEAN_ignoreInvocationExceptionsOnGetters} | Ignore invocation errors on getters. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_ignoreInvocationExceptionsOnSetters BEAN_ignoreInvocationExceptionsOnSetters} | Ignore invocation errors on setters. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_ignorePropertiesWithoutSetters BEAN_ignorePropertiesWithoutSetters} | Ignore properties without setters. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_ignoreUnknownBeanProperties BEAN_ignoreUnknownBeanProperties} | Ignore unknown properties. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_ignoreUnknownNullBeanProperties BEAN_ignoreUnknownNullBeanProperties} | Ignore unknown properties with null values. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_implClasses BEAN_implClasses} | Implementation classes. | Map<String,Class>
| {@link org.apache.juneau.BeanContext#BEAN_locale BEAN_locale} | Locale. | {@link java.util.Locale}
| {@link org.apache.juneau.BeanContext#BEAN_mediaType BEAN_mediaType} | Media type. | {@link org.apache.juneau.http.MediaType}
| {@link org.apache.juneau.BeanContext#BEAN_notBeanClasses BEAN_notBeanClasses} | Bean class exclusions. | Set<Class>
| {@link org.apache.juneau.BeanContext#BEAN_notBeanPackages BEAN_notBeanPackages} | Bean package exclusions. | Set<String>
| {@link org.apache.juneau.BeanContext#BEAN_pojoSwaps BEAN_pojoSwaps} | POJO swaps. | List<Object>
| {@link org.apache.juneau.BeanContext#BEAN_propertyNamer BEAN_propertyNamer} | Bean property namer. | `Class<{@link org.apache.juneau.PropertyNamer}>`
| {@link org.apache.juneau.BeanContext#BEAN_sortProperties BEAN_sortProperties} | Sort bean properties. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_timeZone BEAN_timeZone} | Time zone. | {@link java.util.TimeZone}
| {@link org.apache.juneau.BeanContext#BEAN_useEnumNames BEAN_useEnumNames} | Use enum names. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_useInterfaceProxies BEAN_useInterfaceProxies} | Use interface proxies. | boolean
| {@link org.apache.juneau.BeanContext#BEAN_useJavaBeanIntrospector BEAN_useJavaBeanIntrospector} | Use Java Introspector. | boolean
{@link org.apache.juneau.BeanTraverseContext} | {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_detectRecursions BEANTRAVERSE_detectRecursions} | Automatically detect POJO recursions. | boolean
| {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_ignoreRecursions BEANTRAVERSE_ignoreRecursions} | Ignore recursion errors. | boolean
| {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_initialDepth BEANTRAVERSE_initialDepth} | Initial depth. | int
| {@link org.apache.juneau.BeanTraverseContext#BEANTRAVERSE_maxDepth BEANTRAVERSE_maxDepth} | Max traversal depth. | int
{@link org.apache.juneau.config.Config} | {@link org.apache.juneau.config.Config#CONFIG_binaryFormat CONFIG_binaryFormat} | Binary value format. | {@link org.apache.juneau.BinaryFormat}
| {@link org.apache.juneau.config.Config#CONFIG_binaryLineLength CONFIG_binaryLineLength} | Binary value line length. | int
| {@link org.apache.juneau.config.Config#CONFIG_encoder CONFIG_encoder} | Value encoder. | {@link org.apache.juneau.config.encode.ConfigEncoder}
| {@link org.apache.juneau.config.Config#CONFIG_multiLineValuesOnSeparateLines CONFIG_multiLineValuesOnSeparateLines} | Multi-line values should always be on separate lines. | boolean
| {@link org.apache.juneau.config.Config#CONFIG_name CONFIG_name} | Configuration name. | String
| {@link org.apache.juneau.config.Config#CONFIG_parser CONFIG_parser} | POJO parser. | {@link org.apache.juneau.parser.ReaderParser}
| {@link org.apache.juneau.config.Config#CONFIG_readOnly CONFIG_readOnly} | Read-only. | boolean
| {@link org.apache.juneau.config.Config#CONFIG_serializer CONFIG_serializer} | POJO serializer. | {@link org.apache.juneau.serializer.WriterSerializer}
| {@link org.apache.juneau.config.Config#CONFIG_store CONFIG_store} | Configuration store. | {@link org.apache.juneau.config.store.ConfigStore}
| {@link org.apache.juneau.config.Config#CONFIG_varResolver CONFIG_varResolver} | SVL variable resolver. | {@link org.apache.juneau.svl.VarResolver}
{@link org.apache.juneau.config.store.ConfigFileStore} | {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_charset FILESTORE_charset} | Charset. | {@link java.nio.charset.Charset}
| {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_directory FILESTORE_directory} | Local file system directory. | String
| {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_extensions FILESTORE_extensions} | File extensions. | String (comma-delimited)
| {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_updateOnWrite FILESTORE_updateOnWrite} | Update-on-write. | boolean
| {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_useWatcher FILESTORE_useWatcher} | Use watcher. | boolean
| {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_watcherSensitivity FILESTORE_watcherSensitivity} | Watcher sensitivity. | {@link org.apache.juneau.config.store.WatcherSensitivity}
{@link org.apache.juneau.html.HtmlDocSerializer} | {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_aside HTMLDOC_aside} | Aside section contents. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_footer HTMLDOC_footer} | Footer section contents. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_head HTMLDOC_head} | Additional head section content. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_header HTMLDOC_header} | Header section contents. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_nav HTMLDOC_nav} | Nav section contents. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_navlinks HTMLDOC_navlinks} | Page navigation links. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_noResultsMessage HTMLDOC_noResultsMessage} | No-results message. | String
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_nowrap HTMLDOC_nowrap} | Prevent word wrap on page. | boolean
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_script HTMLDOC_script} | Javascript code. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_style HTMLDOC_style} | CSS style code. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_stylesheet HTMLDOC_stylesheet} | Stylesheet import URLs. | List<String>
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_template HTMLDOC_template} | HTML document template. | `Class<{@link org.apache.juneau.html.HtmlDocTemplate}>`
| {@link org.apache.juneau.html.HtmlDocSerializer#HTMLDOC_widgets HTMLDOC_widgets} | HTML Widgets. | List<{@link org.apache.juneau.html.HtmlWidget}|Class<{@link org.apache.juneau.html.HtmlWidget}>>
{@link org.apache.juneau.html.HtmlSerializer} | {@link org.apache.juneau.html.HtmlSerializer#HTML_addBeanTypes HTML_addBeanTypes} | Add "_type" properties when needed. | boolean
| {@link org.apache.juneau.html.HtmlSerializer#HTML_addKeyValueTableHeaders HTML_addKeyValueTableHeaders} | Add key/value headers on bean/map tables. | boolean
| {@link org.apache.juneau.html.HtmlSerializer#HTML_detectLabelParameters HTML_detectLabelParameters} | Look for link labels in URIs. | boolean
| {@link org.apache.juneau.html.HtmlSerializer#HTML_detectLinksInStrings HTML_detectLinksInStrings} | Look for URLs in {@link java.lang.String Strings}. | boolean
| {@link org.apache.juneau.html.HtmlSerializer#HTML_labelParameter HTML_labelParameter} | Link label parameter name. | String
| {@link org.apache.juneau.html.HtmlSerializer#HTML_uriAnchorText HTML_uriAnchorText} | Anchor text source. | {@link org.apache.juneau.html.AnchorText}
{@link org.apache.juneau.parser.InputStreamParser} | {@link org.apache.juneau.parser.InputStreamParser#ISPARSER_binaryFormat ISPARSER_binaryFormat} | Binary input format. | {@link org.apache.juneau.BinaryFormat}
{@link org.apache.juneau.json.JsonParser} | {@link org.apache.juneau.json.JsonParser#JSON_validateEnd JSON_validateEnd} | Validate end. | boolean
{@link org.apache.juneau.jsonschema.JsonSchemaGenerator} | {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_addDescriptionsTo JSONSCHEMA_addDescriptionsTo} | Add descriptions to types. | String
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_addExamplesTo JSONSCHEMA_addExamplesTo} | Add examples. | String
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_allowNestedDescriptions JSONSCHEMA_allowNestedDescriptions} | Allow nested descriptions. | boolean
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_allowNestedExamples JSONSCHEMA_allowNestedExamples} | Allow nested examples. | boolean
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_beanDefMapper JSONSCHEMA_beanDefMapper} | Bean schema definition mapper. | {@link org.apache.juneau.jsonschema.BeanDefMapper}
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_defaultSchemas JSONSCHEMA_defaultSchemas} | Default schemas. | Map<String,{@link org.apache.juneau.ObjectMap}>
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_ignoreTypes JSONSCHEMA_ignoreTypes} | Ignore types from schema definitions. | String (comma-delimited)
| {@link org.apache.juneau.jsonschema.JsonSchemaGenerator#JSONSCHEMA_useBeanDefs JSONSCHEMA_useBeanDefs} | Use bean definitions. | boolean
{@link org.apache.juneau.json.JsonSerializer} | {@link org.apache.juneau.json.JsonSerializer#JSON_addBeanTypes JSON_addBeanTypes} | Add "_type" properties when needed. | boolean
| {@link org.apache.juneau.json.JsonSerializer#JSON_escapeSolidus JSON_escapeSolidus} | Prefix solidus '/' characters with escapes. | boolean
| {@link org.apache.juneau.json.JsonSerializer#JSON_simpleMode JSON_simpleMode} | Simple JSON mode. | boolean
{@link org.apache.juneau.msgpack.MsgPackSerializer} | {@link org.apache.juneau.msgpack.MsgPackSerializer#MSGPACK_addBeanTypes MSGPACK_addBeanTypes} | Add "_type" properties when needed. | boolean
{@link org.apache.juneau.serializer.OutputStreamSerializer} | {@link org.apache.juneau.serializer.OutputStreamSerializer#OSSERIALIZER_binaryFormat OSSERIALIZER_binaryFormat} | Binary output format. | {@link org.apache.juneau.BinaryFormat}
{@link org.apache.juneau.parser.Parser} | {@link org.apache.juneau.parser.Parser#PARSER_autoCloseStreams PARSER_autoCloseStreams} | Auto-close streams. | boolean
| {@link org.apache.juneau.parser.Parser#PARSER_debugOutputLines PARSER_debugOutputLines} | Debug output lines. | int
| {@link org.apache.juneau.parser.Parser#PARSER_listener PARSER_listener} | Parser listener. | Class<{@link org.apache.juneau.parser.ParserListener}>
| {@link org.apache.juneau.parser.Parser#PARSER_strict PARSER_strict} | Strict mode. | boolean
| {@link org.apache.juneau.parser.Parser#PARSER_trimStrings PARSER_trimStrings} | Trim parsed strings. | boolean
| {@link org.apache.juneau.parser.Parser#PARSER_unbuffered PARSER_unbuffered} | Unbuffered. | boolean
{@link org.apache.juneau.jena.RdfCommon} | {@link org.apache.juneau.jena.RdfCommon#RDF_collectionFormat RDF_collectionFormat} | RDF format for representing collections and arrays. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_abbrevBaseUri RDF_n3_abbrevBaseUri} | N3/Turtle property: abbrevBaseURI. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_indentProperty RDF_n3_indentProperty} | N3/Turtle property: indentProperty. | int
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_minGap RDF_n3_minGap} | N3/Turtle property: minGap. | int
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_objectLists RDF_n3_objectLists} | N3/Turtle property: objectLists. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_propertyColumn RDF_n3_propertyColumn} | N3/Turtle property: propertyColumn. | int
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_subjectColumn RDF_n3_subjectColumn} | N3/Turtle property: subjectColumn. | int
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_useDoubles RDF_n3_useDoubles} | N3/Turtle property: useDoubles. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_usePropertySymbols RDF_n3_usePropertySymbols} | N3/Turtle property: usePropertySymbols. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_useTripleQuotedStrings RDF_n3_useTripleQuotedStrings} | N3/Turtle property: useTripleQuotedStrings. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_n3_widePropertyLen RDF_n3_widePropertyLen} | N3/Turtle property: widePropertyLen. | int
| {@link org.apache.juneau.jena.RdfCommon#RDF_arp_err_ RDF_arp_err_} | RDF/XML ARP property: ERR_xxx. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_arp_ign_ RDF_arp_ign_} |  | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_arp_warn_ RDF_arp_warn_} | RDF/XML ARP property: WARN_xxx. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_allowBadUris RDF_rdfxml_allowBadUris} | RDF/XML property: allowBadURIs. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_attributeQuoteChar RDF_rdfxml_attributeQuoteChar} | RDF/XML property: attributeQuoteChar. | Character
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_blockRules RDF_rdfxml_blockRules} | RDF/XML property: blockRules. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_arp_embedding RDF_arp_embedding} | RDF/XML ARP property: embedding. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_arp_errorMode RDF_arp_errorMode} | RDF/XML ARP property: error-mode. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_arp_iriRules RDF_arp_iriRules} | RDF/XML property: iri_rules. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_longId RDF_rdfxml_longId} | RDF/XML property: longId. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_relativeUris RDF_rdfxml_relativeUris} | RDF/XML property: relativeURIs. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_showDoctypeDeclaration RDF_rdfxml_showDoctypeDeclaration} | RDF/XML property: showDoctypeDeclaration. | boolean
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_showXmlDeclaration RDF_rdfxml_showXmlDeclaration} | RDF/XML property: showXmlDeclaration. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_tab RDF_rdfxml_tab} | RDF/XML property: tab. | int
| {@link org.apache.juneau.jena.RdfCommon#RDF_rdfxml_xmlBase RDF_rdfxml_xmlBase} | RDF/XML property: xmlbase. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_juneauBpNs RDF_juneauBpNs} | Default XML namespace for bean properties. | {@link org.apache.juneau.xml.Namespace}
| {@link org.apache.juneau.jena.RdfCommon#RDF_juneauNs RDF_juneauNs} | XML namespace for Juneau properties. | {@link org.apache.juneau.xml.Namespace}
| {@link org.apache.juneau.jena.RdfCommon#RDF_language RDF_language} | RDF language. | String
| {@link org.apache.juneau.jena.RdfCommon#RDF_looseCollections RDF_looseCollections} | Collections should be serialized and parsed as loose collections. | boolean
{@link org.apache.juneau.jena.RdfParser} | {@link org.apache.juneau.jena.RdfParser#RDF_trimWhitespace RDF_trimWhitespace} | Trim whitespace from text elements. | boolean
{@link org.apache.juneau.jena.RdfSerializer} | {@link org.apache.juneau.jena.RdfSerializer#RDF_useXmlNamespaces RDF_useXmlNamespaces} | Reuse XML namespaces when RDF namespaces not specified. | boolean
| {@link org.apache.juneau.jena.RdfSerializer#RDF_addBeanTypes RDF_addBeanTypes} | Add "_type" properties when needed. | boolean
| {@link org.apache.juneau.jena.RdfSerializer#RDF_addLiteralTypes RDF_addLiteralTypes} | Add XSI data types to non-String literals. | boolean
| {@link org.apache.juneau.jena.RdfSerializer#RDF_addRootProperty RDF_addRootProperty} | Add RDF root identifier property to root node. | boolean
| {@link org.apache.juneau.jena.RdfSerializer#RDF_autoDetectNamespaces RDF_autoDetectNamespaces} | Auto-detect namespace usage. | boolean
| {@link org.apache.juneau.jena.RdfSerializer#RDF_namespaces RDF_namespaces} | Default namespaces. | List<{@link org.apache.juneau.xml.Namespace}>
{@link org.apache.juneau.parser.ReaderParser} | {@link org.apache.juneau.parser.ReaderParser#RPARSER_fileCharset RPARSER_fileCharset} | File charset. | String
| {@link org.apache.juneau.parser.ReaderParser#RPARSER_streamCharset RPARSER_streamCharset} | Input stream charset. | String
{@link org.apache.juneau.rest.client.RestClient} | {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_debug RESTCLIENT_debug} | Debug. | boolean
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_executorService RESTCLIENT_executorService} | Executor service. | Class<{@link java.util.concurrent.ExecutorService}> {@link java.util.concurrent.ExecutorService}
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_executorServiceShutdownOnClose RESTCLIENT_executorServiceShutdownOnClose} | Shut down executor service on close. | boolean
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_interceptors RESTCLIENT_interceptors} | Call interceptors. | List<Class<{@link org.apache.juneau.rest.client.RestCallInterceptor}>|{@link org.apache.juneau.rest.client.RestCallInterceptor}>
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_keepHttpClientOpen RESTCLIENT_keepHttpClientOpen} | Keep HttpClient open. | boolean
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_parser RESTCLIENT_parser} | Parser. | Class<{@link org.apache.juneau.parser.Parser}> {@link org.apache.juneau.parser.Parser}
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_partParser RESTCLIENT_partParser} | Part parser. | Class<{@link org.apache.juneau.httppart.HttpPartParser}> {@link org.apache.juneau.httppart.HttpPartParser}
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_partSerializer RESTCLIENT_partSerializer} | Part serializer. | Class<{@link org.apache.juneau.httppart.HttpPartSerializer}> {@link org.apache.juneau.httppart.HttpPartSerializer}
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_query RESTCLIENT_query} | Request query parameters. | Map<String,String>
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_headers RESTCLIENT_headers} | Request headers. | Map<String,String>
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_retries RESTCLIENT_retries} | Number of retries to attempt. | int
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_retryInterval RESTCLIENT_retryInterval} | The time in milliseconds between retry attempts. | int
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_retryOn RESTCLIENT_retryOn} | Retry-on determination object. | Class<{@link org.apache.juneau.rest.client.RetryOn}> {@link org.apache.juneau.rest.client.RetryOn}
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_rootUri RESTCLIENT_rootUri} | Root URI. | String
| {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_serializer RESTCLIENT_serializer} | Serializer. | Class<{@link org.apache.juneau.serializer.Serializer}> {@link org.apache.juneau.serializer.Serializer}
{@link org.apache.juneau.rest.RestContext} | {@link org.apache.juneau.rest.RestContext#REST_allowBodyParam REST_allowBodyParam} | Allow body URL parameter. | boolean
| {@link org.apache.juneau.rest.RestContext#REST_allowedHeaderParams REST_allowedHeaderParams} | Allowed header URL parameters. | String (comma-delimited)
| {@link org.apache.juneau.rest.RestContext#REST_allowedMethodHeaders REST_allowedMethodHeaders} | Allowed method headers. | String (comma-delimited)
| {@link org.apache.juneau.rest.RestContext#REST_allowedMethodParams REST_allowedMethodParams} | Allowed method URL parameters. | String (comma-delimited)
| {@link org.apache.juneau.rest.RestContext#REST_callHandler REST_callHandler} | REST call handler. | {@link org.apache.juneau.rest.RestCallHandler} Class<{@link org.apache.juneau.rest.RestCallHandler}>
| {@link org.apache.juneau.rest.RestContext#REST_callLogger REST_callLogger} | REST call logger. | {@link org.apache.juneau.rest.RestCallLogger} Class<{@link org.apache.juneau.rest.RestCallLogger}>
| {@link org.apache.juneau.rest.RestContext#REST_callLoggerConfig REST_callLoggerConfig} | REST call logging rules. | {@link org.apache.juneau.rest.RestCallLoggerConfig}
| {@link org.apache.juneau.rest.RestContext#REST_children REST_children} | Children. | List<Class|Object|{@link org.apache.juneau.rest.RestChild}>
| {@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder REST_classpathResourceFinder} | Classpath resource finder. | {@link org.apache.juneau.utils.ClasspathResourceFinder}
| {@link org.apache.juneau.rest.RestContext#REST_clientVersionHeader REST_clientVersionHeader} | Client version header. | String
| {@link org.apache.juneau.rest.RestContext#REST_consumes REST_consumes} | Supported content media types. | List<String>
| {@link org.apache.juneau.rest.RestContext#REST_converters REST_converters} | Class-level response converters. | List<{@link org.apache.juneau.rest.RestConverter}|Class<{@link org.apache.juneau.rest.RestConverter}>>
| {@link org.apache.juneau.rest.RestContext#REST_debug REST_debug} | Debug mode. | {@link org.apache.juneau.rest.Enablement}
| {@link org.apache.juneau.rest.RestContext#REST_defaultCharset REST_defaultCharset} | Default character encoding. | String
| {@link org.apache.juneau.rest.RestContext#REST_encoders REST_encoders} | Compression encoders. | List<{@link org.apache.juneau.encoders.Encoder}|Class<{@link org.apache.juneau.encoders.Encoder}>>
| {@link org.apache.juneau.rest.RestContext#REST_guards REST_guards} | Class-level guards. | List<{@link org.apache.juneau.rest.RestGuard}|Class<{@link org.apache.juneau.rest.RestGuard}>>
| {@link org.apache.juneau.rest.RestContext#REST_infoProvider REST_infoProvider} | REST info provider. | {@link org.apache.juneau.rest.RestInfoProvider} Class<{@link org.apache.juneau.rest.RestInfoProvider}>
| {@link org.apache.juneau.rest.RestContext#REST_maxInput REST_maxInput} | The maximum allowed input size (in bytes) on HTTP requests. | String
| {@link org.apache.juneau.rest.RestContext#REST_messages REST_messages} | Messages. | List<{@link org.apache.juneau.rest.MessageBundleLocation}>
| {@link org.apache.juneau.rest.RestContext#REST_mimeTypes REST_mimeTypes} | MIME types. | Set<String>
| {@link org.apache.juneau.rest.RestContext#REST_paramResolvers REST_paramResolvers} | Java method parameter resolvers. | List<{@link org.apache.juneau.rest.RestMethodParam}|Class<{@link org.apache.juneau.rest.RestMethodParam}>>
| {@link org.apache.juneau.rest.RestContext#REST_parsers REST_parsers} | Parsers. | List<{@link org.apache.juneau.parser.Parser}|Class<{@link org.apache.juneau.parser.Parser}>>
| {@link org.apache.juneau.rest.RestContext#REST_partParser REST_partParser} | HTTP part parser. | {@link org.apache.juneau.httppart.HttpPartParser}|Class<{@link org.apache.juneau.httppart.HttpPartParser}>
| {@link org.apache.juneau.rest.RestContext#REST_partSerializer REST_partSerializer} | HTTP part serializer. | {@link org.apache.juneau.httppart.HttpPartSerializer} Class<{@link org.apache.juneau.httppart.HttpPartSerializer}>
| {@link org.apache.juneau.rest.RestContext#REST_path REST_path} | Resource path. | String
| {@link org.apache.juneau.rest.RestContext#REST_produces REST_produces} | Supported accept media types. | List<String>
| {@link org.apache.juneau.rest.RestContext#REST_properties REST_properties} | Properties. | Map<String,String>
| {@link org.apache.juneau.rest.RestContext#REST_renderResponseStackTraces REST_renderResponseStackTraces} | Render response stack traces in responses. | boolean
| {@link org.apache.juneau.rest.RestContext#REST_reqAttrs REST_reqAttrs} | Default request attributes. | Map<String,Object>
| {@link org.apache.juneau.rest.RestContext#REST_reqHeaders REST_reqHeaders} | Default request headers. | Map<String,String>
| {@link org.apache.juneau.rest.RestContext#REST_resHeaders REST_resHeaders} | Default response headers. | Map<String,String>
| {@link org.apache.juneau.rest.RestContext#REST_resourceResolver REST_resourceResolver} | REST resource resolver. | {@link org.apache.juneau.rest.RestResourceResolver} Class<{@link org.apache.juneau.rest.RestResourceResolver}>
| {@link org.apache.juneau.rest.RestContext#REST_responseHandlers REST_responseHandlers} | Response handlers. | List<{@link org.apache.juneau.rest.ResponseHandler}|Class<{@link org.apache.juneau.rest.ResponseHandler}>>
| {@link org.apache.juneau.rest.RestContext#REST_roleGuard REST_roleGuard} | Role guard. | Set<String>
| {@link org.apache.juneau.rest.RestContext#REST_rolesDeclared REST_rolesDeclared} | Declared roles. | Set<String>
| {@link org.apache.juneau.rest.RestContext#REST_serializers REST_serializers} | Serializers. | List<{@link org.apache.juneau.serializer.Serializer}|Class<{@link org.apache.juneau.serializer.Serializer}>>
| {@link org.apache.juneau.rest.RestContext#REST_staticFileResponseHeaders REST_staticFileResponseHeaders} | Static file response headers. | Map<String,String>
| {@link org.apache.juneau.rest.RestContext#REST_staticFiles REST_staticFiles} | Static file mappings. | List<{@link org.apache.juneau.rest.StaticFileMapping}>
| {@link org.apache.juneau.rest.RestContext#REST_uriAuthority REST_uriAuthority} | Resource URI authority path. | String
| {@link org.apache.juneau.rest.RestContext#REST_uriContext REST_uriContext} | Resource URI context path. | String
| {@link org.apache.juneau.rest.RestContext#REST_uriRelativity REST_uriRelativity} | URI resolution relativity. | String
| {@link org.apache.juneau.rest.RestContext#REST_uriResolution REST_uriResolution} | URI resolution. | String
| {@link org.apache.juneau.rest.RestContext#REST_useClasspathResourceCaching REST_useClasspathResourceCaching} | Use classpath resource caching. | boolean
{@link org.apache.juneau.rest.RestMethodContext} | {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_callLoggerConfig RESTMETHOD_callLoggerConfig} | Logging rules. | {@link org.apache.juneau.rest.RestCallLoggerConfig}
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_clientVersion RESTMETHOD_clientVersion} | Client version pattern matcher. | String
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_debug RESTMETHOD_debug} | Debug mode. | {@link org.apache.juneau.rest.Enablement}
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_defaultFormData RESTMETHOD_defaultFormData} | Default form data. | Map<String,Object>
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_defaultQuery RESTMETHOD_defaultQuery} | Default query parameters. | Map<String,Object>
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_httpMethod RESTMETHOD_httpMethod} | HTTP method name. | String
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_matchers RESTMETHOD_matchers} | Method-level matchers. | List<{@link org.apache.juneau.rest.RestMatcher}|Class<{@link org.apache.juneau.rest.RestMatcher}>>
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_path RESTMETHOD_path} | Resource method path. | String
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_priority RESTMETHOD_priority} | Priority. | int
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_reqAttrs RESTMETHOD_reqAttrs} | Default request attributes. | Map<String,Object>
| {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_reqHeaders RESTMETHOD_reqHeaders} | Default request headers. | Map<String,Object>
{@link org.apache.juneau.serializer.Serializer} | {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addBeanTypes SERIALIZER_addBeanTypes} | Add "_type" properties when needed. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addRootType SERIALIZER_addRootType} | Add type attribute to root nodes. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_listener SERIALIZER_listener} | Serializer listener. | Class<{@link org.apache.juneau.serializer.SerializerListener}>
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_sortCollections SERIALIZER_sortCollections} | Sort arrays and collections alphabetically. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_sortMaps SERIALIZER_sortMaps} | Sort maps alphabetically. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimEmptyCollections SERIALIZER_trimEmptyCollections} | Trim empty lists and arrays. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimEmptyMaps SERIALIZER_trimEmptyMaps} | Trim empty maps. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimNullProperties SERIALIZER_trimNullProperties} | Trim null bean property values. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_trimStrings SERIALIZER_trimStrings} | Trim strings. | boolean
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriContext SERIALIZER_uriContext} | URI context bean. | {@link org.apache.juneau.UriContext}
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriRelativity SERIALIZER_uriRelativity} | URI relativity. | {@link org.apache.juneau.UriRelativity}
| {@link org.apache.juneau.serializer.Serializer#SERIALIZER_uriResolution SERIALIZER_uriResolution} | URI resolution. | {@link org.apache.juneau.UriResolution}
{@link org.apache.juneau.soap.SoapXmlSerializer} | {@link org.apache.juneau.soap.SoapXmlSerializer#SOAPXML_SOAPAction SOAPXML_SOAPAction} | The SOAPAction HTTP header value to set on responses. | String
{@link org.apache.juneau.dto.swagger.ui.SwaggerUI} | {@link org.apache.juneau.dto.swagger.ui.SwaggerUI#SWAGGERUI_resolveRefsMaxDepth SWAGGERUI_resolveRefsMaxDepth} | Resolve $ref references in schema up to the specified depth. | int
{@link org.apache.juneau.uon.UonParser} | {@link org.apache.juneau.uon.UonParser#UON_decoding UON_decoding} | Decode "%xx" sequences. | boolean
| {@link org.apache.juneau.uon.UonParser#UON_validateEnd UON_validateEnd} | Validate end. | boolean
{@link org.apache.juneau.uon.UonSerializer} | {@link org.apache.juneau.uon.UonSerializer#UON_addBeanTypes UON_addBeanTypes} | Add "_type" properties when needed. | boolean
| {@link org.apache.juneau.uon.UonSerializer#UON_encoding UON_encoding} | Encode non-valid URI characters. | boolean
| {@link org.apache.juneau.uon.UonSerializer#UON_paramFormat UON_paramFormat} | Format to use for query/form-data/header values. | {@link org.apache.juneau.uon.ParamFormat}
{@link org.apache.juneau.urlencoding.UrlEncodingParser} | {@link org.apache.juneau.urlencoding.UrlEncodingParser#URLENC_expandedParams URLENC_expandedParams} | Parser bean property collections/arrays as separate key/value pairs. | boolean
{@link org.apache.juneau.urlencoding.UrlEncodingSerializer} | {@link org.apache.juneau.urlencoding.UrlEncodingSerializer#URLENC_expandedParams URLENC_expandedParams} | Serialize bean property collections/arrays as separate key/value pairs. | boolean
{@link org.apache.juneau.serializer.WriterSerializer} | {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_fileCharset WSERIALIZER_fileCharset} | File charset. | String
| {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_maxIndent WSERIALIZER_maxIndent} | Maximum indentation. | int
| {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_quoteChar WSERIALIZER_quoteChar} | Quote character. | String
| {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_streamCharset WSERIALIZER_streamCharset} | Output stream charset. | String
| {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_useWhitespace WSERIALIZER_useWhitespace} | Use whitespace. | boolean
{@link org.apache.juneau.xml.XmlParser} | {@link org.apache.juneau.xml.XmlParser#XML_eventAllocator XML_eventAllocator} | XML event allocator. | `Class<{@link javax.xml.stream.util.XMLEventAllocator}>`
| {@link org.apache.juneau.xml.XmlParser#XML_preserveRootElement XML_preserveRootElement} | Preserve root element during generalized parsing. | boolean
| {@link org.apache.juneau.xml.XmlParser#XML_reporter XML_reporter} | XML reporter. | `Class<{@link javax.xml.stream.XMLReporter}>`
| {@link org.apache.juneau.xml.XmlParser#XML_resolver XML_resolver} | XML resolver. | `Class<{@link javax.xml.stream.XMLResolver}>`
| {@link org.apache.juneau.xml.XmlParser#XML_validating XML_validating} | Enable validation. | boolean
{@link org.apache.juneau.xml.XmlSerializer} | {@link org.apache.juneau.xml.XmlSerializer#XML_addBeanTypes XML_addBeanTypes} | Add "_type" properties when needed. | boolean
| {@link org.apache.juneau.xml.XmlSerializer#XML_addNamespaceUrisToRoot XML_addNamespaceUrisToRoot} | Add namespace URLs to the root element. | boolean
| {@link org.apache.juneau.xml.XmlSerializer#XML_autoDetectNamespaces XML_autoDetectNamespaces} | Auto-detect namespace usage. | boolean
| {@link org.apache.juneau.xml.XmlSerializer#XML_defaultNamespace XML_defaultNamespace} | Default namespace. | {@link org.apache.juneau.xml.Namespace}
| {@link org.apache.juneau.xml.XmlSerializer#XML_enableNamespaces XML_enableNamespaces} | Enable support for XML namespaces. | boolean
| {@link org.apache.juneau.xml.XmlSerializer#XML_namespaces XML_namespaces} | Default namespaces. | Set<{@link org.apache.juneau.xml.Namespace}>
| {@link org.apache.juneau.xml.XmlSerializer#XML_xsNamespace XML_xsNamespace} | XMLSchema namespace. | String ({@link org.apache.juneau.xml.Namespace})

## 20 - Security Best-Practices

Security is always an ongoing concern in any library. If you discover any security vulnerabilities in this code, please refer to the instructions found here:

- {@doc http://www.apache.org/security SECURITY}

### 20.1 - juneau-marshall

##### Demarshalling vulnerabilities

One common security vulnerability is the ability to create arbitrary Java object instances through crafted user input. For example, support for constructing POJOs based on an input attribute defining a fully-qualified class name like "{class:'com.foo.MyBean',...}"

Fortunately, Juneau does not support an open-ended "class attribute. As a rule, it should not be possible to create arbitrary POJOs by any of the parsers. The demarshalled object types are inferred via reflection of the class objects passed in through the parser method (e.g. JsonParser.DEFAULT.parse(input, MyBean.class)). As long as the Class object passed into this method is not constructed from user-generated input, it should be free from demarshalling vulnerabilities.

The following example shows a potential vector that circumvents the restriction above:

// Don't do this! Class c = Class.forName(someUserInputString); JsonParser.DEFAULT.parse(input, c); // Oops! Security hole!

Juneau does support something similar to a "class" attribute that allows you to define the POJO type at runtime. This is the "type" attribute. The difference is that it's not possible to specify fully-qualified class names in "type" attributes, and instead can only specify type keys defined through bean dictionaries. Instead of serializing the fully-qualified class names in the output, we instead serialize type names that represent those POJO types. i.e. instead of "class='com.foo.MyBean'", we instead serialize "type='MyBeanIdentifier'". Since bean types are defined at compile time, it's impossible to instantiate arbitrary POJOs.

POJO types of generalized input are also inferred through swaps. Again, since the POJO types are hardcoded at compile time, these should not be subject to demarshalling vulnerabilities. However, it is possible to circumvent this through your swap implementation as shown below:

// Don't do this! public class MyInsecureSwap extends PojoSwap<ObjectMap,Object> { public Object swap(BeanSession session, ObjectMap input) throws Exception { // Security hole! return Class.forName(input.getString("class")).newInstance(); } }

Note that the {@link org.apache.juneau.jso.JsoParser}, a thin layer of the Juneau Parser API written on top of plain-old Java Object Serialization which itself is vulnerable to demarshalling issues. Due to this, the JSO parser is not included in any of the default REST servlet implementations. Be especially careful when using this parser, particularly if you want to use it for handing application/x-java-serialized-object input through REST servlets.

All other parsers (JSON, URL-Encoding, MessagePack, etc...) work the same way in determining POJO types, so should be safe from demarshalling vulnerabilities.

##### Dependent libraries

When accessing security vulnerabilities of any library, dependent libraries must also be taken into account:

- The JSON, HTML, MsgPack, URL-Encoding, and UON parsers are written from scratch and do not rely on any other parsing technologies.
- The XML and HTML parsers uses the built-in Java StAX parser. This *should* be free from vulnerabilities.
- The RDF parsers rely on Apache Jena 2.7.1. As of 7.0.1, no known security vulnerabilities exist that affect Juneau at this time.

### 20.2 - juneau-svl

Care must be used when defining new {@link org.apache.juneau.svl.Var Vars} using the SVL API since mistakes could potentially expose system properties, environment variables, or even file system files.

For recap, the SVL support allows you to embed variables of the form "$X{key}" inside strings that get resolved to other strings. The resolved strings themselves can also contain variables that also get recursively resolved.

An example of a potential security hole is shown below that could potentially expose any file on a file system through a REST request:

public String doUnsafeGet(RestRequest req) { // Security hole! return req.getVarResolver().resolve("$RQ{foo}"); }

This code is simply echoing the value of the foo query parameter. Now say for example that a bad actor passes in the query string "foo=$F{/some/file/on/file/system}". The $F variable allows you to resolve the contents of files using SVL, and is provided by default using the built-in variable resolver returned by the RestRequest object. You've potentially just exposed the contents of that file through your REST interface.

In reality, the above security hole does not exist because of the following restrictions:

- Vars have two methods {@link org.apache.juneau.svl.Var#allowNested()} and {@link org.apache.juneau.svl.Var#allowRecurse()} that can be overridden to prevent recursive processing of string variables. These are both false for the $R variable, so the $F variable in the result will never get processed and instead be treated as plain text.
- The $F variable only allows you to retrieve files within the JVM starting directory.

Even though the built-in Juneau variables are safe, special care is needed when defining your own custom variables. If your variable resolves user input in any way, it's HIGHLY recommended that you override the {@link org.apache.juneau.svl.Var#allowNested()} and {@link org.apache.juneau.svl.Var#allowRecurse()} methods to prevent recursive handling of variables.

### 20.3 - juneau-rest-server

Denial of service attacks can be alleviated through the {@link org.apache.juneau.rest.annotation.Rest#maxInput() maxInput()} setting. Arbitrarily-large input will trigger an exception before causing out-of-memory errors. The default value for this setting is 100MB.

Since the parsers do not use intermediate DOMs and instead parse directly into Java objects, deeply nested data structures will almost always trigger stack overflow errors long before memory consumption becomes an issue. However, this is NOT true of the RDF parsers that use an intermediate DOM. If parsing RDF, you may want to consider lowering the max-input value above.

## Release Notes

### 5.0.0.0 (Jun 11, 2012)

Version 5.0 marks a major release milestone for the Juno/JJSON library. It is now available for download from iRAM under the name "Juno (previously JJSON)". The Juno Starters Guide has been updated to reflect new functionality in this release.

- New name.
  Unfortunately, "JJSON" was already trademarked by another similar library. Therefore, it's been renamed "Juno" (after the Roman goddess and wife of Jupiter) which does not appear to have any similar trademark issues (crosses fingers). The name is also a play on the word "Uno", indicating that this is a single simple unifying interface of several kinds of technology.
- Simplified APIs for working with beans.
  Significant improvements have been made to the parsers to make it easier to convert serialized POJOs back into their original forms.
- Serializer/Parser classes now directly subclass from {@link org.apache.juneau.BeanContext}.
  In previous releases, if you wanted to change the way beans were handled by the serializers and parsers, you had to construct a separate bean map factory and pass it to the serializer or parser. Now, you can call the bean map factory methods directly on the serializer or parser class.
- Simplified Filter API for handling non-standard POJOs.
  The API for handling non-standard POJOs has been simplified by introducing the concept of a Transform class, which is associated with the BeanContext class (and thus the Serializer and Parser classes too) through the BeanContext.addTransforms(Class[]) method.
  Two new subclasses of Transform:
  - {@link org.apache.juneau.transform.BeanFilter} - Filter POJO beans.
  - {@link org.apache.juneau.transform.PojoSwap} - Filter POJOs that aren't beans.
  This new API replaces the previous separate Cast and BeanFilter APIs which were considerably more complicated and puts them under a common API.
- Elimination of _class attributes in parsable output.
  One of the complaints about the previous version of JJSON was that if you wanted to have the resulting JSON or XML be parsable back into beans, you had to enable the "addClassAttrs" property on the bean map factory class so that "_class" attributes could be added to the output.
  This requirement is virtually eliminated in v5. In many cases, the parsers are able to determine through reflection what the correct target type is based on the top-level class passed in on the parse method.
- Performance improvements.
  Several significant performance improvements have been made in this release.
  - New Reader-based JSON parser.
    Previously, the JSON parser required that the entire JSON text be loaded into memory as a String before being parsed. The new JSON parser is Reader-based which significantly reduces memory consumption.
  - New StAX-based XML parser.
    The old XML parser was based on DOM. The new XML parser uses a StAX parser which significantly reduces memory consumption.
  - Caching of reflection data in the BeanMap API.
    The number of reflection calls have been significantly reduced in the BeanMap API code. Reflection is used to determine the class types of property values on beans. This information is now cached and persisted so that the reflection API calls to determine class types are only performed the first time a bean type is encountered.
  - Automatic support for GZIP compression/decompression in RestServlets.
    This is completely transparent to the developer. The output writer is negotiated by the framework to automatically handle compression and charset requests without the developer needing to know anything about it.
- Cognos/XML support.
- JSON-schema support.
- New {@link org.apache.juneau.utils.PojoIntrospector} class.
- Significant REST servlet API improvements.
  - Defining child resources is considerably simpler now. In addition to the standard doX() methods for handling the requests for the current resource, you can also define getX() methods for returning child resources which automatically become available under the child URL specified by the getter name.
  - Initialization of the child resources occurs automatically when the parent resource initialization occurs.
  - Other improvments have been made in the area of automatic negotiation of input and output type streams. For example, automatic support is provided for GZIP (Accept-Encoding: gzip) and charsets (e.g Accept-Charset: SJIS) on both incoming and outgoing data. It's all transparent from a developers perspective. The developer simply working with POJOs, and all details about content types, encoding, charsets, and so forth are handled by the framework.
  - Support for generating complex OPTIONS pages for resources.
- Automatic support for SOAP XML output on "text/soap+xml" requests against RestServlet.
- Support for XML namespaces.
- Support for setting the XML root element name by either passing in a parameter on the serializer, or by specifying it via a @Bean annotation.
- Support for loading beans directly from Readers and Strings.
- Parsing support for POJOs of type Enum.
- Significant improved support for various flavors of parameterized types, such as subclasses of parameterized types (e.g. MyBeanList extends LinkedList<MyBean>).
- Improved ordering of bean properties (should now be ordered as they are defined in the class).
- Various default filters provided:
  - byte[]<-->Base64 encoded strings
  - Date/Calendar<-->ISO8601/RFC822/Long
- New {@link org.apache.juneau.html.HtmlParser} and {@link org.apache.juneau.urlencoding.UrlEncodingParser} classes.
- HtmlSerializer now produces XHTML.

### 5.0.0.1 (Jun 14, 2012)

Juno 5.0.0.1 is a moderate update.

- New support for generating XML-Schema documents from POJO models.
- New support for serializing to RDF/XML.

### 5.0.0.2 (Sept 28, 2012)

Juno 5.0.0.2 is a minor update.

- Improvements to Javadocs. Most of the information in the Juno Starters Guide wiki has been moved into the overview and package-level javadocs.
  Since the information is now written in HTML, you can now copy and paste the code examples directly from the Javadocs.
  The code examples are also syntax-highlighted using CSS.
- Support for defining default XML namespaces on packages and classes for the XML and RDF serializers.
- Restructured the packages along content type support (e.g. all JSON support moved to org.apache.juneau.json).
- Automatic support for parsing maps with Enum keys, and parsing Enum strings.
  This was previously possible using filters, but now it's built-in for all the parsers.
- Replaced the ObjectList.toXArray() methods with a new elements(Class<T> type) method that's more efficient and avoids creating an unnecessary array.
- Support for parsing into beans with read-only properties.
  New @BeanConstructor annotation allows you to specify bean property values to be passed in through a constructor.
- Separated the rest library into separate independent client and server libraries.
  Use one, use both, it's up to you.

### 5.0.0.3 (Oct 3, 2012)

Juno 5.0.0.3 is a minor update.

- Support for parsing into read-only beans (i.e. beans with only getters, property values set through constructor args).
  To support this, the @BeanConstructor annotation has been added.
- Merged separate settings classes back into their base classes (simplifies the API).
- {@link org.apache.juneau.serializer.SerializerGroup SerializerGroups} and {@link org.apache.juneau.parser.ParserGroup ParserGroups} now share {@link org.apache.juneau.BeanContext BeanContexts} to reduce memory consumption of class type metadata.

### 5.0.0.4 (Oct 7, 2012)

Juno 5.0.0.4 is a minor update.

- New {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} annotation on {@link org.apache.juneau.rest.RestServlet} methods.
  Allows the usage of URL pattern matching and automatic conversion of URL variables to arguments passed to method handlers.
  See {@link org.apache.juneau.rest.RestServlet} for more information.
- Enhancements to BeanContext.convertToType(Object,Class) to be able to convert Strings to classes with fromString(String)/valueOf(String) static methods or T(String) constructors.

### 5.0.0.5 (Oct 29, 2012)

Juno 5.0.0.5 is a major update.

- New @RestChild annotation for identifying child resources.
- New traversable and filterable attributes added to {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} annotation.
  Eliminates the need for PojoResource and FilteredRestResource classes.
- Simplified client API. Easier to use when making multiple connections to the same server.
- Support for pluggable authentication in the client API.
- Support for authenticating against Jazz Team Servers.
- Support for rendering package-level Javadocs in REST resources.
- Support for parsing of header values into specific object types.
- Changed default XML representation to not include JSON-type attributes. Produces cleaner XML.
- New resourceUri attributed added to @Bean annotation to associate beans with resource URIs.
  - Used for automatically creating hyperlinks in {@link org.apache.juneau.html.HtmlSerializer}.
  - Used for automatically creating uri attributes in {@link org.apache.juneau.xml.XmlSerializer}.
  - Used for automatically creating rdf:about attributes in RdfXmlSerializer.

### 5.0.0.6 (Oct 30, 2012)

Juno 5.0.0.6 is a minor update that fixes a small bug in 5.0.0.5.

### 5.0.0.7 (Jan 20, 2013)

Juno 5.0.0.7 is a major update.

##### Core API updates

- Combined previous 3 libraries into a single library.
- New {@link org.apache.juneau.parser.ParserListener} class.
  Adds ability to find and process unknown bean properties during parsing.
- Enhancements to {@link org.apache.juneau.xml.XmlParser}:
  - Coalescing support
  - Validations support
  - Support for replacing entity references
  - Resolver support
  - Event allocator support
  - Trim-whitespace support
- Enhanced XML support:
  - New {@link org.apache.juneau.xml.annotation.Xml#format() @Xml.format} annotation.
    Controls how POJOs get serialized to XML.
    Also allows you to collapse collections and arrays.
  - New @Xml.namespaces annotation.
    Namespaces can be defined at package, class, method, or field levels.
  - New @Xml.nsUri annotation.
    Shortcut for specifying namespace URIs.
  - New @Xml.valAttr annotation.
    Serializes a bean property value as an attribute.
  - Ability to override XS and XSI namespaces on XML and RDF/XML serializers.
  - Ability to override RDF namespace on RDF/XML serializer.
  - New more-efficient namespace resolution.
- New configurable property classes for everything are now structured better and easier to locate and identify through the following new classes:
  - {@link org.apache.juneau.BeanContext}
  - SerializerContext
  - ParserContext
- Enhancements to {@link org.apache.juneau.BeanContext}:
  - Ability to mark bean properties as hidden using @BeanProperty(hidden) so that they don't get serialized.
  - Simplified ClassType {@link org.apache.juneau.ClassMeta} API.
    Combined 4 classes into a single class.
  - New @Bean.filter and @BeanProperty.filter annotations.
    Used for defining filters on bean classes and bean properties instead of just globally through BeanContext.addTransforms(Class[]).
  - New {@link org.apache.juneau.PropertyNamer} API / {@link org.apache.juneau.annotation.Bean#propertyNamer() @Bean.propertyNamer} annotation.
    Used for customizing bean property names.
  - New @BeanProperty.beanUri and @BeanProperty.id annotations.
    Used for associating beans with URLs and IDs.
    Used by XML serializer to add a url attribute on a bean element.
    Used by RDF/XML serializer to construct rdf:resource attributes.
  - New BeanProperty.properties() annotation. Used for limiting properties on child elements.
- Automatic support for {@link java.net.URL} and {@link java.net.URI} objects.
  - Converted to hrefs in HTML.
  - Converted to url attributes in XML.
  - Converted to resource:about attributes in RDF/XML.
- Improvements to Javadocs.
- Improved {@link org.apache.juneau.utils.PojoQuery} support.

##### REST client updates

- GZIP compression support.
- Bug fixes.

##### REST server updates

- Support for overriding bean context and serializer properties in a REST method call through new RestResponse.setProperty(String,Object) method.
  For example, allows you to control whitespace options on a per-request basis.
- Several new annotations on REST servlets:
  - @RestResource(filters) - Associate post-formatting filters on a resource level.
  - @RestResource.guards - Associate resource-level guards.
  - @RestResource.messages - Associate a resource bundle with a REST servlet. Comes with several convenience methods for looking up messages for the client locale.
  - @RestResource.properties - Override default bean context, serializer, and parser properties though an annotation.
- Several new annotations on REST methods:
  - @RestMethod(filters) - Associate post-formatting filters on a method level.
  - {@link org.apache.juneau.rest.annotation.RestMethod#guards() @RestMethod(guards)} - Associate method-level guards.
- New annotations on REST method parameters with automatic conversion:
  - @Attr - A parameter or URL variable value as a parsed POJO.
  - @Param - A query parameter value as a parsed POJO.
  - @PathRemainder- The remainder after a URL pattern match as a String.
  - @Header - An HTTP header value as a parsed POJO.
  - @Content - The HTTP content as a parsed POJO.
  - {@link org.apache.juneau.rest.annotation.Method @Method} - The HTTP method name as a String.
- HTTP response content POJOs can now simply be returned from methods instead of calling {@link org.apache.juneau.rest.RestResponse#setOutput(Object)}.

### 5.0.0.8 (Jan 30, 2013)

Juno 5.0.0.8 is a minor update.

- New {@link org.apache.juneau.config INI file} support.
  - Makes reading, updating, and manipulating INI configuration files a snap.
  - Supports automatic conversion of data types in line with the functionality of the rest of the product.
  - Comments and layout of INI files are persisted during saves.

### 5.0.0.9 (Feb 26, 2013)

Juno 5.0.0.9 is a moderate update.

##### Core API changes

- {@link org.apache.juneau.config INI config file support}:
  - A convenient API for reading, writing, and manipulating INI files.
  - Ability to convert INI files to batch and shell environment variables.
  - Command-line interface for updating INI files.
  - Support for encoded INI file values.
- Support for fluent-style bean setters (setters that return the bean itself).
- Ability to use {@link org.apache.juneau.annotation.Bean @Bean} annotation to override bean identification settings.
- New {@link org.apache.juneau.ObjectMap#cast(Class)} method to convert ObjectMaps directly to beans.

##### REST server API changes

- Build-in default OPTIONS pages.
- New @RestResource.defaultRequestHeaders and @RestResource.defaultResponseHeaders annotations.
- New {@link org.apache.juneau.rest.annotation.RestMethod#serializers() @RestMethod(serializers)} and {@link org.apache.juneau.rest.annotation.RestMethod#parsers() @RestMethod(parsers)} annotations.
- New {@link org.apache.juneau.rest.annotation.RestMethod#properties() @RestMethod(properties)} annotation.
- New @RestMethod(defaultRequestHeaders) annotation.
- New {@link org.apache.juneau.rest.annotation.RestMethod#matchers() @RestMethod(matchers)} annotation and {@link org.apache.juneau.rest.RestMatcher} class.
- Readers and InputStreams can be specified on @Content annotated parameters.
- New @HasParam annotation.
- Full RFC2616 support for matching Accept headers to serializers.

##### Other notes

- Smaller library size (460kB).

### 5.0.0.10 (Mar 7, 2013)

Juno 5.0.0.10 is a minor update.

##### Core API changes

- New {@link org.apache.juneau.ObjectMap#findKeyIgnoreCase(String)} method.
- HtmlSerializer will now create 2-dimensional tables for collections of mixed beans/maps if all object have the same set of property names/keys.

##### REST server API changes

- New RestServletProperties class that defines all the class-level properties that can be set on the servlet.
- Properties can be set through @RestResource.propertie annotation, or new RestServlet.setProperty(String,Object) method.
- New "?noTrace" URL parameter to prevent stack traces from being logged (for JUnit testing of error conditions).
- New RestServletProperties.REST_useStackTraceHashes property to prevent the same stack trace from being logged multiple times.
- New RestServletProperties.REST_renderResponseStackTraces property for preventing stack traces in responses for security reasons.
- New overridable RestServlet.onError(HttpServletRequest,HttpServletResponse,RestException,boolean) and RestServlet.onSuccess(RestRequest,RestResponse,long) methods for plugging in your own logging and peformance monitoring.
- Eliminated RestServlet.getInitParams() method, since it's now redundant with RestServlet.getProperties().
- Header parameters passed as URL parameters are now case-insensitive.

### 5.0.0.11 (Mar 8, 2013)

Juno 5.0.0.11 is a moderate update.

##### REST server API changes

- New UrlEncodingRestSerializer and UrlEncodingRestParser classes.
  Allows parsing form posts directly to POJOs.
- Support for Accept and Content-Type "application/x-www-form-urlencoded" added by default on {@link org.apache.juneau.rest.BasicRestServlet}.
- New RestServlet.renderError(HttpServletRequest,HttpServletResponse,RestException) method to allow customized handling of response errors.

### 5.0.0.12 (Mar 10, 2013)

Juno 5.0.0.12 is a minor update.

##### Core API changes

- Relaxed method naming conventions when using @BeanProperty annotation.
  Methods with zero parameters are interpreted as getters, and methods with one parameter are interpreted as setters.
  Eliminated the BeanProperty.method annotation, since it's now unnecessary.

##### REST server API changes

- Significantly improved response error messages.
  Older messages were rather cryptic. Error conditions should be much easier to debug now.
- New PlainTextRestSerializer class for serializing "plain/text" requests.
  Useful for debugging purposes.
- Readers and InputStreams can now be passed in as @Content parameters if you need direct access to the HTTP body content without involving the parsers.
  Equivalent to previously calling {@link org.apache.juneau.rest.RestRequest#getInputStream()} and {@link org.apache.juneau.rest.RestRequest#getReader()}.
- Improved support for the ?debug parameter.
  Dumps better information to the log file, such as all header parameters.

### 5.0.0.13 (Mar 14, 2013)

Juno 5.0.0.13 is a minor update.

##### Core API changes

- New support for relative URIs.
  - URIs of the form "foo/bar" are interpreted as relative to the context root of the web application.
  - URIs of the form "/foo/bar" are interpreted as relative to the HTTP authority (e.g. "http://myhost:9080").
- New SerializerContext.SERIALIZER_uriContext and SerializerContext.SERIALIZER_uriAuthority serializer properties for specifying values for relative URIs.
- New {@link org.apache.juneau.annotation.URI @URI} annotation that allows you to specify classes and bean properties as URLs that aren't java.net.URI or java.net.URL.
- New {@link org.apache.juneau.html.HtmlSerializer#HTML_uriAnchorText} HTML serializer property for tailoring how anchor text is rendered.
- Renamed BeanProperty#uri annotation to BeanProperty#beanUri to make it clear that this property represents the URI of the bean itself instead of an arbitrary property containing a URI.
- Removed BeanProperty#id annotation.

##### REST server API changes

- Improvements to {@link org.apache.juneau.rest.RestServlet} to automatically handle relative URIs in POJOs.
  - SerializerContext.SERIALIZER_uriContext property set by default to web app context root.
  - SerializerContext.SERIALIZER_uriAuthority property set by default to the request scheme+hostname+port.
- Fixed bug involving Accept-Charset header in Chrome that prevented HTML output from rendering correctly in that browser.
  Accept-Charset handling should now be fully W3C compliant.

### 5.0.0.14 (Mar 23, 2013)

Juno 5.0.0.14 is a major update.

The biggest change is that the RestSerializer, RestParser, RestSerializerGroup, and RestParserGroup classes have been eliminated entirely.
Instead, the existing {@link org.apache.juneau.serializer.Serializer}, {@link org.apache.juneau.parser.Parser}, {@link org.apache.juneau.serializer.SerializerGroup}, and {@link org.apache.juneau.parser.ParserGroup} classes of the core API have been augmented to replace them.

Adoptions will be required if you have previously used these classes.

##### Core API changes

- New org.apache.juneau.serializer package.
  - Entirely reworked class hierarchy to make it easier to define new serializers.
  - New {@link org.apache.juneau.serializer.WriterSerializer} base class for defining character-based serializers.
  - New {@link org.apache.juneau.serializer.OutputStreamSerializer} base class for defining byte-based serializers.
  - Updated {@link org.apache.juneau.serializer.SerializerGroup} class with full support for RFC2616 Accept-Content headers.
  - Improved cloning support on serializers and serializer groups.
- New org.apache.juneau.parser package.
  - Entirely reworked class hierarchy to make it easier to define new parsers.
  - New {@link org.apache.juneau.parser.ReaderParser} base class for defining character-based parsers.
  - New {@link org.apache.juneau.parser.InputStreamParser} base class for defining byte-based parsers.
  - Improved cloning support on parsers and parser groups.
- New org.apache.juneau.transform package.
  - Cleaner class structure.
  - Improved {@link org.apache.juneau.transform.BeanFilter} class for defining property filters on beans.
  - Improved {@link org.apache.juneau.utils.PojoQuery} class for defining filters on objects (previously called ObjectFilter).
- New org.apache.juneau.encoders package.
  - Defines API for {@link org.apache.juneau.encoders.Encoder Encoders} for enabling compression in REST servlets and clients.
  - Previously, gzip compression was enabled by default. This new API allows you to plug in your own compression algorithms.
  - New {@link org.apache.juneau.encoders.GzipEncoder} class for enabling gzip compression.
  - New {@link org.apache.juneau.encoders.EncoderGroup} class for managing multiple encoders and finding them based on RFC2616 Accept-Encoding header values.
- New org.apache.juneau.plaintext package.
  - New {@link org.apache.juneau.plaintext.PlainTextSerializer} and {@link org.apache.juneau.plaintext.PlainTextParser} classes for serializing/parsing text/plain content.
- New org.apache.juneau.jso package.
  - New {@link org.apache.juneau.jso.JsoSerializer} class for serializing application/x-java-serialized-object content.
- New org.apache.juneau.soap package.
  - New {@link org.apache.juneau.soap.SoapXmlSerializer} class for serializing text/xml+soap content.
- Improved cloning support on the {@link org.apache.juneau.BeanContext} class.
  - Better caching. Improved caching performance.
- JsonMap and JsonList changed to {@link org.apache.juneau.ObjectMap} and {@link org.apache.juneau.ObjectList} to better reflect that they're not limited to just JSON support.
- Renamed PojoSwap to {@link org.apache.juneau.utils.PojoQuery} to not confuse it with the new Filter API.

##### REST server API changes

- Eliminated org.apache.juneau.rest.serializers and org.apache.juneau.rest.parsers packages.
  - All existing REST serializers and parsers merged into the core API.

##### REST client API changes

- Simplified {@link org.apache.juneau.rest.client.RestClient} API.
  - You can now only specify a single serializer or parser per client. This significantly simplifies the code.
  - Support for {@link org.apache.juneau.encoders.Encoder Encoders}.
- Eliminated RestCmdLine (since it's essentially redundant with CURL).

### 5.0.0.15 (Mar 24, 2013)

Juno 5.0.0.15 is a moderate update.

- Juno-Wink integration components that have been requested by many for a long time!
  Refer to org.apache.juneau.rest.jaxrs for information.
- New @Produces annotation in place of ISerializer.getMediaTypes() for specifying what media types a serializer produces.
  Available when subclassing from {@link org.apache.juneau.serializer.Serializer}.
- New @Consumes annotation in place of IParser.getMediaTypes() for specifying what media types a parser consumes.
  Available when subclassing from {@link org.apache.juneau.parser.Parser}.

### 5.0.0.16 (Mar 25, 2013)

Juno 5.0.0.16 is a minor update.

- New @Properties REST method parameter annotation that can be used to get the runtime properties map through a parameter instead of through {@link org.apache.juneau.rest.RestResponse}.

### 5.0.0.17 (Mar 25, 2013)

Juno 5.0.0.17 is a minor update.

- Charset now passed as a parameter to IOutputStreamSerializer.serialize() and IInputStreamParser.parse().

### 5.0.0.18 (Mar 27, 2013)

Juno 5.0.0.18 is a moderate update.

The biggest change is the introduction of the {@link org.apache.juneau.jena.RdfSerializer} class that uses Jena to generate RDF/XML, RDF/XML-ABBREV, N-Tuple, N3, and Turtle output.

This code should be considered prototype-quality, and subject to change in the future.
There are plans of adding an equivalent RdfParser class in the future, so the serializer logic may need to be tweaked to allow POJOs to be reconstituted correctly in the parser.

The RdfXmlSerializer class should be considered deprecated for now.
However, I'm keeping it around, since it's considerably faster and uses far less memory than the Jena-based serializer since it serializes directly from POJOs to RDF/XML.
It may or may not be removed in the future depending on demand.

##### Other changes

- New {@link org.apache.juneau.jso.JsoParser} class.

### 5.0.0.19 (Apr 1, 2013)

Juno 5.0.0.19 is a minor update.

- New methods on {@link org.apache.juneau.rest.RestServlet}:
  - RestServlet.onPreCall(RestRequest)
  - RestServlet.onPostCall(RestRequest,RestResponse)
- TRIM_NULLS setting changed to SerializerContext.SERIALIZER_trimNullProperties.
  New property default is true. Only applies to bean properties, not map or collection entries.

### 5.0.0.20 (Apr 7, 2013)

Juno 5.0.0.20 is a major update.

##### Core API changes

- New Jena-based {@link org.apache.juneau.jena.RdfSerializer} for serializing POJOs to RDF/XML, RDF/XML-ABBREV, N-Triple, Turtle, and N3.
  Serializes ANY POJOs to RDF, even simple objects and primitives.
- New Jena-based {@link org.apache.juneau.jena.RdfParser} for parsing RDF/XML, RDF/XML-ABBREV, N3, Turtle, and N-Triple back into POJOs.
- XmlSerializerContext.XML_autoDetectNamespaces default changed to true.
  The old default value would cause XML with unmapped namespaces if you didn't manually specify them via the XmlSerializerContext.XML_namespaces annotation.
  While setting the default to true is somewhat slower (since the serializer must crawl the POJO tree to find namespaces), the benefits of having it work out-of-the-box outweighs the performance concerns.
  For developers concerned about performance, they can always change it back to false and specify the namespaces themselves.

##### REST server API changes

- Allow inheritance of @RestResource annotation.
  Serializers, parsers, filters, properties , guards, and converters definitions are automatically inherited from parent classes and interfaces.
- Enhancements to {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} annotation:
  - New RestMethod.filters() annotation for defining POJO filters at the method level.
  - New RestMethod.serializersInherit() and RestMethod.parsersInherit() annotations for controlling how serializers and parsers (and associated filters and properties) are inherited from the class.
    This replaces the previous addSerializers and addParsers annotations.
- New RestServletJenaDefault servlet that includes serialization/parsing support for all Jena-based serializers and parsers.
- New DefaultJenaProvider JAX-RS provider that includes serialization/parsing support for all Jena-based serializers and parsers.
- Eliminated RestServletChild class.
  It's redundant with the introduction of inheritable annotations.
- New methods on {@link org.apache.juneau.rest.RestServlet}:
  - RestServlet.createConfigFactory()
  - RestServlet.createSerializers()
  - RestServlet.createParsers()
  These augment the existing getBeanContext() / getSerializers() / getParsers() methods.

##### REST client API changes

- New RestCall.setDateHeader(String,Object) method for setting ISO8601 datetime headers.

### 5.0.0.21 (Apr 9, 2013)

Juno 5.0.0.21 is a minor update.

##### Core API changes

- New HtmlDocSerializerContext.HTMLDOC_navlinks annotation for addint links to HTML page views.
- Renamed the properties in HtmlDocSerializerContext for clarity.

##### Servlet API changes

- Added new RestServlet.addDefaultProperties(ObjectMap,RestRequest) method for programatically adding properties to the property map per request.
- Added the following new properties in the properties map to make them easily available to serializers and parsers (since they don't have access to the HTTP request object).
  Note that the SerializerContext.SERIALIZER_uriAuthority and SerializerContext.SERIALIZER_uriContext properties were previously available.
  - RestServletProperties.REST_servletPath
  - RestServletProperties.REST_pathInfo
  - RestServletProperties.REST_method
- Path variables annotated with @Attr are now automatically URL-decoded.

### 5.0.0.22 (Apr 12, 2013)

Juno 5.0.0.22 is a minor update.

##### Core API changes

- New @Property.nls() annotation for specifying localized property values.
  For example, allows you to set the HTMLDOC_title and HTMLDOC_description properties to localized values pulled from a resource bundle.
  See the AddressBookResource class for an example.

##### REST Servlet API changes

- Fix a bug where the &Content query parameter was not always parsed correctly.

### 5.0.0.23 (Apr 14, 2013)

Juno 5.0.0.23 is a minor update.

- Simplified {@link org.apache.juneau.dto.cognos Cognos} support.
- Fixed bug where @Xml annotation was not being inherited by inner classes.
- Javadoc stylesheet improvements.

### 5.0.0.24 (May 9, 2013)

Juno 5.0.0.24 is a major update.

##### Core API updates

- New support for {@link org.apache.juneau.dto.atom ATOM}.
  - New AtomFeedResource class added to sample war.
- New XmlFormat.CONTENT enum value.
  Allows bean properties to be persisted as XML element text.
- New XmlContentHandler class and @Xml.contentHandler annotation.
  Allows customized serialization and parsing of beans to XML element text.
  Added for support of ATOM text content that must support both plain text and embedded XHTML.
- New {@link org.apache.juneau.xml.annotation.XmlSchema @XmlSchema} and updated {@link org.apache.juneau.xml.annotation.XmlNs @XmlNs} annotations to better mimic JAXB.
- Removed @Xml.valAttr annotation since it's now redundant with @Xml(format=CONTENT).
- Fixed timezone bug in {@link org.apache.juneau.transforms.CalendarSwap}.
- Simplified Serializer.serialize(Object,Object,SerializerContext) method.
- Fixed bug where lists returned by {@link org.apache.juneau.ObjectMap#getObjectList(String)} were not updatable.
- Eliminated old RDF/XML serializer.

##### Documentation updates

- New {@link org.apache.juneau.json JSON Support Overview} document.
- New {@link org.apache.juneau.xml XML Support Overview} document.
- New {@link org.apache.juneau.jena RDF Languages Support Overview} document.
- New {@link org.apache.juneau.dto.atom ATOM Support Overview} document.

### 5.0.0.25 (May 11, 2013)

Juno 5.0.0.25 is a minor update.

##### Core API updates

- New {@link org.apache.juneau.dto.ResultSetList} DTO for serializing SQL result sets to JSON/XML/HTML and so forth.
- New SqlQueryResource class in the sample war for demonstrating the ResultSetList DTO.

##### Server API updates

- Fixed issue with media type for CSS files being reported as "text/plain" instead of "text/css".
- Moved initialization of class properties to before the call to Servlet.init() so that getProperties() can be called during servlet initialization.
- New @Property.type annotation with support for using system properties as resource properties.

### 5.0.0.26 (Jun 5, 2013)

Juno 5.0.0.26 is a minor update.

- FindBug fixes.
- Changed the way child REST resources are defined.
  Eliminated the @RestChild annotation on getter methods and replaced it with @RestResource(children) defined on the resource class itself.
  Child resource paths are specified through @RestResource(path).
- New ChildResourceDescriptions bean for automatically generating the contents of router resource pages.
- Changed @RestMethod.pattern() to {@link org.apache.juneau.rest.annotation.RestMethod#path() @RestMethod(path)} for naming consistency.

### 5.0.0.27 (July 7, 2013)

Juno 5.0.0.27 is a moderate update.

- Fixed some HTML formatting issues in {@link org.apache.juneau.html.HtmlSerializer}.
- {@link org.apache.juneau.rest.BasicRestServlet} now includes {@link org.apache.juneau.plaintext.PlainTextSerializer} and {@link org.apache.juneau.plaintext.PlainTextParser} for plain-text support.
- Child resources now render on default OPTIONS pages through new method ResourceOptions.getChildren().
- Changes to {@link org.apache.juneau.urlencoding.UrlEncodingSerializer}/{@link org.apache.juneau.urlencoding.UrlEncodingParser} to reduce the need for quoted string values.
  More changes are likely in this area of the code to support multipart form posts.
- FindBugs fixes.

### 5.0.0.28 (July 9, 2013)

Juno 5.0.0.28 is a moderate update.

- Fixes an OutOfMemoryError and performance issue caused by incorrect caching of class metadata.
- Added WriterSerializer.serialize(Object,Writer) convenience method for serializing directly to a writer.
  Applies to all serializers.

### 5.0.0.29 (Aug 2, 2013)

Juno 5.0.0.29 is a moderate update.

- Revamped the API for filter support:
  - Updated {@link org.apache.juneau.transform.BeanFilter} class to mirror the {@link org.apache.juneau.annotation.Bean @Bean} annotation.
  - Introduced support for bean Bean.subTypeProperty() subtypes.
  - Replaced @Bean(filter=xxx) with new @Transform annotation.
- Revamped URL-Encoding support.
  The old URL-Encoding serializer and parser simply used the JSON serializer/parser with a thin URL-encoding top layer.
  The new URL-Encoding serialize and parser was written from scratch and is considerably more consistent in design and output.
- Improved number parsing.
  The new number parser should handle any valid numeric syntax for decimals and floats that Java itself supports.
- {@link org.apache.juneau.json.JsonSerializer} LAX mode now quotes reserved word attributes.
- New predefined DateFilters with millisecond precision:
  - org.apache.juneau.transforms.DateSwap.ISO8601DTP
  - org.apache.juneau.transforms.DateSwap.ISO8601DTZP

### 5.0.0.30 (Aug 8, 2013)

Juno 5.0.0.30 is a minor update.

- Fixed bug involving beans using Bean.subTypes() annotation in addition to subTypes property.
- Modified the JSON parser to handle non-existent JSON values to get around an issue where Cognos was generating invalid JSON.

### 5.0.0.31 (Aug 9, 2013)

Juno 5.0.0.31 is a moderate update.

- Simplified the {@link org.apache.juneau.serializer.Serializer} and {@link org.apache.juneau.parser.Parser} class hierarchies.
  This reverses a previous change that added a bunch of interfaces in these APIs (and subsequently required compiling with Java 7 to get around a compiler bug).
  The new class hierarchy is much simpler to understand.
- Added {@link org.apache.juneau.transforms.XMLGregorianCalendarSwap} to convert these to ISO8601 strings during serialization, and vice versa during parsing.
- Added a strict mode to {@link org.apache.juneau.json.JsonParser}.
- Added default {@link org.apache.juneau.json.JsonParser#DEFAULT_STRICT} parser.

### 5.0.0.32 (Oct 5, 2013)

Juno 5.0.0.32 is a moderate update.

- New support for generating and consuming fully-compliant JSON-Schema documents.
  See org.apache.juneau.dto.jsonschema for information.
- New methods added to {@link org.apache.juneau.parser.Parser}:
  - org.apache.juneau.parser.Parser.parseMap(Object,int,Class,Class,Class)
  - org.apache.juneau.parser.Parser.parseCollection(Object,int,Class,Class)
- {@link org.apache.juneau.annotation.Bean @Bean} annotation can now be defined on interfaces and inherited by subclasses.
- Support for customizing serialized values for Enums through overriding toString() and fromString() on the enum class.
  Previously used Enum.valueOf() to convert strings back into Enums.
  Used for JSON-Schema support to allow {@link org.apache.juneau.dto.jsonschema.JsonType} enum to be serialized to lowercase per the specification (e.g. "string" instead of "STRING").
- {@link org.apache.juneau.dto.cognos Cognos} DTOs now have fluent-style bean setters.
- Support for generic bean objects whose type was erased at compile time.
  Previous behavior gave you an error message that the type could not be determined.
  New behavior assumes a type of Object when the type is erased.
- Bug fixes:
  - When duplicate fluent-style setters were defined with different parameter types (e.g. setFoo(Foo f), setFoo(Bar b)), the {@link org.apache.juneau.BeanMap} API would sometime choose the wrong setter as the bean property setter.
    Now validates that the setter being chosen is the one whose return type matches the property getter.
  - Passing in Accept GET parameters with '+' (e.g. &Accept=text/json+simple) wasn't working anymore.
    The Accept parameter is supposed to interpret spaces as '+' to allow you to not have to write &Accept=text/json%2Bsimple.
  - Parsers would not set bean properties of abstract type {@link java.lang.Number}.
    Now it detects the numeric type based on input and sets the value accordingly.

### 5.0.0.33 (Oct 20, 2013)

Juno 5.0.0.33 is a moderate update.

- Removed generic parameter from {@link org.apache.juneau.serializer.WriterSerializer} class.
  - Many of the examples in the documentation were written as follows, which resulted in "unchecked" compile warnings:
    WriterSerializer s = new JsonSerializer();
    These compile warnings will now go away.
- New settings in BeanContext. These can be applied to all serializers/parsers.
  - {@link org.apache.juneau.BeanContext#BEAN_ignoreInvocationExceptionsOnGetters}
  - {@link org.apache.juneau.BeanContext#BEAN_ignoreInvocationExceptionsOnSetters}
  - {@link org.apache.juneau.BeanContext#BEAN_notBeanPackages_add}
  - {@link org.apache.juneau.BeanContext#BEAN_notBeanPackages_remove}
- Eliminated addNotBeanClassPatterns(String...) methods throughout API since these are now controlled by {@link org.apache.juneau.BeanContext#BEAN_notBeanPackages_add} / {@link org.apache.juneau.BeanContext#BEAN_notBeanPackages_remove} properties.
- New settings in RestServletProperties.
  - RestServletProperties.REST_trimTrailingUriSlashes
    Also removed RestRequest.getRequestURI(boolean trimTrailingSlashes) method which is now redundant with this property.
  - RestServletProperties.REST_pathInfoBlankForNull
    Also removed RestRequest.getPathInfo(boolean returnBlankForNull) method which is now redundant with this property.
- New JSON-Schema {@link org.apache.juneau.dto.jsonschema.JsonSchemaMap} class for supporting linked schemas.
- Serializers will no longer throw an exception when maxDepth setting is reached, and will instead simply ignore content below the specified depth.
  While the old behavior was as-designed, the new behavior is more in-line with expected behavior.
- Added support for HTTP header "X-Response-Headers" to {@link org.apache.juneau.rest.RestServlet}.
  Allows you to specify one or more headers that should be returned on the response from the servlet.
  For example, to get a page to automatically refresh every 1 second, you can append the following to a URL: ?x-response-headers={Refresh=1}
- Removed HtmlDocSerializerContext.HTML_REFRESH setting that added a Refresh meta tag to HTML documents, since this can now be controlled through X-Response-Headers.
- Small improvements to samples.
  - PhotosResource now includes a default entry.

### 5.0.0.34 (Nov 10, 2013)

Juno 5.0.0.34 is a moderate update.

- New support for runtime-replaced variables in REST resource properties:

  @RestResource( messages="nls/Messages", properties={ @Property(name="label",value="$L{servletTitle}"), // Localized variable in Messages.properties @Property(name="javaVendor",value="$S{java.vendor}"), // System property @Property(name="foo",value="bar"), @Property(name="bar",value="baz"), @Property(name="v1",value="$R{foo}"), // Request variable. value="bar" @Property(name="v2",value="$R{$R{foo}}") // Nested request variable. value="baz" } )

  See RestServlet.createRequestVarResolver(RestRequest) for more information.
- Eliminated @Property.type annotation which was the old way of specifying NLS variables that got resolved at runtime.
- New methods on {@link org.apache.juneau.rest.RestRequest}:
  - RestRequest.getVarResolver()
  - RestRequest.getServletURI()
  - RestRequest.getRequestParentURI()
- New methods on {@link org.apache.juneau.rest.RestResponse}:
  - RestResponse.sendRedirect(CharSequence)
- New methods on {@link org.apache.juneau.rest.RestServlet} that allow easier customization by subclasses:
  - RestServlet.createConfigFactory()
  - RestServlet.createConverters()
  - RestServlet.createDefaultRequestHeaders()
  - RestServlet.createDefaultResponseHeaders()
  - RestServlet.createEncoders()
  - RestServlet.createFilters()
  - RestServlet.createGuards()
  - RestServlet.createMimetypesFileTypeMap()
  - RestServlet.createParsers()
  - RestServlet.createProperties()
  - RestServlet.createRequestProperties(ObjectMap,RestRequest)
  - RestServlet.createRequestVarResolver(RestRequest)
  - RestServlet.createSerializers()
  - RestServlet.createUrlEncodingParser()
- Changed RestServletNls to use ResourceDescription/MethodDescription instead of RestResource/RestMethod
- New property RestServletProperties.REST_htDocsFolder.
  New support for serving up static documents from classpath through REST interface.
- Exception APIs now use {@link java.text.MessageFormat} (e.g. "{0}") for message variables instead of "%s".
- New {@link org.apache.juneau.annotation.Bean#stopClass @Bean.stopClass} annotation for specifying stop classes for bean properties.
- New BeanFilter.setStopClass(Class) which is the program equivalent to the annotation above.
- New methods on {@link org.apache.juneau.dto.ResultSetList}:
  - ResultSetList.handleBlob(Blob)
  - ResultSetList.handleClob(Clob)

### 5.0.0.35 (Nov 26, 2013)

Juno 5.0.0.35 is a minor update.

- {@link org.apache.juneau.rest.RestGuard#guard(RestRequest,RestResponse)} now returns a boolean to allow redirects to login pages.
- Fixed bug in RestServlet where occasional false positive "duplicate method with same name and path" errors were occurring.

### 5.0.0.36 (Dec 18, 2013)

Juno 5.0.0.36 is a minor update.

- Implemented org.apache.juneau.urlencoding.UrlEncodingParser.parseArgs(Reader,int,ClassMeta[]).
- name parameter of ResourceDescription#ResourceDescription(String,String,String). is now automatically URL-encoded so that the name can contain special characters (e.g. "foo/bar(baz)").
- Support for URL-matching and path info containing encoded characters (e.g. '/') now supported.
- Removed some lazy-initialization of bean information in {@link org.apache.juneau.ClassMeta} that allowed the removal of some synchronized blocks.
- Improved support of BeanContext.getClassMetaFromString(String). Now supports primitive arrays such as "long[]" in addition to the previous support for the equivalent "[J".
- Various new convenience methods added to {@link org.apache.juneau.internal.StringUtils} and {@link org.apache.juneau.internal.ClassUtils}.

### 5.1.0.0 (Jan 18, 2014)

Juno 5.1.0.0 is a major update.

##### Major changes

- Brand new REST client API that uses Apache HttpClient for HTTP communication.
  The new client API is simply a thin layer on top of HttpClient that performs serialization and parsing using Juno parsers, but leaves all the details of the HTTP connection to the Apache code.
  See the org.apache.juneau.rest.client package for details.
- New org.apache.juneau.rest.client.jazz package and org.apache.juneau.rest.client.jazz.JazzRestClient class for performing REST operations against Jazz servers.
  Includes improved support for FORM authentication, and better SSL certificate validation.
- Completely redesigned URL-Encoding support.
  See org.apache.juneau.urlencoding package for details.
- Changes to Parser API.
  - Removal of ExtendedReaderParser abstract class and moved methods into {@link org.apache.juneau.parser.ReaderParser} class.
  - Removal of DataFormat class from API since it was no longer necessary due to API change above.
  - Removal of ParserStringReader class.
    This was a reader optimized to work with String input.
    However, it could interfere with garbage collection of the original string object.
    Instead, the existing {@link org.apache.juneau.parser.ParserReader} was enhanced to work well with String input, and tests show no significant performance differences.
  - New org.apache.juneau.parser.Parser.parse(Object,int,ClassMeta) convenience method added.

##### Other changes

- Various new methods added to {@link org.apache.juneau.internal.StringUtils} and {@link org.apache.juneau.internal.ClassUtils}.
- Improved support on BeanContext.getClassMetaFromString(String).
  Now supports resolving "long[]", and so forth.
- ResourceDescription name parameter is now automatically URL-encoded in links.
- {@link org.apache.juneau.rest.RestRequest} now correctly handles cases involving URL-encoded characters in the path info portion of URLs (e.g. http://host/contextRoot/foo%2Fbar).
- Removed lazy-initialization that required locking in {@link org.apache.juneau.ClassMeta}.
- New BeanContext.setDefaultParser(ReaderParser) method added for specifying a default parser to use in a bean context (used when converting beans to Strings using BeanContext.convertToType(Object,Class). Old behavior simply used the default JSON serializer in these cases.
- More consistent handling of exceptions across all parsers.
- Minor changes to {@link org.apache.juneau.rest.RestRequest} class.
  - Changed the order of parameters on RestRequest#getParameter(String,Class).
  - Added RestRequest.getMapParameter(String,Class,Class,Class) and RestRequest.getCollectionParameter(String,Class,Class)} methods.

### 5.1.0.1 (Jan 25, 2014)

Juno 5.1.0.1 is a minor update.

- Addressed some behavioral differences between Tomcat and WAS.
  - Query parameter lookup is now always case-insensitive (per WAS behavior).
  - Consistent handling of redirect requests (Tomcat and WAS handle relative redirect paths differently).
- Fixed bug involving incorrect resolution of overlapping URL match patterns.
- Overall improvements in HTTP request parameter and header value resolution.
- Made workspace changes so as not to be dependent on the WAS test environment being loaded.
- Renamed @Remainder annotation to @PathRemainder.
- Fixed bug involving incorrect calculation of pathInfo on child resources.

### 5.1.0.2 (Apr 27, 2014)

Juno 5.1.0.2 is a minor update.

- Fixed issue preventing &Accept-Language from being used as a GET parameter.
- Minor XSS vulnerability fix.
- Empty results on HTML pages now shows "no results" instead of a blank page.
- Fixed issues preventing REST pages from rendering HTML in newer versions of Internet Explorer.
- Changed RestServletProperties.REST_allowMethodParam to be disabled by default.

### 5.1.0.3 (Jun 28, 2014)

Juno 5.1.0.3 is a moderate update.

##### Core API updates

- Ability to detect and use non-public bean classes, getters/setters, and fields using the following new properties:
  - {@link org.apache.juneau.BeanContext#BEAN_beanConstructorVisibility} - Control which bean constructors are visible to Juno.
  - {@link org.apache.juneau.BeanContext#BEAN_beanClassVisibility} - Control which bean classes are interpreted as beans to Juno.
  - {@link org.apache.juneau.BeanContext#BEAN_beanFieldVisibility} - Control which fields are visible to Juno as bean properties.
  - {@link org.apache.juneau.BeanContext#BEAN_beanMethodVisibility} - Control which getters/setters are visible to Juno as bean properties.
  Removed BeanContext.INCLUDE_BEAN_FIELD_PROPERTIES and BeanContext.INCLUDE_BEAN_METHOD_PROPERTIES properties, since ignoring fields and methods can be accomplished by setting the appropriate properties above to {@link org.apache.juneau.Visibility#NONE NONE}. Also, the @BeanProperty annotation can now be used on non-public fields/getters/setters to override the default behavior defined by the VISIBILITY properties identified above. This is a convenient way of identifying protected or private fields or methods as bean properties. Previously, you could only identify public fields/getters/setters using this annotation.
- New {@link org.apache.juneau.BeanContext#BEAN_useJavaBeanIntrospector} property that lets Juno use the Java bean Introspector class to determine bean properties. In the previous release, the method for determining bean properties was a mixture of Juno-based and Introspector-based. Now it's either pure Juno-based or pure Introspector-based. The result is considerably cleaner code and consistent behavior.
- New {@link org.apache.juneau.annotation.BeanIgnore @BeanIgnore} annotation. Replaces the previous @BeanProperty(hidden=true) annotation for ignoring bean properties. Can also be used on classes that look like beans so that they're not treated as beans.
- Support for parsing into non-static member classes. This applies to all parsers.
- New {@link org.apache.juneau.json.annotation.Json#wrapperAttr() @Json(wrapperAttr)} annotation that automatically wraps beans and objects in a wrapper attribute when serializing to or parsing from JSON.
- Changed the default ordering of bean properties to be in parent-to-child class order.
- New {@link org.apache.juneau.transform.BeanFilter#readProperty(Object,String,Object) readProperty()} and {@link org.apache.juneau.transform.BeanFilter#writeProperty(Object,String,Object) writeProperty()} methods added to {@link org.apache.juneau.transform.BeanFilter} class to allow individualized serialization and parsing behavior on a class-by-class basis.
- Eliminated previous restriction where bean subtype attributes had to be listed first in JSON objects when using the Bean.subTypeProperty() annotation. The previous behavior was not strictly JSON-compliant since JSON objects are supposed to consist of unordered lists of key/value pairs. While targeted for JSON, the restriction is also lifted for all other parsers.
- New fluent-style {@link org.apache.juneau.BeanMap#load(String) BeanMap.load()} methods for initializing bean maps.
- {@link org.apache.juneau.html.HtmlDocSerializer} will now embed the data portion of the output in a <div id='data'> element to make it easier to extract the data portion of the page in Javascript in browsers.

##### REST Server API updates

- New {@link org.apache.juneau.rest.RestRequest#getJavaMethod()} method for getting access to the method used to handle a request. Useful for accessing the method name or annotations during requests, such as in calls to {@link org.apache.juneau.rest.RestGuard#guard(RestRequest,RestResponse)}.
- Fixed bug when using Jetty where you tried to read text input after a header was written.
- Added new string variables $A{...} (request attributes) and $P{...} (request parameters) to RestServlet.createRequestVarResolver(RestRequest).

### 5.1.0.4 (Aug 25, 2014)

Juno 5.1.0.4 is a minor update.

- New RestServlet.getPath() method.
- New SerializerContext.getJavaMethod() and ParserContext.getJavaMethod() to allow access to REST methods that invoked the serializers or parsers. For example, can be used to access additional annotations on REST methods to perform special handing during serialization or parsing.
- Better behavior on overriding of filters in BeanContext.addTransforms(Class[]). Previously, adding multiple conflicting filters resulted in random behavior. Now filters are overridden when multiple matching filters are applied.
- Allow HtmlDocSerializerContext properties to be set via Serializer.setProperty(String,Object). Previously, these could only be defined through override properties (e.g. through REST class and method annotations).
- Fixed memory leak in XML parser.

### 5.1.0.5 (Sept 1, 2014)

Juno 5.1.0.5 is a moderate update.

- New Redirect class that simplifies performing redirections in REST methods.
- New pluggable {@link org.apache.juneau.rest.ResponseHandler} class and @RestResource(responseHandlers) annotation for defining customer response handlers for special kinds of POJOs.
- New method UrlEncodingSerializer.serializeUrlPart(Object) method.
- New method RestRequest.getServletURIBuilder() for construcing servlet-based URLs more efficiently.
- New method {@link org.apache.juneau.rest.RestResponse#getNegotiatedOutputStream()} that uses encoders if a match is found, and {@link org.apache.juneau.rest.RestResponse#getOutputStream()} that just return the underlying output stream without any modifications.
- Fixed bug where some properties were not being propagated correctly when using CoreObject.setProperties(ObjectMap) on serializer and parser subclasses.
- Fixed bug in {@link org.apache.juneau.html.HtmlSerializer} where URL keys in Maps were not being serialized as hyperlinks.
- Fixed bug in {@link org.apache.juneau.json.JsonSerializer} where "_class" and "items" attributes were not quoted in strict mode when using SERIALIZER_addClassAttrs feature.
- Fixed bug where Content-Encoding andCharacter-Encoding headers were being set when calling {@link org.apache.juneau.rest.RestResponse#getOutputStream()}. These should not be set if interacting with the output streams at a low level.
- Eliminated various convenience RestResponse.sendRedirect(...) methods due to the introduction of the Redirect class.

### 5.1.0.6 (Sept 21, 2014)

Juno 5.1.0.6 is a moderate update.

- Simplified API for {@link org.apache.juneau.transform.PojoSwap}. Since it's rarely used, the beanContext parameter was replaced with a PojoSwap#getBeanContext() method on the class.
- New simplified way of defining POJO filters without needing to extend {@link org.apache.juneau.transform.PojoSwap}. See {@link org.apache.juneau.transform.SurrogateSwap} for details.
- New {@link org.apache.juneau.html.annotation.Html @Html} annotation. Will allow the definition of standard XHTML DTOs in future releases. For now, Img is an example of defining an XHTML element using Juno DTOs.
- {@link org.apache.juneau.json.JsonParser} now ignores trailing ';' characters in input so that it can parse strings of the form "var x = {'foo':'bar'};".
- New TumblrParserResource in the samples war file showing how to combine the REST client and server APIs into a single resource in order to download Tumblr blogs and convert the response into any supported response content type.

### 5.1.0.7 (Oct 5, 2014)

Juno 5.1.0.7 is a moderate update.

- Improved error handling.
- New ParserContext.PARSER_debug and SerializerContext.SERIALIZER_debug. settings for logging additional information for debugging problems.
- New SERIALIZER_ignoreRecursions setting for explicitly ignoring recursions when serializing models. Previously, the SERIALIZER_detectRecursions setting did this, but now it simply looks for recursions and throws exceptions when they occur.
- Improved handling of StackOverflowErrors. When SERIALIZER_detectRecursions is enabled, a useful error message is displayed showing the exact chain of objects that resulted in the stack overflow.
- Bug fixes in {@link org.apache.juneau.dto.ResultSetList} for Oracle and SQL Server.
- Serializers and parsers can now access HTTP request attributes, parameters, and headers through SerializerContext.getProperties() and ParserContext.getProperties().
- Removed media-type and encoding attributes from SerializerContext and ParserContext since these are now available through context properties, and are typically not used.
- {@link org.apache.juneau.xml.XmlParser} now accepts application/xml.
- Improved handling of bean property serialization when multiple matching pojo filters for the bean property class exist.
- Improved concurrency on BeanContext class.
- Fixed bug in {@link org.apache.juneau.rest.converters.Traversable} that was causing it to be executed even if the servlet extra path info was empty.
- Fixed bug in {@link org.apache.juneau.rest.converters.Traversable} where it was not picking up filters and properties defined on REST Java methods.

### 5.1.0.8 (Oct 25, 2014)

Juno 5.1.0.8 is a moderate update, focused primarily on performance improvements.

- Improved performance on JSON and URL-Encoding parsers by approximately 50% on large data sets.
  - Rewrote {@link org.apache.juneau.parser.ParserReader} class to handle it's own buffering. The change allowed several optimizations to be made when dealing with JSON and URL-Encoding text by avoiding char array copies.
  - Added a estimatedSize parameter to the {@link org.apache.juneau.parser.Parser} parse methods to optimize buffering when the input size is known beforehand.
- Revamped the {@link org.apache.juneau.BeanContext} API to perform better in multi-threaded environments.
  - Introduced a new BeanPropertyStore class that handles creation of {@link org.apache.juneau.BeanContext} objects. This allows BeanContext objects to be considered immutable, and therefore cacheable/reusable by the framework. While this was technically possible to cache these objects beforehand, it relied on a locking mechanism to prevent bean contexts from being modified after being created. The new mechanism is much more straightforward.
- Modifications to the org.apache.juneau.rest.client APIs to make it easier to work with custom Apache HTTP clients.
  - Added overridable RestClient#createHttpClient() to allow customized subclasses to construct customized HTTP clients.
  - Removed the DefaultRestClient class since it's now fully redundant with RestClient.
  - Added RestClient.shutdown() method for cleaning up the internal HTTP client when you're done using a REST client.

### 5.1.0.9 (Dec 1, 2014)

Juno 5.1.0.9 is a major update. There weren't very many code changes, but the source has been made a part of Jazz Foundation. This required some restructuring of the project. The project on Jazz Hub will eventually be discontinued. However, the libraries on IBM Community Source will continue to be updated regularly.

- Project split up into 3 separate bundles:
  - org.apache.juneau - Core serializers and parsers.
  - org.apache.juneau.rest - REST server component.
  - org.apache.juneau.rest.client - REST client component.
- Code changes to facilitate breaking up bundles:
  - org.apache.juneau.rest.labels.Link class moved to Link.
  - References to org.apache.juneau.rest.RestException in {@link org.apache.juneau.encoders.Encoder} class changed to IOException.
- Changed configuration names for consistency with Jazz Framework.
- RestClient.execute(HttpUriRequest) method that allows subclasses to handle their own HTTP request execution.
- Changes in JazzRestClient to handle introduction of SSO support in v6.
- &plainText debug feature was broken.
- Removed double-buffering in RestRequest.
- Metadata cleanup, Find Bug fixes.

### 5.1.0.10 (Dec 23, 2014)

Juno 5.1.0.10 is a moderate update.

##### Core

- Major changes to URL-Encoded serializer and parser.
  - Logic for serializing and parsing URL-Encoded key-value pairs moved to {@link org.apache.juneau.urlencoding.UrlEncodingSerializer} and {@link org.apache.juneau.urlencoding.UrlEncodingParser} classes.
  - Logic for serializing and parsing URL-Encoded values moved to new {@link org.apache.juneau.uon.UonSerializer} and {@link org.apache.juneau.uon.UonParser} classes.
- Fix bug where BeanRuntimeExceptions weren't being thrown on subsequent calls to {@link org.apache.juneau.BeanContext#getClassMeta(Class)}.
- Moved logic for BeanContext.getPrimitiveDefault(Class) to new {@link org.apache.juneau.ClassMeta#getPrimitiveDefault()} method for performance reasons.
- Fixed bug in BeanContext.addTransforms(Class[]) that would cause filter order to get messed up.
- {@link org.apache.juneau.ClassMeta#newInstance()} can now create array instances.
- Fixed indentation bugs in {@link org.apache.juneau.html.HtmlSerializer}.
- Fixed issue in {@link org.apache.juneau.html.HtmlSerializer} where newlines were not being converted into line breaks.
- New {@link org.apache.juneau.serializer.WriterSerializer#toString(Object)} method that's identical to the serialize method but throws RuntimeExceptions to make the serializer easier to use for debugging.

##### Server

- Fixed major issue that prevented parsing URL-Encoded form posts into POJOs. Calling HttpServlet.getParameter(String) was forcing the underlying servlet code to process the HTTP body itself, preventing the UrlEncodingSerializer class from being able to parse the content. Updated code no longer inadvertantly calls this method.
- New RestRequest.getQueryParameter(String), RestRequest.hasQueryParameter(String), and RestRequest.hasAnyQueryParameters(String[]) methods that only look for parameters in the URL query string to prevent loading and parsing of URL-Encoded form posts.
- New @QParam and @HasQParam annotations for accessing query parameters from the URL query string.
- &plainText parameter can now specify a false value.
- Removed properties parameters from RestServlet.onPreCall(RestRequest) and RestServlet#onPostCall(RestRequest,RestResponse) methods since the properties are already accessible through RestRequest.getProperties().
- Added {@link org.apache.juneau.uon.UonSerializer} and {@link org.apache.juneau.uon.UonParser} to serializer and parser lists on {@link org.apache.juneau.rest.BasicRestServlet} and RestServletJenaDefault.

##### Client

- Moved to Apache HttpClient 4.3 to match Jazz 6.0.
- Renamed RestResponseEntity to {@link org.apache.juneau.rest.client.RestRequestEntity}.
- Improved performance on URL-Encoded form posts by serializing directly to output stream instead of serialized to string first.
- New methods on {@link org.apache.juneau.rest.client.RestClient} class that makes it easier to associate serializer and parser attributes with registered serializer and parser:
  - RestClient#setProperty(String,Object)
  - RestClient#setProperties(ObjectMap)
  - RestClient#addNotBeanClasses(Class[])
  - RestClient.addTransforms(Class[])
  - RestClient#addImplClass(Class,Class)
- Renamed RestClient.shutdown() to {@link org.apache.juneau.rest.client.RestClient#close()} to mirror change in Apache API.

##### Samples

- New CodeFormatterResource for quickly formatting Java and XML code samples in Javadocs.
- New UrlEncodedFormResource for showing how to work with URL-Encoded form posts.

### 5.1.0.11 (Feb 14, 2015)

Juno 5.1.0.11 is a moderate update.

##### Core

- Additions to {@link org.apache.juneau.html.annotation.Html @Html} bean annotation.
  - New {@link org.apache.juneau.html.annotation.Html#noTables() @Html(noTables)} annotation that prevents arrays/Collections from being serialized as tables.
  - New {@link org.apache.juneau.html.annotation.Html#noTableHeaders() @Html(noTableHeaders)} annotation that prevents HTML tables from having header rows.
- Several improvements to URL-Encoding support.
  - Improved whitespace handling in {@link org.apache.juneau.uon.UonParser}.
  - New UonParserContext.UON_whitespaceAware property for controlling whether whitespace is ignored.
  - New UrlEncodingContext.URLENC_expandedParams property for controlling whether arrays/Collections should be serialized/parsed as multi-part parameters.
  - New {@link org.apache.juneau.urlencoding.annotation.UrlEncoding#expandedParams() @UrlEncoding(expandedParams)} annotation that specifies that bean properties of type array/Collection be serialized as multi-part parameters (e.g. &key=val1&key=val2).
- New JsonSerializerContext.JSON_escapeSolidus property for controlling whether slash characters should be escaped.
- New {@link org.apache.juneau.internal.TeeOutputStream} and {@link org.apache.juneau.internal.TeeWriter} classes.
- New {@link org.apache.juneau.ClassMeta#isInstance(Object)} method.
- Performance improvements when using the {@link org.apache.juneau.BeanMap#add(String,Object)} method. Array properties are stored in a temporary list cache until {@link org.apache.juneau.BeanMap#getBean()} is called.
- New BeanPropertyMeta.add(BeanMap,Object) method for adding values to Collection and array properties.
- Config INI files now support keys with name "*".

##### Server

- REST method parameters can now be generic types (e.g. @Param("foo") Map<String,Integer> foo). This applies to headers, attributes, and parameters.
- New @Param(multipart) and @Query(multipart) annotations for handling multi-part GET and POST parameters.
- GET parameters are now CASE-SENSITIVE per W3C standards.
  - &Content must now be specified as &content.
  - &Method must now be specified as &method.
  - &debug must now be specified as &debug=true.
  - &plainText must now be specified as &plainText=true.
  - &notrace must now be specified as &noTrace=true.
- Performance improvements around query parameters.
- New methods on {@link org.apache.juneau.rest.RestRequest} for handling multi-part parameters:
  - RestRequest.getParameters(String,Class)
  - RestRequest#getQueryParameters(String,Class)
- Fixed Jetty issue in {@link org.apache.juneau.rest.RestResponse#setHeader(String,String)} where setting the Content-Type through this method was inconsistent with the behavior in WAS/Tomcat.
- &noTrace=true now prevents any errors from being logged in log file.
- Workaround for Jetty issue where ServletContext.getContextPath() always ends with "null".
- RestServletProperties.REST_allowMethodParam is now true by default on all subclasses of {@link org.apache.juneau.rest.BasicRestServlet} and RestServletJenaDefault.

##### Client

- New method {@link org.apache.juneau.rest.client.RestCall#allowRedirectsOnPosts(boolean)}.
- New method RestCall.peekInputStream() allows you to read response bodies without interrupting execution flow.
- New method {@link org.apache.juneau.rest.client.RestCall#toString()} now useful for debugging purposes. Shows all request/response headers and bodies.
- {@link org.apache.juneau.rest.client.RestCallException} now includes HttpResponse object for easier debugging.
- New method RestClient.addListener(RestClientListener) for registering request/response listeners.
- New RestClient.setClassLoader(ClassLoader) method.
- TLS support in JazzRestClient.

##### Other changes

- samples.ear and samples.war projects have been replaced with an OSGi bundle with activated servlets in juno.samples.

### 5.1.0.12 (Mar 28, 2015)

Juno 5.1.0.12 is a minor update.

##### Core

- Fixed ConfigFile.isEmpty() method.
- Changed behavior on {@link org.apache.juneau.uon.UonParser} to not treat '~' characters as escapes unless followed by one of the following characters: ( ) , $ = ~.

##### Client

- New class {@link org.apache.juneau.rest.client.RestCallInterceptor}. Allows responses to be inspected and modified before being processed. Replaces RestClientListener class.
- Minor connection cleanup fixes.

### 5.1.0.13 (Apr 24, 2015)

Juno 5.1.0.13 is a minor update.

##### Core

- {@link org.apache.juneau.ClassMeta#newInstance()} method can now create new instances of arrays.
- Arguments passed to Link are now serialized using {@link org.apache.juneau.urlencoding.UrlEncodingSerializer}, so arbitrary POJOs can now be passed as arguments.
- New date filters: org.apache.juneau.transforms.Datefilter.ISO8601DTZP and org.apache.juneau.transforms.Datefilter.SimpleP.
- New HtmlDocSerializerContext.HTMLDOC_nowrap setting for {@link org.apache.juneau.html.HtmlDocSerializer} class. Adds "* {white-space:nowrap}" to the style header to prevent word wrapping.
- Fixed bug in {@link org.apache.juneau.uon.UonParser} where passing in a blank value on an array or collection type in a form post would cause a ClassCastException. New behavior creates an empty array or Collection.
- Improved implementation of UrlEncodingSerializer.serializeUrlPart(Object) method.

##### Server

- {@link org.apache.juneau.rest.RestConverter} API fixed to handle the existence of POJO filters. {@link org.apache.juneau.rest.converters.Introspectable}/{@link org.apache.juneau.rest.converters.Queryable}/{@link org.apache.juneau.rest.converters.Traversable} classes can now work with filtered POJOs.
- @RestResource(messages) annotation can now be defined on super and subclasses so that NLS messages can be defined in multiple resource bundles.
- Performance improvements in RestServletNls class.
- Fixed bug where two REST java methods mapped to the same path pattern wasn't triggering an exception when it was supposed to.

##### Client

- New RestCall.setRedirectMaxAttempts(int) method to prevent endless redirection loops.
- New RestCall#setRetryable(int,long,RetryOn) method to automatically retry on failed connection attempts.
- New RestCallInterceptor.onRetry(RestCall,int,HttpRequest,HttpResponse) method for listening in on retry attempts.

### 5.1.0.14 (May 10, 2015)

Juno 5.1.0.14 is a moderate update.

The major addition is support for Remoteable Services, the ability to invoke server-side POJO methods through client-side proxy interfaces.

##### Core

- Simplified {@link org.apache.juneau.utils.PojoIntrospector} class.
- New ClassUtils.getMethodSignature(Method) method.

##### Client

- New methods in {@link org.apache.juneau.rest.client.RestClient} for working with remoteable services:
  - RestClient.setRemoteableServletUri(String)
  - RestClient#getRemoteableProxy(Class)

##### Server

- Added a default OPTIONS page to {@link org.apache.juneau.rest.BasicRestServlet} and RestServletJenaDefault.
- RestServletProperties.REST_allowMethodParam has been enhanced to allow you to explicitly specify which HTTP methods can be used in the &method parameter.
- New methods added to {@link org.apache.juneau.rest.RestRequest}:
  - RestRequest.getParser()
  - RestRequest.getReaderParser()

### 5.1.0.15 (May 24, 2015)

Juno 5.1.0.15 is a minor update.

##### Core

- New properties in SerializerContext:
  1. SerializerContext.SERIALIZER_relativeUriBase
  2. SerializerContext.SERIALIZER_absolutePathUriBase
  These replace the SERIALIZER_uriAuthority and SERIALIZER_uriContext properties.
- Improvements in {@link org.apache.juneau.csv.CsvSerializer}.

##### Server

- New properties in RestServletProperties:
  1. REST_defaultCharset
  2. REST_servletURI
  3. REST_relativeServletURI
- Improvements involving path calculations when servlets deployed outside of a war file with a context root.

##### Client

- New methods in {@link org.apache.juneau.rest.client.RestCall}:
  1. RestRequest.getHeader(String,Class)
  2. RestRequest.getHeader(String,Object,Class)
  3. RestRequest.getHeader(String,Type,Type...)
  4. RestRequest.getQueryParameter(String,Class)
  5. RestRequest.getQueryParameter(String,Object,Class)
  6. RestRequest.getQueryParameter(String,Type,Type...)
  7. RestRequest.getQueryParameter(String,Object,Type,Type...)
  8. RestRequest.getQueryParameters(String,Class)
  9. RestRequest.getQueryParameters(String,Type,Type...)
  10. RestRequest.getFormDataParameter(String,Class)
  11. RestRequest.getFormDataParameter(String,Object,Class)
  12. RestRequest.getFormDataParameters(String,Class)
  13. RestRequest.getFormDataParameter(String,Type,Type...)
  14. RestRequest.getFormDataParameters(String,Type,Type...)
  15. RestRequest.getPathParameter(String,Class)
  16. RestRequest.getPathParameter(String,Type,Type...)
  17. RestRequest.getBody(Class)
  18. RestRequest.getBody(Type,Type...)

### 5.1.0.16 (June 28, 2015)

Juno 5.1.0.16 is a moderate update.

##### Core

- New methods on {@link org.apache.juneau.ClassMeta} that eliminates language-specific code in the general class metadata.
  - ClassMeta.getXmlMeta()
  - ClassMeta.getJsonMeta()
  - ClassMeta.getHtmlMeta()
  - ClassMeta.getUrlEncodingMeta()
  - ClassMeta.getRdfMeta()
- New {@link org.apache.juneau.dto.jsonschema.JsonType#ANY} enum.
- New @Html(asPlainText) annotation.
- New HtmlDocSerializerContext.HTMLDOC_cssImports property.
- Significant changes to RDF support.
  - New {@link org.apache.juneau.jena.annotation.Rdf @Rdf} and {@link org.apache.juneau.jena.annotation.RdfSchema @RdfSchema} annotations. These replace the use of defining namespaced through the XML annotations, and allows XML and RDF to be serialized using different namespaces.
  - Support for serializing arrays/collections as RDF bags, RDF lists, and multi-valued properties.
  - Fixed warning message about "tab" setting when using the N3/Turtle serializers.
- New SerializerContext.SERIALIZER_sortCollections and SerializerContext.SERIALIZER_sortMaps properties.
- FindBug fixes.

##### Server

- New RestRequest.getServletParentURI() method.
- New $R{servletParentURI} variable.
- Removed final modifier from ChildResourceDescriptions.

##### Samples

- Added source code links to examples.

### 5.1.0.17 (Aug 3, 2015)

Juno 5.1.0.17 is a major update.

##### Core

- {@link org.apache.juneau.BeanMap#get(Object)} and {@link org.apache.juneau.BeanMap#put(String,Object)} now automatically performs filtering if filters are defined on the bean property or bean property class.
  - Deleted the following methods which are now unnecessary:
    - BeanMap.getFiltered(String)
    - BeanMap.putFiltered(String,Object)
    - BeanMapEntry.getFiltered(String)
    - BeanMapEntry.putFiltered(String,Object)
    - BeanMapEntry.putFiltered(String,Object)
    - BeanPropertyMeta.getFiltered()
    - BeanPropertyMeta.setFiltered(Object)
    - BeanPropertyMeta.getTransformedClassMeta()
  - {@link org.apache.juneau.BeanPropertyMeta#getClassMeta()} now returns the filtered type of the property.
- StringVarResolver now has support for chained resolvers.
- StringVarResolver now resolves variables inside resolved values. i.e. if a resolved variable value itself contains a variable, it now resolves that variable too.
- Fixed bug where inner interface classes being used in RestResource.filters() were being interpreted as surrogate classes because they have hidden 1-arg constructors due to being inner classes.
- Fixed bug in {@link org.apache.juneau.internal.MultiSet} where exception was being thrown if last set was empty.
- New {@link org.apache.juneau.utils.ZipFileList} class for providing efficiently zipped directories through the REST interface.
- New RdfProperties.RDF_useXmlNamespaces property.
- New XmlParserContext.XML_preserveRootElement property.
- Worked around bug in Sun VM on OS/X where XML parser was throwing an exception when trying to set a reporter.

##### Server

- New ZipFileListResponseHandler class.
- Simplified labels in servlet resource bundles:
  - "[ClassName].ResourceDescription" is now "[ClassName].label".
  - "[ClassName].MethodDescription.[methodName]" is now "[ClassName].[methodName]".
- Several changes to {@link org.apache.juneau.rest.RestRequest}:
  - Added new methods:
    - RestRequest.getQueryParameterMap()
    - RestRequest.getQueryParameterNames()
    - RestRequest.getPathInfoUndecoded()
    - RestRequest.getPathRemainderUndecoded()
    - RestRequest.getTrimmedRequestURI()
    - RestRequest.getTrimmedRequestURL()
    - RestRequest.getServletTitle()
    - RestRequest.getServletDescription()
    - {@link org.apache.juneau.rest.RestRequest#getMethodDescription()}
  - Behavior changes to {@link org.apache.juneau.rest.RestRequest#getPathInfo()} to follow Servlet specs. Returns null instead of blank for no path info.
  - RestRequest.getPathRemainder() now automatically decodes the path remainder. Use RestRequest.getPathRemainderUndecoded() to get the unencoded path remainder.
  - Bug fixes in RestRequest.getRequestParentURI() when servlet is mapped to "/*".
  - Bug fixes in RestRequest.getServletURI() when servlet is mapped to "/*".
- New string replacement variables:
  - $R{contextPath} - Returns value from {@link org.apache.juneau.rest.RestRequest#getContextPath()}
  - $R{methodDescription} - Returns value from {@link org.apache.juneau.rest.RestRequest#getMethodDescription()}
  - $R{resourceTitle} - Returns value from RestRequest.getServletTitle()
  - $R{resourceDescription} - Returns value from RestRequest.getServletDescription()
  - $R{trimmedRequestURI} - Returns value from RestRequest.getTrimmedRequestURI()
  - $E{var} - Environment variables.
- Added methods RestServlet.getDescription(RestRequest) and RestServlet.getLabel(RestRequest).
- {@link org.apache.juneau.rest.BasicRestServlet} and RestServletJenaDefault now provide default HTML titles and descriptions:

  @Property(name=HTMLDOC_title, value="$R{resourceTitle}"), @Property(name=HTMLDOC_description, value="$R{resourceDescription}")

- Options pages on {@link org.apache.juneau.rest.BasicRestServlet} and RestServletJenaDefault now provide default descriptions and back links: and descriptions:

  @Property(name=HTMLDOC_navlinks, value="{back:'$R{servletURI}"), @Property(name=HTMLDOC_description, value="Resource options")

- New {@link org.apache.juneau.rest.BasicRestServletGroup} class.
- Removed RestServletProperties.REST_trimTrailingUriSlashes and RestServletProperties.REST_pathInfoBlankForNull.
- New annotations for providing labels and descriptions. Useful if you don't plan on having to support other languages, so you don't want to provide labels in resource bundles.
  - RestResource.label()
  - @RestResource(description)
  - {@link org.apache.juneau.rest.annotation.RestMethod#description() @RestMethod(description)}
  - RestMethod#responses()
  - Attr.description()
  - Content.description()
  - HasParam.description()
  - HasQParam.description()
  - Header.description()
  - Param.description()
  - QParam.description()
- Support for sorting resources by name in ChildResourceDescriptions.

##### Samples

- Added /tempDir/upload showing how to use ServletFileUpload with multipart form posts.

### 5.1.0.18 (Aug 5, 2015)

Juno 5.1.0.18 is a minor update affecting the server component only.

##### Server

- Fixed bug where localized strings weren't resolving when using chained resource bundles.
- Servlet and method labels and descriptions can now contain embedded string variables.
- New RestMethod.input() and RestMethod.responses() annotations. These replace the various description annotations added 2 days ago with a simpler design.
- New methods on {@link org.apache.juneau.rest.RestServlet}:
  - RestServlet.getMethodDescription(String,RestRequest) so that subclasses can override the method description in the OPTIONS page.
  - RestServlet.createRequestVarResolver(RestRequest) so that subclasses can override and augment the variable resolver.
  - RestServlet.resolveChild(Class) and RestServlet.replaceChild(RestServlet) classes that allows customized resolution of servlet instances (e.g. if services are defined in OSGi).
- Reverted the MethodDescription back to 5.1.0.16 since it was being used by someone.

### 5.1.0.19 (Aug 15, 2015)

Juno 5.1.0.19 is a minor update in terms of core functionality. But it introduces a Microservices project for building REST microservices and docker containers.

##### Core

- Beans can now be serialized to and parsed from {@link org.apache.juneau.ObjectMap ObjectMaps}. See Serializing to ObjectMaps for details.
- New {@link org.apache.juneau.ObjectMap#include(String[])} and {@link org.apache.juneau.ObjectMap#exclude(String[])} methods.
- {@link org.apache.juneau.html.annotation.Html @Html} annotations can now be applied to bean properties.
- New {@link org.apache.juneau.utils.IOPipe} utility class.
- Behavior change on StringVarResolver. null input now results in blank strings instead of null.

##### Client

- New {@link org.apache.juneau.rest.client.RestClient#doCallback(String)} method.

##### Server

- New {@link org.apache.juneau.rest.RestRequest#getHeaders()} method.
- New RestResponse.getUnbufferedWriter() method.
- Fixed bug that was preventing x-response-headers parameter from working correctly.
- Added {@link org.apache.juneau.annotation.Bean#properties() @Bean.properties} annotations to the various classes in org.apache.juneau.rest.labels so that the order of the bean properties are consistent on all JVMs. On IBM JVMs this is unnecessary because the order of the properties as defined in the class are stored in the bytecode. Other JVMs such as OpenJRE do not implement this feature causing the bean properties to be in random order.
- New ResourceDescription.ResourceDescription(RestRequest,String,String) constructor.

### 5.1.0.20 (Sept 5, 2015)

Juno 5.1.0.20 is a moderate update. The biggest improvement is the ability to associate external INI config files with REST servlets using the ConfigFile functionality.

##### Core

- Significant API changes to org.apache.juneau.config API.
  - ConfigFile is now thread safe and can be shared across multiple threads.
  - New ConfigMgr class for managing configuration files.
  - Serializers and parsers can be associated with config files for storing and retrieving POJOs. Default support provided for JSON.
- New {@link org.apache.juneau.html.SimpleHtmlWriter} class. Can be used for simple HTML DOM construction.
- New {@link org.apache.juneau.utils.ProcBuilder} class for calling external processes.
- New ObjectMap.remove(Class,String,Object) method.
- "class='link'" added to links generated by {@link org.apache.juneau.html.HtmlDocSerializer}.
- New EncoderGroup#append(EncoderGroup) method.
- New HtmlDocSerializerContext.HTMLDOC_addLinks configuration property.
- Modified the Parser.createContext(ObjectMap,Method,Object) method. Outer context objects can be passed in to create instances of non-static inner classes.
- Fixed bug in {@link org.apache.juneau.html.HtmlStrippedDocSerializer} where exception was thrown when trying to serialize primitive arrays.
- {@link org.apache.juneau.json.JsonParser} now handles parsing JSON boolean/numeric values as strings to bean properties of type boolean or number.
- {@link org.apache.juneau.urlencoding.UrlEncodingSerializer} and {@link org.apache.juneau.urlencoding.UrlEncodingParser} now represent arrays and collections as key-value pairs where the keys are numbers (e.g. "?0=foo&1=bar").
- Various internal improvements to {@link org.apache.juneau.utils.IOPipe}.
- New ReflectionUtils.getResource(Class,String) method.
- {@link org.apache.juneau.internal.StringUtils#parseNumber(String,Class)} now returns zero for empty strings. This affects the way most parsers handle blank values.

##### Server

- You can now parse into non-static inner classes of a servlet for parameters/attributes/content. Useful if you like to define your marshaller beans inside your servlet.
- Changes to {@link org.apache.juneau.rest.RestServlet}:
  - New methods for accessing external INI config files:
    RestServlet.getConfig()
    RestServlet.createConfigFile()
  - New "$C{...}" variable that resolve to INI config file values.
  - New "$UE{...}" variable that URL-encodes the value inside the variable.
  - New convenience methods for retrieving classpath resource files:
    RestServlet.getResource(String)
    RestServlet.getResourceAsString(String)
    RestServlet.getResource(Class,String,String). Useful if you want to load predefined POJOs from JSON files in your classpath.
  - New RestServlet.handleNotFound(int,RestRequest,RestResponse) method for customized handling of when a resource or method was not found.
- {@link org.apache.juneau.rest.BasicRestServlet} now automatically processes "/favicon.ico" requests by overriding the new RestServlet.handleNotFound(int,RestRequest,RestResponse) method.
- New {@link org.apache.juneau.rest.RestRequest} methods:
  - RestRequest.resolveVars(String)
  - RestRequest.getVarResource(String)
  - RestRequest.getConfig()
- New {@link org.apache.juneau.rest.RestResponse} methods:
  - {@link org.apache.juneau.rest.RestResponse#getDirectWriter(String)}.
  - {@link org.apache.juneau.rest.RestResponse#getNegotiatedWriter()}. getWriter() now returns an unnegotiated writer. getUnbufferedWriter() has been removed.
- New {@link org.apache.juneau.rest.annotation.RestMethod#encoders() @RestMethod(encoders)} and RestMethod.inheritEncoders() annotations. Allows encoders to be fine-tuned at the method level.
- New @RestResource(config) annotation for associating external ConfigFile config files with servlets.
- ResourceLink.
- New org.apache.juneau.rest.matchers package for commonly-used {@link org.apache.juneau.rest.RestMatcher RestMatchers}:
  - {@link org.apache.juneau.rest.matchers#MultipartFormDataMatcher}
  - {@link org.apache.juneau.rest.matchers#UrlEncodedFormMatcher}

##### Microservice

- New juneau-microservice.jar file that encapsulates all 3 juneau jars with code necessary for creating fast and efficent jetty-powered REST microservices.
  Contains the following:
  - Jetty 8.0
  - Apache HttpClient 4.3.5
  - Apache Commons FileUpload 1.3.1
- Microservice now supports Java 6 (previously required Java 7)

### 5.2.0.0 (Dec 30, 2015)

Juno 5.2.0.0 is a major update. Major changes have been made to the microservice architecture and config INI file APIs.

##### Core

- Significant changes and enhancements to the org.apache.juneau.config API.
  - More consistent handling of comma-delimited lists of objects.
  - New methods in ConfigFile:
    - ConfigFile.getStringArray(String),ConfigFile.getStringArray(String,String[])
    - ConfigFile.getSectionAsBean(String,Class) - Instantiate a new bean with property values in the specified section..
    - ConfigFile.writeProperties(String,Object,boolean,Class[]) - Copy the properties in a config file section into properties on an existing bean or POJO.
    - ConfigFile.getSectionMap(String) - Get all the resolved values in a section.
    - ConfigFile.containsNonEmptyValue(String)
    - ConfigFile.isEncoded(String)
    - ConfigFile.addListener(ConfigFileListener) - Listen for modification events on the config file.
    - ConfigFile.merge(ConfigFile) - Merge the contents of another config file into this config file.
    - ConfigFile.getResolving(), ConfigFile.getResolving(StringVarResolver) - Return an instance of the config file that resolves string variables. Much more efficient than the previous design since the same underlying config file object is shared.
    - ConfigFile.toWritable() - Wraps the config file in a {@link org.apache.juneau.Writable} interface so that it can be serialized by the REST interface as a plain-text INI file instead of as a serialized POJO.
    - ConfigFile.getInt(String) - Now supports "M" and "K" to identify millions and thousands.
  - New methods in ConfigMgr:
    - ConfigMgr.create(), ConfigMgr.create(Reader), ConfigMgr.create(File)
    - ConfigMgr.deleteAll()
  - New methods in Section:
    - Section.setParent(ConfigFileImpl) - Used by parsers to set the config file for this section.
    - Section.setName(String) - Used by parsers to set the name for this section.
  - New interfaces:
    - org.apache.juneau.config.ConfigFileListener
    - org.apache.juneau.config.SectionListener
    - org.apache.juneau.config.EntryListener
  - org.apache.juneau.config.Encoder methods have access to field names to use them as salt values.
  - The name of the default section is now "default". Before it was just null.
  - org.apache.juneau.config.XorEncoder XOR key can be overridden through the "org.apache.juneau.config.XorEncoder.key" system property.
- Support for converting Strings to POJOs if the POJO class has any of the following static methods:
  - fromString(String)
  - valueOf(String) (e.g. enums)
  - parse(String) (e.g. logging Level class)
  - parseString(String)
  - forName(String) (e.g. Class and Charset classes)
- Support for parsing into objects with unbound type variables. For example, if you have a class Pair<S,T> and you try to parse into this class (e.g. parser.parse(in, Pair.class)), the unbound type variables is interpreted as Object instead of throwing an exception.
- Support for serializing/parsing the following new types:
  - AtomicInteger
  - AtomicLong
  - BigInteger
  - BigDecimal
- Parsers have been enhanced to allow parent POJOs and field names to be passed into child POJOs. New {@link org.apache.juneau.annotation.NameProperty @NameProperty} and {@link org.apache.juneau.annotation.ParentProperty @ParentProperty} annotations are provided for identifying methods for setting names and parent POJOs on child POJOs. For example, the config file Section class represents a section in a config file. It needs to know it's own name and have a link to the ConfigFile that it belongs to. With these new annotations, config files can be reconstructed using any of the parsers.
- New classes and interfaces:
  - {@link org.apache.juneau.Streamable} interface for identifying objects that can be serialized directly to an output stream.
  - {@link org.apache.juneau.Writable} interface for identifying objects that can be serialized directly to a writer.
  - StringObject class that can be used for delayed object serialization.
  - ByteArrayCache
  - {@link org.apache.juneau.internal.ByteArrayInOutStream}
  - {@link org.apache.juneau.internal.FileUtils}
  - {@link org.apache.juneau.internal.ThrowableUtils}
  - StringVarMultipart
  - StringVarWithDefault
- New fields on {@link org.apache.juneau.ObjectList}:
  - {@link org.apache.juneau.ObjectList#EMPTY_LIST}
- New fields and methods on {@link org.apache.juneau.ObjectMap}:
  - {@link org.apache.juneau.ObjectMap#EMPTY_MAP}
  - {@link org.apache.juneau.ObjectMap#getStringArray(String)}
  - {@link org.apache.juneau.ObjectMap#getStringArray(String,String[])}
  - {@link org.apache.juneau.ObjectMap#putIfNull(String,Object)}
  - {@link org.apache.juneau.ObjectMap#putIfEmpty(String,Object)}
- New methods in {@link org.apache.juneau.internal.ArrayUtils}:
  - {@link org.apache.juneau.internal.ArrayUtils#contains(Object,Object[])}
  - {@link org.apache.juneau.internal.ArrayUtils#indexOf(Object,Object[])}
  - {@link org.apache.juneau.internal.ArrayUtils#toPrimitiveArray(Object)}
- New methods in {@link org.apache.juneau.internal.IOUtils}:
  - IOUtils.pipe(Reader,Writer)
  - {@link org.apache.juneau.internal.IOUtils#read(File)}
  - {@link org.apache.juneau.internal.IOUtils#readFile(String)}
  - {@link org.apache.juneau.internal.IOUtils#write(File,Reader)}
- New methods on {@link org.apache.juneau.utils.PojoRest}:
  - PojoRest.get(Class,String,Object)
  - {@link org.apache.juneau.utils.PojoRest#getString(String)}
  - {@link org.apache.juneau.utils.PojoRest#getString(String,String)}
  - {@link org.apache.juneau.utils.PojoRest#getInt(String)}
  - {@link org.apache.juneau.utils.PojoRest#getInt(String,Integer)}
  - {@link org.apache.juneau.utils.PojoRest#getLong(String)}
  - {@link org.apache.juneau.utils.PojoRest#getLong(String,Long)}
  - {@link org.apache.juneau.utils.PojoRest#getBoolean(String)}
  - {@link org.apache.juneau.utils.PojoRest#getBoolean(String,Boolean)}
  - {@link org.apache.juneau.utils.PojoRest#getMap(String)}
  - {@link org.apache.juneau.utils.PojoRest#getMap(String,Map)}
  - {@link org.apache.juneau.utils.PojoRest#getList(String)}
  - {@link org.apache.juneau.utils.PojoRest#getList(String,List)}
  - {@link org.apache.juneau.utils.PojoRest#getObjectMap(String)}
  - {@link org.apache.juneau.utils.PojoRest#getObjectMap(String,ObjectMap)}
  - {@link org.apache.juneau.utils.PojoRest#getObjectList(String)}
  - {@link org.apache.juneau.utils.PojoRest#getObjectList(String,ObjectList)}
- New methods on {@link org.apache.juneau.utils.ProcBuilder}:
  - {@link org.apache.juneau.utils.ProcBuilder#pipeTo(Writer,boolean)}
  - {@link org.apache.juneau.utils.ProcBuilder#pipeTo(Writer)}
  - {@link org.apache.juneau.utils.ProcBuilder#logTo(Writer,boolean)}
  - {@link org.apache.juneau.utils.ProcBuilder#logTo(Writer)}
  - {@link org.apache.juneau.utils.ProcBuilder#logTo(Level,Logger)}
  - {@link org.apache.juneau.utils.ProcBuilder#maxExitStatus(int)}
- New methods on {@link org.apache.juneau.internal.StringUtils}:
  - {@link org.apache.juneau.internal.StringUtils#isEmpty(Object)}
  - {@link org.apache.juneau.internal.StringUtils#nullIfEmpty(String)}
  - {@link org.apache.juneau.internal.StringUtils#base64EncodeToString(String)}
  - {@link org.apache.juneau.internal.StringUtils#base64Encode(byte[])}
  - {@link org.apache.juneau.internal.StringUtils#base64DecodeToString(String)}
  - {@link org.apache.juneau.internal.StringUtils#base64Decode(String)}
  - {@link org.apache.juneau.internal.StringUtils#generateUUID(int)}
  - {@link org.apache.juneau.internal.StringUtils#trim(String)}
  - StringUtils.parseISO8601Date(String)
  - {@link org.apache.juneau.internal.StringUtils#replaceVars(String,Map)}
  - {@link org.apache.juneau.internal.StringUtils#pathStartsWith(String,String)}
  - {@link org.apache.juneau.internal.StringUtils#pathStartsWith(String,String[])}
- New StringVar.doResolve(String) method.
- New StringVarResolver.DEFAULT field.
- Eliminated dependency on javax.mail.internet.MimeUtility by implementing our own {@link org.apache.juneau.internal.StringUtils#base64Encode(byte[])} method.
- {@link org.apache.juneau.transforms.CalendarSwap} and {@link org.apache.juneau.transforms.DateSwap} classes now handle blank input better. Returns null instead of throwing an exception.
- {@link org.apache.juneau.html.HtmlDocSerializer} specifies the default CSS location as /servletPath/style.css instead of /servletPath/htdocs/juneau.css. This coincides with enhancements made in the server code for specifying styles.
- {@link org.apache.juneau.html.HtmlDocSerializer} wraps output in two div tags instead of one (e.g. <div class='outerdata'><div class='data' id='data'>...</div></div>). Needed for supporting the new devops look-and-feel.
- Fixed indentation inconsistencies in {@link org.apache.juneau.html.HtmlDocSerializer}.
- Renamed HtmlSchemaSerializer to HtmlSchemaDocSerializer.
- RDF serializers and parsers now support RdfProperties.RDF_looseCollection loose collections.
- RDF parser handles case where resources point to themselves (an unfortunate behavior in JFS RDF documents).
- JSON parser with throw an exception in strict mode if it encounters numbers that are valid in Java but invalid in JSON (e.g. octal, hexadecimal numbers).
- {@link org.apache.juneau.parser.Parser} methods now check for null input.
- {@link org.apache.juneau.serializer.SerializerGroup} and {@link org.apache.juneau.parser.ParserGroup} ignores serializers and parsers if they throw NoClassDefFoundErrors.
- {@link org.apache.juneau.urlencoding.UrlEncodingParser} creates lists if the same attribute name is encountered more than once. Before it would just replace the previous value with the new value.
- New UrlEncodingSerializer.DEFAULT_SIMPLE_EXPANDED serializer.
- Changes to {@link org.apache.juneau.utils.Args}:
  - getMainArg(int) changed to {@link org.apache.juneau.utils.Args#getArg(int)}. Non-existent arguments are returned as null instead of blank strings. This is more inline with the behavior of the rest of the library.
  - New {@link org.apache.juneau.utils.Args#hasArg(int)} method.
- Removed org.apache.juneau.utils.CharsetUtils class.
- Removed org.apache.juneau.utils.ConcurrentIdentityList class.
- Fixed bug in {@link org.apache.juneau.internal.MultiIterable} class.
- {@link org.apache.juneau.utils.PojoIntrospector} must now be instantiated with a ReaderParser. Simplifies the API on the class.
- {@link org.apache.juneau.utils.PojoRest} must now be instantiated with a ReaderParser. Simplifies the API on the class.
- {@link org.apache.juneau.utils.MessageBundle} and SafeResourceMultiBundle moved from server component.
- Several bug fixes and performance improvements in StringVarResolver.
- Various enhancements to {@link org.apache.juneau.internal.TeeWriter} and {@link org.apache.juneau.internal.TeeOutputStream}.
- Renamed CharSet to {@link org.apache.juneau.internal.AsciiSet}.
- {@link org.apache.juneau.serializer.SerializerGroup} and {@link org.apache.juneau.parser.ParserGroup} now ignores NoClassDefFoundErrors so that resources that include Jena support can continue to operate even if the Jena libraries are not present.
- New {@link org.apache.juneau.internal.FileUtils#createTempFile(String)} method.
- New {@link org.apache.juneau.utils.PojoQuery} modified to handle bean getters that throw exceptions.

##### Client

- Upgraded to use Apache HttpClient 4.5.
- New classes:
  - {@link org.apache.juneau.rest.client.AllowAllRedirects}
  - {@link org.apache.juneau.rest.client.HttpMethod}
  - {@link org.apache.juneau.rest.client.ResponsePattern}
  - {@link org.apache.juneau.rest.client.SimpleX509TrustManager}
  - SSLOpts
- Removed org.apache.juneau.rest.client.LaxRedirectStrategy. Use HTTP Client equivalent.
- New methods on {@link org.apache.juneau.rest.client.RestCall}:
  - RestCall#addInterceptor(RestCallInterceptor)
  - {@link org.apache.juneau.rest.client.RestCall#pipeTo(Writer)}
  - {@link org.apache.juneau.rest.client.RestCall#pipeTo(Writer,boolean)}
  - {@link org.apache.juneau.rest.client.RestCall#pipeTo(String,Writer,boolean)}
  - {@link org.apache.juneau.rest.client.RestCall#getWriter(String)}
  - {@link org.apache.juneau.rest.client.RestCall#pipeTo(OutputStream)}
  - {@link org.apache.juneau.rest.client.RestCall#pipeTo(OutputStream,boolean)}
  - {@link org.apache.juneau.rest.client.RestCall#pipeTo(String,OutputStream,boolean)}
  - {@link org.apache.juneau.rest.client.RestCall#getOutputStream(String)}
  - {@link org.apache.juneau.rest.client.RestCall#byLines()}
  - {@link org.apache.juneau.rest.client.RestCall#captureResponse()}
  - {@link org.apache.juneau.rest.client.RestCall#successPattern(String)}
  - {@link org.apache.juneau.rest.client.RestCall#failurePattern(String)}
  - RestCall#addResponsePattern(ResponsePattern)
  - {@link org.apache.juneau.rest.client.RestCall#run()} - Renamed from execute().
  - {@link org.apache.juneau.rest.client.RestCall#getCapturedResponse()}
  - {@link org.apache.juneau.rest.client.RestCall#getResponsePojoRest(Class)}
  - {@link org.apache.juneau.rest.client.RestCall#getResponsePojoRest()}
  - {@link org.apache.juneau.rest.client.RestCall#logTo(Level,Logger)}
  - {@link org.apache.juneau.rest.client.RestCall#setConfig(RequestConfig)}
- New lifecycle listener methods on {@link org.apache.juneau.rest.client.RestCallInterceptor}:
  - {@link org.apache.juneau.rest.client.RestCallInterceptor#onInit(RestCall)}
  - {@link org.apache.juneau.rest.client.RestCallInterceptor#onClose(RestCall)}
- New methods on {@link org.apache.juneau.rest.client.RestClient}:
  - RestClient.setBasicAuth(String,int,String,String)
  - RestClient.logTo(Level,Logger)
  - RestClient.setRootUrl(String)
  - RestClient.enableSSL(SSLOpts)
  - RestClient.enableLaxSSL()
  - {@link org.apache.juneau.rest.client.RestClient#doCall(HttpMethod,Object,Object)}
  - RestClient.createHttpClientBuilder()
- New passthrough methods on {@link org.apache.juneau.rest.client.RestClient} defined on HttpClientBuilder:
  - RestClient.setRedirectStrategy(RedirectStrategy)
  - RestClient.setDefaultCookieSpecRegistry(Lookup)
  - RestClient.setRequestExecutor(HttpRequestExecutor)
  - RestClient.setSSLHostnameVerifier(HostnameVerifier)
  - RestClient.setPublicSuffixMatcher(PublicSuffixMatcher)
  - RestClient.setSSLContext(SSLContext)
  - RestClient.setSSLSocketFactory(LayeredConnectionSocketFactory)
  - RestClient.setMaxConnTotal(int)
  - RestClient.setMaxConnPerRoute(int)
  - RestClient.setDefaultSocketConfig(SocketConfig)
  - RestClient.setDefaultConnectionConfig(ConnectionConfig)
  - RestClient.setConnectionTimeToLive(long,TimeUnit)
  - RestClient.setConnectionManager(HttpClientConnectionManager)
  - RestClient.setConnectionManagerShared(boolean)
  - RestClient.setConnectionReuseStrategy(ConnectionReuseStrategy)
  - RestClient.setKeepAliveStrategy(ConnectionKeepAliveStrategy)
  - RestClient.setTargetAuthenticationStrategy(AuthenticationStrategy)
  - RestClient.setProxyAuthenticationStrategy(AuthenticationStrategy)
  - RestClient.setUserTokenHandler(UserTokenHandler)
  - RestClient.disableConnectionState()
  - RestClient.setSchemePortResolver(SchemePortResolver)
  - RestClient.setUserAgent(String userAgent)
  - RestClient.setDefaultHeaders(Collection)
  - RestClient.addInterceptorFirst(HttpResponseInterceptor)
  - RestClient.addInterceptorLast(HttpResponseInterceptor)
  - RestClient.addInterceptorFirst(HttpRequestInterceptor)
  - RestClient.addInterceptorLast(HttpRequestInterceptor)
  - RestClient.disableCookieManagement()
  - RestClient.disableContentCompression()
  - RestClient.disableAuthCaching()
  - RestClient.setHttpProcessor(HttpProcessor)
  - RestClient.setRetryHandler(HttpRequestRetryHandler)
  - RestClient.disableAutomaticRetries()
  - RestClient.setProxy(HttpHost)
  - RestClient.setRoutePlanner(HttpRoutePlanner)
  - RestClient.disableRedirectHandling()
  - RestClient.setConnectionBackoffStrategy(ConnectionBackoffStrategy)
  - RestClient.setBackoffManager(BackoffManager)
  - RestClient.setServiceUnavailableRetryStrategy(ServiceUnavailableRetryStrategy)
  - RestClient.setDefaultCookieStore(CookieStore)
  - RestClient.setDefaultCredentialsProvider(CredentialsProvider)
  - RestClient.setDefaultAuthSchemeRegistry(Lookup)
  - RestClient.setContentDecoderRegistry(Map)
  - RestClient.setDefaultRequestConfig(RequestConfig)
  - RestClient.useSystemProperties()
  - RestClient.evictExpiredConnections()
  - RestClient.evictIdleConnections(long,TimeUnit)
- JazzRestClient now supports OIDC authentication.
- These classes are now deprecated and will be removed in a future release:
  - org.apache.juneau.rest.client.jazz.CertificateStore
  - org.apache.juneau.rest.client.jazz.ICertificateValidator
  - org.apache.juneau.rest.client.jazz.ITrustStoreProvider
  - org.apache.juneau.rest.client.jazz.LenientCertificateValidator
  - org.apache.juneau.rest.client.jazz.SharedTrustStoreProvider
  - org.apache.juneau.rest.client.jazz.ValidatingX509TrustManager

##### Server

- New ReaderResource class. Represents the contents of a text file with convenience methods for resolving StringVar variables and adding HTTP response headers. REST Java methods can return instances of these to serialize Readers containing text with StringVarResolver variables in them.
- New StreamResource class. REST Java methods can return instances of these to serialize OutputStreams.
- Fixed a bug in the stack trace hash algorithm in {@link org.apache.juneau.rest.RestException}.
- New methods in {@link org.apache.juneau.rest.RestRequest}:
  - RestRequest.getReaderResource(String) - Replaces getVarResource(String).
  - RestRequest.getReaderResource(String,boolean)
  - RestRequest.getReaderResource(String,boolean,String)
- Changes in {@link org.apache.juneau.rest.RestResponse}:
  - Don't set Content-Encoding: identity when no encoding is used. Some clients don't interpret it correctly.
- New methods in {@link org.apache.juneau.rest.RestServlet}:
  - RestServlet.getChildClasses() - Programmatic equivalent to @RestResource(children) annotation.
  - RestServlet.shouldLog(HttpServletRequest,HttpServletResponse,RestException)
  - RestServlet.shouldLogStackTrace(HttpServletRequest,HttpServletResponse,RestException)
  - RestServlet.logObjects(Level,String,Object[])
  - RestServlet.resolveStaticFile(String)
  - RestServlet.createStyleSheet()
  - RestServlet.createFavIcon()
  - RestServlet.createStaticFilesMap()
  - RestServlet.getConfigMgr()
- Removed {@link org.apache.juneau.jso.JsoParser} from {@link org.apache.juneau.rest.BasicRestServlet} and RestServletJenaDefault. These may represent a security risk if not handled correctly, so removed them as a precaution.
- Removed RestServletProperties.REST_htDocsFolder. Replaced with @RestResource(staticFiles)}.
- New annotations on @RestResource.
  - RestResource.stylesheet()
  - RestResource.favicon()
  - @RestResource(staticFiles)
- Eliminated org.apache.juneau.rest.jaxrs.JsonProvider class. Some JAX-RS implementations use code scanning to find providers, so if you were using DefaultJenaProvider, it would pick up JsonProvider as well. It's easy enough to create your own implementation if needed.
- OPTIONS pages now specify consumes and produces fields instead of accept and contentType which was confusing.
- Eliminated properties from OPTIONS pages.
- New ResourceLink.ResourceLink(String,RestRequest,String,Object[]) constructor.
- New response handlers:
  - StreamableHandler - Allows REST Java methods to return instances of {@link org.apache.juneau.Streamable}.
  - WritableHandler - Allows REST Java methods to return instances of {@link org.apache.juneau.Writable}.
- New DevOps stylesheet.
- Servlet initialization and HTTP requests are now logged at FINE level.
- Added abstract modifier on various RestServlet subclasses to indicate that they're meant to be subclassed.
- New RestUtils.trimPathInfo(StringBuffer,String,String) method.

##### Microservice

- Completely revamped API.
- New {@link org.apache.juneau.microservice.Microservice} class that serves as a generic interface for microservices and their lifecycles.
- New RestMicroservice class that implements a microservice consisting of a REST interface.
  - REST resources and configuration settings can be defined through either manifest files or config files.
  - Enhanced logging support.
  - Easy-to-configure SSL support.
  - BASIC auth support.
  - Automatic restartability if the config file changes.
- Eliminated org.apache.juneau.microservice.Main class. This is replaced by the microservice classes defined above.
- Resource and ResourceGroup classes now support the following new string variables:
  - "$A{key,default}"" - Command line arguments.
  - "$MF{key,default}"" - Manifest file entries.
- CSS stylesheet now configurable through config file entry "REST/stylesheet".
- New BasicRestServletJena class if you want your REST interface to support RDF.
- Eliminated the following classes:
  - org.apache.juneau.microservice.RootResource
  - org.apache.juneau.microservice.SampleResource
- New predefined reusable resources:
  - {@link org.apache.juneau.microservice.resources.ConfigResource} - REST resource for viewing and editing microservice config file.
  - {@link org.apache.juneau.microservice.resources.LogsResource} - REST resource for viewing log files.
  - {@link org.apache.juneau.microservice.resources.SampleRootResource} - Sample REST resource that contains the config and logs resource as children.
  - {@link org.apache.juneau.microservice.resources.ShutdownResource} - REST resource for stopping the microservice JVM. Useful for testing purposes.

##### Samples

- Converted to a REST microservice.
- Look-and-feel changed to IBM DevOps.

##### Documentation Updates

- org.apache.juneau.microservice - New package-level javadoc.
- org.apache.juneau.config - New package-level javadoc.
- StringVarResolver - New documentation.
- org.apache.juneau.rest.client - New package-level javadoc.
- Overview / Samples - New section.
- org.apache.juneau.transform / Stop Classes - New section.
- org.apache.juneau.rest - Extensive updates.

### 5.2.0.1 (Mar 23, 2016)

Juno 5.2.0.1 is a moderate update.

##### com.ibm.team.juno

- Improved support for multi-line values in config files. Any line that begins with whitespace is interpreted as a continuation of the previous line.
- Support for '\uXXXX' character sequences in config files.
- Fixed issue in {@link org.apache.juneau.xml.XmlSerializer} where '\r' and '\n' characters were not being handled per XML specs.
- New methods on {@link org.apache.juneau.ObjectList}:
  - ObjectList.getAt(Class,String)
  - {@link org.apache.juneau.ObjectList#putAt(String,Object)}
  - {@link org.apache.juneau.ObjectList#postAt(String,Object)}
  - {@link org.apache.juneau.ObjectList#deleteAt(String)}
- New methods on {@link org.apache.juneau.ObjectMap}:
  - ObjectMap.getAt(Class,String)
  - {@link org.apache.juneau.ObjectMap#putAt(String,Object)}
  - {@link org.apache.juneau.ObjectMap#postAt(String,Object)}
  - {@link org.apache.juneau.ObjectMap#deleteAt(String)}
- @ThreadSafe annotation.
- New ClassFilter class.
- ConfigFile.getResolving(StringVarResolver,boolean) method.
- ConfigFile.getStringVar() method.
- New ParserContext.PARSER_trimStrings property.
- New SerializerContext.SERIALIZER_trimStrings property.
- Args.getStringVar()} method.
- New {@link org.apache.juneau.utils.ManifestFile} class
- New {@link org.apache.juneau.utils.MessageBundle} class. Replaces SafeResourceBundle/SafeResourceMultiBundle/RestNls.
- New StringMapVar class.
- New StringVars class with reusable common StringVar instances.
- New {@link org.apache.juneau.internal.JuneauLogger} class.
- Default value for XmlParserContext.XML_trimWhitespace changed to true.

##### Server

- New methods on {@link org.apache.juneau.rest.RestContext}:
  - {@link org.apache.juneau.rest.RestContext#getMessages()}

##### Client

- Fixed potential issue in {@link org.apache.juneau.rest.client.RestClient} where the HTTP connection pool could end up exhausted if an error occurred.
- Improved thread safety on {@link org.apache.juneau.rest.client.RestClient}.
- New warning message is logged if a {@link org.apache.juneau.rest.client.RestClient} is garbage collected without being closed: "WARNING: RestClient garbage collected before it was finalized."

### 6.0.0 (Oct 3, 2016)

Juneau 6.0.0 is a major update.

The major change is rebranding from "Juno" to "Juneau" in preparation for donation to the Apache Foundation.

##### org.apache.juneau

- Major changes around how serializer and parser class properties are defined to improve performance and concurrency.
  - New {@link org.apache.juneau.PropertyStore} class - Used for creating context objects.
  - New {@link org.apache.juneau.Context} class - Read-only configurations for serializers and parsers.
  - New {@link org.apache.juneau.Session} class - One-time use objects used by serializers and parsers.
  - All context context properties can now also be specified via system properties.
- Refactored serializer and parser APIs for more consistency between stream-based and character-based serializers and parsers.
  - More consistent handling of exceptions.
  - More consistent method declarations.
- Refactored var resolver API and added them to a new package - org.apache.juneau.svl.
  - Support for stream-based variables - {@link org.apache.juneau.svl.StreamedVar}.
  - Added support for context and session objects.
- Eliminated "_class" properties and replaced them with "_type" properties. The class properties were a little-used feature where we would serialize fully-qualified class names when the class type could not be inferred through reflection. It's been replaced with bean type names and bean dictionaries. Instead of class names, we serialize "_type" properties whose name is the type name defined on the bean being serialized. The parsers use a 'dictionary' of bean classes to resolve those names to actual bean classes. The following features were added to enable this support:
  - {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)} - Annotation that defines an identifying name for a bean class.
  - {@link org.apache.juneau.transform.BeanFilterBuilder#typeName(String)} - Programmatic equivalent to annotation above.
  - {@link org.apache.juneau.BeanContext#BEAN_beanDictionary} - List of bean classes that make up the bean dictionary for lookup during parsing.
  - {@link org.apache.juneau.BeanContext#BEAN_beanTypePropertyName} - The overridable type property name. Default is "_type".
  - @BeanProperty(beanDictionary) - Define a type dictionary for a particular bean property value. This overrides the value specified using {@link org.apache.juneau.BeanContext#BEAN_beanDictionary}.
  - SerializerContext.SERIALIZER_addBeanTypeProperties - Controls whether type properties are serialized.
  In addition, the {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)} value replaces the @Xml(name) annotation, and the "type" and "_class" attributes in the XML and HTML serializers have been standardized on a single "_type" attribute.
- Refactor bean filter support to use {@link org.apache.juneau.transform.BeanFilterBuilder} class. Allows the BeanFilter class to use final fields.
- {@link org.apache.juneau.msgpack MessagePack} support.
- Serializers can now serialize directly to {@link java.io.File Files}. See {@link org.apache.juneau.serializer.Serializer#serialize(Object,Object)}
- Parsers can now parse directly from {@link java.io.File Files} and other types. See {@link org.apache.juneau.parser.Parser#parse(Object,ClassMeta)}
- Parsers will automatically covert numeric input to POJOs that have numeric constructors (e.g. java.util.Date).
- Renamed 'Filters' to 'BeanFilters' and 'PojoSwaps'. Filters is just too overloaded a term.
- Internal utility classes moved to a new org.apache.juneau.internal package. These internal utility classes are not meant for consumption outside the Juneau codebase.
- New methods on {@link org.apache.juneau.parser.Parser}:
  - org.apache.juneau.parser.Parser.createSession(ObjectMap,Method,Object)
  - Parser.getMediaRanges()
- New methods on {@link org.apache.juneau.serializer.Serializer}:
  - org.apache.juneau.serializer.Serializer.createSession(ObjectMap,Method)
  - Serializer.getMediaRanges()
- New {@link org.apache.juneau.annotation.Bean#sort() @Bean(sort)} annotation.
- Added @Bean.properties annotations on various DTO beans to make the ordering consistent between IBM and Oracle JVMs.
  IBM JVMs maintain the order of methods in a class, whereas Oracle JVMs do not.
- Serializers and parsers now automatically convert {@link java.lang.Class} objects to readable names via ClassUtils.getReadableClassName(Class).
- Eliminated the ClassFilter class since it's no longer needed.
- Code and concurrency improvements to {@link org.apache.juneau.serializer.SerializerGroup} and {@link org.apache.juneau.parser.ParserGroup}.
- Various enhancements to BeanContext.convertToType(Object,Class).
- New properties on {@link org.apache.juneau.html.HtmlSerializer}:
  - HtmlSerializerContext.HTML_detectLinksInStrings - Automatically detect hyperlinks in strings.
  - HtmlSerializerContext.HTML_lookForLabelParameters - Specify anchor text by appending &label=MyLabel to URL.
  - HtmlSerializerContext.HTML_labelParameter - Specify what URL parameter to use as the anchor text label.
  - HtmlSerializerContext.URI_ANCHOR option for HtmlSerializerContext.HTML_uriAnchorText.
- Removed generics from {@link org.apache.juneau.BeanPropertyMeta}.
- Introduced new classes to eliminate the references to language-specific metadata in the core metadata classes:
  - ClassMetaExtended / ClassMeta.getExtendedMeta(Class)
  - BeanMetaExtended /BeanMeta.getExtendedMeta(Class)
  - BeanPropertyMetaExtended / BeanPropertyMeta.getExtendedMeta(Class)
- Renamed @Transform annotation to @Pojo so that it can be used for various POJO-related behavior, not just associating transforms.
- Introduced {@link org.apache.juneau.dto.swagger Swagger DTOs}.

##### org.apache.juneau.rest

- OPTIONS pages replaced with Swagger documents. Lots of changes related to supporting Swagger.
  - Annotation name changes to conform to Swagger specs: @Attr->@Path, @QParam->@Query, @Param->@FormData, @Content->@Body
  - Eliminated ResourceOptions and related code.
  - New annotations and related methods:
    - @RestResource(title) / {@link org.apache.juneau.rest.RestInfoProvider#getTitle(RestRequest)}
    - @RestResource(description) / {@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest)}
    - @RestResource(termsOfService) / RestInfoProvider.getTermsOfService(RestRequest)
    - @RestResource(contact) / RestInfoProvider.getContact(RestRequest)
    - @RestResource(license) / RestInfoProvider.getLicense(RestRequest)
    - @RestResource(version) / RestInfoProvider.getVersion(RestRequest)
    - @RestResource(tags) / RestInfoProvider.getTags(RestRequest)
    - @RestResource(externalDocs) / RestInfoProvidergetExternalDocs(RestRequest)
    - {@link org.apache.juneau.rest.annotation.RestMethod#summary() @RestMethod(summary)} / RestInfoProvider.getMethodSummary(String,RestRequest)
    - {@link org.apache.juneau.rest.annotation.RestMethod#description() @RestMethod(description)} /RestInfoProvider.getMethodDescription(String,RestRequest)
    - @RestMethod(externalDocs)
    - @RestMethod(tags)
    - @RestMethod(deprecated)
    - @RestMethod(parameters)
    - @RestMethod(responses)
- New RestServletContext.paramFormat context property.
- New/updated methods on {@link org.apache.juneau.rest.RestServlet}:
  - RestServlet.createProperties()
  - RestServlet.createBeanContext(ObjectMap,Class[],Class[])
  - RestServlet.createBeanFilters()
  - RestServlet.createPojoSwaps()
  - RestServlet.createParsers(ObjectMap,Class[],Class[])
  - RestServlet.createUrlEncodingSerializer(ObjectMap,Class[],Class[])
  - RestServlet.createUrlEncodingParser(ObjectMap,Class[],Class[])
  - RestServlet.createConverters(ObjectMap)
  - RestServlet.createDefaultRequestHeaders(ObjectMap)
  - RestServlet.createDefaultResponseHeaders(ObjectMap)
  - RestServlet.createEncoders(ObjectMap)
  - RestServlet.createGuards(ObjectMap)
  - RestServlet.createMimetypesFileTypeMap(ObjectMap)
  - RestServlet.createResponseHandlers(ObjectMap)
- New client-version annotations:
  - RestResource.clientVersionHeader - The name of the header used to identify the client version.
  - {@link org.apache.juneau.rest.annotation.RestMethod#clientVersion} - The client version range applied to a Java method.

##### org.apache.juneau.rest.client

- Removed the JazzRestClient class.
- New method RestClient.setClientVersion(String).

### 6.0.1 (Jan 3, 2017)

Juneau 6.0.1 is a minor update.

##### org.apache.juneau

- General improvements to JSON parser.
  - Several fixes to handle obscure edge cases.
- New properties in ParserContext.
  - ParserContext.PARSER_strict
  - ParserContext.PARSER_inputStreamCharset
  - ParserContext.PARSER_fileCharset
- Removed JsonParserContext.JSON_strictMode. Replaced by PARSER_strict.
- byte[] arrays can now be passed to {@link org.apache.juneau.parser.Parser#parse(Object,Class)} for reader-based parsers.

### 6.1.0 (Feb 25, 2017)

Juneau 6.1.0 is a major update.

In particular, this release cleans up the {@link org.apache.juneau.BeanContext} API to match the {@link org.apache.juneau.PropertyStore}/{@link org.apache.juneau.Context}/{@link org.apache.juneau.Session} paradigm previously used in the serializer and parser APIs. It also makes several improvements to the HTML and XML serialization support and introduces HTML5 DTO beans.

##### org.apache.juneau

- Improvements to XML serialization support.
  - New supported XML formats:
    - {@link org.apache.juneau.xml.annotation.XmlFormat#ATTRS} format can now be applied to bean classes to have all bean properties serialized as attributes instead of elements by default.
    - {@link org.apache.juneau.xml.annotation.XmlFormat#ELEMENT} format can now be applied to bean properties to override the {@link org.apache.juneau.xml.annotation.XmlFormat#ATTRS} setting above on specific bean properties.
    - New {@link org.apache.juneau.xml.annotation.XmlFormat#ELEMENTS} format can be applied to a bean property of type array/Collection to represent the child elements.
    - New {@link org.apache.juneau.xml.annotation.XmlFormat#MIXED} format can be applied to a bean property of type array/Collection to represent mixed content (text + child elements).
    - New {@link org.apache.juneau.xml.annotation.XmlFormat#MIXED_PWS} format. Identical to MIXED except preserves whitespace.
    - New {@link org.apache.juneau.xml.annotation.XmlFormat#TEXT} format can be applied to a bean property of a single object to represent a text node as a child.
    - New {@link org.apache.juneau.xml.annotation.XmlFormat#TEXT_PWS} format. Identical to TEXT except preserves whitespace.
    - New {@link org.apache.juneau.xml.annotation.XmlFormat#XMLTEXT} format that's identical to {@link org.apache.juneau.xml.annotation.XmlFormat#TEXT} except XML content is not escaped and serialized directly as the child content. The parser will reconvert this to the original XML text during parsing.
  - New support methodology and other improvements to org.apache.juneau.xml documentation.
  - Eliminated unnecessary <string> elements.
  - Eliminated XmlContentHandler class.
  - Parser efficiency improvements through reuse of string builders.
  - Reworked and simplified the default XML serializers. The {@link org.apache.juneau.xml.XmlSerializer#DEFAULT} serializer now has namespaces disabled, and {@link org.apache.juneau.xml.XmlSerializer#DEFAULT_NS} has namespaces enabled. The 'XML-JSON' serializers have been eliminated.
  - Eliminated the addJsonTypeAttrs and addJsonStringTypeAttrs settings.
  - Namespace support is now disabled by default.
- Significant modifications and improvements to HTML serialization support.
  - Parser converted from XMLEventReader-based to XMLStreamReader.
  - Eliminated many unnecessary type tags and <string> elements and improved the readable layout. The new format is much leaner.
  - New exhaustive support methodology section added to org.apache.juneau.html documentation.
- New HTML5 DTO support: org.apache.juneau.dto.html5.
- {@link org.apache.juneau.BeanContext} class split into separate {@link org.apache.juneau.BeanContext} and {@link org.apache.juneau.BeanSession} classes.
  - Session object meant to be single-use that can be discarded after use and contains session-level object cache and overridable Locale and TimeZone.
- SerializerContext and ParserContext now extend directly from {@link org.apache.juneau.BeanContext}.
- {@link org.apache.juneau.serializer.SerializerSession} and {@link org.apache.juneau.parser.ParserSession} now extend directly from {@link org.apache.juneau.BeanSession}.
- New settings in {@link org.apache.juneau.BeanContext}:
  - {@link org.apache.juneau.BeanContext#BEAN_debug} - Debug setting. Replaces individual debug properties in the serializer and parser contexts.
  - {@link org.apache.juneau.BeanContext#BEAN_locale} - Specifies a default locale at the context level.
  - {@link org.apache.juneau.BeanContext#BEAN_timeZone} - Specifies a default timezone at the context level.
  - {@link org.apache.juneau.BeanContext#BEAN_mediaType} - Specifies a default media type at the context level.
- Improvements to Parser class:
  - Simplified the parse methods (e.g. parseMap(), parseCollection()) by replacing them with two simple methods:
    - {@link org.apache.juneau.parser.Parser#parse(Object,Class)} - Normal method.
    - {@link org.apache.juneau.parser.Parser#parse(Object,Type,Type...)} - Method for parsing into parameterized maps and collections.
    Using these methods, you can construct arbitrarily complex objects consisting of maps and collections. You could do this before, but it required constructing a ClassMeta object.
    For example:

    // Old way: ClassMeta<?> cm = parser.getMapClassMeta( HashMap.class, String.class, parser.getCollectionClassMeta( LinkedList.class, MyBean.class ) ); Map<String,List<MyBean>> map = (Map<String,List<MyBean>>)parser.parse(input, cm); // New way: Map<String,List<MyBean>> map = parser.parse(input, HashMap.class, String.class, LinkedList.class, MyBean.class);

  - Arbitrarily-complex parameterized maps and collections can now be parsed without the need for creating intermediate ClassMeta objects.
  - No need for casting anymore if you were using the old parseMap() and parseCollection() methods!
  - Changes allow me to eliminate BeanContext.normalizeClassMeta() method.
  - Convenience methods added for setting parser properties:

    // Old way: new JsonParser().setProperty(PARSER_strict, true).setProperty(BEAN_locale, mylocale); // New way: new JsonParser().setStrict(true).setLocale(mylocale);

- Improvements to Serializer class:
  - Convenience methods added for setting serializer properties:

    // Old way: new JsonSerializer().setProperty(JSON_simpleMode, true).setProperty(SERIALIZER_quoteChar, '"'); // New way: new JsonSerializer().setSimpleMode(true).setQuoteChar('"');

- Simplified {@link org.apache.juneau.transform.PojoSwap} class. Now just two methods:
  - {@link org.apache.juneau.transform.PojoSwap#swap(BeanSession,Object)}
  - {@link org.apache.juneau.transform.PojoSwap#unswap(BeanSession,Object,ClassMeta)}
- General code improvements made to {@link org.apache.juneau.ClassMeta} class.
  - All fields are now final which should improve overall performance.
  - Replaced support for toObjectMap() and fromObjectMap()/T(ObjectMap) methods with generalized swap(BeanSession)/unswap(BeanSession,X)/T(BeanSession,X) methods.
    See new section Swap methods for information.
- Session-level media type now available through {@link org.apache.juneau.BeanSession#getMediaType()} method. Allows for swaps and serializer/parser behavior to be tailored to individual media types.
- Several new {@link java.util.Calendar} and {@link java.util.Date} swaps:
  - {@link org.apache.juneau.transforms.CalendarSwap.ToString},{@link org.apache.juneau.transforms.DateSwap.ToString} - To {@link java.lang.String Strings} using the {@code Date.toString()} method.
  - {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DT},{@link org.apache.juneau.transforms.DateSwap.ISO8601DT} - To ISO8601 date-time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DTZ},{@link org.apache.juneau.transforms.DateSwap.ISO8601DTZ} - Same as ISO8601DT, except always serializes in GMT.
  - {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DTP},{@link org.apache.juneau.transforms.DateSwap.ISO8601DTP} - Same as ISO8601DT except with millisecond precision.
  - {@link org.apache.juneau.transforms.CalendarSwap.ISO8601DTPZ},{@link org.apache.juneau.transforms.DateSwap.ISO8601DTPZ} - Same as ISO8601DTZ except with millisecond precision.
  - {@link org.apache.juneau.transforms.CalendarSwap.RFC2822DT},{@link org.apache.juneau.transforms.DateSwap.RFC2822DT} - To RFC2822 date-time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.RFC2822DTZ},{@link org.apache.juneau.transforms.DateSwap.RFC2822DTZ} - Same as RFC2822DT, except always serializes in GMT.
  - {@link org.apache.juneau.transforms.CalendarSwap.RFC2822D},{@link org.apache.juneau.transforms.DateSwap.RFC2822D} - To RFC2822 date strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateTimeSimple},{@link org.apache.juneau.transforms.DateSwap.DateTimeSimple} - To simple "yyyy/MM/dd HH:mm:ss" date-time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateSimple},{@link org.apache.juneau.transforms.DateSwap.DateSimple} - To simple "yyyy/MM/dd" date strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.TimeSimple},{@link org.apache.juneau.transforms.DateSwap.TimeSimple} - To simple "HH:mm:ss" time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateFull},{@link org.apache.juneau.transforms.DateSwap.DateFull} - To {@link java.text.DateFormat#FULL} date strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateLong},{@link org.apache.juneau.transforms.DateSwap.DateLong} - To {@link java.text.DateFormat#LONG} date strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateMedium},{@link org.apache.juneau.transforms.DateSwap.DateMedium} - To {@link java.text.DateFormat#MEDIUM} date strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateShort},{@link org.apache.juneau.transforms.DateSwap.DateShort} - To {@link java.text.DateFormat#SHORT} date strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.TimeFull},{@link org.apache.juneau.transforms.DateSwap.TimeFull} - To {@link java.text.DateFormat#FULL} time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.TimeLong},{@link org.apache.juneau.transforms.DateSwap.TimeLong} - To {@link java.text.DateFormat#LONG} time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.TimeMedium},{@link org.apache.juneau.transforms.DateSwap.TimeMedium} - To {@link java.text.DateFormat#MEDIUM} time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.TimeShort},{@link org.apache.juneau.transforms.DateSwap.TimeShort} - To {@link java.text.DateFormat#SHORT} time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateTimeFull},{@link org.apache.juneau.transforms.DateSwap.DateTimeFull} - To {@link java.text.DateFormat#FULL} date-time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateTimeLong},{@link org.apache.juneau.transforms.DateSwap.DateTimeLong} - To {@link java.text.DateFormat#LONG} date-time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateTimeMedium},{@link org.apache.juneau.transforms.DateSwap.DateTimeMedium} - To {@link java.text.DateFormat#MEDIUM} date-time strings.
  - {@link org.apache.juneau.transforms.CalendarSwap.DateTimeShort},{@link org.apache.juneau.transforms.DateSwap.DateTimeShort} - To {@link java.text.DateFormat#SHORT} date-time strings.
- New method {@link org.apache.juneau.serializer.SerializerGroup#getSerializerMatch(String)} that returns the matched serializer and media type.
- New method {@link org.apache.juneau.parser.ParserGroup#getParserMatch(String)} that returns the matched parser and media type.
- New method {@link org.apache.juneau.encoders.EncoderGroup#getEncoderMatch(String)} that returns the matched encoder and encoding.
- General improvements to Bean Dictionary support.
  - New {@link org.apache.juneau.BeanDictionaryList} class can be used for defining reusable sets of bean dictionaries consisting of classes annotated with {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)}.
  - New {@link org.apache.juneau.BeanDictionaryMap} class can be used for defining reusable sets of bean dictionaries consisting of classes not annotated with {@link org.apache.juneau.annotation.Bean#typeName() @Bean(typeName)}.
  - New @Bean(beanDictionary) annotation.
- Removed restriction on getters and setters to be prefixed with "getX/setX/isX" if a @BeanProperty(name) annotation is used.
- Improvements to ATOM DTO:
  - New {@link org.apache.juneau.dto.atom.AtomBuilder} class.
  - New setter method names for a better fluent design.
  - Updated org.apache.juneau.dto.atom documentation.
- New {@link org.apache.juneau.transform.MapSwap} and {@link org.apache.juneau.transform.StringSwap} classes.
- New {@link org.apache.juneau.serializer.WriterSerializer#println(Object)} method. Useful for debugging purposes.
- New {@link org.apache.juneau.BeanContext#getClassMeta(Type,Type...)} and {@link org.apache.juneau.BeanSession#getClassMeta(Type,Type...)} methods for retrieving Map and Collection class metas. Replaces the various getMapClassMeta()/getCollectionClassMeta() methods.
- New section added to this document: Juneau Data Transfer Objects (org.apache.juneau.dto)
- Modified the UON specification to work with mixed content.
  - The new specification is considerably cleaner and eliminates the need for separate normal/simple modes.
    It also allows for arbitrary whitespace to be added to the output without any confusion.
  - Eliminated the UonParser.DEFAULT_WS_AWARE and UrlEncodingParser.DEFAULT_WS_AWARE parsers.
    The normal {@link org.apache.juneau.uon.UonParser#DEFAULT} and {@link org.apache.juneau.urlencoding.UrlEncodingParser#DEFAULT} parsers will now handle whitespace.
  - Eliminated the UonParserContext.UON_whitespaceAware configuration setting.
  - Eliminated the UonSerializer.DEFAULT_SIMPLE, UonSerializer.DEFAULT_SIMPLE_ENCODING and UrlEncodingSerializer.DEFAULT_SIMPLE serializers since there is no separate simple mode anymore.
  - Eliminated the UonParserContext.UON_simpleMode configuration setting.
- Added new OutputStreamSerializer.serializeToHex(Object) method.
  Useful mostly for testing purposes.
  Equivalently, the {@link org.apache.juneau.parser.InputStreamParser#parse(Object,Class)} method can now read the output from this method.
- Eliminated the @Bean(subTypeProperty) and @Bean(subTypes) annotations and replaced them with the ability to define subtypes using the existing @Bean(beanDictionary) annotation on parent classes and interfaces.
  This has the added benefit of simplifying the overall code.
- The SerializerContext.SERIALIZER_addBeanTypeProperties setting is now enabled by default.
- Combined the SERIALIZER_addIndentation/JSON_addWhitespace/UON_addWhitespace properties into a single SerializerContext.SERIALIZER_useWhitespace setting.

##### org.apache.juneau.rest

- {@link org.apache.juneau.rest.RestRequest} now passes locale and timezone to serializers/parsers/transforms.
- RestRequest.getTimeZone() method.
- Standardized the following methods in {@link org.apache.juneau.rest.RestRequest} to remove dependency on ClassMeta objects and eliminate the need for casts:
  - RestRequest.getHeader(String,Class)
  - RestRequest.getHeader(String,Object,Class)
  - RestRequest.getHeader(String,Type,Type...)
  - RestRequest.getQueryParameter(String,Class)
  - RestRequest.getQueryParameter(String,Object,Class)
  - RestRequest.getQueryParameter(String,Type,Type...)
  - RestRequest.getQueryParameter(String,Object,Type,Type...)
  - RestRequest.getQueryParameters(String,Class)
  - RestRequest.getQueryParameters(String,Type,Type...)
  - RestRequest.getFormDataParameter(String,Class)
  - RestRequest.getFormDataParameter(String,Object,Class)
  - RestRequest.getFormDataParameters(String,Class)
  - RestRequest.getFormDataParameter(String,Type,Type...)
  - RestRequest.getFormDataParameters(String,Type,Type...)
  - RestRequest.getPathParameter(String,Class)
  - RestRequest.getPathParameter(String,Type,Type...)
  - RestRequest.getBody(Class)
  - RestRequest.getBody(Type,Type...)
- New methods on {@link org.apache.juneau.rest.client.NameValuePairs}
- Fixed issue where whitespace was not added to UON/URL-Encoding output when &plainText=true specified.

### 6.2.0 (Apr 28, 2017)

Juneau 6.2.0 is a major update.

##### org.apache.juneau

- Revamped the serializer, parser classes to use builders for creation. Serializers and parsers are now unmodifiable objects once they are created. This is a breaking code change that will require adoption.

  /* Creating a new serializer or parser */ // Old way WriterSerializer s = new JsonSerializer().setUseWhitespace(true).pojoSwaps(BSwap.class).lock(); // New way WriterSerializer s = JsonSerializer.create().ws().pojoSwaps(BSwap.class).build(); /* Cloning an existing serializer or parser */ // Old way WriterSerializer s = SimpleJsonSerializer.DEFAULT .clone().setUseWhitespace(true).pojoSwaps(BSwap.class).lock(); // New way WriterSerializer s = SimpleJsonSerializer.DEFAULT .builder().ws().pojoSwaps(BSwap.class).build();

- Also introduced the following builder classes and related architecture changes to make the built objects unmodifiable:
  - {@link org.apache.juneau.serializer.SerializerGroupBuilder}
  - {@link org.apache.juneau.parser.ParserGroupBuilder}
  - {@link org.apache.juneau.encoders.EncoderGroupBuilder}
- Revamped the config file API to use a build: ConfigFileBuilder.
- Removed the Lockable interface.
- New addBeanTypeProperties setting added to serializers to override the SerializerContext.SERIALIZER_addBeanTypeProperties setting for individual serializers in a serializer group:
  - HtmlSerializerContext.HTML_addBeanTypeProperties
  - JsonSerializerContext.JSON_addBeanTypeProperties
  - MsgPackSerializerContext.MSGPACK_addBeanTypeProperties
  - UonSerializerContext.UON_addBeanTypeProperties
  - XmlSerializerContext.#XML_addBeanTypeProperties
  - RdfSerializerContext.RDF_addBeanTypeProperties
- UON notation serializers and parsers moved into the new org.apache.juneau.uon package.
- New {@link org.apache.juneau.xml.annotation.XmlFormat#VOID} format to identify HTML void elements.
- Tweaks to HTML5 support.
  - Fixed handling of empty non-void elements in HTML serializer.
  - Added style() override methods to all elements.
- Improvements to Swagger support.
  - New {@link org.apache.juneau.dto.swagger.SwaggerBuilder} class.
  - Fluent-style setters added to the Swagger beans.
  - Added Swagger examples here and in the org.apache.juneau.dto.swagger javadocs.
- Improvements to {@link org.apache.juneau.svl.VarResolver}.
  - New {@link org.apache.juneau.svl.vars.IfVar $IF} variable for if-else block logic.
  - $SWITCH variable for switch block logic.
  - Whitespace wasn't being ignored in some cases.
- {@link org.apache.juneau.html.HtmlParser} can now parse full body contents generated by {@link org.apache.juneau.html.HtmlDocSerializer}.
- Parse-args supported added to {@link org.apache.juneau.msgpack.MsgPackParser} to allow it to be used in remoteable proxies.
- Added some convenience classes for constructing collections using a fluent interface:
  - {@link org.apache.juneau.utils.AList}
  - {@link org.apache.juneau.utils.ASet}
  - {@link org.apache.juneau.utils.AMap}
- New {@link org.apache.juneau.annotation.Bean#typePropertyName @Bean(typePropertyName)} annotation allows you to specify the name of the "_type" property at the class level.
- New methods added to HTML5 container beans:
  - {@link org.apache.juneau.dto.html5.HtmlElementContainer#getChild(int...)}
  - {@link org.apache.juneau.dto.html5.HtmlElementMixed#getChild(int...)}
- New common serializer setting: SerializerContext.SERIALIZER_abridged.
- Support for defining interface proxies against 3rd-party REST interfaces.
  New package org.apache.juneau.remoteable for all remoteable proxy interface annotations.
  @Remoteable annotation has been moved to this package.
- Updated doc: 6 - Remoteable Services
- New doc: 6.1 - Interface proxies against 3rd-party REST interfaces
- New URL-encoding serializer setting: UrlEncodingSerializerContext.URLENC_paramFormat.
- New methods on {@link org.apache.juneau.urlencoding.UrlEncodingSerializerBuilder}:
  - UrlEncodingSerializerBuilder.paramFormat(String)
  - UrlEncodingSerializerBuilder.plainTextParams()

##### org.apache.juneau.rest

- @RestResource annotation can now be applied to any class! You're no longer restricted to subclassing your resources from {@link org.apache.juneau.rest.RestServlet}.
  This is a major enhancement in the API. Anything you could do by subclassing from RestServlet should have an equivalent for non-RestServlet classes.
  The only restriction is that the top-level resource must subclass from RestServlet. Child resources do not.
  The majority of code has been split up into two separate classes:
  - RestConfig - A modifiable configuration of a resource. Subclasses from {@link javax.servlet.ServletConfig}.
  - {@link org.apache.juneau.rest.RestContext} - A read-only configuration that's the result of a snapshot of the config.
  The {@link org.apache.juneau.rest.RestServlet} class now has the following initialization method that allows you to override the config settings define via annotations:
  - RestServlet.init(RestConfig) - A modifiable configuration of a resource.
  Non-RestServlet classes must have one of the following to allow it to be instantiated:
  - A public T(RestConfig) constructor.
  - A public T() constructor.
  - The parent resource must have a customized {@link org.apache.juneau.rest.RestResourceResolver} for instantiating it.
  Non-RestServlet classes can optionally include the following init methods to gain access to the config and context:
  - public init(RestConfig)
  - public init(RestContext)
- New annotations added to @RestResource to allow non-RestServlet resources to do the same as subclassing directly from RestServlet:
  - RestResource.resourceResolver() - Specify a {@link org.apache.juneau.rest.RestResourceResolver} class for resolving child resources.
  - RestResource.callHandler() - Specify a {@link org.apache.juneau.rest.RestCallHandler} class for handling the lifecycle of a REST call.
  - RestResource.infoProvider() - Specify a {@link org.apache.juneau.rest.RestInfoProvider} class for customizing title/description/Swagger information on a REST resource.
  - RestResource.logger() - Specify a {@link org.apache.juneau.rest.RestLogger} class for handling logging.
- New annotations added to @RestResource and {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} to simplify defining page title, text, and links on HTML views:
  - @RestResource(pageTitle)
  - @RestMethod(pageTitle)
  - @RestResource(pageText)
  - @RestMethod(pageText)
  - @RestResource(pageLinks)
  - @RestMethod(pageLinks)

  // Old method @RestResource( properties={ @Property(name=HTMLDOC_title, value="System properties resource"), @Property(name=HTMLDOC_description, value="REST interface for performing CRUD operations on system properties."), @Property(name=HTMLDOC_navlinks, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}") } ) // New method @RestResource( pageTitle="System properties resource", pageDescription="REST interface for performing CRUD operations on system properties.", pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}" )

  Typically you're going to simply want to use the title and description annotations which apply to both the page title/text and the swagger doc:

  @RestResource( title="System properties resource", description="REST interface for performing CRUD operations on system properties.", pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}" )

- RestResource.stylesheet() can now take in a comma-delimited list of stylesheet paths.
- StreamResource can now contain multiple sources from a variety of source types (e.g. byte[] arrays, InputStreams, Files, etc...) and is now immutable. It also includes a new StreamResourceBuilder class.
- Simplified remoteable proxies using the @RestMethod(name="PROXY") annotation on REST methods. Used to expose interface proxies without the need for RemoteableServlet.

  // Server side @RestMethod(name="PROXY", path="/myproxy/*") public IAddressBook getProxy() { return addressBook; } // Client side RestClient client = RestClient.create().rootUrl(samplesUrl).build(); IAddressBook ab = client.getRemoteableProxy(IAddressBook.class, "/addressBook/myproxy");

  See {@link org.apache.juneau.rest.annotation.RestMethod#name() @RestMethod(name)} for more information.
- {@link org.apache.juneau.rest.RestRequest#toString()} can be called at any time to view the headers and content of the request without affecting functionality. Very useful for debugging.
- {@link org.apache.juneau.rest.annotation.RestMethod#name() @RestMethod(name)} annotation is now optional. Defaults to "GET".

##### org.apache.juneau.rest.client

- Revamped the client API to use builders.
- New doc: 1.5 - Debugging
- The RestClient class doX(Object url) methods now handle HttpClient URIBuilder instances.
- New methods added/updated to {@link org.apache.juneau.rest.client.RestClient}:
  - RestClient.getRemoteableProxy(Class,Object) - For interface proxies defined using @RestMethod(name="PROXY").
  - RestClient.getRemoteableProxy(Class,Object,Serializer,Parser) - Same as above, but overrides the serializer and parser defined on the client.
  - {@link org.apache.juneau.rest.client.RestClient#doPost(Object) doPost(Object)}
  - {@link org.apache.juneau.rest.client.RestClient#doCall(HttpMethod,Object,Object) doCall(HttpMethod,Object,Object)} - Can now pass in instances of {@link org.apache.juneau.rest.client.NameValuePairs} for easy form posts.
    This extends to all methods that take in the input.
- New methods on {@link org.apache.juneau.rest.client.RestCall}:
  - {@link org.apache.juneau.rest.client.RestCall#uri(Object) uri(Object)}
  - query(String,Object,boolean,PartSerializer)
  - {@link org.apache.juneau.rest.client.RestCall#query(String,Object) query(String,Object)}
  - {@link org.apache.juneau.rest.client.RestCall#queryIfNE(String,Object) queryIfNE(String,Object)}
  - {@link org.apache.juneau.rest.client.RestCall#query(Map) query(Map)}
  - {@link org.apache.juneau.rest.client.RestCall#queryIfNE(Map) queryIfNE(Map)}
  - {@link org.apache.juneau.rest.client.RestCall#query(String) query(String)}
  - formData(String,Object,boolean,PartSerializer)
  - {@link org.apache.juneau.rest.client.RestCall#formData(String,Object) formData(String,Object)}
  - {@link org.apache.juneau.rest.client.RestCall#formDataIfNE(String,Object) formDataIfNE(String,Object)}
  - {@link org.apache.juneau.rest.client.RestCall#formData(Map) formData(Map)}
  - {@link org.apache.juneau.rest.client.RestCall#formDataIfNE(Map) formDataIfNE(Map)}
  - header(String,Object,boolean,PartSerializer)
  - {@link org.apache.juneau.rest.client.RestCall#header(String,Object) header(String,Object)}
  - {@link org.apache.juneau.rest.client.RestCall#headerIfNE(String,Object) headerIfNE(String,Object)}
  - {@link org.apache.juneau.rest.client.RestCall#headers(Map) headers(Map)}
  - {@link org.apache.juneau.rest.client.RestCall#headersIfNE(Map) headersIfNE(Map)}
  - {@link org.apache.juneau.rest.client.RestCall#host(String) host(String)}
  - {@link org.apache.juneau.rest.client.RestCall#port(int) port(int)}
  - {@link org.apache.juneau.rest.client.RestCall#userInfo(String,String) userInfo(String,String)}
  - {@link org.apache.juneau.rest.client.RestCall#userInfo(String) userInfo(String)}
  - {@link org.apache.juneau.rest.client.RestCall#scheme(String) scheme(String)}
- New methods added to {@link org.apache.juneau.rest.client.RestClientBuilder}:
  - {@link org.apache.juneau.rest.client.RestClientBuilder#executorService(ExecutorService,boolean) executorService(ExecutorService,boolean)}
  - {@link org.apache.juneau.rest.client.RestClientBuilder#paramFormat(String) paramFormat(ExecutorService,boolean)}
  - RestClientBuilder.plainTextParams()
  - {@link org.apache.juneau.rest.client.RestClientBuilder#noTrace() noTrace()} - Adds a No-Trace: true header on all requests to prevent the servlet from logging errors.
    Useful for testing scenarios when you don't want the console to end up showing errors done on purpose.
  - {@link org.apache.juneau.rest.client.RestClientBuilder#debug() debug()} now adds a Debug: true header on all requests.
- New methods added/updated to {@link org.apache.juneau.rest.client.RestCall}:
  - {@link org.apache.juneau.rest.client.RestCall#runFuture() runFuture()}
  - {@link org.apache.juneau.rest.client.RestCall#getResponseFuture(Class) getResponseFuture(Class)}
  - {@link org.apache.juneau.rest.client.RestCall#getResponseFuture(Type,Type...) getResponseFuture(Type,Type...)}
  - {@link org.apache.juneau.rest.client.RestCall#getResponseAsStringFuture() getResponseAsStringFuture()}
  - {@link org.apache.juneau.rest.client.RestCall#serializer(Serializer) serializer(Serializer)} - Override the serializer defined on the client for a single call.
  - {@link org.apache.juneau.rest.client.RestCall#parser(Parser) parser(Parser)} - Override the parser defined on the client for a single call.
  - input(Object) - Now accepts instances of {@link org.apache.juneau.rest.client.NameValuePairs}.
  - {@link org.apache.juneau.rest.client.RestCall#getResponse(Class) getResponse(Class)} - Can now pass in any of the following:
    - {@link org.apache.http.HttpResponse} - Returns the raw HttpResponse returned by the inner HttpClient.
    - {@link java.io.Reader} - Returns access to the raw reader of the response.
    - {@link java.io.InputStream} - Returns access to the raw input stream of the response.
- New methods added to {@link org.apache.juneau.rest.client.NameValuePairs}:
  - {@link org.apache.juneau.rest.client.NameValuePairs#append(String,Object) append(String,Object)}
  - append(String,Object,PartSerializer)
- {@link org.apache.juneau.rest.client.RetryOn} is now an abstract class with an additional method:
  - {@link org.apache.juneau.rest.client.RetryOn#onResponse(HttpResponse) onResponse(HttpResponse)}

##### org.apache.juneau.microservice

- "REST/port" configuration setting can now be a comma-limited list of port numbers to try.
  You can also specify one or more 0s to try a random port.
- Methods added to RestMicroservice class:
  - getPort()
  - getURI()
  - Override methods added from {@link org.apache.juneau.microservice.Microservice} class for easier method chaining.

### 6.3.0 (Jun 30, 2017)

Juneau 6.3.0 is a major update with significant new functionality for defining proxy interfaces against arbitrary 3rd-party REST interfaces.

##### org.apache.juneau

- New package: {@link org.apache.juneau.http}.
- Support for dynamic beans. See @BeanProperty(name).
- New doc: 2.8 - Virtual Beans
- New doc: 2.13 - Comparison with Jackson
- All parsers now allow for numeric types with 'K'/'M'/'G' suffixes to represent kilobytes, megabytes, and gigabytes.

  // Example int i = JsonParser.DEFAULT.parse("123M"); // 123MB

- New/modified methods on ConfigFile:
  - ConfigFile.put(String,String,String,boolean)
  - ConfigFile.put(String,String,Object,Serializer,boolean,boolean)
  - ConfigFile.getObject(String,Type,Type...)
  - ConfigFile.getObject(String,Parser,Type,Type...)
  - ConfigFile.getObject(String,Class)
  - ConfigFile.getObject(String,Parser,Class)
  - ConfigFile.getObject(String,String,Type,Type...)
  - ConfigFile.getObject(String,String,Parser,Type,Type...)
  - ConfigFile.getObject(String,String,Class)
  - ConfigFile.getObject(String,String,Parser,Class)
  - ConfigFile.getObjectWithDefault(String,Object,Type,Type...)
  - ConfigFile.getObjectWithDefault(String,Parser,Object,Type,Type...)
  - ConfigFile.getObjectWithDefault(String,Object,Class)
  - ConfigFile.getObjectWithDefault(String,Parser,Object,Class)
- New ability to interact with config file sections with proxy interfaces with new method ConfigFile.getSectionAsInterface(String,Class).
- @BeanProperty annotation can now be applied to getters and setters defined on interfaces.
- New methods on {@link org.apache.juneau.serializer.SerializerSession} and {@link org.apache.juneau.parser.ParserSession} for retrieving context and runtime-override properties:
  - Session.getProperty(String)
  - Session.getProperty(String,String)
  - Session.getProperty(Class,String)
  - Session.getProperty(Class,String,Object)
- New org.apache.juneau.serializer.PartSerializer interface particularly tailored to HTTP headers, query parameters, form-data parameters, and path variables.
  Allows easy user-defined serialization of these objects.
  The interface can be used in the following locations:
  - org.apache.juneau.rest.client.RestClientBuilder.partSerializer(Class)
  - org.apache.juneau.remoteable.Path.serializer
  - org.apache.juneau.remoteable.Query.serializer
  - org.apache.juneau.remoteable.QueryIfNE.serializer
  - org.apache.juneau.remoteable.FormData.serializer
  - org.apache.juneau.remoteable.FormDataIfNE.serializer
  - org.apache.juneau.remoteable.Header.serializer
  - org.apache.juneau.remoteable.HeaderIfNE.serializer
- Across-the-board improvements to the URI-resolution support (i.e. how URIs get serialized).
  - New support for resolving URIs with the following newly-recognized protocols:
    - "context:/..." - Relative to context-root of the application.
    - "servlet:/..." - Relative to the servlet URI.
    - "request:/..." - Relative to the request URI.
    For example, currently we define HTML page links using variables and servlet-relative URIs...

    pages="{up:'$R{requestParentURI}', options:'?method=OPTIONS', upload:'upload'}"

    With these new protocols, we can define them like so:

    links="{top:'context:/', up:'request:/..' ,options:'servlet:/?method=OPTIONS', upload:'servlet:/upload'}"

    The old method of using variables and servlet-relative URIs will still be supported, but using these new protocols should (hopefully) be easier to understand.
    These protocols work on all serialized URL and URI objects, as well as classes and properties annotated with {@link org.apache.juneau.annotation.URI @URI}.
  - New classes:
    - {@link org.apache.juneau.UriContext}
    - {@link org.apache.juneau.UriRelativity}
    - {@link org.apache.juneau.UriResolution}
    - {@link org.apache.juneau.UriResolver}
  - New configuration properties:
  - SerializerContext.SERIALIZER_uriContext
  - SerializerContext.SERIALIZER_uriRelativity
  - SerializerContext.SERIALIZER_uriResolution
  - SerializerContext.SERIALIZER_maxIndent
- New annotation property: @BeanProperty(value).
  The following two annotations are considered equivalent:

  @BeanProperty(name="foo") @BeanProperty("foo")

- Fixed a race condition in ClassMeta.
- URLENC_paramFormat has been moved to UonSerializer.UON_paramFormat, and the UON/URL-Encoding serializers will now always serialize all values as plain text.
  This means that arrays and maps are converted to simple comma-delimited lists.
- Listener APIs added to serializers and parsers:
  - {@link org.apache.juneau.serializer.SerializerListener}
  - {@link org.apache.juneau.serializer.SerializerBuilder#listener(Class)}
  - @RestResource(serializerListener)
  - RestConfig.serializerListener(Class)
  - {@link org.apache.juneau.parser.ParserListener}
  - {@link org.apache.juneau.parser.ParserBuilder#listener(Class)}
  - @RestResource(parserListener)
  - RestConfig.parserListener(Class)
  - RestClientBuilder.listeners(Class,Class)
  juneau-examples-core.import1.pngjuneau-examples-core.import1.png
- The {@link org.apache.juneau.BeanContext#BEAN_debug} flag will now capture parser input and make it available through the ParserSession.getInputAsString() method so that it can be used in the listeners.
- Significant new functionality introduced to the HTML serializer.
  Lots of new options for customizing the HTML output.
  - New {@link org.apache.juneau.html.annotation.Html#render() @Html(render)} annotation and {@link org.apache.juneau.html.HtmlRender} class that allows you to customize the HTML output and CSS style on bean properties:
    Annotation can be applied to POJO classes and bean properties.
  - Several new properties for customizing parts of the HTML page:
    - HtmlDocSerializerContext.HTMLDOC_title
    - HtmlDocSerializerContext.HTMLDOC_description
    - HtmlDocSerializerContext.HTMLDOC_branding
    - HtmlDocSerializerContext.HTMLDOC_header
    - HtmlDocSerializerContext.HTMLDOC_nav
    - HtmlDocSerializerContext.HTMLDOC_aside
    - HtmlDocSerializerContext.HTMLDOC_footer
    - HtmlDocSerializerContext.HTMLDOC_noResultsMessage
    - HtmlDocSerializerContext.HTMLDOC_cssUrl
    - HtmlDocSerializerContext.HTMLDOC_css
    - HtmlDocSerializerContext.HTMLDOC_template
  - New interface {@link org.apache.juneau.html.HtmlDocTemplate} that allows full control over rendering of HTML produced by {@link org.apache.juneau.html.HtmlDocSerializer}.
- {@link org.apache.juneau.annotation.NameProperty @NameProperty} and {@link org.apache.juneau.annotation.ParentProperty @ParentProperty} can now be applied to fields.
- New properties on {@link org.apache.juneau.BeanContext}:
  - BEAN_includeProperties
  - BEAN_excludeProperties
- New annotation property: @BeanProperty(format).

##### org.apache.juneau.rest

- MAJOR enhancements made to the REST API.
- The {@link org.apache.juneau.rest.RestRequest} class functionality has been broken up into the following functional pieces to reduce its complexity:
  - {@link org.apache.juneau.rest.RestRequest#getBody()} - The request body.
  - {@link org.apache.juneau.rest.RestRequest#getHeaders()} - The request headers.
  - {@link org.apache.juneau.rest.RestRequest#getQuery()} - The request query parameters.
  - {@link org.apache.juneau.rest.RestRequest#getFormData()} - The request form data parameters.
  - {@link org.apache.juneau.rest.RestRequest#getPathMatch()} - The path variables and remainder.
  The following classes have been introduced:
  - {@link org.apache.juneau.rest.RequestBody}
  - {@link org.apache.juneau.rest.RequestHeaders}
  - {@link org.apache.juneau.rest.RequestQuery}
  - {@link org.apache.juneau.rest.RequestFormData}
  - {@link org.apache.juneau.rest.RequestPath}
- The un-annotated parameter types that can be passed in through REST Java methods has been significantly expanded.
  For reference, the previous supported types were:
  - {@link org.apache.juneau.rest.RestRequest} - The request object.
  - {@link javax.servlet.http.HttpServletRequest} - The superclass of RestRequest.
  - {@link org.apache.juneau.rest.RestResponse} - The response object.
  - {@link javax.servlet.http.HttpServletResponse} - The superclass of RestResponse.
  The new supported types are:
  - {@link org.apache.juneau.http.Accept}
  - {@link org.apache.juneau.http.AcceptCharset}
  - {@link org.apache.juneau.http.AcceptEncoding}
  - {@link org.apache.juneau.http.AcceptLanguage}
  - {@link org.apache.juneau.http.Authorization}
  - {@link org.apache.juneau.http.CacheControl}
  - {@link org.apache.juneau.http.Connection}
  - {@link org.apache.juneau.http.ContentLength}
  - {@link org.apache.juneau.http.ContentType}
  - {@link org.apache.juneau.http.Date}
  - {@link org.apache.juneau.http.Expect}
  - {@link org.apache.juneau.http.From}
  - {@link org.apache.juneau.http.Host}
  - {@link org.apache.juneau.http.IfMatch}
  - {@link org.apache.juneau.http.IfModifiedSince}
  - {@link org.apache.juneau.http.IfNoneMatch}
  - {@link org.apache.juneau.http.IfRange}
  - {@link org.apache.juneau.http.IfUnmodifiedSince}
  - {@link org.apache.juneau.http.MaxForwards}
  - {@link org.apache.juneau.http.Pragma}
  - {@link org.apache.juneau.http.ProxyAuthorization}
  - {@link org.apache.juneau.http.Range}
  - {@link org.apache.juneau.http.Referer}
  - {@link org.apache.juneau.http.TE}
  - {@link org.apache.juneau.http.UserAgent}
  - {@link org.apache.juneau.http.Upgrade}
  - {@link org.apache.juneau.http.Via}
  - {@link org.apache.juneau.http.Warning}
  - {@link java.util.TimeZone}
  - {@link java.io.InputStream}
  - {@link javax.servlet.ServletInputStream}
  - {@link java.io.Reader}
  - {@link java.io.OutputStream}
  - {@link javax.servlet.ServletOutputStream}
  - {@link java.io.Writer}
  - {@link java.util.ResourceBundle} - Client-localized resource bundle.
  - {@link org.apache.juneau.utils.MessageBundle} - A resource bundle with additional features.
  - {@link java.util.Locale} - Client locale.
  - {@link org.apache.juneau.rest.RequestHeaders} - API for accessing request headers.
  - {@link org.apache.juneau.rest.RequestQuery} - API for accessing request query parameters.
  - {@link org.apache.juneau.rest.RequestFormData} - API for accessing request form data.
  - {@link org.apache.juneau.rest.RequestPath} - API for accessing path variables.
  - {@link org.apache.juneau.rest.RequestBody} - API for accessing request body.
  - {@link org.apache.juneau.http.HttpMethod} - The method name matched (when using @RestMethod(name="*"))
  - {@link java.util.logging.Logger} - The logger to use for logging.
  - {@link org.apache.juneau.internal.JuneauLogger} - Logger with additional features.
  - {@link org.apache.juneau.rest.RestContext} - The resource read-only context.
  - {@link org.apache.juneau.parser.Parser} - The parser matching the request content type.
  - {@link org.apache.juneau.dto.swagger.Swagger} - The auto-generated Swagger doc.
  - ConfigFile - The external config file for the resource.
  So, for example...

  /** Old way */ @RestMethod(name="*", path="/example1/{a1}/{a2}/{a3}/*") public String example1( @Method String method, @Path("a1") String a1, @Path("a2") int a2, @Path("a3") UUID a3, @Query("p1") int p1, @Query("p2") String p2, @Query("p3") UUID p3, @Header("Accept-Language") String lang, @Header("Accept") String accept ) /** New way */ @RestMethod(name="*", path="/example2/{a1}/{a2}/{a3}/*") public String example2( HttpMethod httpMethod, RequestPathParams pathParams, RequestQuery query, AcceptLanguage acceptLanguage, Accept accept )

- A new annotation @RestResource(paramResolvers)} that allows you to define your own custom Java method parameter resolvers.
- Fixed bug where Writer returned by {@link org.apache.juneau.rest.RestResponse#getWriter()} was not being flushed automatically at the end of the HTTP call.
- New annotations added to {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}:
  - {@link org.apache.juneau.rest.annotation.RestMethod#defaultQuery() defaultQuery()}
  - {@link org.apache.juneau.rest.annotation.RestMethod#defaultFormData() defaultFormData()}
  - bpIncludes()
  - bpExcludes()
- Default values on header, query, and form-data annotations:
  - @Header(def) - Default header value.
  - @Query(def) - Default query parameter value.
  - @FormData(def) - Default form data parameter value.
- New attributes on @RestResource:
  - serializerListener()
  - parserListener()
  - widgets()
  - swagger()
  - htmldoc()
- New attributes on {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}:
  - widgets()
  - {@link org.apache.juneau.rest.annotation.RestMethod#swagger() swagger()}
  - {@link org.apache.juneau.rest.annotation.RestMethod#htmldoc() htmldoc()}
- New string vars:
  - {@link org.apache.juneau.rest.vars.UrlVar} - Resolve "$U{...}" variables to URLs.
  - {@link org.apache.juneau.rest.vars.WidgetVar} - Resolve "$W{...}" variables to widget contents.
- New methods on RestConfig:
  - setHtmlTitle(String)
  - setHtmlDescription(String)
  - setHtmlBranding(String)
  - setHtmlHeader(String)
  - setHtmlLinks(String)
  - setHtmlNav(String)
  - setHtmlAside(String)
  - setHtmlFooter(String)
  - setHtmlCss(String)
  - setHtmlCssUrl(String)
  - setHtmlNoWrap(boolean)
  - setHtmlNoResultsMessage(String)
  - setHtmlTemplate(Class)
  - setHtmlTemplate(HtmlDocTemplate)
  - addWidget(Class)
- New methods on {@link org.apache.juneau.rest.RestResponse}:
  - setHtmlTitle(Object)
  - setHtmlDescription(Object)
  - setHtmlBranding(Object)
  - setHtmlHeader(Object)
  - setHtmlLinks(Object)
  - setHtmlNav(Object)
  - setHtmlAside(Object)
  - setHtmlFooter(Object)
  - setHtmlCss(Object)
  - setHtmlCssUrl(Object)
  - setHtmlNoWrap(boolean)
  - setHtmlNoResultsMessage(Object)
  - setHtmlTemplate(Class)
  - setHtmlTemplate(HtmlDocTemplate)
- &plainText=true parameter now works on byte-based serializers by converting the output to hex.
- New classes for widget support:
  - {@link org.apache.juneau.rest.widget.Widget}
  - PoweredByJuneauWidget
  - ContentTypeLinksColumnWidget
  - ContentTypeLinksRowWidget
  - QueryWidget
- devops.css cleaned up.
- Removed a bunch of URL-related methods from {@link org.apache.juneau.rest.RestRequest}. These all have equivalents in {@link org.apache.juneau.rest.RestRequest#getUriContext()}.
- New annotation attributes:
  - {@link org.apache.juneau.http.annotation.Query#name() @Query(name)}
  - {@link org.apache.juneau.http.annotation.FormData#name() @FormData(name)}
  - {@link org.apache.juneau.http.annotation.Header#name() @Header(name)}
  - {@link org.apache.juneau.http.annotation.Path#name() @Path(name)}
  - {@link org.apache.juneau.http.annotation.HasQuery#name() @HasQuery(name)}
  - {@link org.apache.juneau.http.annotation.HasFormData#name() @HasFormData(name)}

##### org.apache.juneau.rest.client

- New org.apache.juneau.remoteable.Path annotation for specifying path variables on remoteable interfaces.
- New @RequestBean annotation for specifying beans with remoteable annotations defined on properties.
- The following annotations (and related methods on RestCall) can now take NameValuePairs and beans as input when using "*" as the name.
  org.apache.juneau.remoteable.FormData,org.apache.juneau.remoteable.FormDataIfNE, org.apache.juneau.remoteable.Query,org.apache.juneau.remoteable.QueryIfNE, org.apache.juneau.remoteable.Header,org.apache.juneau.remoteable.HeaderIfNE

##### org.apache.juneau.microservice

##### org.apache.juneau.examples.rest

- Many code enhancements make to examples to reflect new functionality.
- All pages now render aside comments to help explain what feature they're trying to explain using the new features that allow you to customize various elements of the page.

### 6.3.1 (Aug 1, 2017)

Juneau 6.3.1 is a minor release.

##### org.apache.juneau

- {@link org.apache.juneau.utils.PojoQuery} improvements.
- New RemoteMethod.returns() annotation.
  Allows you to specify whether the remote method returns the HTTP body or status code.
- Fixed bugs with BEAN_includeProperties and BEAN_excludeProperties settings.
- New/modified settings in HtmlDocSerializerContext:
  - HTMLDOC_script
  - HTMLDOC_style - Was HTMLDOC_css.
  - HTMLDOC_stylesheet - Was HTMLDOC_cssUrl. Now an array.
- New ResourceFinder utility class. Allows you to search for resources up the parent hierarchy chain. Also allows you to search for localized resources.
- Eliminated the following properties from HtmlDocSerializerContext: HTMLDOC_title, HTMLDOC_description, HTMLDOC_description
  See below on changes to simplify HTML headers.
- {@link org.apache.juneau.svl.Var} implementations can now throw exceptions and will be converted to ""{exceptionMessage}" values.

##### org.apache.juneau.rest

- New 'light' stylesheet:
  Compared with previous 'devops':
  For those nolstalgic for old times, there's also 'original':
- Simplified the stylesheets and HTML code.
  For example, the nav links are now an ordered list of elements which makes rendering as as side-bar (for example) easier to do in CSS.
- Modifications to the following @HtmlDoc annotations:
  - {@link org.apache.juneau.rest.annotation.HtmlDoc#navlinks() navlinks()} - Now an array of strings instead of a JSON object. Simplified syntax.
    For example:

    // Old syntax htmldoc=@HtmlDoc( links="{" + "up:'request:/..'," + "options:'servlet:/?method=OPTIONS'," + "contentTypes:'$W{ContentTypeMenuItem}'," + "styles:'$W{StyleMenuItem}'," + "source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/PetStoreResource.java'" + "}" ) // New syntax htmldoc=@HtmlDoc( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS", "$W{ContentTypeMenuItem}", "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/PetStoreResource.java" } )

    Previous syntax will still work, but you're encouraged to use the simplified syntax.
  - Several annotations are now arrays of strings instead of simple strings. Values are simply concatenated with newlines which makes multi-line values cleaner.
    - {@link org.apache.juneau.rest.annotation.HtmlDoc#header() header()}
    - {@link org.apache.juneau.rest.annotation.HtmlDoc#nav() nav()}
    - {@link org.apache.juneau.rest.annotation.HtmlDoc#aside() aside()}
    - {@link org.apache.juneau.rest.annotation.HtmlDoc#footer() footer()}
    - {@link org.apache.juneau.rest.annotation.HtmlDoc#script() script()}
    - {@link org.apache.juneau.rest.annotation.HtmlDoc#style() style()}
    Additionally, the "INHERIT" string literal can be used to combine the value with the value defined on the servlet or parent class. Links can also be inserted at specific index positions.
- Improvements made to the {@link org.apache.juneau.rest.widget.Widget} API.
  - You can now add arbitrary CSS and Javascript along with your widgets through new methods:
    - Widget#getHtml(RestRequest)
    - Widget#getScript(RestRequest)
    - Widget#getStyle(RestRequest)
  - Declaration of widgets moved to {@link org.apache.juneau.rest.annotation.HtmlDoc#widgets() @HtmlDoc(widgets)} instead of separately on @RestResource and @RestMethod annotations.
  - {@link org.apache.juneau.rest.widget.Widget#getName()} now defaults to the simple class name.
    So now you can just refer to the class name: "$W{ContentTypeMenuItem}".
  - Renamed widgets:
    - PoweredByApacheWidget -> PoweredByApache
    - PoweredByJuneauWidget -> PoweredByJuneau
  - New {@link org.apache.juneau.rest.widget.MenuItemWidget} can be used as a starting point for creatint pull-down menu items.
  - New {@link org.apache.juneau.rest.widget.ContentTypeMenuItem} widget that provides a pull-down menu with hyperlinks for all supported languages for that page:
  - Improved {@link org.apache.juneau.rest.widget.QueryMenuItem} widget that provides a pull-down menu of a search/view/order-by/page form:
    Fields are now pre-filled with current query parameters.
  - New {@link org.apache.juneau.rest.widget.ThemeMenuItem} widget that provides a pull-down menu with hyperlinks to show the content in the default stylesheets:
- New/modified annotations on {@link org.apache.juneau.rest.annotation.HtmlDoc @HtmlDoc}:
  - {@link org.apache.juneau.rest.annotation.HtmlDoc#style() style()} - Renamed from css().
  - {@link org.apache.juneau.rest.annotation.HtmlDoc#stylesheet() stylesheet()} - Renamed from cssUrl().
    Can now be a comma-delimited list of URLs.
  - {@link org.apache.juneau.rest.annotation.HtmlDoc#script() script()} - Add arbitrary Javascript to page header.
- Bug fix with {@link org.apache.juneau.rest.annotation.HtmlDoc#nowrap() @HtmlDoc(nowrap)} so that the setting only applies to the data contents, not the whole page.
- Two convenience methods added to {@link org.apache.juneau.rest.RestRequest}:
  - {@link org.apache.juneau.rest.RestRequest#attr(String,Object) attr(String,Object)}
  - {@link org.apache.juneau.rest.RestRequest#prop(String,Object) prop(String,Object)}
- Annotations added:
  - @RestResource(siteName)
  - @RestResource(flags)
  - {@link org.apache.juneau.rest.annotation.RestMethod#flags() @RestMethod(flags)}
- Eliminated the @RestResource(stylesheet) annotation. It's no longer needed now that you can easily specify styles via @Htmldoc.
- Eliminated the following annotations since they are now redundant with {@link org.apache.juneau.rest.annotation.HtmlDoc#header() @HtmlDoc(header)}:
  - title()
  - description()
  - branding()
  Instead, the {@link org.apache.juneau.rest.BasicRestServlet} class defines the following default header that can be easily overridden:

  htmldoc=@HtmlDoc( header={ "<h1>$R{resourceTitle}</h1>", "<h2>$R{methodSummary,resourceDescription}</h2>", "<a href='http://juneau.apache.org'><img src='$U{servlet:/htdocs/juneau.png}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/></a>" } )

  Note that the subtitle first tries using the method summary and then the servlet description.
- New {@link org.apache.juneau.rest.vars.FileVar $F} variable resolver for resolving the contents of files in the classpath.
  The DockerRegistryResource examples shows how it can be used to pull in a localized file from the classpath to populate the aside section of a page.

  htmldoc=@HtmlDoc( // Pull in aside contents from file. aside="$F{resources/DockerRegistryResourceAside.html}" )

- New ReaderResource.toCommentStrippedString() method.
- The bpIncludes() and bpExcludes() annotations on @RestMethod has been replaced with the following:
  - {@link org.apache.juneau.rest.annotation.RestMethod#bpi() bpi()} - Now an array of simplified values instead of LAX JSON.
  - {@link org.apache.juneau.rest.annotation.RestMethod#bpx() bpx()} - Now an array of simplified values instead of LAX JSON.
- Two new variables added to $R variable: "$R{servletClass}", "$R{servletClassSimple}"

##### org.apache.juneau.rest.examples

- Added CONTENT-TYPE and STYLES menu items to most pages.
- Added improved QUERY menu item to PetStore page.

### 6.4.0 (Oct 5, 2017)

The major change in this release is the project structure.

The library now consists of the following artifacts found in the Maven group "org.apache.juneau":

Category | Maven Artifacts | Description | Prereqs
--- | --- | --- | ---
Juneau Core | juneau-marshall | Serializers and parsers for: JSON XML HTML UON URL-Encoding MessagePack SOAP/XML CSV BSON (coming soon) YAML (coming soon) Protobuf (coming soon) | Java 6
juneau-marshall-rdf | Serializers and parsers for: RDF/XML RDF/XML-Abbrev N-Triple Turtle N3 | Java 6 Apache Jena 2.7.1
juneau-dto | Data Transfer Objects for: HTML5 Atom Cognos JSON-Schema Swagger 2.0 | Java 6
juneau-svl | Simple Variable Language API | Java 6
juneau-config | Configuration file API | Java 6
Juneau REST | juneau-rest-server | REST Servlet API | Java 6 Servlet 3.1
juneau-rest-server-jaxrs | Optional JAX-RS support | Java 6 JAX-RS 2.0
juneau-rest-client | REST Client API | Java 6 Apache HttpClient 4.5
Juneau Microservice | juneau-microservice-server | REST Microservice Server API | Java 8 Eclipse Jetty 9.4.3
juneau-microservice-template | Developer template project | Java 8 Eclipse Jetty 9.4.3
Examples | juneau-examples-core | Core code examples |
juneau-examples-rest | REST code examples |
Juneau All | juneau-all | Combination of the following: juneau-marshall juneau-dto juneau-svl juneau-config juneau-rest-server juneau-rest-client | Java 6 Servlet 3.1 Apache HttpClient 4.5

##### juneau-marshall

- Improvements to swap support.
  - New {@link org.apache.juneau.annotation.Swap @Swap} annotation.
    Replaces the @Pojo and @BeanProperty(swap) annotations.
  - Support for per-media-type swaps.
    Programmatic example:

    @Swap(MyJsonOnlySwap.class) public class MyPojo {} public class MyJsonOnlySwap extends PojoSwap<MyPojo,String> { public MediaType[] forMediaTypes() { return MediaType.forStrings("*/json"); } public String swap(BeanSession session, MyPojo o) throws Exception { return "It's JSON!"; }

    Annotated example:

    @Swap(impl=ToStringSwap.class, mediaTypes="*/json") public class MyBean { ... } public class ToStringSwap extends PojoSwap<Object,String> { public String swap(BeanSession session, Object o) throws Exception { return o.toString(); } }

  - Support for templated swaps which provide additional context information for a swap.
    The following is an example of a templated swap class used to serialize POJOs to HTML using FreeMarker:

    // Our abstracted templated swap class. public abstract class FreeMarkerSwap extends PojoSwap<Object,Reader> { public MediaType[] forMediaTypes() { return MediaType.forStrings("*/html"); } public Reader swap(BeanSession session, Object o, String template) throws Exception { return getFreeMarkerReader(template, o); // Some method that creates raw HTML. } }

    @Swap(impl=FreeMarkerSwap.class, template="MyPojo.div.ftl") public class MyPojo {}

  - New {@link org.apache.juneau.annotation.Swaps @Swaps} annotation for defining multiple swaps against the same POJO when they're differentiated by media types:

    @Swaps( { @Swap(MyJsonSwap.class), @Swap(MyXmlSwap.class), @Swap(MyOtherSwap.class) } ) public class MyPojo {}

- New {@link org.apache.juneau.transform.Surrogate} interface for identifying surrogate classes.
- Serializers can now serialize to {@link java.util.StringBuilder StringBuilders}.
- Serializers now serialize the contents of {@link java.io.Reader Readers} and {@link java.io.InputStream InputStreams} directly to the output stream or writer.
  When used with conjunction with PojoSwaps, this can be used to provide customized output for specific content types.

  @Pojo(swap=MyBeanSwap.class) public class MyBean {...} public class MyBeanSwap extends PojoSwap<MyBean,Object> { public Object swap(BeanSession session, MyPojo o) throws Exception { MediaType mt = session.getMediaType(); if (mt.hasSubType("json")) return new StringReader("{foo:'bar'}"); // Custom JSON output return o; // Otherwise treat as normal bean } } // Produces "{foo:'bar'}" String json = SimpleJsonSerializer.DEFAULT .toString(new MyBean());

  This feature helps with the implementation of language-agnostic template support such as for using FreeMaker to serialize POJOs to HTML.
- {@link org.apache.juneau.serializer.SerializerSession} and {@link org.apache.juneau.parser.ParserSession} objects are now reusable if used within the same thread.

  // Old way (still works) JsonSerializer.DEFAULT.serialize(writer1, pojo1); JsonSerializer.DEFAULT.serialize(writer2, pojo2); // Same, but using a session object SerializerSession session = JsonSerializer.DEFAULT.createSession(); try { session.serialize(writer1, pojo1); session.serialize(writer2, pojo2); } finally { session.close(); }

  This is mostly an internal change and doesn't affect the existing APIs.
- {@link org.apache.juneau.transform.PojoSwap#swap(BeanSession,Object)} and {@link org.apache.juneau.transform.PojoSwap#unswap(BeanSession,Object,ClassMeta)} can now throw arbitrary exceptions instead of having to wrap them in SerializeException/ParseException.
- New {@link org.apache.juneau.utils.CalendarUtils} class that encapsulates serialization/parsing logic from {@link org.apache.juneau.transforms.CalendarSwap} and {@link org.apache.juneau.transforms.DateSwap}.
- New annotation {@link org.apache.juneau.html.annotation.Html#anchorText}.
- New methods on {@link org.apache.juneau.ObjectList}:
  - {@link org.apache.juneau.ObjectList#get(int,Class) get(int,Class)}
  - {@link org.apache.juneau.ObjectList#get(int,Type,Type...) get(int,Type,Type...)}
  - {@link org.apache.juneau.ObjectList#getMap(int,Class,Class) getMap(int,Class,Class)}
  - {@link org.apache.juneau.ObjectList#getList(int,Class) getList(int,Class)}
- New methods on {@link org.apache.juneau.ObjectMap}:
  - {@link org.apache.juneau.ObjectMap#get(String,Class) get(String,Class)}
  - {@link org.apache.juneau.ObjectMap#get(String,Type,Type...) get(String,Type,Type...)}
  - {@link org.apache.juneau.ObjectMap#getWithDefault(String,Object) getWithDefault(String,Object)}
  - {@link org.apache.juneau.ObjectMap#getWithDefault(String,Object,Class) getWithDefault(String,Object,Class)}
  - {@link org.apache.juneau.ObjectMap#getWithDefault(String,Object,Type,Type...) getWithDefault(String,Object,Type,Type...)}
  - {@link org.apache.juneau.ObjectMap#getSwapped(String,PojoSwap) getSwapped(String,PojoSwap)}
  - {@link org.apache.juneau.ObjectMap#getAt(String,Class) getAt(String,Class)}
  - {@link org.apache.juneau.ObjectMap#getAt(String,Type,Type...) getAt(String,Type,Type...)}
  - {@link org.apache.juneau.ObjectMap#getMap(String,Class,Class,Map) getMap(String,Class,Class,Map)}
  - {@link org.apache.juneau.ObjectMap#getList(String,Class,List) getList(String,Class,List)}
- New methods on {@link org.apache.juneau.utils.PojoRest}:
  - {@link org.apache.juneau.utils.PojoRest#get(String,Class) get(String,Class)}
  - {@link org.apache.juneau.utils.PojoRest#get(String,Type,Type...) get(String,Type,Type...)}
  - {@link org.apache.juneau.utils.PojoRest#getWithDefault(String,Object) getWithDefault(String,Object)}
  - {@link org.apache.juneau.utils.PojoRest#getWithDefault(String,Object,Class) getWithDefault(String,Object,Class)}
  - {@link org.apache.juneau.utils.PojoRest#getWithDefault(String,Object,Type,Type...) getWithDefault(String,Object,Type,Type...)}
- Fixed bug where {@link org.apache.juneau.BeanSession#getMediaType()} wasn't returning a value.
- Eliminated the @Consumes and @Produces annotations.
  The supported media types are now passed in through the constructors.
  This was changed to eliminate a performance issue where a field could not be set as final because the call to getClass() to retrieve the annotation value could not be called before calling the super() method.
- New class: {@link org.apache.juneau.utils.PojoMerge}
- New doc: 2.6.2 - @Pojo annotation
- New doc: 2.6.5 - Serializing Readers and InputStreams

##### juneau-dto

- {@link org.apache.juneau.dto.html5.HtmlElementMixed#children(Object...)} can now take in collections of objects.
- The DTO beans can now be serialized to strings of their typical language by calling the toString() method.
  For example, Swagger.toString() produces JSON and the HTML5 Form.toString() produces HTML.

##### juneau-rest-server

- Revamped and simplified servlet and REST-call lifecycle handling through new {@link org.apache.juneau.rest.annotation.RestHook @RestHook} annotation.
  - The {@link org.apache.juneau.rest.RestServlet#init(ServletConfig)} method is now final and can no longer be extended.
    Instead, use {@link org.apache.juneau.rest.annotation.HookEvent#INIT} or {@link org.apache.juneau.rest.annotation.HookEvent#POST_INIT} for initialization.
  - The following methods on {@link org.apache.juneau.rest.RestServlet} have been removed:
    - init(RestConfig) - Use {@link org.apache.juneau.rest.annotation.HookEvent#INIT} instead.
    - onSuccess(RestRequest, RestResponse, long) - Use {@link org.apache.juneau.rest.annotation.HookEvent#END_CALL} instead.
    - onPreCall(RestRequest) - Use {@link org.apache.juneau.rest.annotation.HookEvent#PRE_CALL} instead.
    - onPostCall(RestRequest, RestResponse) - Use {@link org.apache.juneau.rest.annotation.HookEvent#POST_CALL} instead.
- Simplified {@link org.apache.juneau.rest.widget.MenuItemWidget}.
  Exposes an abstract method getContent(RestRequest) that can return raw HTML via readers or char-sequences, or any other object (such as HTML5 beans) that will get converted to HTML using {@link org.apache.juneau.html.HtmlSerializer#DEFAULT}.
- {@link org.apache.juneau.rest.RestResourceResolver} instances are now inherited from parent resources to child resources unless explicitly overridden at the child level.
  It's also been changed to an interface.
- New annotations on @RestResource:
  - resourceResolver()
    Allows you to specify a resource resolver on the servlet context to make it easier to work with dependency injection frameworks.
  - contextPath() -
    Allows you to override the context path value inherited from the servlet container.
  - allowHeaderParams() -
    Replaces the RestContext.REST_allowHeaderParams setting.
  - allowMethodParam() -
    Replaces the RestContext.REST_allowMethodParam setting.
  - allowBodyParam() -
    Replaces the RestContext.REST_allowBodyParam setting.
  - renderResponseStackTraces() -
    Replaces the RestContext.REST_xxx setting.
  - useStackTraceHashes() -
    Replaces the RestContext.REST_useStackTraceHashes setting.
  - defaultCharset() -
    Replaces the RestContext.REST_defaultCharset setting.
  - paramFormat() -
    Replaces the RestContext.REST_paramFormat setting.
- New annotations on {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}:
  - {@link org.apache.juneau.rest.annotation.RestMethod#defaultCharset() defaultCharset()} -
    Replaces the RestContext.REST_defaultCharset setting.
  - RestMethod.paramFormat() -
    Replaces the RestContext.REST_paramFormat setting.
- The following implementation classes can now be defined as non-static inner classes of servlets/resources:
  - {@link org.apache.juneau.rest.widget.Widget}
  - {@link org.apache.juneau.rest.RestConverter}
  - {@link org.apache.juneau.rest.RestGuard}
  - {@link org.apache.juneau.rest.ResponseHandler}
  - {@link org.apache.juneau.rest.RestCallHandler}
  - {@link org.apache.juneau.rest.RestInfoProvider}
  - {@link org.apache.juneau.rest.RestResourceResolver}
  - {@link org.apache.juneau.rest.RestLogger}
  - {@link org.apache.juneau.html.HtmlDocTemplate}
- New tooltip template: {@link org.apache.juneau.rest.widget.Tooltip}
- New dark theme:
- Stylesheet selection now stored in HTTP session when passed in via ?stylesheet query parameter.
- New doc: Lifecycle Hooks
- Eliminated the RestServletJenaDefault class to remove the Jena dependency class on the juneau-rest-server artifact.
  It's simple enough to simply extend BasicRestServlet and add the RDF serializers and parsers.

##### juneau-microservice

- The microservice has been significantly modified to be configured via a jetty.xml file for maximum flexibility instead of the hodge-podge of support in the config file.
  Top-level servlets should now be defined in the provided jetty.xml file.
- New methods on RestMicroservice:
  - addServlet(Servlet,String)
  - addServletAttribute(String,Object)
  - getServer()
  - getInstance()
  - getPort()
  - getContextPath()
  - getProtocol()
  - getHostName()
- New methods on {@link org.apache.juneau.microservice.Microservice}:
  - {@link org.apache.juneau.microservice.Microservice#getInstance() getInstance()}
- New class JettyLogger for directing Jetty logging to the java.util.logging framework.
- New class DebugResource for viewing and generating Jetty thread dumps through REST calls.

##### org.apache.juneau.rest.examples

- New example of adding a menu-item widget to the Pet Store resource (including tooltips):

### 7.0.0 (Oct 25, 2017)

This release ups the Java prerequisite to Java 7.

##### juneau-marshall

- New class {@link org.apache.juneau.http.HttpMethodName} with valid static string HTTP method names.

##### juneau-dto

- Class org.apache.juneau.dto.Link renamed to {@link org.apache.juneau.dto.LinkString}. Helps avoid confusion since there are other Link classes in the library.

##### juneau-rest-server

- Annotation @HtmlDoc(links) renamed to {@link org.apache.juneau.rest.annotation.HtmlDoc#navlinks() navlinks}.
- New annotation {@link org.apache.juneau.rest.annotation.HtmlDoc#head() @HtmlDoc(head)}.
  Allows you to specify arbitrary HTML content in the <head> section of the page.
- Removed annotation @HtmlDoc(favIcon).
  This was a discouraged way of defining fav-icons anyway, and with the addition of @HtmlDoc(head), you can define them using:

  head={ "<link rel='icon' href='$U{servlet:/htdocs/juneau.png}'/>" }

- Removed several of the HTMLDOC-related methods from the RestResponse/RestConfig/RestContext classes and moved it into the new {@link org.apache.juneau.rest.HtmlDocBuilder} class.

### 7.0.1 (Dec 24, 2017)

This release is a minor update. It includes the following prereq updates:

- Apache HttpClient: 4.5.3 to 4.5.4
- Eclipse Jetty: 9.4.6.v20170531 to 9.4.8.v20171121

##### juneau-marshall

- New static create() methods for builders on serializers and parsers.
  This simplifies the syntax of creation of serializers and parsers by scratch.

  // Old way JsonSerializer s1 = new JsonSerializerBuilder().ws().build(); // New way JsonSerializer s2 = JsonSerializer.create().ws().build();

  The same static create methods have also been added to the following classes:
  - {@link org.apache.juneau.serializer.SerializerGroup#create()}
  - {@link org.apache.juneau.parser.ParserGroup#create()}
  - {@link org.apache.juneau.encoders.EncoderGroup#create()}
  - {@link org.apache.juneau.rest.client.RestClient#create()}
  - ConfigFile.create()
- The order of the parameters in {@link org.apache.juneau.serializer.SerializerSession#serialize(Object,Object)} has been change to match {@link org.apache.juneau.serializer.Serializer#serialize(Object,Object)}.
- Fixed some bugs in the XML parser related to whitespace and comments.

##### juneau-svl

- New methods on {@link org.apache.juneau.svl.Var} class to restrict when nested and embedded variables are resolved.
  - {@link org.apache.juneau.svl.Var#allowNested()}
  - {@link org.apache.juneau.svl.Var#allowRecurse()}

##### juneau-rest-server

- New @RestResource(maxInput) and {@link org.apache.juneau.rest.annotation.RestMethod#maxInput() @RestMethod(maxInput)} for alleviating potential DoS attacks.

##### juneau-microservice-server

- New pluggable console commands.
  When you start up the microservice, you'll now see the following:

  Running class 'RestMicroservice' using config file 'examples.cfg'. Server started on port 10000 List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help echo -- Echo command > help help NAME help -- Commands help SYNOPSIS help [command] DESCRIPTION When called without arguments, prints the descriptions of all available commands. Can also be called with one or more arguments to get detailed information on a command. EXAMPLES List all commands: > help List help on the help command: > help help >

  Commands are pluggable and extensible through the config file.

  #======================================================================================================================= # Console settings #======================================================================================================================= [Console] enabled = true # List of available console commands. # These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via # the console. # When listed here, the implementations must provide a no-arg constructor. # They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method. commands = org.apache.juneau.microservice.console.ExitCommand, org.apache.juneau.microservice.console.RestartCommand, org.apache.juneau.microservice.console.HelpCommand

  - New classes:
    - {@link org.apache.juneau.microservice.console.ConsoleCommand}
    - {@link org.apache.juneau.microservice.console.ExitCommand}
    - {@link org.apache.juneau.microservice.console.RestartCommand}
    - {@link org.apache.juneau.microservice.console.HelpCommand}
  - New methods on {@link org.apache.juneau.microservice.Microservice}
    - {@link org.apache.juneau.microservice.Microservice#startConsole() startConsole()}
    - createConsoleCommands()
    - {@link org.apache.juneau.microservice.Microservice#getConsoleReader() getConsoleReader()}
    - {@link org.apache.juneau.microservice.Microservice#getConsoleWriter() getConsoleWriter()}
- Console input reader and output writer can now be overridden.
- Console strings are now internationalized.

### 7.1.0 (Mar 08, 2018)

Version 7.1.0 is a major update with major implementation refactoring across all aspects of the product.

##### juneau-marshall

- Significant improvements made to the internals of the Serializer and Parser classes.
  - Caching improvements on serializers and parsers have reduced execution time of the core JUnits by approximately 1/3.
    The 17000+ JUnit tests now execute in less than 10 seconds and have a cache-reuse hit rate of 98% (164104 serializers/parsers/bean-contexts retrieved, but only 1801 created from scratch).
  - All the various separate Context classes (e.g. JsonSerializerContext) have been folded into their respective serializer or parser classes (e.g. JsonSerializer).
    Additionally, these classes are their own bean contexts.
    For example, the class hierarchy of JsonSerializer is now:
    - {@link org.apache.juneau.Context}
      - {@link org.apache.juneau.BeanContext}
        - {@link org.apache.juneau.serializer.Serializer}
          - {@link org.apache.juneau.serializer.WriterSerializer}
            - {@link org.apache.juneau.json.JsonSerializer}
    All Context objects are thread-safe and read-only.
  - Session objects also now have a consistent class hierarchy.
    For example, the class hierarchy of JsonSerializerSession is now:
    - {@link org.apache.juneau.Session}
      - {@link org.apache.juneau.BeanSession}
        - {@link org.apache.juneau.serializer.SerializerSession}
          - {@link org.apache.juneau.serializer.WriterSerializerSession}
            - {@link org.apache.juneau.json.JsonSerializerSession}
    Session objects are transient objects that live for the duration of a single parse.
  - Builder objects also now have a consistent class hierarchy.
    For example, the class hierarchy of JsonSerializerBuilder is now:
    - {@link org.apache.juneau.ContextBuilder}
      - {@link org.apache.juneau.BeanContextBuilder}
        - {@link org.apache.juneau.serializer.SerializerBuilder}
          - {@link org.apache.juneau.json.JsonSerializerBuilder}
    Builder objects are used for building up and creating Context objects.
  - The {@link org.apache.juneau.PropertyStore} class has been completely rewritten. It is now a read-only configuration store build using the {@link org.apache.juneau.PropertyStoreBuilder} class.
    The previous PropertyStore class was overly-complicated with many read/write locks to ensure thread-safety.
    The new design shifts to a builder-based model with read-only PropertyStore objects that can be used as hash keys.
- Improvements to the HTTP-Part APIs.
  The existing PartSerializer/PartParser classes have been replaced with the following all located in the new org.apache.juneau.httppart package:
  - {@link org.apache.juneau.httppart}
    - {@link org.apache.juneau.httppart.HttpPartType}
    - {@link org.apache.juneau.httppart.HttpPartSerializer}
      - UonPartSerializer
      - SimpleUonPartSerializer
      - {@link org.apache.juneau.httppart.SimplePartSerializer}
    - {@link org.apache.juneau.httppart.HttpPartParser}
      - UonPartParser
      - SimplePartParser
  Code for marshalling of parts have been removed from the URL-Encoding serializers and parsers.
- ContextBuilder.property(String,Object) renamed to {@link org.apache.juneau.ContextBuilder#set(String,Object)}.
- ResourceFinder class has been replaced with the following:
  - {@link org.apache.juneau.utils.ClasspathResourceFinder}
  - {@link org.apache.juneau.utils.ClasspathResourceFinderSimple}
  - {@link org.apache.juneau.utils.ClasspathResourceFinderBasic}
  - {@link org.apache.juneau.utils.ClasspathResourceFinderRecursive}
  - {@link org.apache.juneau.utils.ClasspathResourceManager}
- New methods on {@link org.apache.juneau.serializer.SerializerSession}:
  - {@link org.apache.juneau.serializer.SerializerSession#getListener() getListener()}
  - {@link org.apache.juneau.serializer.SerializerSession#getListener(Class) getListener(Class)}
- New methods on {@link org.apache.juneau.parser.ParserSession}:
  - {@link org.apache.juneau.parser.ParserSession#getListener() getListener()}
  - {@link org.apache.juneau.parser.ParserSession#getListener(Class) getListener(Class)}
- New {@link org.apache.juneau.parser.Parser#PARSER_unbuffered} setting allows you to disable internal buffering on the JSON and UON parsers so that they can be used to read continous streams of objects.
- New {@link org.apache.juneau.json.JsonParser#JSON_validateEnd} and {@link org.apache.juneau.uon.UonParser#UON_validateEnd} settings allow you to control whether we validate that there is no garbage at the end of the parsed input.
- New {@link org.apache.juneau.parser.Parser#PARSER_autoCloseStreams} setting allows input streams and readers passed into parsers to be automatically closed after parsing.
- Syntax changed on unswap method on {@link org.apache.juneau.transform.Surrogate} classes.
  It's now a regular method instead of a static method.
- {@link org.apache.juneau.annotation.Swap @Swap} annotation can now be used with {@link org.apache.juneau.transform.Surrogate} classes.
- New support for {@doc juneau-marshall.Transforms.PojoBuilders POJO Builders}.

##### juneau-svl

- New variables:
  - {@link org.apache.juneau.svl.vars.CoalesceVar}
  - {@link org.apache.juneau.svl.vars.PatternMatchVar}
  - {@link org.apache.juneau.svl.vars.NotEmptyVar}
  - {@link org.apache.juneau.svl.vars.UpperCaseVar}
  - {@link org.apache.juneau.svl.vars.LowerCaseVar}
- Variables moved from juneau-microservice:
  - {@link org.apache.juneau.svl.vars.ArgsVar}
  - {@link org.apache.juneau.svl.vars.ManifestFileVar}

##### juneau-config

- The Config API has been completely revamped.
  New features include:
  - Support for pluggable storage.
  - File-system watcher integration support.
    Changes made to file system files now automatically reflected in configurations and interface proxies.
  - New builder-based design.

##### juneau-dto

- Enhancements to Swagger DTO:
  - New methods for setting and retrieving properties via name:
    - {@link org.apache.juneau.dto.swagger.SwaggerElement#get(String,Class)}
    - {@link org.apache.juneau.dto.swagger.SwaggerElement#set(String,Object)}
  - Support for setting non-standard fields such as "$ref" via getter and setter above.
  - Setter methods that take in beans and collections of beans can now take in JSON strings.

##### juneau-rest-server

- RestServletDefault renamed to {@link org.apache.juneau.rest.BasicRestServlet}.
- RestServletGroupDefault renamed to {@link org.apache.juneau.rest.BasicRestServletGroup}.
- The "$R{...}" variable has been split into the following:
  - "$RA{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RequestAttributeVar}, first non-null value returned by HttpServletRequest.getAttribute(String).
  - "$RF{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RequestFormDataVar}, first non-null value returned by {@link org.apache.juneau.rest.RestRequest#getFormData(String)}.
  - "$RH{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RequestHeaderVar}, first non-null value returned by {@link org.apache.juneau.rest.RestRequest#getHeader(String)}.
  - "$RI{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RestInfoVar}, first non-null value returned by {@link org.apache.juneau.rest.RestRequest#getInfoProvider()}.
    The possible values are:
    - "contact" - Value returned by {@link org.apache.juneau.dto.swagger.Info#getContact()}
    - "description" - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest)}
    - "externalDocs" - Value returned by {@link org.apache.juneau.dto.swagger.Swagger#getExternalDocs()}
    - "license" - Value returned by {@link org.apache.juneau.dto.swagger.Info#getLicense()}
    - "methodDescription" - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getMethodDescription(Method,RestRequest)}
    - "methodSummary" - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getMethodSummary(Method,RestRequest)}
    - "siteName" - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getSiteName(RestRequest)}
    - "tags" - Value returned by {@link org.apache.juneau.dto.swagger.Swagger#getTags()}
    - "termsOfService" - Value returned by {@link org.apache.juneau.dto.swagger.Info#getTermsOfService()}
    - "title" - See {@link org.apache.juneau.rest.RestInfoProvider#getTitle(RestRequest)}
    - "version" - See {@link org.apache.juneau.dto.swagger.Info#getVersion()}
  - "$RP{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RequestPathVar}, first non-null value returned by {@link org.apache.juneau.rest.RestRequest#getPath(String)}.
  - "$RQ{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RequestQueryVar}, first non-null value returned by {@link org.apache.juneau.rest.RestRequest#getQuery(String)}
  - "$R{key1[,key2...]}" - {@link org.apache.juneau.rest.vars.RequestVar}, first non-null other request variable.
    The possible values are:
    - "contextPath" - Value returned by {@link org.apache.juneau.rest.RestRequest#getContextPath()}
    - "method" - Value returned by {@link org.apache.juneau.rest.RestRequest#getMethod()}
    - "methodDescription" - Value returned by {@link org.apache.juneau.rest.RestRequest#getMethodDescription()}
    - "methodSummary" - Value returned by {@link org.apache.juneau.rest.RestRequest#getMethodSummary()}
    - "pathInfo" - Value returned by {@link org.apache.juneau.rest.RestRequest#getPathInfo()}
    - "requestParentURI" - Value returned by {@link org.apache.juneau.UriContext#getRootRelativePathInfoParent()}
    - "requestURI" - Value returned by {@link org.apache.juneau.rest.RestRequest#getRequestURI()}
    - "resourceDescription" - Value returned by {@link org.apache.juneau.rest.RestRequest#getResourceDescription()}
    - "resourceTitle" - See {@link org.apache.juneau.rest.RestRequest#getResourceTitle()}
    - "servletParentURI" - Value returned by {@link org.apache.juneau.UriContext#getRootRelativeServletPathParent()}
    - "servletPath" - See {@link org.apache.juneau.rest.RestRequest#getServletPath()}
    - "servletURI" - See {@link org.apache.juneau.UriContext#getRootRelativeServletPath()}
    - "siteName" - See {@link org.apache.juneau.rest.RestRequest#getSiteName()}
- Refactored the RestConfig class into {@link org.apache.juneau.rest.RestContextBuilder}.
  Settings on {@link org.apache.juneau.rest.RestContext} objects can now be set declaratively through the following new properties:
  - {@link org.apache.juneau.rest.RestContext#REST_allowHeaderParams REST_allowHeaderParams}
  - {@link org.apache.juneau.rest.RestContext#REST_allowBodyParam REST_allowBodyParam}
  - {@link org.apache.juneau.rest.RestContext#REST_allowedMethodParams REST_allowedMethodParams}
  - {@link org.apache.juneau.rest.RestContext#REST_renderResponseStackTraces REST_renderResponseStackTraces}
  - {@link org.apache.juneau.rest.RestContext#REST_useStackTraceHashes REST_useStackTraceHashes}
  - {@link org.apache.juneau.rest.RestContext#REST_defaultCharset REST_defaultCharset}
  - {@link org.apache.juneau.rest.RestContext#REST_maxInput REST_maxInput}
  - {@link org.apache.juneau.rest.RestContext#REST_paramResolvers REST_paramResolvers}
  - {@link org.apache.juneau.rest.RestContext#REST_converters REST_converters}
  - {@link org.apache.juneau.rest.RestContext#REST_guards REST_guards}
  - {@link org.apache.juneau.rest.RestContext#REST_responseHandlers REST_responseHandlers}
  - REST_defaultRequestHeaders
  - REST_defaultResponseHeaders
  - {@link org.apache.juneau.rest.RestContext#REST_produces REST_produces}
  - {@link org.apache.juneau.rest.RestContext#REST_consumes REST_consumes}
  - {@link org.apache.juneau.rest.RestContext#REST_clientVersionHeader REST_clientVersionHeader}
  - {@link org.apache.juneau.rest.RestContext#REST_resourceResolver REST_resourceResolver}
  - {@link org.apache.juneau.rest.RestContext#REST_logger REST_logger}
  - {@link org.apache.juneau.rest.RestContext#REST_callHandler REST_callHandler}
  - {@link org.apache.juneau.rest.RestContext#REST_infoProvider REST_infoProvider}
  - {@link org.apache.juneau.rest.RestContext#REST_path REST_path}
  - REST_contextPath
  - {@link org.apache.juneau.rest.RestContext#REST_staticFiles REST_staticFiles}
  - {@link org.apache.juneau.rest.RestContext#REST_staticFileResponseHeaders REST_staticFileResponseHeaders}
  - {@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder REST_classpathResourceFinder}
  - {@link org.apache.juneau.rest.RestContext#REST_useClasspathResourceCaching REST_useClasspathResourceCaching}
  - {@link org.apache.juneau.rest.RestContext#REST_widgets REST_widgets}
  - {@link org.apache.juneau.rest.RestContext#REST_mimeTypes REST_mimeTypes}
- Support for static files has been simplified and improved.
  - Syntax on @RestResource(staticFiles) has been simplified, and now allows you to specify response headers in the strings.
  - Response headers for static files can also be configured through {@link org.apache.juneau.rest.RestContext#REST_staticFileResponseHeaders REST_staticFileResponseHeaders}.
  - Static file in-memory caching now configurable through {@link org.apache.juneau.rest.RestContext#REST_useClasspathResourceCaching REST_useClasspathResourceCaching}.
  - Static file retrieval can be customized through {@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder REST_classpathResourceFinder}
- Eliminated the RestMatcherReflecting class.
  You can now simply create a {@link org.apache.juneau.rest.RestMatcher} that has a public constructor that takes in the server and method arguments.
- @RestResource.allowMethodParam renamed to RestResource.allowedMethodParams.
- @RestMethod.serializersInherit and @RestMethod.parsersInherit replaced with simplified @RestMethod(inherit).
- Changes to {@link org.apache.juneau.rest.RequestFormData}:
  - {@link org.apache.juneau.rest.RequestFormData#addDefault(Map) addDefault(Map)} takes in a Map<String,Object> instead of Map<String,String>.
- Changes to {@link org.apache.juneau.rest.RequestHeaders}:
  - {@link org.apache.juneau.rest.RequestHeaders#addDefault(Map) addDefault(Map)} takes in a Map<String,Object> instead of Map<String,String>.
- Changes to {@link org.apache.juneau.rest.RequestQuery}:
  - {@link org.apache.juneau.rest.RequestQuery#addDefault(Map) addDefault(Map)} takes in a Map<String,Object> instead of Map<String,String>.
- Changes to {@link org.apache.juneau.rest.RestContext}:
  - getResource(String,Locale) renamed to {@link org.apache.juneau.rest.RestContext#getClasspathResource(String,Locale) getClasspathResource(String,Locale)}
  - getResourceAsString(String,Locale) renamed to {@link org.apache.juneau.rest.RestContext#getClasspathResourceAsString(String,Locale) getClasspathResourceAsString(String,Locale)}
  - getResource(Class,MediaType,String,Locale) renamed to {@link org.apache.juneau.rest.RestContext#getClasspathResource(Class,MediaType,String,Locale) getClasspathResourceAsString(Class,MediaType,String,Locale)}
  - New method {@link org.apache.juneau.rest.RestContext#getClasspathResource(Class,String,Locale) getClasspathResource(Class,String,Locale)}.
  - New method {@link org.apache.juneau.rest.RestContext#getClasspathResourceAsString(Class,String,Locale) getClasspathResourceAsString(Class,String,Locale)}.
  - New method {@link org.apache.juneau.rest.RestContext#getClasspathResource(Class,Class,MediaType,String,Locale) getClasspathResource(Class,Class,MediaType,String,Locale)}.
  - RestContext.getDefaultRequestHeaders() returns a Map<String,Object> instead of Map<String,String>.
  - RestContext.getDefaultResponseHeaders() returns a Map<String,Object> instead of Map<String,String>.
- Changes to {@link org.apache.juneau.rest.RestRequest}:
  - getSupportedMediaTypes() replaced with {@link org.apache.juneau.rest.RestRequest#getConsumes() getConsumes()} and {@link org.apache.juneau.rest.RestRequest#getProduces() getProduces()}.
  - getReaderResource(String,boolean,MediaType) renamed to getClasspathReaderResource(String,boolean,MediaType)
  - getReaderResource(String,boolean) renamed to {@link org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String,boolean) getClasspathReaderResource(String,boolean)}
  - getReaderResource(String) renamed to {@link org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String) getClasspathReaderResource(String)}
- Changes to @RestResource
  - New mimeTypes() annotation.
- Changes to {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}:
  - New {@link org.apache.juneau.rest.annotation.RestMethod#consumes() consumes()} and {@link org.apache.juneau.rest.annotation.RestMethod#produces() produces()} for overriding the supported media types inferred from the serializers and parsers.
- RestCallHandler split up into {@link org.apache.juneau.rest.RestCallHandler} and {@link org.apache.juneau.rest.BasicRestCallHandler}
- RestInfoProvider split up into {@link org.apache.juneau.rest.RestInfoProvider} and {@link org.apache.juneau.rest.BasicRestInfoProvider}
- RestLogger split up into {@link org.apache.juneau.rest.RestLogger}, {@link org.apache.juneau.rest.BasicRestLogger} and {@link org.apache.juneau.rest.NoOpRestLogger}
- RestResourceResolverSimple renamed to {@link org.apache.juneau.rest.BasicRestResourceResolver}
- Introduced the following classes that helps make the code more understandable:
  - {@link org.apache.juneau.rest.RestContextProperties}
  - {@link org.apache.juneau.rest.RestMethodProperties}
  - {@link org.apache.juneau.rest.RequestProperties}
- Eliminated the @Messages and @Properties REST java method parameter annotations.
  These aren't needed anymore since you can just pass in MessageBundle and RestRequestProperties as unannotated parameters.
- Revamped the {@link org.apache.juneau.rest.RestInfoProvider} class.
- New builder classes:
  - ReaderResourceBuilder
  - StreamResourceBuilder
- {@link org.apache.juneau.rest.RestResponse#getNegotiatedOutputStream()} now returns a FinishableServletOutputStream and {@link org.apache.juneau.rest.RestResponse#getNegotiatedWriter()} now returns a FinishablePrintWriter that allows you to finish the output without closing the stream.
  The {@link org.apache.juneau.rest.reshandlers.DefaultHandler} class now calls finish() instead of close() on the stream.
- Added the following annotations to the {@link org.apache.juneau.rest.BasicRestServlet} class (which were previously defined on the Resource class):

  @RestResource( htmldoc=@HtmlDoc( navlinks={ "up: request:/..", "options: servlet:/?method=OPTIONS" }, stylesheet="$C{REST/stylesheet,servlet:/styles/devops.css}" ), // Optional external configuration file. config="$S{juneau.configFile}" )

##### juneau-rest-client

- New configuration property {@link org.apache.juneau.rest.client.RestClient#RESTCLIENT_query} and builder method {@link org.apache.juneau.rest.client.RestClientBuilder#query(String,Object)}.
- API changes to replace PartSerializer with {@link org.apache.juneau.httppart.HttpPartSerializer}.
  The default value is now SimpleUonPartSerializer which will serialize strings as plain-text and collections/arrays as comma-delimited lists.
  We decided to change the default behavior in favor of practicality over purity.
- New methods on {@link org.apache.juneau.rest.client.RestCall} class:
  - {@link org.apache.juneau.rest.client.RestCall#getResponseHeader(String) getResponseHeader(String)}
  - {@link org.apache.juneau.rest.client.RestCall#getResponseCode() getResponseCode()}
- {@link org.apache.juneau.rest.client.RestCall} and {@link org.apache.juneau.rest.client.RestClient} now implement the Closeable interface.

##### juneau-microservice

- Resource and ResourceGroup classes removed.
  {@link org.apache.juneau.rest.BasicRestServlet} and {@link org.apache.juneau.rest.BasicRestServletGroup} can be used instead.
- ResourceJena and ResourceJenaGroup classes renamed to BasicRestServletJena and BasicRestServletJenaGroup.

### 7.2.0 (Sept 25, 2018)

7.2.0 is a major release that introduces several significant new features:

- OpenAPI part serializing and parsing with full support for OpenAPI validation of input and output in the REST servlet and client APIs.
- Swagger UI.
- New HTTP-Part annotations that are applicable to both the servlet and client APIs.
- Serverless servlet and client unit testing.
- Simplified UI customization.
- Marshalls that combines serializers and parsers into a single API.

##### juneau-marshall

- The REST client @Remoteable annotations and REST server @RemoteMethod annotations which used to be in separate packages in the client and server projects have been combined into a single set of annotations in the {@link org.apache.juneau.http.annotation} package.
  This fixes a long-standing problem where it was easy to mix up using client-side annotations in server-side code, and vis-versa.
  Additionally, much work has been done on these annotations to add support for Swagger-style validations and documentation.
  - {@link org.apache.juneau.http.annotation.Body}
  - {@link org.apache.juneau.http.annotation.FormData}
  - {@link org.apache.juneau.http.annotation.Header}
  - {@link org.apache.juneau.http.annotation.Path}
  - {@link org.apache.juneau.http.annotation.Query}
  - {@link org.apache.juneau.http.annotation.HasFormData}
  - {@link org.apache.juneau.http.annotation.HasQuery}
  - {@link org.apache.juneau.http.annotation.Request}
  These are used with new Swagger schema/documentation annotations to produce schema-based serialization/parsing/validation and auto-generated Swagger documentation:
  - {@link org.apache.juneau.http.annotation.Contact}
  - ExternalDocs
  - Items
  - {@link org.apache.juneau.http.annotation.License}
  - Schema
  - SubItems
  - {@link org.apache.juneau.http.annotation.Tag}
  Additionally, the @Remoteable annotation has been split into the following two annotations:
  - {@link org.apache.juneau.remote.RemoteInterface} - Used for remote proxy interfaces served up through RemoteInterfaceServlet or REST "PROXY" methods.
    Defaults to "POST" with method signatures as paths.
  - RemoteResource - Used for 3rd-party REST interfaces.
    Defaults to "GET" with standardized naming conventions for paths.
- Support for multi-valued parameters as maps or beans on server-side annotations (it was previously supported on client-side): @Query("*"), @FormData("*"), @Header("*"), @Path("*")
- Support for server-side use of @Request annotation on @RestMethod annotations and new {@link org.apache.juneau.rest.RestRequest#getRequest(RequestBeanMeta)} method.
- Fixed bug where @Bean(typeName) was not being detected on non-bean POJO classes.
- Fixed bug where HTML-Schema was not being rendered correctly.
- Support for POJO examples:
  - {@link org.apache.juneau.BeanContext#BEAN_examples}
  - {@link org.apache.juneau.annotation.Example}
- Fixed bug where parsers could report the wrong line number when an error occurred.
- A runtime exception is now thrown if you define a @BeanProperty(name) but forget to add it to your @Bean(properties) annotation.
- @Html(asXml) and @Html(asPlainText) replaced with {@link org.apache.juneau.html.annotation.Html#format() @Html(format)}.
- HTML serializer will now serializers beans and maps as HTML even when those objects are embedded within an object with @Html(format=XML).
  The previous behavior was to serialize it as XML.
- New settings for binary-based serializers and parsers:
  - {@link org.apache.juneau.serializer.OutputStreamSerializer#OSSERIALIZER_binaryFormat}
  - {@link org.apache.juneau.parser.InputStreamParser#ISPARSER_binaryFormat}
- Added support for auto-detection of fluent-style setters:
  - {@link org.apache.juneau.BeanContext#BEAN_fluentSetters}
  - {@link org.apache.juneau.annotation.Bean#fluentSetters()}
- The SERIALIZER_abridged setting has been replaced with {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addRootType SERIALIZER_addRootType}
- The SERIALIZER_addBeanTypeProperties setting has been replaced with {@link org.apache.juneau.serializer.Serializer#SERIALIZER_addBeanTypes SERIALIZER_addBeanTypes} and is disabled by default.
- Parse exception messages are now clearer and include code snippets of where a parse exception occurred:

  org.apache.juneau.parser.ParseException: Expected '[' at beginning of JSON array. At line 80, column 20. While parsing into: currentClass: List<String> currentProperty: required: java.util.List, field=[null], getter=[public java.util.List org.apache.juneau.dto.swagger.SchemaInfo.getRequired()], setter=[public org.apache.juneau.dto.swagger.SchemaInfo org.apache.juneau.dto.swagger.SchemaInfo.setRequired(java.util.Collection)] ---start-- 0075: "name": "body", 0076: "description": "Pet object that needs to be added to the store", 0077: "required": true, 0078: "schema": { 0079: "required": true, 0080: } 0081: } 0082: ], 0083: "responses": { 0084: "405": { 0085: "description": "Invalid input" ---end---

- New property {@link org.apache.juneau.parser.Parser#PARSER_debugOutputLines} for controlling how many input lines are added to the exception message above.
- New property {@link org.apache.juneau.BeanContext#BEAN_useEnumNames} for controlling whether enums are serialized using their name or the toString() method.
- New property {@link org.apache.juneau.BeanContext#BEAN_examples} for defining examples of POJOs.
- New {@link org.apache.juneau.annotation.Example @Example} annotation for defining examples of POJOs.
  Used heavily in JSON-Schema support.
- If a bean has both a getX() and isX() method, the getX() method takes precedence.
  The previous behavior was arbitrary.
- Significant improvements to JSON-Schema serialization support.
  - New @JsonSchema annotation.
- Fixed NullPointerException when serializing beans with a dyna-property (i.e. @Bean("*")) which returns a null value.
- New option for dyna-property (i.e. @Bean("*")) using a method that returns a collection of extra keys.
  See new options #4 on {@link org.apache.juneau.annotation.BeanProperty#name()}
- New formats for the {@link org.apache.juneau.html.annotation.Html#format() @Html(format)} annotation:
  - {@link org.apache.juneau.html.annotation.HtmlFormat#HTML_CDC} - Format collections as comma-delimited lists.
  - {@link org.apache.juneau.html.annotation.HtmlFormat#HTML_SDC} - Format collections as space-delimited lists.
- Serializers now allow for q-values on the media types they handle.
  For example, the accept media type on JsonSerializer.Simple is "application/json+simple,application/json;q=0.9".
  This means the serializer CAN handle requests for "application/json" if no other serializers provide a better match.
- New methods for creating unmodifiable {@link org.apache.juneau.ObjectMap ObjectMaps} and {@link org.apache.juneau.ObjectList ObjectLists}.
  - {@link org.apache.juneau.ObjectMap}
    - {@link org.apache.juneau.ObjectMap#isUnmodifiable() isUnmodifable()}
    - {@link org.apache.juneau.ObjectMap#unmodifiable() unmodifiable()}
    - {@link org.apache.juneau.ObjectMap#modifiable() modifiable()}
  - {@link org.apache.juneau.ObjectList}
    - {@link org.apache.juneau.ObjectList#isUnmodifiable() isUnmodifable()}
    - {@link org.apache.juneau.ObjectList#unmodifiable() unmodifiable()}
    - {@link org.apache.juneau.ObjectList#modifiable() modifiable()}
- The JsonSerializer.Simple class has been moved into the top-level {@link org.apache.juneau.json.SimpleJsonSerializer} class.
- RDF serializer subclasses have been moved into top-level classes:
  - RdfSerializer.Xml -> {@link org.apache.juneau.jena.RdfXmlSerializer}
  - RdfSerializer.XmlAbbrev -> {@link org.apache.juneau.jena.RdfXmlAbbrevSerializer}
  - RdfSerializer.N3 -> {@link org.apache.juneau.jena.N3Serializer}
  - RdfSerializer.NTriple -> {@link org.apache.juneau.jena.NTripleSerializer}
  - RdfSerializer.Turtle -> {@link org.apache.juneau.jena.TurtleSerializer}
  - RdfParser.Xml -> {@link org.apache.juneau.jena.RdfXmlParser}
  - RdfParser.N3 -> {@link org.apache.juneau.jena.N3Parser}
  - RdfParser.NTriple -> {@link org.apache.juneau.jena.NTripleParser}
  - RdfParser.Turtle -> {@link org.apache.juneau.jena.TurtleParser}
- New API for pairing serializers and parsers for simplified syntax:

  ##### Examples:

  // Using instance. Json json = new Json(); MyPojo myPojo = json.read(string, MyPojo.class); String string = json.write(myPojo);

  // Using DEFAULT instance. MyPojo myPojo = Json.DEFAULT.read(string, MyPojo.class); String string = Json.DEFAULT.write(myPojo);

  - {@link org.apache.juneau.marshall.Marshall}
    - {@link org.apache.juneau.marshall.CharMarshall}
      - {@link org.apache.juneau.marshall.Html}
      - {@link org.apache.juneau.marshall.Json}
      - {@link org.apache.juneau.marshall.PlainText}
      - {@link org.apache.juneau.marshall.SimpleJson}
      - {@link org.apache.juneau.marshall.Uon}
      - {@link org.apache.juneau.marshall.UrlEncoding}
      - {@link org.apache.juneau.marshall.Xml}
      - {@link org.apache.juneau.marshall.N3}
      - {@link org.apache.juneau.marshall.NTriple}
      - {@link org.apache.juneau.marshall.RdfXml}
      - {@link org.apache.juneau.marshall.RdfXmlAbbrev}
      - {@link org.apache.juneau.marshall.Turtle}
    - {@link org.apache.juneau.marshall.StreamMarshall}
      - {@link org.apache.juneau.marshall.Jso}
      - {@link org.apache.juneau.marshall.MsgPack}
- New/updated documentation:
  - 2.15.3 - Simplified JSON

##### juneau-dto

- Fixed bug where Swagger {@link org.apache.juneau.dto.swagger.SchemaInfo#required(Object...)} was defined as a boolean instead of a list of strings.
- Boolean attributes are now handled correctly for HTML5.
  For example, calling new Select().disabled(true) will produce <select disabled='disabled'>

##### juneau-rest-server

- Auto-generated {@doc juneau-rest-server.Swagger Swagger UI}.
- Simplified @RestResource(swagger) and {@link org.apache.juneau.rest.annotation.RestMethod#swagger() @RestMethod(swagger)} annotations.
- Fixed bug in UriResolver when request path info had special characters.
- Fixed bug where incorrect media type was being set on responses (e.g. text/html+schema instead of text/html for schema documents).
- The RemoteableServlet class has been moved and renamed to RemoteInterfaceServlet.
- RemoteInterfaceServlet now provides a form page for invoking remote interface methods in a browser.
- Newlines were being stripped from @HtmlDoc(script) when serialized which could cause script lines to become commented out.
- New {@link org.apache.juneau.http.annotation.Response @Response} annotation that can be applied to throwables thrown from REST methods and POJOs returned by REST methods to specify non-200 status return codes and descriptions in Swagger documentation.
- Swagger fields added to the following annotations:
  - {@link org.apache.juneau.http.annotation.Body}
  - {@link org.apache.juneau.http.annotation.FormData}
  - {@link org.apache.juneau.http.annotation.Header}
  - {@link org.apache.juneau.http.annotation.Path}
  - {@link org.apache.juneau.http.annotation.Query}
- The @PathRemainder annotation has been removed entirely.
  Use @Path("/*") to access the path remainder which includes all the new OpenAPI parsing support.
- "Helper" classes (i.e. reusable beans that can be returned by REST methods) have been moved to the following package with some new additions:
  - {@link org.apache.juneau.rest.helper}
    - {@link org.apache.juneau.rest.helper.BeanDescription}
    - {@link org.apache.juneau.rest.helper.ChildResourceDescriptions}
    - ReaderResource
    - ReaderResourceBuilder
    - {@link org.apache.juneau.rest.helper.SeeOtherRoot}
    - {@link org.apache.juneau.rest.helper.ResourceDescription}
    - StreamResource
    - StreamResourceBuilder
- Predefined HTTP responses.
  - {@link org.apache.juneau.rest.response}
    - {@link org.apache.juneau.rest.response.Accepted}
    - {@link org.apache.juneau.rest.response.AlreadyReported}
    - {@link org.apache.juneau.rest.response.Continue}
    - {@link org.apache.juneau.rest.response.Created}
    - {@link org.apache.juneau.rest.response.EarlyHints}
    - {@link org.apache.juneau.rest.response.Found}
    - {@link org.apache.juneau.rest.response.IMUsed}
    - {@link org.apache.juneau.rest.response.MovedPermanently}
    - {@link org.apache.juneau.rest.response.MultipleChoices}
    - {@link org.apache.juneau.rest.response.MultiStatus}
    - {@link org.apache.juneau.rest.response.NoContent}
    - {@link org.apache.juneau.rest.response.NonAuthoritiveInformation}
    - {@link org.apache.juneau.rest.response.NotModified}
    - {@link org.apache.juneau.rest.response.Ok}
    - {@link org.apache.juneau.rest.response.PartialContent}
    - {@link org.apache.juneau.rest.response.PermanentRedirect}
    - {@link org.apache.juneau.rest.response.Processing}
    - {@link org.apache.juneau.rest.response.ResetContent}
    - {@link org.apache.juneau.rest.response.SeeOther}
    - {@link org.apache.juneau.rest.response.SwitchingProtocols}
    - {@link org.apache.juneau.rest.response.TemporaryRedirect}
    - {@link org.apache.juneau.rest.response.UseProxy}
- Predefined HTTP error throwables.
  When added to REST Java methods, reflected in generated Swagger documentation.
  - {@link org.apache.juneau.rest.exception}
    - {@link org.apache.juneau.rest.exception.BadRequest}
    - {@link org.apache.juneau.rest.exception.Conflict}
    - {@link org.apache.juneau.rest.exception.ExpectationFailed}
    - {@link org.apache.juneau.rest.exception.FailedDependency}
    - {@link org.apache.juneau.rest.exception.Forbidden}
    - {@link org.apache.juneau.rest.exception.Gone}
    - {@link org.apache.juneau.rest.exception.HttpVersionNotSupported}
    - {@link org.apache.juneau.rest.exception.InsufficientStorage}
    - {@link org.apache.juneau.rest.exception.InternalServerError}
    - {@link org.apache.juneau.rest.exception.LengthRequired}
    - {@link org.apache.juneau.rest.exception.Locked}
    - {@link org.apache.juneau.rest.exception.LoopDetected}
    - {@link org.apache.juneau.rest.exception.MethodNotAllowed}
    - {@link org.apache.juneau.rest.exception.MisdirectedRequest}
    - {@link org.apache.juneau.rest.exception.NetworkAuthenticationRequired}
    - {@link org.apache.juneau.rest.exception.NotAcceptable}
    - {@link org.apache.juneau.rest.exception.NotExtended}
    - {@link org.apache.juneau.rest.exception.NotFound}
    - {@link org.apache.juneau.rest.exception.NotImplemented}
    - {@link org.apache.juneau.rest.exception.PayloadTooLarge}
    - {@link org.apache.juneau.rest.exception.PreconditionFailed}
    - {@link org.apache.juneau.rest.exception.PreconditionRequired}
    - {@link org.apache.juneau.rest.exception.RangeNotSatisfiable}
    - {@link org.apache.juneau.rest.exception.RequestHeaderFieldsTooLarge}
    - {@link org.apache.juneau.rest.exception.ServiceUnavailable}
    - {@link org.apache.juneau.rest.exception.TooManyRequests}
    - {@link org.apache.juneau.rest.exception.Unauthorized}
    - {@link org.apache.juneau.rest.exception.UnavailableForLegalReasons}
    - {@link org.apache.juneau.rest.exception.UnprocessableEntity}
    - {@link org.apache.juneau.rest.exception.UnsupportedMediaType}
    - {@link org.apache.juneau.rest.exception.UpgradeRequired}
    - {@link org.apache.juneau.rest.exception.UriTooLong}
    - {@link org.apache.juneau.rest.exception.VariantAlsoNegotiates}
- The {@link org.apache.juneau.rest.annotation.HtmlDoc#nav() @HtmlDoc(nav)} and {@link org.apache.juneau.rest.annotation.HtmlDoc#navlinks() @HtmlDoc(navlinks)} can now both be used on the same annotation.
  The contents of nav() are free-form HTML that gets rendered immediately after the navigation links.
- The following new parameter types can be used on REST methods:
  - {@link org.apache.juneau.parser.ReaderParser} - The reader parser matching the request content type.
  - {@link org.apache.juneau.parser.InputStreamParser} - The input stream parser matching the request content type.
- The $F variable can now be used as a initialization time variable.
  For example, the AtomFeedResource example pulls a bean example from a file on the classpath:

  @RestResource( path="/atom", title="Sample ATOM feed resource", properties={ @Property(name=BEAN_examples, value="{'org.apache.juneau.dto.atom.Feed': $F{AtomFeedResource_example.json}}") }, ... )

  It should be noted that you cannot use the $F variable to retrieve localized versions of files (since you're not within the scope of a client request.
- The RestResource.nowrap() annotation has been changed to a string with a default value of "true".
  Having it as a string allows us to differentiate between a set and unset value so that it can be overridden in subclasses.
- The {@link org.apache.juneau.http.annotation.Path#name()} annotation parameter is now required.
- New class for mock unit testing of REST resources:
  - MockRest
- @RestMethod(inherit) annotation has been removed and replaced with the following classes:
  - {@link org.apache.juneau.rest.Inherit}
  - {@link org.apache.juneau.rest.None}
  These can be used in the following locations:
  - RestResource.serializers()
  - RestResource.parsers()
  - RestResource.beanFilters()
  - RestResource.pojoSwaps()
  - {@link org.apache.juneau.rest.annotation.RestMethod#serializers()}
  - {@link org.apache.juneau.rest.annotation.RestMethod#parsers()}
  - {@link org.apache.juneau.rest.annotation.RestMethod#beanFilters()}
  - {@link org.apache.juneau.rest.annotation.RestMethod#pojoSwaps()}
  One advantage is that you now have control over the precedence of serializers and parsers by where you insert the Inherit class.
- RequestPathMatch class has been renamed to {@link org.apache.juneau.rest.RequestPath}.
- {@link org.apache.juneau.http.annotation.Request @Request} objects can now be used as parameters in @RestMethod methods.
  Includes new methods on {@link org.apache.juneau.rest.RestRequest}:
  - {@link org.apache.juneau.rest.RestRequest#getRequest(Class) getRequest(Class)}
  - {@link org.apache.juneau.rest.RestRequest#getRequest(RequestBeanMeta) getRequest(RequestBeanMeta)}
- New methods added to {@link org.apache.juneau.rest.widget.MenuItemWidget} to allow population of menu item content using Javascript and Ajax calls:
  - {@link org.apache.juneau.rest.widget.MenuItemWidget}
    - getBeforeShowScript(RestRequest)
    - getAfterShowScript(RestRequest)
- New methods added to {@link org.apache.juneau.rest.widget.Widget} to allow retrieving classpath resources with embedded SVL variables:
  - {@link org.apache.juneau.rest.widget.Widget}
    - loadHtmlWithVars(RestRequest,String)
    - loadScriptWithVars(RestRequest,String)
    - loadStyleWithVars(RestRequest,String)
- New/updated documentation:
  juneau-rest-server.UnitTesting
- The behavior of the default values for {@link org.apache.juneau.rest.annotation.RestMethod#name()} and {@link org.apache.juneau.rest.annotation.RestMethod#path()} have changed.
  If not specified, the values are inferred from the Java method name.
  See Also: {@doc juneau-rest-server.RestMethod}
- RedirectToServletRoot class has been renamed to {@link org.apache.juneau.rest.helper.SeeOtherRoot}.
- New REST context settings:
  - {@link org.apache.juneau.rest.RestContext}
    - {@link org.apache.juneau.rest.RestContext#REST_uriAuthority REST_uriAuthority}
    - {@link org.apache.juneau.rest.RestContext#REST_uriContext REST_uriContext}
    - {@link org.apache.juneau.rest.RestContext#REST_uriRelativity REST_uriRelativity}
    - {@link org.apache.juneau.rest.RestContext#REST_uriResolution REST_uriResolution}
- New convenience annotations for specifying default Accept and Content-Type headers:
  - RestResource
    - defaultAccept
    - defaultContentType
  - {@link org.apache.juneau.rest.annotation.RestMethod}
    - {@link org.apache.juneau.rest.annotation.RestMethod#defaultAccept defaultAccept}
    - {@link org.apache.juneau.rest.annotation.RestMethod#defaultContentType defaultContentType}

##### juneau-rest-client

- Remote Resource interfaces support OpenAPI annotations.
- Made improvements to the builder API for defining SSL support.
  New methods added:
  - {@link org.apache.juneau.rest.client.RestClientBuilder}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#sslProtocols(String...) sslProtocols(String...)}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#cipherSuites(String...) cipherSuites(String...)}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#hostnameVerifier(HostnameVerifier) hostnameVerifier(HostnameVerifier)}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#keyManagers(KeyManager...) keyManagers(KeyManager...)}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#trustManagers(TrustManager...)}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#secureRandom(SecureRandom)}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#httpClientConnectionManager(HttpClientConnectionManager)}
- Clients no longer have JSON defined as the default serializer and parser.
  Instead, the clients can now be used with no serializer/parser if you're working with InputStreams/Readers or POJOs that can be converted to Strings and converted from Strings/InputStreams/Readers.
- Methods added to client builder to make it easy to define the transport language:
  - {@link org.apache.juneau.rest.client.RestClientBuilder}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#json() json()}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#xml() xml()}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#html() html()}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#uon() uon()}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#urlEnc() urlEnc()}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#msgpack() msgpack()}
    - {@link org.apache.juneau.rest.client.RestClientBuilder#plainText() plainText()}
- New method added for allowing serverless client testing against REST interfaces.
  - {@link org.apache.juneau.rest.client.RestClientBuilder}
    - mockHttpConnection(MockHttpConnection)
- Removed the deprecated RestCall.execute() method.
  Use {@link org.apache.juneau.rest.client.RestCall#run()}.
- RestCall.input(Object) method renamed to {@link org.apache.juneau.rest.client.RestCall#body(Object)} to match OpenAPI terminology.
- Made constructors on RestClient and RestClientBuilder protected so that they can be subclassed.
- The RestClient.getRemoteableProxy() methods have been split into separate methods for Remote Interfaces and Remote Resources:
  - {@link org.apache.juneau.rest.client.RestClient}
    - RestClient.getRemoteInterface(Class)
    - RestClient.getRemoteInterface(Class,Object)
    - RestClient.getRemoteInterface(Class,Object,Serializer,Parser)
    - {@link org.apache.juneau.rest.client.RestClient#getRemoteResource(Class)}
    - {@link org.apache.juneau.rest.client.RestClient#getRemoteResource(Class,Object)}
    - {@link org.apache.juneau.rest.client.RestClient#getRemoteResource(Class,Object,Serializer,Parser)}

##### juneau-rest-microservice

- The look-and-feel of an application is now controlled through the external configuration file and access to CSS stylesheets in the working directory in a new folder called files:
  The default configuration is this:

  #======================================================================================================================= # REST settings #======================================================================================================================= [REST] staticFiles = htdocs:files/htdocs # Stylesheet to use for HTML views. theme = servlet:/htdocs/themes/devops.css headerIcon = servlet:/htdocs/images/juneau.png headerLink = http://juneau.apache.org footerIcon = servlet:/htdocs/images/asf.png footerLink = http://www.apache.org icon = $C{REST/headerIcon} header = <a href='$U{$C{REST/headerLink}}'><img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/></a> footer = <a href='$U{$C{REST/footerLink}}'><img style='float:right;padding-right:20px;height:32px' src='$U{$C{REST/footerIcon}}'>

  Note that static files can now be served up from the files directory in the working directory, and you have access to modify the CSS theme files.
  The SwaggerUI.css file controls the look-and-feel of the Swagger UI, so you can make modification there as well.
  The BasicRestConfig interface (which defines the default settings for the BasicRestServlet class) now looks like this...

  @RestResource( ... htmldoc=@HtmlDoc( header={ "<h1>$R{resourceTitle}</h1>", "<h2>$R{methodSummary,resourceDescription}</h2>", "$C{REST/header}" }, navlinks={ "up: request:/.." }, stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}", head={ "<link rel='icon' href='$U{$C{REST/icon}}'/>" }, footer="$C{REST/footer}" ), // These are static files that are served up by the servlet under the specified sub-paths. // For example, "/servletPath/htdocs/javadoc.css" resolves to the file "[servlet-package]/htdocs/javadoc.css" staticFiles={"$C{REST/staticFiles}"} ) public interface BasicRestConfig {}

  The PoweredByApache widget which used to serve as a page footer has been eliminated.
  If you're testing out changes in the theme stylesheets, you may want to set the following system property that prevents caching of those files so that you don't need to restart the microservice each time a change is made:

  #======================================================================================================================= # System properties #======================================================================================================================= [SystemProperties] # Disable classpath resource caching. # Useful if you're attached using a debugger and you're modifying classpath resources while running. RestContext.useClasspathResourceCaching.b = false

- Upgraded to Jetty 9.4.12.

### 7.2.1 (Oct 23, 2018)

This release contains mostly bug fixes. Code changes have been made to preserve binary backwards compatibility with 7.1.0.

##### juneau-marshall

- The @JsonSchema annotation has been merged with the {@link org.apache.juneau.jsonschema.annotation.Schema @Schema} annotation.
- Annotations typically used on bean properties (getters/setters/public fields) can now be used on private fields. This is inline with behavior on JPA-annotated beans. These include: @Swap, @Html, @Xml, @BeanProperty.

##### juneau-rest-server

- Method-level annotations (e.g. @RestMethod) and parameter-level annotations (e.g. @Query) are now inheritable from parent classes and interfaces.
  This allows you to define {@doc juneau-rest-client.RestProxies.DualPurposeInterfaces}.
- The ReaderResource and StreamResource classes have been moved to the org.apache.juneau.http package in juneau-marshall. This allows them to be used as return types in remote REST interfaces.
  A new {@link org.apache.juneau.rest.helper.ResolvingReaderResource} class has been added that includes the variable-resolving support since this relies on the juneau-svl package.
- The RemoteInterfaceServlet class has been renamed to {@link org.apache.juneau.rest.remote.RrpcServlet}.
- @RestMethod(name="PROXY") has been changed to @RestMethod(name="RRPC").

##### juneau-rest-client

- The RestClient.getRemoteInterface() method has been renamed to {@link org.apache.juneau.rest.client.RestClient#getRrpcInterface(Class)}.
- Fixed a bug where @RemoteMethod(path) values containing '/' characters were erroneously being encoded.

### 7.2.2 (Nov 7, 2018)

This release contains minor bug fixes and general improvements to the PetStore sample application.

### 8.0.0 (Jan 01, 2019)

This release cleans up deprecated APIs from the 7.2.0 release and makes significant modifications to the Microservice APIs.

The project structures of the REST, Microservice, and Examples have been modified to fit new Spring Boot integration support. The structure is now as follows:

- juneau-rest
  - juneau-rest-client
  - juneau-rest-server
  - juneau-rest-server-jaxrs
  - juneau-rest-server-rdf
  - juneau-rest-server-springboot - New Spring Boot integration support classes.
- juneau-microservice
  - juneau-microservice-core - New. Contains base {@link org.apache.juneau.microservice.Microservice} class.
  - juneau-microservice-jetty - New. Contains new {@link org.apache.juneau.microservice.jetty.JettyMicroservice} class.
  - juneau-my-jetty-microservice - New. Template starter project for Jetty-based microservices.
  - juneau-my-springboot-microservice - New. Template starter project for Spring-Boot-based microservices.
- juneau-examples
  - juneau-core
  - juneau-microservice-rest - Now contains only servlet example classes. No Jetty configuration.
  - juneau-microservice-rest-jetty - Servlet examples deployed using Jetty.
  - juneau-microservice-rest-springboot - Servlet examples deployed using Spring Boot.

##### juneau-svl

- New SVL variables:
  - {@link org.apache.juneau.svl.vars.SubstringVar}
  - {@link org.apache.juneau.svl.vars.PatternExtractVar}
  - {@link org.apache.juneau.svl.vars.PatternReplaceVar}
  - {@link org.apache.juneau.svl.vars.LenVar}

##### juneau-config

- New methods for setting a system default configuration:
  - {@link org.apache.juneau.config.Config}
    - {@link org.apache.juneau.config.Config#getSystemDefault() getSystemDefault()}
    - {@link org.apache.juneau.config.Config#setSystemDefault(Config) setSystemDefault(Config)}
- New classpath store.
  - {@link org.apache.juneau.config.store.ConfigClasspathStore}
- New API method:
  - {@link org.apache.juneau.config.store.ConfigStore}
    - {@link org.apache.juneau.config.store.ConfigStore#exists(String) exists(String)}

##### juneau-rest-server

- New methods on {@link org.apache.juneau.rest.RestServlet}:
  - {@link org.apache.juneau.rest.RestServlet#setRestResourceResolver(RestResourceResolver) setRestResourceResolver(RestResourceResolver)}
  - {@link org.apache.juneau.rest.RestServlet#getPath() getPath()}
- The registered resource resolver is now used to instantiate objects of classes defined via @RestResource.
  This allows for any of those instance to be injectable beans.

##### juneau-rest-server-springboot

- New project containing classes for making it easy to use Juneau with Spring Boot.

##### juneau-microservice-core

- New project that consist of just the core {@link org.apache.juneau.microservice.Microservice} class and console support.
- The Microservice API has been revamped to use a builder-based approach to creating microservices.
  The new API is considerably more flexible in design and allows for the configuration and external files to be located in either the home directory or inside the jar classpath.
- If the microservice cannot find a config file in the home directory with the same name as the jar and the "juneau.configFile" system property is not found, it will try to find any file in the home directory that ends with ".cfg".
- New {@link org.apache.juneau.microservice.MicroserviceListener} API for defining lifecycle event listeners.
- New {@link org.apache.juneau.microservice.console.ConfigCommand} class for performing config queries and updates through the microservice console.

##### juneau-microservice-jetty

- New {@link org.apache.juneau.microservice.jetty.JettyMicroservice} class replaces the previous RestMicroservice.

##### juneau-my-jetty-microservice

- New template starter project for Jetty-based microservices.

##### juneau-my-springboot-microservice

- Template starter project for Spring-Boot-based microservices.
- app.json and Procfile files for deploying examples into Heroku.
  Includes instructions.

### 8.1.0 (Aug 21, 2019)

8.1.0 introduces some significant new features including:

- Configurable Annotations
- Default PojoSwaps
- Config Imports
- BasicRest, BasicRestGroup classes
- Path variables on resource paths
- Request Attributes API
- Role Guards
- Improved REST logging/debugging
- New MockRest API

##### juneau-marshall

- New utility class for diffing beans:
  - {@link org.apache.juneau.utils.BeanDiff}
- New annotation for defining bean property names:
  - {@link org.apache.juneau.annotation.Name}
- New serializer properties:
  - {@link org.apache.juneau.serializer.WriterSerializer}
    - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_fileCharset WSERIALIZER_fileCharset}
    - {@link org.apache.juneau.serializer.WriterSerializer#WSERIALIZER_streamCharset WSERIALIZER_streamCharset}
- The following POJO methods can be used to convert a POJO to/from a Map before serialization and after parsing.
  It's a convenient way of defining a POJO transform.
  - public Map toMap() - Can be any type of map with string keys and object vals.
  - public ObjectMap toMap()
  - public Map toMap(BeanSession bs) - Can be any type of map with string keys and object vals.
  - public ObjectMap toMap(BeanSession bs)
  - public static T fromMap(Map m) - Can be any type of map with string keys and object vals.
  - public static T fromMap(ObjectMap m)
  - public static T fromMap(BeanSession bs, Map m) - Can be any type of map with string keys and object vals.
  - public static T fromMap(BeanSession bs, ObjectMap m)
- New convenience debugging methods on Marshall API:
  - {@link org.apache.juneau.marshall.Marshall}
    - {@link org.apache.juneau.marshall.Marshall#format(String,Object...) format(String,Object...)} - MessageFormat-style formatter.
    - {@link org.apache.juneau.marshall.Marshall#out(String,Object...) out(String,Object...)} - Prints MessageFormat-style messages to STDOUT.
    - {@link org.apache.juneau.marshall.Marshall#err(String,Object...) err(String,Object...)} - Prints MessageFormat-style messages to STDERR.
- Serializer and parser APIs now throw IOExceptions in addition to SerializeException and ParseException to make it easier to determine if problems are stream based or syntax based.
- New Java 8 date-time transforms:
  - {@link org.apache.juneau.transforms.TemporalSwap} - For all Java 8 temporal types (e.g. {@link java.time.ZonedDateTime})
  - {@link org.apache.juneau.transforms.TemporalDateSwap} - For {@link java.util.Date}
  - {@link org.apache.juneau.transforms.TemporalCalendarSwap} - For {@link java.util.Calendar}
- All serializers and parsers now have built-in default swaps for common class types:
  - {@link java.util.Enumeration}
  - {@link java.util.Iterator}
  - {@link java.util.Locale}
  - {@link java.util.Calendar} - ISO offset date-time.
  - {@link java.util.Date} - Local date-time
  - {@link java.time.Instant} - ISO instant.
  - {@link java.time.ZonedDateTime} - ISO offset date-time.
  - {@link java.time.LocalDate} - ISO local date.
  - {@link java.time.LocalDateTime} - ISO local date-time.
  - {@link java.time.LocalTime} - ISO local time.
  - {@link java.time.OffsetDateTime} - ISO offset date-time.
  - {@link java.time.OffsetTime} - ISO offset time.
  - {@link java.time.Year} - ISO year.
  - {@link java.time.YearMonth} - ISO year-month.
  - {@link java.time.Temporal} - ISO instant.
  - {@link java.util.TimeZone}
  - {@link javax.xml.datatype.XMLGregorianCalendar}
  - {@link java.time.ZoneId}

##### juneau-config

- Support for import statements:

  # Import values from another configuration: <ParentConfig1> [Foo] bar = baz

- The {@link org.apache.juneau.config.store.ConfigFileStore} now automatically resolves file extensions.
  New configuration property for specifying search paths for file extensions:
  - {@link org.apache.juneau.config.store.ConfigFileStore#FILESTORE_extensions}
- Fixed a bug where instances of {@link org.apache.juneau.config.store.ConfigMemoryStore} ended up resolving to the same object.
- Uses "application.properties" file as a system default if present.
  Useful when being used in a Spring Boot application.
- New {@link org.apache.juneau.config.Config#setSystemProperties} method for quickly moving configuration settings into the system properties.
- Entries in the system config are automatically set as system properties.
  This mean you can set any of the various serializer and parser settings (e.g. "JsonSerializer.simpleMode.b") in the default configuration area or application.properties.

##### juneau-rest-server

- New annotations that can be applied to REST classes and methods to configure serializers and parsers.

  // Old way using generic properties. @RestResource( path="/atom", title="Sample ATOM feed resource", properties={ @Property(name=WSERIALIZER_quoteChar, value="'"), @Property(name=RDF_rdfxml_tab, value="5"), @Property(nameRDF_addRootProperty, value="true"), @Property(name=BEAN_examples, value="{'org.apache.juneau.dto.atom.Feed': $F{AtomFeedResource_example.json}}") } ... ) public class AtomFeedResource extends BasicRestServletJena { ... }

  // New way using specific annotations. @RestResource( path="/atom", title="Sample ATOM feed resource" ... ) @SerializerConfig(quoteChar="'") @RdfConfig(rdfxml_tab="5", addRootProperty="true") @BeanConfig(examples="Feed: $F{AtomFeedResource_example.json}") public class AtomFeedResource extends BasicRestServletJena { ... }

  Config annotations are provided for all serializers and parsers:

  - {@link org.apache.juneau.annotation.BeanConfig BeanConfig}
  - {@link org.apache.juneau.csv.annotation.CsvConfig CsvConfig}
  - {@link org.apache.juneau.html.annotation.HtmlConfig HtmlConfig}
  - {@link org.apache.juneau.html.annotation.HtmlDocConfig HtmlDocConfig}
  - {@link org.apache.juneau.jso.annotation.JsoConfig JsoConfig}
  - {@link org.apache.juneau.json.annotation.JsonConfig JsonConfig}
  - {@link org.apache.juneau.jsonschema.annotation.JsonSchemaConfig JsonSchemaConfig}
  - {@link org.apache.juneau.msgpack.annotation.MsgPackConfig MsgPackConfig}
  - {@link org.apache.juneau.oapi.annotation.OpenApiConfig OpenApiConfig}
  - {@link org.apache.juneau.parser.annotation.ParserConfig ParserConfig}
  - {@link org.apache.juneau.plaintext.annotation.PlainTextConfig PlainTextConfig}
  - {@link org.apache.juneau.jena.annotation.RdfConfig RdfConfig}
  - {@link org.apache.juneau.serializer.annotation.SerializerConfig SerializerConfig}
  - {@link org.apache.juneau.soap.annotation.SoapXmlConfig SoapXmlConfig}
  - {@link org.apache.juneau.uon.annotation.UonConfig UonConfig}
  - {@link org.apache.juneau.urlencoding.annotation.UrlEncodingConfig UrlEncodingConfig}
  - {@link org.apache.juneau.xml.annotation.XmlConfig XmlConfig}
- New support for using Servlet request attributes.
  - {@link org.apache.juneau.rest.RequestAttributes}
  - {@link org.apache.juneau.rest.RestContext}
    - REST_attrs
  - {@link org.apache.juneau.rest.RestContextBuilder}
    - attrs(String...)
    - attr(String,Object)
  - {@link org.apache.juneau.rest.RestMethodContext}
    - {@link org.apache.juneau.rest.RestMethodContext#RESTMETHOD_attrs RESTMETHOD_attrs}
  - {@link org.apache.juneau.rest.RestRequest}
    - {@link org.apache.juneau.rest.RestRequest#getAttributes() getAttributes()}
  - {@link org.apache.juneau.rest.RestResponse}
    - {@link org.apache.juneau.rest.RestResponse#getAttributes() getAttributes()}
    - {@link org.apache.juneau.rest.RestResponse#attr(String,Object) attr(String,Object)}
  - {@link org.apache.juneau.rest.annotation.Attr}
  - RestMethod#attrs()
  - RestResource.attrs()
  This deprecates the following APIs:
  - {@link org.apache.juneau.rest.RequestProperties}
  - {@link org.apache.juneau.rest.RestMethodProperties}
  - {@link org.apache.juneau.rest.RestRequest}
    - {@link org.apache.juneau.rest.RestRequest#getProperties() getProperties()}
    - {@link org.apache.juneau.rest.RestRequest#prop(String,Object) prop(String,Object)}
- Added the following classes that provide the same support as the servlet classes but doesn't extend from HttpServlet.
  This fixes an issue where instances of {@link org.apache.juneau.rest.BasicRestServlet} are registered as top-level servlets even though you don't want them to be.
  - {@link org.apache.juneau.rest.BasicRest} - Non-servlet equivalent to {@link org.apache.juneau.rest.BasicRestServlet}
  - {@link org.apache.juneau.rest.BasicRestGroup} - Non-servlet equivalent to {@link org.apache.juneau.rest.BasicRestServletGroup}
  - {@link org.apache.juneau.rest.BasicRestJena} - Non-servlet equivalent to {@link org.apache.juneau.rest.BasicRestServletJena}
  - {@link org.apache.juneau.rest.BasicRestJenaGroup} - Non-servlet equivalent to {@link org.apache.juneau.rest.BasicRestServletJenaGroup}
- HTML widgets now have access to the RestResponse object if they need access to the output bean.
- New annotations for simplified role-based guards on classes and methods:
  - RestResource
    - roleGuard()
    - rolesDeclared()
  - {@link org.apache.juneau.rest.annotation.RestMethod}
    - {@link org.apache.juneau.rest.annotation.RestMethod#roleGuard roleGuard()}
    - {@link org.apache.juneau.rest.annotation.RestMethod#rolesDeclared rolesDeclared()}
- New annotations for fine-tuned handling of http-methods/http-headers as query parameters and others:
  - RestResource
    - allowedHeaderParams()
    - allowedMethodHeaders()}
    - allowedMethodParams()
- The @RestResource(path) annotation can now use variables:

  @RestResource( path="/myResource/{foo}/{bar}" ) public class MyResource extends BasicRestServlet {...}

- New methods:
  - {@link org.apache.juneau.rest.RestRequest}
    - {@link org.apache.juneau.rest.RestRequest#getCharset() getCharset()}
  - {@link org.apache.juneau.rest.RestResponse}
    - {@link org.apache.juneau.rest.RestResponse#getCharset() getCharset()}
- New interface method for catching arbitrary thrown objects and converting them to other throwables.
  - {@link org.apache.juneau.rest.RestCallHandler}
    - {@link org.apache.juneau.rest.RestCallHandler#convertThrowable(Throwable) convertThrowable(Throwable)}
  - {@link org.apache.juneau.rest.BasicRestCallHandler}
    - {@link org.apache.juneau.rest.BasicRestCallHandler#convertThrowable(Throwable) convertThrowable(Throwable)}
- Support for fine-tuned logging of HTTP requests and responses.

  @RestResource( debug="per-request", logging=@Logging( level="info", rules={ @LoggingRule(codes"400-499", level="warning", req="short", res="short") @LoggingRule(codes"500-", level="severe", req="long", res="long") } ) ) public class MyRest { @RestMethod( method="POST", path="foo" logging=@Logging( level="info", rules={ @LoggingRule(exceptions"NotFound*", level="info") @LoggingRule(codes"200", disabled="true") } ) ) public String myMethod() throws Exception {...}

  See {@doc juneau-rest-server.LoggingAndDebugging} for details.
- Fixed a bug where the HTTP response was returning 405 (method not found) but should really be 404 (not found) when no path patterns match on any of the Java methods.

##### juneau-rest-client

- PATCH support added.

### 8.1.1 (Sept 20, 2019)

Juneau 8.1.1 is a minor release but introduces some new features/modifications.

##### juneau-marshall

- Support for serializing/parsing {@link java.util.Optional} objects and bean properties.
- Fixed a bug in the parsers where the generic subtype of a complex bean property type involving both collections and arrays was not being found. (e.g. List<Long>[])
- New packages of HTTP response/exceptions beans from juneau-rest-server bundle and REST proxy annotations from juneau-rest-client so that they can be used when building REST proxy interfaces while only pulling in the marshall bundle.
  - {@link org.apache.juneau.http.response}
  - {@link org.apache.juneau.http.exception}
  - {@link org.apache.juneau.http.remote}
  These replace the org.apache.juneau.rest.response, org.apache.juneau.rest.exception, and org.apache.juneau.rest.client.remote packages.
- Defaulting SVL variables now won't ignore additional parameters.
  "$S{Foo,bar,baz}" used to default to "bar" but now will default to "bar,baz".
- Ranking support has been added to all @XConfig annotations. This allows you to override the normal precedence of application of config annotations on class and method hierarchies.

##### juneau-rest-server

- Support for {@link java.util.Optional} on method parameters annotated with {@link org.apache.juneau.http.annotation.Header}, {@link org.apache.juneau.http.annotation.FormData}, {@link org.apache.juneau.http.annotation.Query}, {@link org.apache.juneau.http.annotation.Path}.
- Fixed issue where {@link org.apache.juneau.rest.annotation.RestMethod#debug() RestMethod.debug()} annotation wasn't resulting in the HTTP request being logged.
- {@link org.apache.juneau.rest.RestException} has been deprecated and replaced by {@link org.apache.juneau.http.exception.HttpException}.
- Resolved issue where parameterized types on @RestMethod-annotated method parameters of Spring beans. This is due to Spring relying on CGLIB for runtime-recompilation of beans that results in loss of parameterized-type information.
  In the following example, the beans parameter would resolve as an unparameterized List which would typically result in getting a List<ObjectMap> and subsequent ClassCastExceptions.

  @RestMethod public void doFoo(@Body List<MyBean> beans) {...}

  The fix involves resolving the original bean class for resolving parameterized type while leaving method invocation on the proxy method so as not to bypass Spring features.
- New methods on {@link org.apache.juneau.rest.BasicRest} to provide feature-parity with {@link org.apache.juneau.rest.RestServlet}:
  - {@link org.apache.juneau.rest.BasicRest}
    - {@link org.apache.juneau.rest.BasicRest#getContext() getContext()}
    - {@link org.apache.juneau.rest.BasicRest#getRequest() getRequest()}
    - {@link org.apache.juneau.rest.BasicRest#getResponse() getResponse()}
    - {@link org.apache.juneau.rest.BasicRest#log(String) log(String)}
    - {@link org.apache.juneau.rest.BasicRest#log(String,Throwable) log(String,Throwable)}
    - {@link org.apache.juneau.rest.BasicRest#log(Level,String,Object[]) log(Level,String,Object[])}
    - {@link org.apache.juneau.rest.BasicRest#logObjects(Level,String,Object[]) logObjects(Level,String,Object[])}
    - {@link org.apache.juneau.rest.BasicRest#log(Level,Throwable,String,Object[]) log(Level,Throwable,String,Object[])}
- The @RestResource(staticFiles) annotation now supports absolute path locations and multiple mappings:

  // Resolves static files in root package "htdocs" or working directory "htdocs", and then relative package "htdocs". @RestResource(staticFiles="htdocs:/htdocsfolder,htdocs:htdocs.package")

- Fixed a bug in @RestResource(staticFiles) where the order of lookup between parent and child resources was wrong.

##### juneau-rest-client

- Removed the dependency on the juneau-rest-server module. Allows the client API to be used without pulling in all the javax.servlet and server dependencies.

##### juneau-examples

- The PetStore application has been moved to a separate Git repository.
  - GitHub Repo
  - Documentation

### 8.1.2 (Dec 01, 2019)

Juneau 8.1.2 is a moderate release.

##### juneau-marshall

- Support for read-only and write-only properties.
  - {@link org.apache.juneau.annotation.Bean#bpro()}
  - {@link org.apache.juneau.annotation.Bean#bpwo()}
  - {@link org.apache.juneau.annotation.Beanp#ro()}
  - {@link org.apache.juneau.annotation.Beanp#wo()}
  - {@link org.apache.juneau.BeanContext#BEAN_bpro}
  - {@link org.apache.juneau.BeanContext#BEAN_bpwo}
  - {@link org.apache.juneau.BeanContextBuilder#bpro(Map)}
  - {@link org.apache.juneau.BeanContextBuilder#bpwo(Map)}
- New convenience methods:
  - {@link org.apache.juneau.ObjectMap#parse(CharSequence)}
  - {@link org.apache.juneau.ObjectList#parse(CharSequence)}
- {@link org.apache.juneau.marshall.CharMarshall} and {@link org.apache.juneau.marshall.StreamMarshall} now have public constructors.
- {@link org.apache.juneau.annotation.Beanp @Beanp} replaces {@link org.apache.juneau.annotation.BeanProperty @BeanProperty}.
- {@link org.apache.juneau.annotation.Beanc @Beanc} replaces {@link org.apache.juneau.annotation.BeanConstructor @BeanConstructor}.
- {@link org.apache.juneau.http.remote.Remote @Remote} replaces {@link org.apache.juneau.http.remote.RemoteResource @RemoteResource}.
- Shortened names for {@link org.apache.juneau.annotation.Bean#dictionary @Bean(dictionary)} and {@link org.apache.juneau.BeanContextBuilder#dictionary(Class...)}.

##### juneau-rest-server

- {@link org.apache.juneau.rest.annotation.Rest @Rest} replaces {@link org.apache.juneau.rest.annotation.RestResource @RestResource} with shorter syntax.
- New method {@link org.apache.juneau.rest.RestResponse#setHeaderSafe(String,String)} to strip invalid characters from header values.
- Fixed issues related to invalid characters being set on HTTP header values.

##### juneau-rest-client

- {@link org.apache.juneau.rest.client.RestClient} is now extendible. The constructor has been made public and simplified to: {@link org.apache.juneau.rest.client.RestClient#RestClient(RestClientBuilder)}.
- Duplicate methods between {@link org.apache.juneau.rest.client.RestClientBuilder} and {@link org.apache.http.impl.client.HttpClientBuilder} have been made deprecated on the former. This eliminates the need to try to keep the two builder classes in sync.

### 8.1.3 (TBD)

Juneau 8.1.3 is a moderate release.

##### juneau-marshall

- Dynamically applied annotations: {@doc juneau-marshall.DynamicallyAppliedAnnotations}
- Better representation of nulls for XML and HTML content properties.
  Old: "<myBean><null></myBean>"
  New: "<myBean nil='true'></myBean>"
- Configurable properties such as {@link org.apache.juneau.BeanContext#BEAN_debug} can now be set globally by either system properties or environment variables.
  For BEAN_debug you can use either the system property "BeanContext.debug" or environment variables "BEANCONTEXT_DEBUG".
- Fixed an initialization time race condition that can cause initial parse errors when concurrently parsing into array types like so:

  JsonParser.DEFAULT.parse(input, MyBean[].class);

##### juneau-rest-server

- Fixed bug in {@link org.apache.juneau.rest.BasicRestCallHandler} where if you have the following REST methods...

  @RestMethod(name="GET", path="/foo") @RestMethod(name="*", path="/bar")

  ...and you tried to make a GET request to /bar, you'd erroneously get a 404 error instead of matching the 2nd method.
- Fixed an issue involving using Juneau REST with Spring Security. When Spring Security cannot authenticate a request, it sets the URL on the request to "/error" with a 401 status. When Juneau then processes this request, it cannot find that mapping and changes the status to 404 which messes with HTTP clients.
  Solution was to add a default no-op error method to the {@link org.apache.juneau.rest.BasicRestConfig} (and implementers):

  @RestMethod(name="*", path="/error") public void error() {}

- Fixed a bug where @RestResource(debug="true") wouldn't log requests if a @RestMethod-annotated method was not matched.
- Renamed the following annotations:
  - @Rest(attrs) --> {@link org.apache.juneau.rest.annotation.Rest#reqAttrs() @Rest(reqAttrs)}
  - @Rest(defaultRequestHeaders) --> {@link org.apache.juneau.rest.annotation.Rest#reqHeaders() @Rest(reqHeaders)}
  - @Rest(defaultResponseHeaders) --> {@link org.apache.juneau.rest.annotation.Rest#resHeaders() @Rest(resHeaders)}
  - @RestMethod(attrs) --> {@link org.apache.juneau.rest.annotation.RestMethod#reqAttrs() @RestMethod(reqAttrs)}
  - @RestMethod(defaultRequestHeaders) --> {@link org.apache.juneau.rest.annotation.RestMethod#reqHeaders() @RestMethod(reqHeaders)}
- New auto-generated REST method execution statistics: {@doc juneau-rest-server.ExecutionStatistics}

##### juneau-rest-client

- Several convenience methods defined in {@link org.apache.juneau.rest.client.RestClientBuilder} that were deprecated in 8.1.2 have been undeprecated in this release due to user feedback.

##### juneau-doc

- New auto-generated glossary of all configurable properties: {@doc Glossaries.ConfigurablePropertiesGlossary}