JAX-RPC The Java API for XML Remote Procedure Calls Notes from The J2EE Tutorial 1.4 From Sun Microsystems.

Slides:



Advertisements
Similar presentations
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
Advertisements

Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009.
Java Web Services.
Enabling Grids for E-sciencE ISSGC 05 Web Service Tools NeSC Training Team.
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
J2ME RMI 1 Java 2 Platform, Micro Edition Implementation of J2ME RMI Application Farooq Sheikh.
1 Web Services Programming Java Web Services Programming Dickson K.W. Chiu PhD, SMIEEE Deitel et al., Java Web Services for Experienced Programmers.
Lecture 10: Web Services. Outline Overview of Web Services Create a Web Service with Sun J2EE (JAX-RPC)
Web Services Description Language ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes from article.
Introduction to Remote Method Invocation (RMI)
Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
OOP IIICMU/MSCF1 Web Services Description Language ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes.
Organizational Communication Technologies 1 Enterprise Java Beans Detail.
1 Java Server Programming zLecture 1 focuses on: yIntroduction to web services y Web Services using Axis y The bigger Picture: Introduction to J2EE y Java.
1 CPE3010 Lecture 5 Java and Web Services. 2 Many Java gurus/ developers HATE XML and Web services. - too slow, too high an overhead, and “back to the.
1 Lecture 22 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
1 Java Programming II Java Network II (Distributed Objects in Java)
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)
COP 4991 Component Based Software Development Lecture #4 Java Web Services Onyeka Ezenwoye.
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
1 SOA and Enterprise Computing Enterprise Java Beans.
Presented By Pradeep K Sahu. What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
15 - RMI. Java RMI Architecture Example Deployment RMI is a part of J2SE (standard edition), but is used by J2EE) A J2EE server is not nessesary for using.
Session Beans -) stateless -) stateful. Session Beans A session bean represents a single client inside the J2EE server. To access an application that.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
A TUTORIAL TO USING EJBs by SHREERAM IYER 09/17/2001.
EGEE is a project funded by the European Union under contract IST WSDL JAX-RPC 17 th October
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE CLIENT.
Enabling Grids for E-sciencE PPARC Summer School, May 2005 Web Service Tools Oliver Malham, National e-Science Centre, Edinburgh Based.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
SOA support in J2EE Platform overview Primitive SOA support Support for service-orientation principles Contemporary SOA support.
J2EE —— 第 8 章 利用 JAX-RPC 构建 Web 服务. 什么是 JAX-RPC Java API for XML-based RPC SOAP: Simple Object Access Protocol 信封结构 编码规则 远程过程调用和响应的转换 JAX-RPC 隐藏了 SOAP.
J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
OCT 1 Master of Information System Management Distributed Systems Lecture 19: Enterprise Java Beans.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
WP3 Implementing R-GMA grid services in GT3 Abdeslem Djaoui & WP3 Grid Services Task Force 7 th EU Datagrid meeting 26/09/2003
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
Netprog Java RMI1 Remote Method Invocation.
Beginning 자바 웹 서비스 웹 서비스 호출 Meilan JIANG Cyber infrastructure Research Laboratory Department of Advanced Technology.
The Java API for XML-Based Web Services. A Web Service example in Java SOAP-awareServlet (e.g. Apache Axis2) SOAP-awareServlet Any class processing the.
1 EJB 3.0: There’s Something Different About You Martin Jäkle, TSBU Middleware.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Chapter 5 Remote Procedure Call
WSDL JAX-RPC 17th October 2004
Web Services-JAX-RPC JAX-RPC enables a Web Service endpoint to be developed using either a Java Servlet or Enterprise JavaBeans (EJB) component model.
Java RMI (more) CS-328 Internet Programming.
Java Web Services Programming
Introduction to Web Services
Understanding Web Services based on dev. java
WebServices Using JAX-RPC
Introduction to Web Services
Distributed System using Web Services
Introduction to Session beans
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Distributed System using Web Services
Enterprise Java Beans.
Presentation transcript:

JAX-RPC The Java API for XML Remote Procedure Calls Notes from The J2EE Tutorial 1.4 From Sun Microsystems

JAX-RPC Notes Based on W3C Technologies SOAP WSDL HTTP Java types are mapped to XML/WSDL String to xsd:string BigDecimal[] and more… Primitive types

JAX-RPC Server Side package helloservice; import java.rmi.Remote; Import java.rmi.RemoteException; public interface HelloIF extends Remote { public String sayHello(String s) throws RemoteException; } The service endpoint interface

Implement the service package helloservice; public class HelloImpl implements HelloIF { public String message ="Hello"; public String sayHello(String s) { return message + s; }

Provide a config-interface.xml <configuration xmlns=" <service name="MyHelloService" targetNamespace="urn:Foo" typeNamespace="urn:Foo" packageName="helloservice">

Three steps to build 1.compile-service 2.generate-wsdl 3.generate-mapping from service classes package names to namespace URI’s in the WSDL and create ties (skeletons) J2EE1.4 provides an ant task to perform all three steps

Behind the Scenes The JAX-RPC web service is actually a servlet and placed in the web tier

On the client side We’ll examine four options 1.Static stubs compiled by wscompile before runtime 2.Dynamic stubs has an interface but fetches the WSDL at runtime 3.Dynamic Invocation Interface knows no interface - the method names and signatures 4.A J2EE Application Client Locate the local web service with JNDI

Client Using a Static Stub import javax.xml.rpc.Stub; public class HelloClient { private String endpointAddress; public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); It almost looks like a local call.

try { Stub stub = createProxy(); stub._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); // cast the stub to the proper interface HelloIF hello = (HelloIF)stub; // call the methods defined there System.out.println(hello.sayHello("Duke!")); } catch (Exception ex) { ex.printStackTrace(); }

private static Stub createProxy() { // MyHelloService_Impl is created by wscompile return (Stub) (new MyHelloService_Impl().getHelloIFPort()); }

Using a Dynamic Stub public class HelloClient { public static void main(String[] args) { try { String UrlString = args[0] + "?WSDL"; String nameSpaceUri = "urn:Foo"; String serviceName = "MyHelloService"; String portName = "HelloIFPort"; // We have more work to do

System.out.println("UrlString = " + UrlString); URL helloWsdlUrl = new URL(UrlString); ServiceFactory serviceFactory = ServiceFactory.newInstance(); Service helloService = serviceFactory.createService(helloWsdlUrl, new QName(nameSpaceUri, serviceName)); WSDL is fetched at runtime

dynamicproxy.HelloIF myProxy = (dynamicproxy.HelloIF) helloService.getPort( new QName(nameSpaceUri, portName), dynamicproxy.HelloIF.class); System.out.println(myProxy.sayHello("Buzz")); } catch (Exception ex) { ex.printStackTrace(); }

Client Using a Dynamic Invocation Interface import javax.xml.rpc.Call; import javax.xml.rpc.Service; import javax.xml.rpc.JAXRPCException; import javax.xml.namespace.QName; import javax.xml.rpc.ServiceFactory; import javax.xml.rpc.ParameterMode;

public class HelloClient { private static String qnameService = "MyHelloService"; private static String qnamePort = "HelloIF"; private static String BODY_NAMESPACE_VALUE = "urn:Foo"; private static String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri"; private static String NS_XSD = " private static String URI_ENCODING = "

public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); try { ServiceFactory factory = ServiceFactory.newInstance(); Service service = factory.createService( new QName(qnameService)); QName port = new QName(qnamePort); The URL and service names are all specified at runtime “MyHelloService” HelloIF

Call call = service.createCall(port); call.setTargetEndpointAddress(args[0]); call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true)); call.setProperty(Call.SOAPACTION_URI_PROPERTY ""); call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING); QName QNAME_TYPE_STRING = new QName(NS_XSD, "string"); call.setReturnType(QNAME_TYPE_STRING); Who we are calling and how is determined at runtime SOAP details must be specified

call.setOperationName( new QName(BODY_NAMESPACE_VALUE,"sayHello")); call.addParameter("String_1", QNAME_TYPE_STRING, ParameterMode.IN); String[] params = { "Murph!" }; String result = (String)call.invoke(params); System.out.println(result); } catch (Exception ex) { ex.printStackTrace(); } Very carefully prepare the call. Make the call Get the result Harder to program but allows for a great deal of flexibility. There is a lot less hard coding going on here. A lot of this could be chosen by a sophisticated user at runtime

J2EE Application Client import javax.xml.rpc.Stub; import javax.naming.*; public class HelloClient { private String endpointAddress; public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); try { Context ic = new InitialContext(); MyHelloService myHelloService = (MyHelloService) ic.lookup("java:comp/env/service/MyJAXRPCHello"); Ask JNDI for a reference to a stub for the object

HelloIF helloPort = myHelloService.getHelloIFPort(); ((Stub)helloPort)._setProperty (Stub.ENDPOINT_ADDRESS_PROPERTY,args[0]); System.out.println(helloPort.sayHello("Jake!")); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); }

From The J2EE Tutorial

The Web Service as an EJB A Web service client can access J2EE applications in two ways. First, the client can access a Web service created with JAX-RPC. Behind the scenes, JAX- RPC uses a servlet to implement the Web service. Second, a Web service client can access a stateless session bean through the service endpoint interface of the bean. Other types of enterprise beans cannot be accessed by Web service clients.

A Stateless Session Bean as a Web Service The client need not know that its interacting with a Java EJB It calls the bean like it calls any other web service

The Web Service Endpoint Interface package helloservice; import java.rmi.RemoteException; import java.rmi.Remote; public interface HelloIF extends Remote { public String sayHello(String name) throws RemoteException; } The client cannot see that it’s interacting with an EJB

The Web Service Session Bean package helloservice; import java.rmi.RemoteException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class HelloServiceBean implements SessionBean { public String sayHello(String name) { return "Hello " + name + "from HelloServiceEJB"; } public HelloServiceBean() {} public void ejbCreate() {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sc) {} } If we added remote and home Interfaces then this bean could also be called using in the traditional manner – with remote references. No change to the bean would be necessary. WSDL can be generated and all of the previous clients will work.