Tutorial on Web Services
HY559 Infrastructure Technologies for Large- Scale Service-Oriented Systems
Jason Polakis [email protected] Required Software
•Eclipse IDE for Java developers EE http://www.eclipse.org/downloads/ •Netbeans IDE http://netbeans.org/downloads/ •Apache Tomcat http://tomcat.apache.org/ •Apache AXIS2 http://axis.apache.org/axis2/java/core/download.cgi •Apache JUDDI http://juddi.apache.org/releases.html Getting Software
• Either directly from given links, or: • In Ubuntu (as root) • To search for software – apt -cache search
•Web Service Protocol Stack –Service transport (transport messages between applications) •HTTP, SMTP, FTP –XML messaging (encode messages in common XML format ) • XML-RPC, WS-Addressing, and SOAP –Service description (describe public interface of service) –Service discovery (centralize services into common registry) •Programming models: –REST-based web services –SOAP-based web services SOAP-based Services
•Use SOAP –protocol for exchanging structured information •Use WSDL –xml-based language for describing Web services •WSDL file –created based on the JAVA code in the service –exposed on the net •To use service, must create a client –based on WSDL info •Messages exchanged in SOAP
•Java API for XML Web Services (JAX-WS) model also used for SOAP services. Can use instead of AXIS2. WSDL example
•Web service •Single publicly available function sayHello –argument: string –return value: string WSDL Definitions element
•container of all other elements •specifies that this document is the HelloService •Namespace: abstract container providing context -> logical grouping of code •specifies a targetNamespace attribute (XML convention) → enables self reference •specifies a default namespace •specifies numerous namespaces that will be used WSDL types
•
•Defines ports supported by Web service •Service element: a collection of ports •For each supported protocol, there is one port element •clients learn from service element –where to access the service –through which port to access the Web service •Human-readable documentation •Binding attribute associates service with binding element Apache Tomcat
•Open source servlet container •HTTP web server environment for serving Java Implements •Java Servlet: class for responding to HTTP requests –Create object that receives a request –Generates responses based on requests •JavaServer Pages (JSP): serve dynamically generated web pages –Java code interleaved with static web content –Compiled and executed on server –Resulting HTML or XML document served Apache AXIS2
• Web service framework • Will run over Tomcat • SOAP / WSDL engine • Also supports RESTful web services • Web service creation example – http://netbeans.org/kb/docs/websvc/gs- axis.html#deploy_axis – http://today.java.net/pub/a/today/2006/12/13/in voking-web-services-using-apache-axis2.html Apache AXIS2
• Send SOAP messages • Receive and process SOAP messages • Create a Web service out of a plain Java class • Create implementation classes for both the server and client using WSDL • Easily retrieve the WSDL for a service • Send and receive SOAP messages with attachments • Create or utilize a REST-based Web service Netbeans IDE
•Creating an Axis2 “Hello World” Web Service •First setup Axis2 and Tomcat –http://netbeans.org/kb/docs/websvc/gs- axis.html#setup –http://netbeans.org/kb/docs/websvc/gs- axis.html#axis_options_tomcat Netbeans IDE example File -> New Project Name it AxisHello, click Finish Right-click project node , context menu opens choose New -> Other, Wizard opens Netbeans IDE example
• Click Next, Name the Java class HelloAxisWorld. • Name the package axishello. Click Finish. • Application created. Netbeans IDE example Netbeans IDE example • Time to deploy Axis2 web service to the server • Right-click the web service's node -> Deploy to Server • Axis2 AAR file created, copied to .war file used by server • To test service, expand web service node • Right-click “hello: String” node. -> Test in Browser Netbeans IDE example
• Browser opens, with test value for variables Netbeans IDE example
• Change value and press Enter. Results change. Netbeans IDE example
• Change Web Service Operation. • Edit Java file in Editor.
• Save the Java file, Redeploy Web Service and test!!! Apache JUDDI
•XML-based registry for registering and locating web service applications •Interact through SOAP, access WSDL documents Link1 , link2 , link3