1 / 23

Labs: Create, deploy and test a simple web service

Labs: Create, deploy and test a simple web service. SOA concept Web service: components and implementation approaches Activity 1: Implementing a simple web service. What is SOA.

lbentley
Download Presentation

Labs: Create, deploy and test a simple web service

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Labs: Create, deploy and test a simple web service SOA concept Web service: components and implementation approaches Activity 1: Implementing a simple web service

  2. 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 • ...

  3. 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.

  4. 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

  5. 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.

  6. 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

  7. 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

  8. 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

  9. 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.

  10. Added a server runtime environment

  11. 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

  12. 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)

  13. 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

  14. Step 2: Generating a web service and client • Select the Hello.java in the Project Explorer • File > New > Other > Web Services > Web Service

  15. 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.

  16. 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.

  17. 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.

  18. 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.

  19. 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>

  20. What is Axis? • Copy the actual web service URL into a web browser:

  21. 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.

  22. Axis and WSDL • Eclipse and Axis provide a very good level of support for the development and description of web services.

  23. 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

More Related