Cocoon A Framework for Web Services Using Cocoon
Cocoon: A Framework for Web Services Using Cocoon to consume and produce Web Services Pankaj Kumar pankaj_kumar@hp. com Web Services Architect, HP Middleware Choose View, Header and Footer to enter text here Thursday, June 3, 2021 1
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 Choose View, Header and Footer to enter text here 6/3/2021 2
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 JSR 109 Expert Group Member • Personal web-site: http: //www. pankaj-k. net Choose View, Header and Footer to enter text here 6/3/2021 3
Presentation Topics • • • What is Cocoon? Exploring Cocoon What are Web Services? Cocoon and Web Services A Simple Cocoon Web Application Choose View, Header and Footer to enter text here 6/3/2021 4
What is Cocoon? Choose View, Header and Footer to enter text here 6/3/2021 5
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 Choose View, Header and Footer to enter text here 6/3/2021 6
Apache Cocoon ( Contd. ) • Promotes separation of Content, Logic, Presentation and Management in web-site design. Choose View, Header and Footer to enter text here 6/3/2021 7
Exploring Cocoon Choose View, Header and Footer to enter text here 6/3/2021 8
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 Choose View, Header and Footer to enter text here 6/3/2021 9
Cocoon Welcome Page Choose View, Header and Footer to enter text here 6/3/2021 10
Cocoon Servlet Dirs. & Files Directory for auto mounting sub-sitemaps Cocoon Configuration file A sub-sitemap directory Main sitemap file Directory for log files Choose View, Header and Footer to enter text here 6/3/2021 11
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 Choose View, Header and Footer to enter text here 6/3/2021 12
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 ! ). Choose View, Header and Footer to enter text here 6/3/2021 13
A sample pipeline <map: pipeline> <map: match pattern="hello. html"> <map: generate src="docs/samples/hello-page. xml"/> <map: transform src="stylesheets/page/simple-page 2 html. 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/error 2 html. xsl"/> <map: serialize status-code="500"/> </map: handle-errors> </map: pipeline> Choose View, Header and Footer to enter text here 6/3/2021 14
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, I 18 N, Log, … • Different Kind of Serializers – HTML, XML, Text, PDF, SVG, . . . Choose View, Header and Footer to enter text here 6/3/2021 15
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> Choose View, Header and Footer to enter text here 6/3/2021 16
What Are Web Services? Choose View, Header and Footer to enter text here 6/3/2021 17
Defining Web Services Most 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. Choose View, Header and Footer to enter text here 6/3/2021 18
SOAP 1. 1 • XML based protocol for exchange of information SOAP 1. 1 Message Structure SOAP Envelope – Encoding rules for datatype instances – Convention for representing RPC invocations Header Entries [Header Element] • Designed for loosely-coupled distributed computing • Used with XML Schema • Transport independent • SOAP with Attachments allow arbitrary data to be packaged. Body Element [Fault Element] Choose View, Header and Footer to enter text here 6/3/2021 19
WSDL 1. 1 • A WSDL document describes WSDL 1. 1 Document Structure WSDL Document – What the service can do – Where it resides – How to invoke it [Types] {Messages} • WSDL are like IDL but lot more flexible and extensible • Defines binding for SOAP 1. 1, HTTP GET/POST and MIME • WSDL descriptions can be made available from an UDDI registry {Port. Types} {Bindings} {Services} Choose View, Header and Footer to enter text here 6/3/2021 20
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 Choose View, Header and Footer to enter text here 6/3/2021 21
Java Platforms and Standards • Java Platforms for Web Services – – HP WSP, HP WSR, HP WST Apache SOAP 2. 2, Apache Axis, UDDI 4 J, 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 ) J 2 EE 1. 4 ( J 2 EE platform for Web Services ) • Java standards promise portability Choose View, Header and Footer to enter text here 6/3/2021 22
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. . . Choose View, Header and Footer to enter text here 6/3/2021 23
Cocoon and Web Services Choose View, Header and Footer to enter text here 6/3/2021 24
Cocoon as a Presentation Framework for Web. Services WS Registry Cocoon Web Services Servlet Container Client Tier Web Tier Enterprise Apps Choose View, Header and Footer to enter text here 6/3/2021 25
Cocoon as a Processing Framework for Web Services WS Registry Cocoon Servlet Container Web Services P 1 Web Tier P 2 Client Tier Enterprise Apps Choose View, Header and Footer to enter text here 6/3/2021 26
A Simple Cocoon Web Application Choose View, Header and Footer to enter text here 6/3/2021 27
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. Choose View, Header and Footer to enter text here 6/3/2021 28
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/sdwest 2002/google. zip Choose View, Header and Footer to enter text here 6/3/2021 29
Application Architecture Cocoon Servlet Browser Google WS http: //<host>/cocoon/mount/google/ index. html Maps request to index. html …/search? q=. . . SOAP request executes google. xsp Search results in HTML SOAP response Applies search-results. xsl Choose View, Header and Footer to enter text here 6/3/2021 30
Demo Architecture Cocoon Servlet Browser http: //<host>/cocoon/mount/google/welcome-local index. html Maps request to index-local. html …/search-local? q=. . . Reads google. results Search results in HTML Applies search-results. xsl Choose View, Header and Footer to enter text here 6/3/2021 31
Web Application Demo [Walk through the Design, Sources and the Demo] Choose View, Header and Footer to enter text here 6/3/2021 32
- Slides: 32