Return to Home Page
Overview
    History
    Acknowledgements
    Podcasts
    Notification Form
    Feedback Form
    Press Release #1
    Press Release #2
    Press Release #3

Master SOA Design
Pattern Catalog
    Master Pattern List (alphabetical)
    Master Pattern List (by category)
    Master Pattern List with
Page Numbers (PDF)
    Master Pattern List (Text)
    Pattern Notation
    Pattern Profiles
    Symbol Legend
    Pattern Contribution Form

SOA Candidate Patterns
    SOA Patterns Review Committee
    Candidate Patterns Overview
    Candidate Patterns List
    Candidate Pattern Contribution Form
    Candidate Pattern
Feedback Form
    SOA Pattern Template

Design Pattern Basics
    What's a Design Pattern?
    What's a Design Pattern Language?
    What's a Compound Pattern?

Supplemental
    SOA Patterns and Application Technologies
    SOA Design Patterns Historical Influences
    SOA Design Patterns and Design Principles
    SOA Design Patterns and Design Granularity
    Legal

Resources
    Design Patterns Publications
    Reference Posters
    SOAPrinciples.com
    WhatIsSOA.com
    SOA Visio Stencil

About the Book



SOA Design Patterns
by Thomas Erl

For more information visit: www.soapatterns.com

Related Publications


"Introducing SOA Design Patterns", SOA World Magazine (PDF)



"The Case for Single-Purpose Services: Understanding the Non-Agnostic Context and a Strategy for Implementation", SOA Magazine (HTML)



"REST-Inspired SOA Design Patterns", SOA Magazine (HTML)



"Service-Orientation and Object-Orientation Part I: A Comparison of Goals and Concepts", SOA Magazine (HTML)



"Service-Orientation and Object-Orientation Part II: A Comparison of Design Principles", SOA Magazine (HTML)



"Service Facade", InformIT (HTML)



"Non-Agnostic Context", InformIT (HTML)



"Domain Inventory", InformIT (HTML)



"Service Normalization", InformIT (HTML)



"Service Decomposition", InformIT (HTML)



"Canonical Schema", InformIT (HTML)



"Policy Centralization", InformIT (HTML)





Alternative Format (candidate)


Home > Candidate Patterns List > Alternative Format

How can services exchange data based on less common or non-standard formats?

Problem

Service consumers may have data exchange requirements based on non-XML formats.

Solution

Services can be designed to exchange data in alternative representation formats, thereby accommodating special consumer requirements.

Application

How this pattern is applied is dependent on the endpoint type of the service and technology required to support the desired data format.

Impacts

This pattern can deviate from the goal of establishing Canonical Schema.

Principles

Standardized Service Contract, Service Reusability

Architecture

Composition, Service

Status

Under Review

Contributors

Raj Balasubramanian, Jim Webber, Thomas Erl, David Booth, Chris Riley
 

Problem

Service consumers can have diverse requirements, especially when they exist as alternative programs in mobile devices or on desktop applications. Whereas most consumers will tend to expect a standard XML representation, others may require different formats, such as binary-encoded images or portable data format (PDF) based data.



Solution

Services are designed to support data exchange in multiple or alternative data formats. Either service contracts are extended to include additional capabilities with the functionality to receive and respond with messages containing different formats, or processing is added to transform a serviceˇ¦s natural data representation format to and from the consumerˇ¦s desired representation format.



Application

There are two common approaches for supporting Alternative Format in services:
Use an attachment technology to associate the alternatively formatted data with an XML message and configure the service to address the processing of these attached content formats.
Use any one of the supported content-types or custom representation, available natively to the application protocol (such as HTTP) and configure the service to address the processing of these different content formats.
For SOAP-based Web services, this pattern can be applied using a SOAP-based attachment technology, such as SwA (SOAP with Attachments), which allows non-XML-based data to be associated with a SOAP message. SwA can be further supplemented by XML-binary Optimization Packaging (XOP), SOAP Message Transmission Optimization Mechanism (MTOM), and Resource Representation SOAP Header Block (RRSHB).

All of these technologies work together with Multipurpose Internet Mail Extension (MIME) packaging standards to represent and encode data in different formats.

For example, a SOAP message may contain the following header that establishes the primary message contents as being XML:

MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=PART_BOUNDARY;
              type="application/xop+xml";
              start="";
              startinfo="application/soap+xml"
...along with a separate part that identifies the attached content as being a PNG image file:

Content-Type: image/png
Content-Transfer-Encoding: binary
Content-ID: <image@alleywoodcorp.com>
Note: An alternative technology to SwA is WS-Attachments, which is based on Direct Internet Message Encapsulation (DIME), an alternative media representation standard to MIME.


Another approach (to the latter option) is to leverage HTTP specifications, to accommodate the need for alternative formats of information. This mechanism of interaction between service and its consumer to decide on the best content format (within the context of HTTP) is termed content negotiation. HTTP Specification provides the Accept request header, Content-Type request and response headers along with Accept-Language, Accept-Range and other Accept headers to accomplish this feature.

The Content-Type and Accept headers specify any one of the valid media types from the Internet Media Types listing. As new formats become prominent, they also get added to the standards list and can be used. The media types are of the general format-

media-type = type "/" subtype *( ";" parameter )

For example, to represent XML the media-type value would be text/xml or application/xml, to represent HTML it is text/html, and the Adobe PDF format is application/pdf.

When using HTTP functionality with a REST framework (such as Restlet etc.) of choice, the JSON (JavaScript Object Notation) format is also commonly supported. Hence a web application consuming this service from a browser can process this response with little overhead as these are just another JavaScript objects.

For example, this simple XML fragment:

<customers>
  <customer>
    <name>John Smith</name>
    <type>Gold</type>
  </customer>
</customers>
...would be represented in JSON as follows:

{
    customers:{
        customer:[
            {
                name:"John Smith",
                type:"Gold"
            }
        ]
    }
}


Impact

The primary impact is on the service implementation, since the additional logic to accept the various media-types and respond with unique media-types has to be addressed as part of the implementation. The impact on the consumer is that they have to perform additional calls to the service to inquire about the supported content as part of the content negotiation process.



Case Study Example

Alleywood has been providing the Customer Listing service to all of its internal consumers. However, new requirements have recently emerged by some new consumer program design projects that need data returned to them in a JSON representation.

This requirement is related to the fact that these new programs must provide a user-interface with a dynamic query feature. Therefore, the customer data is ideally delivered in the JSON representation format.

The development team proposes two data structures to address these requirements:
the listing of customers given the first two letters of the name (last name in case of people and entity name in case of businesses)
customer details for a given customer
Additionally, this rich user-interface needs to be able to handle queries specifically on the last name of customers. To address this function, the development team decides to enhance the service implementation itself. They propose to accept a specific query string in the URL to provide the listing of customers meeting the query criteria.

As a result, the /services/customers URI structure is enhanced to accept parameters, as follows:

/services/customers/?q=nameStr

The reason this approach is chosen over the option of modifying the underlying service implementation to return a listing based on /services/customers/[id] is to keep the distinction between the "official" customer REST service (as represented by the URL /services/customers/[id]) and the temporary collection of customer data based on a query that could change dynamically.

A sample JSON data structure that might be provided by the updated Customer service is shown here:

{"customer": {
 "id": "ab123", "type": "gold",
 "profile": {
  	"name": "Ablutions Solutions",
    "owner": "Charlie Jones",
    "contact": "Bonita Watson",
  	"address": {
		"street": "10 Dowing St.",
		"city": "Charleston",
		"state": "SC",
		"zip": "99999"
	}
    "phone": "1-222-444-5555",
    "sector": "Public Construction"
 },
 "accounts": {
         "customer_id": "ab123",
         "account": [
{ "id": "19829", "limit": 20000, "type": "Business 
    Checking","since": "Jan 20, 2001"},
{"id": "12998","limit": 3000, "type": "Savings",
   "since": "Jan 20, 2001"} 
         ]
     }
}}


If the consumer wants to query for a particular substring of the customer name, the customer collection data structure for query "an" string (by using http://alleywoodcorp.com/services/customers/?q=an yields the following:

{"customers": {
 "q": "an", 
 "customer": [
  {"name": "Anderson Solutions", "id":"an123"},
  {"name": "Anthony, Mark", "id":"mams12"},
  {"name": "Anthony Brothers", "id":"an909"}
 ]
}}


The Prentice Hall Service-Oriented Computing Series from Thomas Erl
Home    SOA Books    SOA Magazine    What is SOA?    SOA Principles    SOASchool.com    SOA Glossary Copyright © 2007-2010
SOA Systems Inc.