Chapter 11. Web Services Using Fast Infoset

Table of Contents

11.1. Overview
11.2. Using Fast Infoset
11.2.1. Content Negotiation
11.3. Example of Fast Infoset
11.4. Executing Fast Infoset Web Services

This chapter introduces a new JEUS web service type that uses Fast Infoset, and describes how to implement and use the service.

11.1. Overview

The Fast Infoset standard specifies effective XML infosets, which can be used in place of XML, in a binary format.

The Fast Infoset specification with the full name "ITU-T Rec. X.891 | ISO/IEC 24824-1 Fast Infoset" is defined by the following organizations.

Like an XML document, a Fast Infoset document denotes a binary instance of such XML Infosets. An XML document and Fast Infoset document internally contain XML Infoset. The Fast Infoset document can be serialized or parsed faster and the size is smaller than that of an XML document. A Fast Infoset document can be used when the processing speed and size of an XML document are a concern.

Designing Fast Infoset

A Fast Infoset document can be serialized or parsed like an XML document.

  • Serialization process

    Serialization process involves obtaining Fast Infoset from XML Infoset that corresponds to an SAX event or a DOM document obtained from an XML document. The Fast Infoset is used to obtain a Fast Infoset document.

  • Parsing process

    Parsing process involves obtaining a Fast Infoset from the Fast Infoset document, and then obtaining an XML Infoset from the Fast Infoset. The Fast Infoset specification guarantees an effective serialization and parsing processes as well as optimal file size reduction.

The following figure shows the serialization and parsing processes.

[Figure 11.1] Serializing/Parsing Fast Infoset

Serializing/Parsing Fast Infoset

Advantages of Fast Infoset

A Fast Infoset document can be serialized and parsed faster and can be compressed more than an XML document.

Other advantages are:

  • No end-tag like the one used in an XML document exists.

  • No escape character data exists.

  • The decoder that converts a Fast Infoset document into Fast Infoset already has the length information.

  • Indexing of repeated strings.

  • Indexing of namespaces.

  • Can contain binary contents.

  • Preserves the states of documents with similar vocabularies.

Advantages of binary Fast Infoset documents are:

  • Element items or character information are encoded into smaller bits.

  • Fast Infoset encoder and decoder can be implemented easily and efficiently due to well-defined boundaries.

  • Speed can be enhanced when serialized or parsed by using indexing information due to the reduced target size.

  • Suitable for using the streaming function.

11.2. Using Fast Infoset

This section describes the ContentNegotiation, a mechanism for using the Fast Infoset function.

11.2.1. Content Negotiation

To use the Fast Infoset function in a JAX-WS web service, the user must specify whether to use the function for Accept, which is the standard HTTP header, or Content-Type. Since the client, who invokes the web service, always decides whether to use Fast Infoset and implements it through the HTTP header, this technique is called Content Negotiation.

The first SOAP message transmitted from the Web service's Fast Infoset, which is decided by whether the client inserts information into the HTTP header, is XML- encoded. If the client includes information about MIME type 'application/fastinfoset' in the HTTP Accept header, all SOAP messages, after the first transmission, are encoded by using Fast Infoset as long as the server supports Fast Infoset. In other words, if the client transmits an XML encoded SOAP message to MIME type 'application/fastinfoset' in the HTTP Accept header, the server, that supports Fast Infoset, transmits a response message encoded by Fast Infoset. If the client later transmits another message through the same stub object, the client and server will exchange messages encoded by Fast Infoset. Such technique is called Negotiation Pessimistic.

Use the following configuration to use Fast Infoset in the JAX-WS web service.

  • Configure client property.

    ((BindingProvider) stubOrDispatch).getRequestContext().put(
    com.sun.xml.ws.client.ContentNegotiation.PROPERTY, "pessimistic");

  • Configure a system variable of the client VM.

    java -Dcom.sun.xml.ws.client.ContentNegotiation=pessimistic

11.3. Example of Fast Infoset

To use Fast Infoset in a JAX-WS web service, a user can configure the client property in the client application, or the system variable on the client VM.

This section describes the former.

Note

Functions provided through other options are not available on the server. As already mentioned, all Fast Infoset properties are configured by the client.

The following is an example of configuring the Fast Infoset property in a client application.

[Example 11.1] << AddNumbersClient.java >>

public class AddNumbersClient {
    public static void main(String[] args) { 
      AddNumbersImpl port = new AddNumbersImplService().getAddNumbersImplPort();
      ((BindingProvider) port).getRequestContext().put(
              ContentNegotiation.PROPERTY, "pessimistic");

      int number1 = 10;
      int number2 = 20;

      System.out.println("#################################################");
      System.out.println("### JAX-WS Webservices examples - fastinfoset ###");
      System.out.println("#################################################");
      System.out.println("Testing Fast Infoset webservices...");
      int result = port.addNumbers(number1, number2);
      if (result == 30) {
          System.out.println("Success!");
      }
   }
}


As shown in the previous example, set the 'pessimistic' property to ContentNegotiation of the request context through a proxy(stub) object obtained from the service interface.

11.4. Executing Fast Infoset Web Services

The following shows how to execute a Fast Infoset Web service by using the implemented classes and other configuration files in this section. Other SEI implementation classes and configuration files are the same as those in the examples of the previous section.

Create a service with Fast Infoset Web service configured, and deploy it to JEUS.

$ ant build deploy

Since the client is processed by using the wsimport tool, it can only be built after the service has been deployed.

As shown in the following example, create a client in which Fast Infoset is configured and then invoke the service.

$ ant run

...

run:
     [java] #################################################
     [java] ### JAX-WS Webservices examples - fastinfoset ###
     [java] #################################################
     [java] Testing Fast Infoset webservices...
     [java] Success!

...

BUILD SUCCESSFUL
$ ant run


---[HTTP request]---
Host: localhost:8088
Content-length: 218
Content-type: text/xml; charset=utf-8
Accept: application/fastinfoset, text/xml, multipart/related, text/html, image/g
if, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Soapaction: ""
User-agent: JAX-WS RI 2.2 - JEUS 8
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envel
ope/"><S:Body><ns2:addNumbers xmlns:ns2="http://server.fastinfoset/"><arg0>10</a
rg0><arg1>20</arg1></ns2:addNumbers></S:Body></S:Envelope>
--------------------
---[HTTP response 200]---
?