Upload
madonna-meadows
View
38
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Using Cocoon to consume and produce Web Services. Cocoon: A Framework for Web Services. Pankaj Kumar [email protected] Web Services Architect, HP Middleware. Presentation Goals. Understand Apache Cocoon, Web Services and how Cocoon can be used to build - PowerPoint PPT Presentation
Citation preview
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 1
Cocoon: A Framework for Web ServicesUsing Cocoon to consume and produce Web Services
Pankaj [email protected] Services Architect,HP Middleware
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 2
Presentation Goals
Understand Apache Cocoon, Web Services and how Cocoon can be used to build –Web Applications that consume Web
Services; and–Web Services that process huge XML
documents
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 3
Speakers’ Qualifications
• More than 12 years of System Programming experience
• Development manager in HP E-speak development• Development manager of HP XML Application
Frameworks ( Cocoon connection … )• Currently Web Services Architect at HP
Middleware ( Web Services connection … )• Contributor to Cocoon project• JAX-RPC and JSR109 Expert Group Member• Personal web-site: http://www.pankaj-k.net
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 4
Presentation Topics
• What is Cocoon?• Exploring Cocoon• What are Web Services?• Cocoon and Web Services• A Simple Cocoon Web Application
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 6
Apache Cocoon
• XML based publishing Framework• An Apache Software Foundation opensource project• Written in Java, runs as a servlet ( not strictly true ! )• Project Home Page: http://xml.apache.org/cocoon• Started as a simple servlet based XSL styling engine for
http://java.apache.org site• Current version is in the second generation of evolution• Designed for scalability ( uses SAX processing ) -- can
process huge documents using small amount of memory
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 7
Apache Cocoon ( Contd. )
• Promotes separation of Content, Logic, Presentation and Management in web-site design.
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 9
Getting Started
• Download Cocoon Distribution from http://xml.apache.org/cocoon– I used Cocoon 2.0.1 for this presentation
• Unzip the distribution file cocoon-2.0.1-bin.zip.
• Drop cocoon.war to webapps directory of your Servlet Container– I used Tomcat 4.0.1 as the Servlet Container
• Start the Servlet Container• Point your browser to http://localhost:8080/cocoon
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 11
Cocoon ServletDirs. & FilesDirectory for auto mounting
sub-sitemaps
Cocoon Configuration file
A sub-sitemap directory
Main sitemap file
Directory for log files
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 12
Cocoon Sitemap
• Why Sitemap ?– need to de-couple exposed URI space from actual
location of resources– need easily changeable specification of processing steps
• What does it contain?– Component declarations
– generators, transformers, serializers, ...
– Resource declarations– named collection of pipeline components
– Pipeline declarations– sequential arrangement of components for processing
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 13
Cocoon Sitemap ( Contd. )
• A sitemap is an XML file• Sitemaps are hierarchical -- A sitemap can point,
explicitly or implicitly, to sub-sitemaps• A sitemap is translated into a java program and is
compiled to bytecode• Changes to sitemaps can be loaded dynamically
and asynchronously.• Cocoon community has debated extensively on
philosophical aspects of Sitemap but nothing better has come out ( yet ! ).
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 14
A sample pipeline<map:pipeline> <map:match pattern="hello.html"> <map:generate src="docs/samples/hello-page.xml"/> <map:transform src="stylesheets/page/simple-page2html.xsl"/> <map:serialize type="html"/> </map:match>
<map:match pattern="images/**.png"> <map:read src="resources/images/{1}.png" mime-type="image/png"/> </map:match>
<map:handle-errors> <map:transform src="context://stylesheets/system/error2html.xsl"/> <map:serialize status-code="500"/> </map:handle-errors></map:pipeline>
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 15
Request Processing By Cocoon• Request is dispatched to matching pipeline
• Basic pipeline operation– The generator generates XML content– Zero or more transformers transform the content– The serializer writes it to the output stream
• Different Kinds of generators– File, Directory, XSP, JSP, Stream, …
• Different Kinds of transformers– XSLT, I18N, Log, …
• Different Kind of Serializers– HTML, XML, Text, PDF, SVG, ...
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 16
Dynamic Content from XSP
<!-- A simple XSP Page --><xsp:page language="java” xmlns:xsp=“http://apache.org/xsp” > <page> <title>A Simple XSP Page</title> <content> <para>dynamically generated list:</para> <ul> <xsp:logic> for (int i=0; i < 3; i++) { <li> Item <xsp:expr>i</xsp:expr> </li> } </xsp:logic> </ul> </content> </page>
</xsp:page>
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 17
What Are Web Services?
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 18
Defining Web ServicesMost commonly used definition:
• Web Services are– described in WSDL– exchange SOAP messages– use HTTP as transport– optionally, registered in UDDI registry
• Interaction can happen using RPC style or Document Exchange style, synchronously or asynchronously
• Knowledge of Implementation language or deployment platform is not required for interaction.
• Web Services promise Interoperability.
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 19
SOAP 1.1
• XML based protocol for exchange of information– Encoding rules for datatype
instances
– Convention for representing RPC invocations
• Designed for loosely-coupled distributed computing
• Used with XML Schema• Transport independent• SOAP with Attachments allow
arbitrary data to be packaged.
SOAP 1.1 Message StructureSOAP Envelope
[HeaderElement]
HeaderEntries
Body Element
[FaultElement]
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 20
WSDL 1.1
• A WSDL document describes– What the service can do
– Where it resides
– How to invoke it
• WSDL are like IDL but lot more flexible and extensible
• Defines binding for SOAP1.1, HTTP GET/POST and MIME
• WSDL descriptions can be made available from an UDDI registry
WSDL 1.1 Document StructureWSDLDocument
{Messages}
[Types]
{Services}
{PortTypes}
{Bindings}
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 21
What is a Web Services Platform ?
Environment, tools, libraries and other resources for:– Development of web services
– top down -- start with user code and generate WSDL
– bottom up -- start with WSDL and generate interfaces
– middle out -- a combination
– discovery of service interfaces
– Deployment of web services– publishing of services
– pre and post processing of SOAP requests, responses
– processing requests for WSDL descriptions
– Consumption of Web Services– discovery of Web Service
– invocation of/interaction with Web Services
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 22
Java Platforms and Standards• Java Platforms for Web Services
– HP WSP, HP WSR, HP WST– Apache SOAP 2.2, Apache Axis, UDDI4J, Cocoon– JWSDK ( Reference Implementation from Sun )– …
• Emerging Java Standards for Web Services– JAXM ( Java XML Messaging )– JAX-RPC ( Java Web Service Client Prog. model)– JSR 109 ( Java Web Service Prog. Model, deployment, ...)– JAXR ( Java API to access Web Service Registries )– J2EE 1.4 ( J2EE platform for Web Services )
• Java standards promise portability
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 23
Observations on Java Platforms and Standards
• Handle synchronous RPC style Web Services quite well• Not so good at supporting Web Services with document
exchange style, especially with asynchronous interface• Have difficulty dealing with large data• Many approaches to build and consume Web Services ( but
must adhere to wire protocols )• Standards in many areas are still emerging
– routing, reliable messaging
– security
– transactioning
– ...
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 24
Cocoon and Web Services
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 25
Cocoon as a Presentation Framework for Web-Services
Client Tier Web Tier
Web Services
WS Registry
Enterprise Apps
Servlet Container
Cocoon
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 26
Cocoon as a Processing Framework for Web Services
Client Tier Web Tier
Web Services
WS Registry
Enterprise Apps
Servlet ContainerCocoon
P1
P2
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 27
A Simple Cocoon Web Application
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 28
Problem Statement
Use Google Web Services API from http://www.google.com/apis
to create a simple web application that accepts a search string from user and displays the list of result entries.
Acknowledgement: This example is based on the XSP contributed by Ugo Cei in Cocoon-dev mailing list.
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 29
Application Components
sitemap.xmap -- Sitemap for this application
index.html -- HTML file to accept search string
google.xsp -- XSP file that makes the SOAP call to Google Web Service using SOAP logicsheet.
search-results.xsl -- XSL stylesheet to transform SOAP response from Google Web Service to HTML page
Downloadable from
http://www.pankaj-k.net/sdwest2002/google.zip
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 30
Application Architecture
Browser Google WSCocoon Servlet
http://<host>/cocoon/mount/google/
index.html
…/search?q=...
executes google.xsp
SOAP request
SOAP response
Search results in HTML
Maps request to index.html
Applies search-results.xsl
Wednesday, April 19, 2023
Choose View, Header and Footer to enter text here 31
Demo Architecture
Browser Cocoon Servlet
http://<host>/cocoon/mount/google/welcome-local
index.html
…/search-local?q=...
Search results in HTML
Maps request to index-local.html
Applies search-results.xsl
Reads google.results