JAX-RPC Distributor Service WSA

Download Report

Transcript JAX-RPC Distributor Service WSA

Fall OCT 31, 2007
课堂讨论
Web Services and Its
Applications
Li Yinsheng (021-51355352)
Email: [email protected]
Institute of e-Business
Fudan University Software School
http://eb.fudan.edu.cn
Case Description
• This cased is produced based on examples by Sun
Microsystems, Inc.
• Java™ WSDP
Application Architecture
Business Workflow Scenario
• Coffee Break server uses both JAXM
messaging (request/response model) and JAXRPC to communicate with its two distributors
• Coffee Break server uses JAXR to send a
query searching for coffee distributors that
support JAX-RPC
• Coffee Break server requests price lists from
each of the coffee distributors
–price list delivered as JavaBean component
(JAX-RPC)
– price list delivered as XML document
(JAXM)
Business Workflow Scenario
Business Workflow Scenario
• Coffee Break Server creates a local
database of distributors
• When an order is placed, suborders are
sent to one or more distributors using the
distributor's preferred protocol
Architectural Modules
• JAX-RPC distributor service
• JAXM distributor service
• Web server module
• JAXR registry
JAX-RPC Distributor Service
• Service interface
• Service implementation
• Service registration
JAX-RPC Distributor Service
Service Interface
package com.sun.cb;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface SupplierIF extends Remote {
public ConfirmationBean placeOrder(OrderBean order) throws RemoteException;
public PriceListBean getPriceList() throws RemoteException;
}
JAX-RPC Distributor Service
Service Implementation
public ConfirmationBean placeOrder(OrderBean order) {
Date tomorrow = com.sun.cb.DateHelper.addDays(new Date(), 1);
ConfirmationBean confirmation = new ConfirmationBean(order.getId(), tomorrow);
return confirmation;
}
public PriceListBean getPriceList() {
PriceListBean priceList = loadPrices();
return priceList;
}
JAX-RPC Distributor Service
Service registration using JAXR
public class OrgPublisher {
public static void main(String[] args) {
ResourceBundle registryBundle =
ResourceBundle.getBundle("com.sun.cb.CoffeeRegistry");
String queryURL = registryBundle.getString("query.url");
String publishURL = registryBundle.getString("publish.url");
String username = registryBundle.getString("registry.username");
String password = registryBundle.getString("registry.password");
String endpoint = registryBundle.getString("endpoint");
String keyFile = registryBundle.getString("key.file");
JAX-RPC Distributor Service
Service registration using JAXR
JAXRPublisher publisher = new JAXRPublisher();
publisher.makeConnection(queryURL, publishURL);
String key = publisher.executePublish (username, password, endpoint);
try { FileWriter out = new FileWriter(keyFile);
out.write(key);
out.flush();
out.close();
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}}
JAX-RPC Distributor Service
Messaging Model Used
• Uses request/response messaging
– JAXM provider is not used
• Two request/response interactions
– request: “Requests for current wholesale coffee prices”
– response: “Current price lists”
– request: “Customer orders for coffee”
– response: “Order confirmations”
JAX-RPC Distributor Service
Messages Being Exchanged
• Pre-agreed upon Message formats in DTD's
– request-prices.dtd
– price-list.dtd
– coffee-order.dtd
– confirm.dtd
• Sample Messages
– request-prices.xml
– price-list.xml
– coffee-order.xml
– confirm.xml
JAX-RPC Distributor Service
JAXM Client
• Creating request message
• Extracting information from the response message
JAX-RPC Distributor Service
JAXM Service
• Servlet based
– PriceListServlet for price list response message
– ConfirmationServlet for order confirmation response message
Web Server Modules
• For creating dynamic contents
• Uses
– Servlet
– JSP
* Template Tag library for common look and feel
* JSTL custom tags
– JavaBeans components
* Contains business logic
* Send requests to web services
* Handles responses from web services message
Web Server Modules
MVC Pattern
• Coffee break web module is based on MVC pattern
• Dispatch servlet as Controller
– Examines the request URL
– Creates and initializes model JavaBeans components
– Dispatches requests to view JSP pages
Web Server Modules
JSP Pages and Java Beans
• Update order data
– JSP page: orderForm
– JavaBean: ShoppingCart
• Update delivery and billing data
– JSP page: checkoutForm
– JavaBean: CheckoutFormBean
• Display order confirmation
– JSP page: checkoutAck
– JavaBean: OrderConfirmations
Web Server Modules
Servlets
• RetailPriceListServlet
– Responds to requests to reload the price list
– Creates a new RetailPriceList and a new ShoppingCart
– Used only by administrator
– Protected resource
– In order to load the price list, a user must authenticate (using basic
authentication) and the authenticated user must be in the admin role