370 likes | 382 Views
Introduction to Service oriented architecture. SOA concept Web service: components and implementation approaches Labs: Implementing a simple web service. What is SOA?.
E N D
Introduction to Service oriented architecture SOA concept Web service: components and implementation approaches Labs: Implementing a simple web service
What is SOA? • A set of principals and practices for modeling enterprise business functions as web services or micro services which have following attributes: • Standardized • Loosely coupled • Reusable • Composable • Autonomic • ...
Outline of SOA • The standard SOA model (Figure 1) introduces three key actors: • a web service 'provider' which makes services available and is also responsible for publishing a description of the service in one or more service directories. • a web service 'broker', who maintains a searchable directory of service descriptions. • a service 'requestor' or 'client' who wishes to find and use a service.
What is web service? • Web service is any service that: • Is available over the Internet or private (intranet) networks • Uses a standardized XML messaging system • Is not tied to any one operating system or programming language • Is self-describing via a common XML grammar • Is discoverable via a simple find mechanism
Components of web service • From an implementation point of view, a web service has: • Service logic, i.e. the work required to provide the service function • An interface (implemented in XML) describes how to put a request to the service and what to expect as response
How Does a Web Service Work? • A web service enables communication among various applications by using open standards such as HTML, XML, WSDL, and SOAP/REST. • A web service takes the help of: • XML to tag the data • SOAP(Simple Object Access Protocol) or REST (Representational State Transfer) to transfer a message • WSDL to describe the availability of service.
Web Services Technologies • Characteristics of a web service: • Defined interface in machine readable form (WSDL or WADL) • Conveyed over HTTP/S • Systems interact using request/response messages (SOAP or REST).
SOAP or REST • SOAP or REST protocols are both used to access Web services. • SOAP is a protocol with defined specification by W3. • Lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. • Requires custom methods (e.g. getCustomerName) • REST is an architectural style (not a standard) • Implements standard HTTP operations (GET, POST, PUT, DELETE) • Used to locate and return the representation of a resource (URI) • No XML to parse and process (faster) • Easer to implement
WSDL vs WADL • WSDL (Web Service Description Language) • XML to describe web service • Can define both SOAP and REST web services • Since REST services often use other HTTP verds, such as PUT and DELETE, WSDL is a poor choice for documenting REST services. • WADL (Web Application Description Language) • XML to describe REST web services • Lightweight, easer to understand and easer to write then WSDL. • Limited tooling support.
SOA life cycle Our focus
Tools for SOA development Rational Software Architect (RSA)
Start Building on AWS • https://aws.amazon.com/
Implementation approaches • Bottom-up approach – the code is written first, then the WSDL is produced and published in UDDI (the service code is placed inside a container that provides the required interface for messaging – usually SOAP) • Top-down approach – firstly, produce the WSDL, i.e. XML description of the service (what it does, how it can be called, what results it returns), and then this specification is used as a guide to writing the code that implements the service.
Activity 1: Implementing a simple web service • Lab 1: Setting up your Environment (already set in clasroom) • Step 1: Application Server installation - Install Apache Tomcat Server • Step 2: Eclipse IDE for Java EE Developers installation • Step 3: Add a ServerRuntimeEnvironment • Lab 2: Create a Dynamic Web Application project • Step 1: Writing the service logic • Step 2: Generating a web service and client • Step 3: Testing the web service • Step 4: Monitoring web service messages
Lab 1: Setting up your Environment Step 1: Application Server installation (There are a wide range of application servers such as IBM WebShere, JBoss, BEA’s WebLogic server etc. However, we will focus on use of Apache Tomcat since it is a popular, commercially used but open source (free) application server) • Install Apache Tomcat Server: • Go to: http://tomcat.apache.org/ • Click on the latest version, e.g.: http://tomcat.apache.org/download-90.cgi • Find your Windows version, e.g. under Core choose: 64-bit Windows zip • Under folder “c:\Program Files\” unzip the Application Server software : C:\Program Files\apache-tomcat-9.0.0.M17-windows-x64.zip Note that you should have jdk already installed. Check the path: C:\Program Files\Java\jdk1.8.0_91
Lab 1: Setting up your Environment Step 2: Eclipse IDE for Java EE Developers installation • Go to http://www.eclipse.org/downloads/ • Click on: • Run Eclipse eclipse-inst-win64.exe
Lab 1: Setting up your Environment Step 3: Add a ServerRuntimeEnvironment • Launch Eclipse and invoke the command from the menu bar: • Window > Preferences • Expand the Server category • Click on Runtime Environments • Click Add button to open the New Server Runtime Environment window • Expand the Apache category, and select Apache Tomcat v9.0, click on Next • Click the Browse button to select the directory where Tomcat is installed • The JRE field is initialized to the Workbench default JRE, which is the JVM you used to laund Eclipse – click on Finish • Tomcat is now listed (Figure on the next slide) • With extended Eclipse with a J2EE servlet container you are ready now to create your first Java Web application development project.
Lab 2: Create a Dynamic Web Application project • Launch Eclipse • If the Project Explorer is not open in Java EE perspecitve, then use Window > Open Perspective, and select Java EE • The first step is to create a project that will be used to hold all the code and other elements that will make up your web service: • Select File > New > Project, open up the Web folder and select Dynamic Web Project • Type a Project name: Hello, and click Finish. • Expand the project titled Hello to view the components
Step 1: Writing the service logic • In the Eclipse Project Explorer, expand the Hello project • Right-click on the Java Resources: src, and select New > Class • Enter Package name: Hello • Enter the class name: Hello, and click Finish. • Enter the class code: • Save the code using File > Save. • If all is well done you should find that Eclipse has compiled the source code “Hello.java” (under projects build directory)
Step 2: Generating a web service and client • Until now you have created an empty Dynamic Web Service project and added the code you need to turn into a web service. • Throught the next wizard, Eclipse will do the rest of the work for you by: • Packaging the web service up with an XML interface • Deploying the web service to an application server of your choise • Starting the application server if required • Generating a set of web pages that can be used as a simple client to test the web service
Step 2: Generating a web service and client • Select the Hello.java in the Project Explorer • File > New > Other > Web Services > Web Service
Step 2: Generating a web service and client Indicates that you are producing a web service from the bottom up based on some Java code. The slider controls what action Eclipse will take in terms of assembling, deploying, starting, etc. the web service. The Java proxy is a Java class that is generated as an application to implement the funcionality of the test client. It will be automatically generated and started as a web applicatoin running on Tomcat. The client should be generated in order to test the web service. Select to monitor the web service Click on Finish, that Eclipse can start to create and deploy the web service and make the client for testing the service.
Step 3: Testing the web service • When Eclipse has finished producing the web service and client, the next window will be displayed: The Methods pane containes a list of the actions that the web service can be asked to perform. The last method is defined by the Java code of the web service that you have created, so if you click on it the Inputs pane will display a text box labelled “name”. The web service will send a response, which is displayed in the Result pane.
Service descriptions: Web service endpoint • Click on the method: getEndpoint(), and then click on Invoke (under Inputs pane). • Result pane will display the URL where the service resides and can be accessed. • The HTTP URL used to display the test client. • The URL is that of a Java Server Page (JSP) called “TestClient.jsp”, which includes the frames you are seeing (Methods, Inputs, and Result). • Copy the link and paste it to your favourite web browser.
Step 4: Monitoring web service messages • Under TCP/IP Monitor, Eclipse displays request and response messages – that is a SOAP envelope with a simple body element. • The SOAP request: <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <helloName xmlns="http://DefaultNamespace"> <name>Nikola</name> </helloName> </soapenv:Body> </soapenv:Envelope> SOAP (Simple Object Access Protocol) is a protocol specification for exchanging structured information in the implementation of web services. SOAP allows clients to invoke web services and receive responses independent of language and platforms.
The SOAP response: <?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <helloNameResponse xmlns="http://DefaultNamespace"> <helloNameReturn>Hello there Nikola </helloNameReturn> </helloNameResponse> </soapenv:Body> </soapenv:Envelope>
What is Axis? • Copy the actual web service URL into a web browser:
Axis and WSDL • Axis is a commonly available library of code • Axis provide access to the WSDL document that it has generated for each service • The list of services is given at http://localhost:8080/Hello1/services • Click on the wsdl link next to the Hello service, and you will see the complete WSDL document for this service, which Axis has generated.
Axis and WSDL • Eclipse and Axis provide a very good level of support for the development and description of web services.
What you have learnt? • to create the logic of the service and deploy this to the application server • to create a simple client and used this to test the service • to examine the SOAP message exchange • to generate the WSDL that could be used by other clients to use the service. Video: • https://youtu.be/WktLenwPLS0