Skip to main content

Model-driven XML forms generation, Part 2: Generate forms targeting Web services

Use XML Forms Generator to generate forms directly from WSDL documents

Jan J. Kratky, Advisory Software Engineer, IBM Japan, Software Group
Jan Joseph Kratky is the lead developer for the Compound XML Document Editor and XML Forms Generator. Currently a software engineer with IBM Emerging Software Standards in Research Triangle Park, North Carolina, he holds a B.A. from Cornell University and an M.S. from Rensselaer Polytechnic Institute. A Sun Certified Java Programmer and Sun Certified Web Component Developer, Jan has worked with Java technologies since 1997, and with Eclipse technologies since 2001.
Kevin E. Kelly (kekelly@us.ibm.com), Senior Technical Staff Member, IBM Japan, Software Group
Kevin E. Kelly is a Senior Software Engineer with the IBM Corporation working on Software Standards. Kevin is a member of the W3C XForms Working Group as well as the W3C Compound Document Format Working Group. His focus is on the client technology and evolving open standards-based technologies for faster, more efficient standards adoption through XML-based and model-driven approaches. Before joining IBM, Kevin spent eight years at Rational Software working on UML modeling and Java technologies. Kevin holds a B.S. from Mercer University, and a M.S. from the University of Montana.
Steve Speicher (sspeiche@us.ibm.com), Senior Software Engineer, IBM Japan, Software Group
Steve Speicher is a Senior Software Engineer with IBM working on Software Standards. Steve's current focus is leveraging tools and model-driven development to improve the process of creating standards. Steve has previously worked on software development tools in the Rational division and IBM internal tools. Steve holds a B.S. in Computer Science and Applied Mathematics, both from Kent State University. Contact Steve at sspeiche@us.ibm.com.
Keith Wells, Advisory Software Engineer, IBM Japan, Software Group
Keith Wells is a software developer at the IBM RTP campus. Keith has been involved with Emerging Technologies and the Emerging Technologies Toolkit for several years.

Summary:  Take a closer look at XML Forms Generator. Part 1 of this two-part series showed you how this alphaWorks technology uses Model Driven Development concepts with Eclipse Modeling Framework (EMF) to permit generation of forms from XML instance data. Here in Part 2, the authors show you how XML Forms Generator can generate forms from Web Services Description Language (WSDL) documents.

View more content in this series

Date:  25 Aug 2005
Level:  Advanced
Activity:  2162 views

In the first installment of this two-part series, we detailed the XML Forms Generator’s ability to generate standards-compliant forms, using XML instance documents as a starting point. We showed you how automating form generation accelerates the development of forms and how Model Driven Development techniques assist in that automation.

Aside from XML instance data, another common description mechanism for data that must be gathered is WSDL. By leveraging EMF models of WSDL and XML Schema, you can also generate forms -- and even meaningful form-submission response pages -- directly from WSDL documents.

The XML Forms Generator does just that, automatically generating XHTML/XForms documents from source WSDL documents. The XML Forms Generator distribution also includes tooling for the generation and testing of JavaServer Pages (JSP) Web service response templates.

The generated forms adhere to the XHTML and XForms 1.0 standards, and can be viewed in popular XHTML/XForms renderers.

The tools described in this article are seamlessly integrated into the open source Eclipse tools platform, and are freely available on IBM alphaWorks as the XML Forms Generator.

Generation from WSDL

As it does with XML instance documents (see Part 1), the XML Forms Generator takes a model-driven approach when generating forms from WSDL documents. The Generator reads a WSDL document’s properties (operations, message parts, type definitions, and so on) into run-time Java™ structures determined by an EMF model of WSDL and XML Schema. As a result, the structure facilitates analysis of the WSDL document, allowing for the creation of a prototypical XML instance document that in turn (under the covers) drives the generation of a functioning form that is ready for deployment.

Abbreviations

DTD -- Document Type Definition
EMF -- Eclipse Modeling Framework
JSP -- JavaServer Pages
JSTL -- Java Standard Tag Library
MDA -- Model Driven Architecture
MDD -- Model Driven Development
UML -- Unified Modeling Language
W3C -- World Wide Web Consortium
XHTML -- eXtensible HyperText Markup Language
XMI -- XML Model Interchange
WSDL -- Web Services Description Language

The resulting form may be submitted directly to a Web service endpoint. Note, however, that nothing in the XForms 1.0 Recommendation specifically requires the success of such an invocation, so you may need to include a middleware intermediary. The XML Forms Generator distribution comes with a Java 2 Platform, Enterprise Edition (J2EE) Web application that includes a pair of servlets that provide simple demonstrations of such a middle-tier solution (see Resources).

Also, because a WSDL document encodes the structure of the data to be sent in response to a service invocation, it is possible to generate a template for displaying a response to the invocation of a WSDL-defined Web service operation. There are several possible approaches to generating response templates, including XSLT and even XForms itself with the use of its switch/case mechanism. To demonstrate interactions in a J2EE environment, the XML Forms Generator's current release instead generates response templates as JSP files.

Generating a request form

To avoid the complexity of multiple-submit forms, the XML Forms Generator requires that the user select a single operation for which a form will be generated. It does so by reading the WSDL to determine the available operations and presenting a wizard page that includes a list of these operations, from which one must be chosen (see Figure 1).


Figure 1. Selecting an operation defined in a WSDL document
Selecting an operation defined in a WSDL document

The XML Forms Generator does further analysis, which results in the selection of a default submission target for the form that is the actual service endpoint URL.


Figure 2. The form's default submission target overridden to match the service address
The form's default submission target overridden to match the service address

In Listing 1, the endpoint is discovered through an examination of the service element declared in the WSDL document:


Listing 1. WSDL code with service element

<service name="GoogleSearchService">
    <port name="GoogleSearchPort" binding="typens:GoogleSearchBinding">
        <soap:address location="http://api.google.com/search/beta2"/>
    </port>
</service>

The input message parts of the selected operation, as well as the types defined in XML Schema within the WSDL's types section, are examined to produce a prototypical XML instance document that carries all the data that could be submitted in the request message. Listing 2 shows a simple WSDL portType declaration with a single operation, and its input message definition:


Listing 2. WSDL portType declaration

<portType name="GoogleSearchPort">
    <operation name="doSpellingSuggestion">
        <input message="typens:doSpellingSuggestion"/>
        <output message="typens:doSpellingSuggestionResponse"/>
    </operation>
</portType>
<message name="doSpellingSuggestion">
    <part name="key"            type="xsd:string"/>
    <part name="phrase"         type="xsd:string"/>
</message>

From this input message declaration, the XML Forms Generator generates an XML instance document (see Listing 3), from which it then creates a functioning XHTML/XForms document. The instance document is itself a SOAP envelope, which allows direct invocation to a Web service without the need for any special manipulation of the instance prior to submission of the form.


Listing 3. XML instance document

<?xml version="1.0" encoding="ASCII"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
            encodingStyle="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <typens:doSpellingSuggestion xmlns:typens="urn:GoogleSearch"
                xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
                xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <typens:key xsi:type="xsd:string"/>
            <typens:phrase xsi:type="xsd:string"/>
        </typens:doSpellingSuggestion>
    </soap:Body>
</soap:Envelope>

The XML Forms Generator can also understand more complex type definitions, and can successfully generate forms from both RPC literal-style and document literal-style service definitions.

Figure 3 is the form that results from the example shown in Listing 3, rendered in the formsPlayer plug-in for Internet Explorer (see Resources):


Figure 3. A form generated for a WSDL operation
A form generated for a WSDL operation

Intermediaries for service invocation

When a form is submitted directly from a browser to a Web service, the response the browser receives will itself be a SOAP envelope. It is reasonable to expect that the envelope will not be renderable as anything other than raw XML markup.


Figure 4. The raw XML of a SOAP response to a form submission
The raw XML of a SOAP response to a form submission

The simplest approach to creating a renderable version of the response is to interject an intermediary that actually makes the call and then converts the SOAP envelope into XHTML markup that can be rendered.


Figure 5. A servlet intermediary to the service invocation
A servlet intermediary to the service invocation

The XML Forms Generator distribution includes a Web application containing a servlet that does just this, in order to demonstrate the pros and cons of the approach. The servlet examines the Web service response envelope, extracts the data, and wraps that data in XHTML markup that is renderable:


Figure 6. The rendered response delivered by the servlet
The rendered response delivered by the servlet

While the response data is now consumable by an end user (as seen in Figure 6), the presentation mechanism is hopelessly intertwined with the invocation mechanism. To enable a more flexible architecture that provides the sort of model-view-controller separation encouraged by the J2EE "model 2" architectural pattern, you need a separate template that provides a view of the response.

Response templates

As mentioned previously, the XML Forms Generator allows you to use a WSDL document to create a JSP that serves as a response template. Java Standard Tag Library (JSTL) elements interrogate the XML of the response envelope. Listing 4 is a representative snippet of generated JSP markup:


Listing 4. Generated JSP markup

<?xml version="1.0" encoding="ASCII"?>
<jsp:root xmlns:jsp=http://java.sun.com/JSP/Page
          xmlns:x="http://java.sun.com/jsp/jstl/xml" version="2.0">
...
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>
                WSDL Response Template: doSpellingSuggestion Response
            </title>
            <link href="gen_default.css" rel="stylesheet"/>
        </head>
        <body>
            <h1>doSpellingSuggestion Response</h1>
            <p><b>Return</b></p>
            <p><x:out select="$myDOM//return"/></p>
        </body>
    </html>
</jsp:root>

While the initial visual presentation is not markedly different from that generated by the prior servlet-only approach, the response page is ready for any modifications a developer or designer might apply. The XML Forms Generator has already done the work of constructing the fundamental form elements and matching them to the data with XPath expressions.


Figure 7. The more model-2-architecture flow enabled by the JSP response template
The more model-2-architecture flow enabled by the JSP response template

Integration with Eclipse

As an Eclipse plug-in, the XML Forms Generator provides tight integration with Eclipse and Eclipse-based products, with convenient user interface elements including context menus, wizards, and preference pages.

A variety of options provide control over the generated form's title and heading text, stylesheet, submission target, repeat depth, textarea generation, and more.

The XML Forms Generator also permits quick rendering of generated forms in a variety of renderers, using the same mechanism shown in Part 1 of this series, on the Compound XML Document Editor.

In many cases, you can generate a working form with just a few mouse clicks. In fact, the XML Forms Generator provides a single "Generate All" option for WSDL documents, which permits generation of the XML instance document, the form, and the response JSP template, all with one action.


Figure 8. Generation options for WSDL documents
Generation options for WSDL documents

Conclusion

The XML Forms Generator utilizes Model Driven Development concepts with EMF to permit generation of forms from WSDL descriptions of Web services. Although XForms 1.0 does not require Web service invocation support (that support is forthcoming in XForms 1.1), you still have quite a few options for using XForms against Web services, as we have demonstrated. The form generated from the example in this article can be successfully invoked against the service endpoint today.

As a standards-based, model-driven tool, the XML Forms Generator enables the immediate generation of working forms for Web services, providing a head start in forms development within any Service-Oriented Architecture (SOA).

Acknowledgements: Thanks to Kelvin Lawrence and Henry Tran of IBM.


Resources

Learn

Get products and technologies

About the authors

Jan Joseph Kratky is the lead developer for the Compound XML Document Editor and XML Forms Generator. Currently a software engineer with IBM Emerging Software Standards in Research Triangle Park, North Carolina, he holds a B.A. from Cornell University and an M.S. from Rensselaer Polytechnic Institute. A Sun Certified Java Programmer and Sun Certified Web Component Developer, Jan has worked with Java technologies since 1997, and with Eclipse technologies since 2001.

Kevin E. Kelly is a Senior Software Engineer with the IBM Corporation working on Software Standards. Kevin is a member of the W3C XForms Working Group as well as the W3C Compound Document Format Working Group. His focus is on the client technology and evolving open standards-based technologies for faster, more efficient standards adoption through XML-based and model-driven approaches. Before joining IBM, Kevin spent eight years at Rational Software working on UML modeling and Java technologies. Kevin holds a B.S. from Mercer University, and a M.S. from the University of Montana.

Steve Speicher is a Senior Software Engineer with IBM working on Software Standards. Steve's current focus is leveraging tools and model-driven development to improve the process of creating standards. Steve has previously worked on software development tools in the Rational division and IBM internal tools. Steve holds a B.S. in Computer Science and Applied Mathematics, both from Kent State University. Contact Steve at sspeiche@us.ibm.com.

Keith Wells is a software developer at the IBM RTP campus. Keith has been involved with Emerging Technologies and the Emerging Technologies Toolkit for several years.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML, Open source, SOA and Web services
ArticleID=92650
ArticleTitle=Model-driven XML forms generation, Part 2: Generate forms targeting Web services
publish-date=08252005
author1-email=kratky@us.ibm.com
author1-email-cc=dwxed@us.ibm.com
author2-email=kekelly@us.ibm.com
author2-email-cc=dwxed@us.ibm.com
author3-email=sspeiche@us.ibm.com
author3-email-cc=clarkega@us.ibm.com
author4-email=wellsk@us.ibm.com
author4-email-cc=dwxed@us.ibm.com

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers