Designing to an Interface - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

Designing to an Interface

Description:

Enables legacy code to be incorporated in state-of-the-art systems ... Just extract the zip file somewhere Set the somewhere antbin directory in your PATH ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 55
Provided by: daveel1
Category:

less

Transcript and Presenter's Notes

Title: Designing to an Interface


1
Designing to an Interface
  • Dave Elliman

2
Is there a book?
  • Gregor Hohpe and Bobby Woolf, Enterprise
    Integration Patterns, Addison-Wesley, 2004.
  • A remarkable well-written and authorative text
  • Martin Fowler, Patterns of Enterprise
    Application Architecture. Addison-Wesley, 2003.
  • Martin Fowler is the chief Guru in this field

3
Yet Another Choice
  • Synchronous or Asynchronous
  • Synchronous
  • more familiar
  • less complex
  • Have to wait for it
  • Asynchronous
  • more robust
  • Can send and forget
  • More loosely coupled

4
Some more terminology?
  • MOM
  • Message Oriented Middleware
  • SOA
  • Service Oriented Architectures

5
Design to an Interface
  • Careful thought about Use Cases allows one to
    specify an Interface
  • It is important to get this right as it is a
    nuisance to change later
  • Once the application is deployed Interfaces are
    forever
  • RPC is the easiest approach to understand but
    consider asynchronous approaches as well i.e. SOA

6
We need a case study
  • A Vision for online learning as a process of
    colouring an ontology
  • Could this be what education has been missing
    the killer application?
  • No Ok Anyway
  • We need topics and relationships
  • T1subtopic T2
  • T1 prerequisite T3

7
We have actors
  • Student
  • Tutor
  • Maybe Administrator and System

8
Groups, Test and Tutorials
  • Student
  • Tutor
  • Group
  • Test
  • Tutorial

9
Consider the Interface
  • This is really important to get right

10
Start with user stories
  • The tutor creates a group of students
    corresponding to his class for a topic
  • The tutor create a topic and adds tests and
    tutorial material
  • A student sees what he is able to learn next and
    studies it
  • A student decides he is ready to be tested and
    selects a test on a topic
  • The tutor sees the progress overall and where
    students are stuck

11
Exercise
  • Draw the Use Case UML diagrams for this case
    study

12
Student Methods
  • login
  • logoout
  • learningChoices
  • getTutorial
  • testMe

13
Tutor methods
  • createGroup
  • assignTopicToGroup
  • seeStudentProgress
  • seeGroupProgress
  • disbandGroup
  • addTutorial
  • addTest
  • addTopic

14
Admin Methods
  • createStudent
  • archiveStudent
  • createGroup
  • deleteGroup
  • createTutor
  • deleteTutor

15
Web Services
  • Dave Elliman

16
What is a web service?
  • Usually
  • A method call that uses XML to encode the request
    and response
  • This uses SOAP (XML again) or XML RPC
  • A service that describes itself using a wsdl
    description (XML of course).

17
For Example
  • http//www.sirajgadhia.com/WebServices/quotes.asmx
    ?wsdl
  • http//ws.cdyne.com/emailverify/Emailvernotestemai
    l.asmx

18
Web Services are loosely coupled
  • Web services are an inspired idea
  • The key ideas are
  • A web service is a remote object that you can use
    over the internet
  • It communicates in XML (SOAP) and this means any
    operating system on any machine can use it
  • The object is located at a URL. At that url there
    is also a standard description of what it does
    (.wsdl) (like reflection and introspection in
    classes only better)

19
Interoperability
  • Interoperability
  • Does not matter about make of computer, operating
    system, or programming language
  • Suitable for automatic tools to do all the hard
    work
  • Especially useful for Business to Business
    transactions

20
Why use web services?
  • A general paradigm for building distributed
    applications
  • Enables legacy code to be incorporated in
    state-of-the-art systems by use of a web-service
    wrapper
  • Facilitates INTEGRATION between organisations
  • Intranet and knowledgebase
  • Supply chain
  • E Government etc etc

21
Web services may be foundusing directories
  • Universal Description Discovery and Integration
  • An indexing service for web services
  • See microsoft and IBMs examples
  • http//uddi.microsoft.com/default.aspx
  • http//www-306.ibm.com/software/solutions/webserv
    ices/uddi/

22
A Layered model
Workflow - WSFL
Service Discovery- UDDI
Service Description - WSDL
Messaging - SOAP
Transport - HTTP (not exclusively)
Internet
23
Benefits
  • There is a huge payoff in efficiency
  • It was previously an expensive nightmare to
    achieve INTEROPERABILITY no longer
  • Leverage of existing applications
  • Accessibility to services
  • The market was estimated to be worth 40 billion
    by 2008 nonsense?
  • Another chance to be a millionaire?

24
The old way..
  • Complicated System inter-connection
  • All individually specified and engineered
  • Tied into obsolete hardware and systems
  • Highly paid staff needed
  • Lots of info needed to pass between parties
  • Difficult to change later

25
More about SOAP
  • SOAP is an XML envelope
  • The header is often taken from a URL
  • See
  • http//www.intertwingly.net/stories/2002/03/16/aGe
    ntleIntroductionToSoap.html

26
An example
ltSOAPEnvelope xmlnsSOAP "http//schemas.xmlsoa
p.org/soap/envelope/"gt  ltSOAPBodygt   
ltmgetStateName xmlnsm"http//www.soapware.org/"
gt      ltstatenumgt41lt/statenumgt   
lt/mgetStateNamegt  lt/SOAPBodygtlt/SOAPEnvelopegt
27
WSDL (XML)
28
Almost always processed by a tool not a person
  • Can see the wsdl by pointing your browser at any
    web service eg
  • http//www.sirajgadhia.com/WebServices/quotes.asmx
    ?wsdl

29
SOAP must implement
  • An XML envelope for XML (SOAP is transport
    independent)
  • An HTTP binding for SOAP messaging
  • A convention for doing RPC
  • And a way to pass parameters - an XML
    serialization format for structured data

30
Sounds terrible!
  • So I need to generate SOAP envelopes
  • I need to send them down an HTTP Socket and
    listen for the response
  • I need to parse the SOAP that is returned (SAX or
    DOM?)
  • If I try RPC I need to marshal the parameters
    HELP!

31
  • Thankfully not. There are TOOLS
  • AXIS for the Java world (also C)
  • Built into Microsoft .NET WCF
  • PHP - PEAR
  • Perl has SOAP libraries
  • Python is of course brilliant
  • many others

32
The Client Side
  • When one builds a web service one can get a
    client for free offer this to people!
  • We can build a client with a tool for example
    wsdl2java
  • We can build a client using a library such as
    axis2.jar
  • We can use Microsoft tools we will!

33
Restful Web Services
  • REST we services use no soap no wsdl
  • Faster and conceptually simpler and require no
    special tools
  • Based on Roy Fielding's PhD thesis
  • Not a standard a way of doing things
  • http//www.parts-depot.com/parts
  • http//www.parts-depot.com/parts/003
  • POST sending xml for an order

34
Summary
  • Web services are a powerful idea and they are
    becoming hugely important
  • We will build a web service to expose the methods
    for the case study
  • Quite easy to use in practice given current state
    of tools

35
Deploying a web service
36
How to offer a web service
  • I downloaded Apache Tomcat from
  • http//tomcat.apache.org/ on weed.cs.nott.ac.uk
  • I installed it on port 80 (not default of 8080)
  • Check at http//weed.cs.nott.ac.uk/
  • I downloaded Apache Axis 2 (the web version) for
    building web services
  • http//ws.apache.org/axis2
  • I extracted axis2.war to
  • ltsomewheregt/tomacat 6/webapps
  • I stopped and re-started the tomcat server.
  • http//weed.cs.nott.ac.uk/axis2

37
How to create and deploy a web service
  • We are spoiled for choice of course At least
    five different ways but it is only 3 steps. use
    ant
  • Compile a simple Java POJO class
  • Generate the WSDL for this class
  • Create an .aar file. (Just a jar really).
  • Put the .aar file inlttomcatgt/webapps/axis2/WEB_INF
    /services
  • It is hot deployed at once

38
We need ant
39
What is ant
  • Ant is a build tool reminiscent of make but not
    so evil (eg can fail with a space in front of a
    tab!)
  • It is open source
  • It is powerful and extendible
  • It is written in Java and is portable
  • No o/s specific system calls
  • An ant build file is written in xml

40
Setting ant up
  • You can get ant from http//ant.apache.org/
  • Just extract the zip file ltsomewheregt
  • Set the ltsomewheregt\ ant\bin directory in your
    PATH
  • Set the ANT_HOME environment variable to
    ltsomewheregt\ant

41
Some environment variables
  • ANT_HOMEC\ant
  • JAVA_HOMEC\jdk1.6.05
  • PATHC\ant\binC\jdk1.6.05\bin

42
Invoking ant
  • Similar to running make
  • ant options target target2 ...
  • Options
  • -help print this message
  • -verbose be extra verbose
  • -debug print debugging
    information
  • -buildfile ltfilegt use given buildfile
  • ant (assumes build.xml in .)

43
Things to know
  • Written in XML
  • You can call ant recursively used a lot!
  • build.xml is the default name
  • No Java programmer can live without ant
  • http//ant.apache.org .

44
Simple ant script

ltproject name"hello" default"compile"gt lttarget
name"compile"gt ltjavac srcdir"." destdir"."
/gt lt/targetgt lt/projectgt
45
The Build File Will Create a dependancy Tree
  • You specify targets
  • Each is executed only once honouring the order of
    dependency
  • If files are up-to-date the task is not executed
  • eg the test and deploy targets would depend on
    the compile target

46
How Is This dependancy Expressed?
  • lttarget nameall dependstest, javadoc,
    deploy
  • descriptionrun tests, document and deploy
  • /gt

47
This is easier than make
lttarget namecompile dependsprepare descripti
oncompile the sources ltjavac
srcdirscrDir destdirbuildDir/gtlt/targe
tgt Earlier in the file we define
properties ltproperty namebuildDir
valueclasses/gt
48
see http//ant.apache.org/manual/CoreTasks/
Standard Targets
  • prepare
  • clean
  • compile
  • Javadoc
  • test

49
For the case study
  • ltproject name"CM6" basedir"."
    default"generate.service"gt
  • ltproperty name"AXIS2_HOME" value"C/axis2/axis
    2-1.3"/gt
  • ltproperty name"build.dir" value"build"/gt
  • ltpath id"axis2.classpath"gt
  • ltfileset dir"AXIS2_HOME/lib"gt
  • ltinclude name".jar"/gt
  • lt/filesetgt
  • lt/pathgt

50
Compile task
lttarget name"compile.service"gt ltmkdir
dir"build.dir"/gt ltmkdir
dir"build.dir/classes"/gt lt!--First
let's compile the classes--gt ltjavac
debug"on" fork"true"
destdir"build.dir/classes"
srcdir"basedir/src"
classpathref"axis2.classpath"gt lt/javacgt
lt/targetgt
51
Create WSDL Task
lttarget name"generate.wsdl" depends"compile.serv
ice"gt lttaskdef name"java2wsdl"
classname"org.apache.ws.java2wsdl.Java2WSD
LTask" classpathref"axis2.classp
ath"/gt ltjava2wsdl className"com.dge.Cours
eMarker6.0" outputLocation"b
uild.dir" targetNamespace"htt
p//CM6/"gt ltclasspathgt
ltpathelement path"axis2.classpath"/gt
ltpathelement location"build.dir/classe
s"/gt lt/classpathgt
lt/java2wsdlgt lt/targetgt
52
Create aar file
lttarget name"generate.service"
depends"compile.service"gt lt!--aar them
up --gt ltcopy toDir"build.dir/classes"
failonerror"false"gt ltfileset
dir"basedir/resources"gt
ltinclude name"/.xml"/gt
lt/filesetgt lt/copygt ltjar
destfile"build.dir/StockQuoteService.aar"gt
ltfileset excludes"/Test.class"
dir"build.dir/classes"/gt lt/jargt
lt/targetgt lt/projectgt
53
Once you get build.xml right its easy
  • We create an Interface
  • We create a POJO that implements this
  • We create a build.xml to make an aar file
  • We run ant
  • We have a web service
  • (Some auto-deploy options seem easier but only
    for the very simplest cases)
  • Annotation-based methods are a competitor to this
    _at_WebService _at_Webmethod etc
  • Used to involve a lot of xml several special Java
    classes and deploytool.. was much harder!

54
Wow.. That was a lot to take in
  • Any Questions?
Write a Comment
User Comments (0)
About PowerShow.com