KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > consumerwebsite > actions > OrderTrackingHTMLAction


1 /* @@copyright $Id: OrderTrackingHTMLAction.java,v 1.1.1.1 2005/05/25 12:36:20 wml Exp $ */
2
3 package com.sun.j2ee.blueprints.consumerwebsite.actions;
4
5 import javax.servlet.http.*;
6 import java.util.Collection JavaDoc;
7 import javax.naming.*;
8 import javax.xml.rpc.*;
9
10 // waf imports
11
import com.sun.j2ee.blueprints.waf.controller.Event;
12 import com.sun.j2ee.blueprints.waf.controller.web.html.*;
13
14 //adventure imports
15
import com.sun.j2ee.blueprints.consumerwebsite.*;
16
17 // Catalog imports
18
import com.sun.j2ee.blueprints.catalog.*;
19
20
21 /**
22  * Handles responsibilities related to getting HTTP request
23  * info and making the calls to process the action
24  */

25 public class OrderTrackingHTMLAction extends HTMLActionSupport{
26     
27     /**
28      * Handles the http request and provides an
29      * appropriate response.
30      *
31      * Post-condition: Set the bean with info to populate response.
32      */

33     public Event perform(HttpServletRequest request) throws HTMLActionException {
34         
35         String JavaDoc orderId = null;
36         OrderDetails result = null;
37         orderId = request.getParameter("orderId");
38         // put the orderId in the request to display in the screen
39
request.setAttribute("orderTrackingId", orderId);
40         try {
41             result = this.getOrderDetails(orderId, request);
42             if (result.getPO() == null) {
43                 throw new OrderNotFoundException("Order Not Found: " + orderId);
44             }
45             // places result bean data in the response.
46
request.setAttribute("orderDetails", result);
47         } catch(OrderNotFoundException ex) {
48             System.out.println("OrderTrackingHTMLAction caught the OrderNotFoundException Service Exception");
49             throw new com.sun.j2ee.blueprints.consumerwebsite.exceptions.OrderNotFoundException("Action error calling ordertracking endpoint " + ex);
50         } catch(Exception JavaDoc ex) {
51             System.out.println("OrderTrackingHTMLAction caught an Exception");
52             throw new com.sun.j2ee.blueprints.consumerwebsite.exceptions.OrderNotFoundException("Action error calling ordertracking endpoint " + ex);
53         }
54         return null;
55     }
56     
57     /**
58      * Accesses OrderTracking Web Service endpoint using Jax-rpc
59      */

60     private OrderDetails getOrderDetails(String JavaDoc orderId,
61             HttpServletRequest request) throws Exception JavaDoc {
62         
63         Context ic = new InitialContext();
64         OpcOrderTrackingService opcOrderTrackingSvc =
65                 (OpcOrderTrackingService) ic.lookup("java:comp/env/service/OpcOrderTrackingService");
66         OrderTrackingIntf port = opcOrderTrackingSvc.getOrderTrackingIntfPort();
67         String JavaDoc server = (request.getServerPort() != 0) ?
68             (request.getServerName()+":"+request.getServerPort()) :
69             (request.getServerName());
70         ((Stub)port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,
71                 "http://" + server + "/webservice/OpcOrderTrackingService");
72         return port.getOrderDetails(orderId);
73     }
74 }
75
Popular Tags