Source Code Cross Referenced for ReservationCallbackProviderBean.java in  » IDE-Netbeans » bpel » partnerservices » callback » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » bpel » partnerservices.callback 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2007, Sun Microsystems, Inc. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         * * Redistributions of source code must retain the above copyright notice,
008:         *   this list of conditions and the following disclaimer.
009:         *
010:         * * Redistributions in binary form must reproduce the above copyright notice,
011:         *   this list of conditions and the following disclaimer in the documentation
012:         *   and/or other materials provided with the distribution.
013:         *
014:         * * Neither the name of Sun Microsystems, Inc. nor the names of its contributors
015:         *   may be used to endorse or promote products derived from this software without
016:         *   specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028:         * THE POSSIBILITY OF SUCH DAMAGE.
029:         */
030:        package partnerservices.callback;
031:
032:        import java.io.BufferedInputStream;
033:        import java.io.IOException;
034:        import java.io.InputStreamReader;
035:        import java.io.LineNumberReader;
036:        import java.io.OutputStream;
037:        import java.net.HttpURLConnection;
038:        import java.net.MalformedURLException;
039:        import java.net.URL;
040:        import java.rmi.RemoteException;
041:        import javax.ejb.*;
042:        import javax.jms.MapMessage;
043:        import javax.jms.Message;
044:        import javax.jms.MessageListener;
045:        import javax.naming.InitialContext;
046:        import javax.naming.NamingException;
047:        import javax.xml.parsers.ParserConfigurationException;
048:        import javax.xml.soap.SOAPException;
049:        import javax.xml.transform.TransformerConfigurationException;
050:        import javax.xml.transform.TransformerException;
051:        import org.w3c.dom.Document;
052:        import org.xml.sax.SAXException;
053:
054:        public class ReservationCallbackProviderBean implements 
055:                MessageDrivenBean, MessageListener {
056:            private MessageDrivenContext context;
057:
058:            /**
059:             * @see javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext)
060:             */
061:            public void setMessageDrivenContext(MessageDrivenContext aContext) {
062:                context = aContext;
063:            }
064:
065:            /**
066:             * See section 15.4.4 of the EJB 2.0 specification
067:             * See section 15.7.3 of the EJB 2.1 specification
068:             */
069:            public void ejbCreate() {
070:            }
071:
072:            /**
073:             * @see javax.ejb.MessageDrivenBean#ejbRemove()
074:             */
075:            public void ejbRemove() {
076:            }
077:
078:            public void onMessage(Message aMessage) {
079:                try {
080:                    String messageType, uniqueID;
081:
082:                    MapMessage mapMessage = (MapMessage) aMessage;
083:                    messageType = mapMessage.getString(MESSAGE_TYPE);
084:                    uniqueID = mapMessage.getString(UNIQUE_ID);
085:
086:                    String soapStr = "";
087:                    URL cbURL = null;
088:
089:                    // Initialise to defaults.
090:                    String airlineCallbackURL = "http://localhost:18181/TravelReservationService/airlineReserved";
091:                    String vehicleCallbackURL = "http://localhost:18181/TravelReservationService/vehicleReserved";
092:                    String hotelCallbackURL = "http://localhost:18181/TravelReservationService/hotelReserved";
093:
094:                    // Lookup URL's defined in the deployment descriptor.
095:                    try {
096:                        InitialContext ic = new InitialContext();
097:                        airlineCallbackURL = (String) ic
098:                                .lookup("java:comp/env/AirlineCallbackURL");
099:                        vehicleCallbackURL = (String) ic
100:                                .lookup("java:comp/env/VehicleCallbackURL");
101:                        hotelCallbackURL = (String) ic
102:                                .lookup("java:comp/env/HotelCallbackURL");
103:                    } catch (NamingException ne) {
104:                    }
105:
106:                    if (messageType.equals(AIRLINE_RESERVATION)) {
107:                        cbURL = new URL(airlineCallbackURL);
108:                        soapStr = createSOAPString(AIRLINE_RESERVATION_SIM_FILE);
109:
110:                    } else if (messageType.equals(VEHICLE_RESERVATION)) {
111:                        cbURL = new URL(vehicleCallbackURL);
112:                        soapStr = createSOAPString(VEHICLE_RESERVATION_SIM_FILE);
113:
114:                    } else if (messageType.equals(HOTEL_RESERVATION)) {
115:                        cbURL = new URL(hotelCallbackURL);
116:                        soapStr = createSOAPString(HOTEL_RESERVATION_SIM_FILE);
117:                    } else {
118:                        return;
119:                    }
120:                    soapStr = soapStr.replaceAll("ENTER_ID_HERE", uniqueID);
121:                    sendSOAPMsg(cbURL, soapStr);
122:
123:                } catch (javax.jms.JMSException jmse) {
124:                    jmse.printStackTrace();
125:                }
126:
127:                catch (SOAPException soapE) {
128:                    soapE.printStackTrace();
129:                } catch (RemoteException re) {
130:                    re.printStackTrace();
131:                } catch (IOException ioe) {
132:                    ioe.printStackTrace();
133:                } catch (ParserConfigurationException pce) {
134:                    pce.printStackTrace();
135:                } catch (SAXException saxe) {
136:                    saxe.printStackTrace();
137:                } catch (TransformerConfigurationException tce) {
138:                    tce.printStackTrace();
139:                } catch (TransformerException te) {
140:                    te.printStackTrace();
141:                }
142:            }
143:
144:            private String createSOAPString(String simulationMsgFileName)
145:                    throws SOAPException, IOException,
146:                    ParserConfigurationException, SAXException,
147:                    TransformerConfigurationException, TransformerException {
148:
149:                BufferedInputStream source = null;
150:                StringBuffer sb = new StringBuffer();
151:
152:                try {
153:                    source = new BufferedInputStream(getClass()
154:                            .getResourceAsStream(simulationMsgFileName));
155:
156:                    LineNumberReader reader = new LineNumberReader(
157:                            new InputStreamReader(source));
158:                    String s;
159:                    while ((s = reader.readLine()) != null) {
160:                        sb.append(s);
161:                        sb.append("\n");
162:                    }
163:                    return sb.toString();
164:                } finally {
165:                    if (source != null)
166:                        source.close();
167:                }
168:            }
169:
170:            private void sendSOAPMsg(URL dest, String msg) throws IOException {
171:                HttpURLConnection urlC = null;
172:                OutputStream os = null;
173:                try {
174:
175:                    urlC = (HttpURLConnection) dest.openConnection();
176:                    urlC.setDoOutput(true);
177:
178:                    urlC.setRequestProperty("Content-Type", "text/xml");
179:                    urlC.setRequestMethod("POST");
180:                    os = urlC.getOutputStream();
181:                    os.write(msg.getBytes());
182:                    os.flush();
183:                    urlC.getResponseMessage();
184:                }
185:
186:                catch (MalformedURLException e) {
187:                    e.printStackTrace();
188:
189:                } finally {
190:                    try {
191:                        if (os != null)
192:                            os.close();
193:                    } catch (Exception e) {
194:                    }
195:                }
196:            }
197:
198:            public static final String AIRLINE_RESERVATION = "airline";
199:            public static final String VEHICLE_RESERVATION = "vehicle";
200:            public static final String HOTEL_RESERVATION = "hotel";
201:            public static final String AIRLINE_RESERVATION_SIM_FILE = "ItineraryPlusAirline.xml";
202:            public static final String VEHICLE_RESERVATION_SIM_FILE = "ItineraryPlusVehicle.xml";
203:            public static final String HOTEL_RESERVATION_SIM_FILE = "ItineraryPlusHotel.xml";
204:            public static final String MESSAGE_TYPE = "MESSAGE_TYPE";
205:            public static final String UNIQUE_ID = "UNIQUE_ID";
206:            public static final String BPEL_PROC_NS = "http://www.sun.com/javaone/05/ItineraryReservationService";
207:            public static final String OTA_NS = "http://www.opentravel.org/OTA/2003/05";
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.