Source Code Cross Referenced for JMSOutTransportInfo.java in  » ESB » synapse » org » apache » synapse » transport » jms » 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 » ESB » synapse » org.apache.synapse.transport.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004,2005 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.synapse.transport.jms;
017:
018:        import org.apache.axis2.transport.OutTransportInfo;
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:
022:        import javax.jms.ConnectionFactory;
023:        import javax.jms.Destination;
024:        import javax.naming.Context;
025:        import javax.naming.InitialContext;
026:        import javax.naming.NameNotFoundException;
027:        import javax.naming.NamingException;
028:        import java.util.Hashtable;
029:
030:        /**
031:         * The JMS OutTransportInfo is a holder of information to send an outgoing message
032:         * (e.g. a Response) to a JMS destination. Thus at a minimum a reference to a
033:         * ConnectionFactory and a Destination are held
034:         */
035:        public class JMSOutTransportInfo implements  OutTransportInfo {
036:
037:            private static final Log log = LogFactory
038:                    .getLog(JMSOutTransportInfo.class);
039:
040:            /**
041:             * this is a reference to the underlying JMS connection factory when sending messages
042:             * through connection factories not defined to the transport sender
043:             */
044:            private ConnectionFactory connectionFactory = null;
045:            /**
046:             * this is a reference to a JMS Connection Factory instance, which has a reference
047:             * to the underlying actual connection factory, an open connection to the JMS provider
048:             * and optionally a session already available for use
049:             */
050:            private JMSConnectionFactory jmsConnectionFactory = null;
051:            /** the Destination queue or topic for the outgoing message */
052:            private Destination destination = null;
053:            /** the Destination queue or topic for the outgoing message i.e. JMSConstants.DESTINATION_TYPE_QUEUE, DESTINATION_TYPE_TOPIC */
054:            private String destinationType = JMSConstants.DESTINATION_TYPE_QUEUE;
055:            /** the EPR properties when the out-transport info is generated from a target EPR */
056:            private Hashtable properties = null;
057:            /** the target EPR string where applicable */
058:            private String targetEPR = null;
059:            private String contentType = null;
060:
061:            /**
062:             * Creates an instance using the given connection factory and destination
063:             *
064:             * @param connectionFactory the connection factory
065:             * @param dest the destination
066:             */
067:            JMSOutTransportInfo(ConnectionFactory connectionFactory,
068:                    Destination dest) {
069:                this .connectionFactory = connectionFactory;
070:                this .destination = dest;
071:            }
072:
073:            /**
074:             * Creates an instance using the given JMS connection factory and destination
075:             *
076:             * @param jmsConnectionFactory the JMS connection factory
077:             * @param dest the destination
078:             */
079:            JMSOutTransportInfo(JMSConnectionFactory jmsConnectionFactory,
080:                    Destination dest) {
081:                this .jmsConnectionFactory = jmsConnectionFactory;
082:                this .destination = dest;
083:            }
084:
085:            /**
086:             * Creates and instance using the given URL
087:             *
088:             * @param targetEPR the target EPR
089:             */
090:            JMSOutTransportInfo(String targetEPR) {
091:                this .targetEPR = targetEPR;
092:                if (!targetEPR.startsWith(JMSConstants.JMS_PREFIX)) {
093:                    handleException("Invalid prefix for a JMS EPR : "
094:                            + targetEPR);
095:                } else {
096:                    properties = JMSUtils.getProperties(targetEPR);
097:                    String destinationType = (String) properties
098:                            .get(JMSConstants.DEST_PARAM_TYPE);
099:                    setDestinationType(destinationType);
100:                }
101:            }
102:
103:            /**
104:             * Provides a lazy load when created with a target EPR. This method performs actual
105:             * lookup for the connection factory and desination
106:             */
107:            public void loadConnectionFactoryFromProperies() {
108:                if (properties != null) {
109:                    Context context = null;
110:                    try {
111:                        context = new InitialContext(properties);
112:                    } catch (NamingException e) {
113:                        handleException(
114:                                "Could not get an initial context using "
115:                                        + properties, e);
116:                    }
117:                    connectionFactory = getConnectionFactory(context,
118:                            properties);
119:                    destination = getDestination(context, targetEPR);
120:                }
121:            }
122:
123:            /**
124:             * Get the referenced ConnectionFactory using the properties from the context
125:             *
126:             * @param context the context to use for lookup
127:             * @param props   the properties which contains the JNDI name of the factory
128:             * @return the connection factory
129:             */
130:            private ConnectionFactory getConnectionFactory(Context context,
131:                    Hashtable props) {
132:                try {
133:
134:                    String conFacJndiName = (String) props
135:                            .get(JMSConstants.CONFAC_JNDI_NAME_PARAM);
136:                    if (conFacJndiName != null) {
137:                        return (ConnectionFactory) context
138:                                .lookup(conFacJndiName);
139:                    } else {
140:                        handleException("Connection Factory JNDI name cannot be determined");
141:                    }
142:                } catch (NamingException e) {
143:                    handleException("Connection Factory JNDI name cannot be determined");
144:                }
145:                return null;
146:            }
147:
148:            /**
149:             * Get the JMS destination specified by the given URL from the context
150:             *
151:             * @param context the Context to lookup
152:             * @param url     URL
153:             * @return the JMS destination, or null if it does not exist
154:             */
155:            private Destination getDestination(Context context, String url) {
156:                String destinationName = JMSUtils.getDestination(url);
157:                try {
158:                    return (Destination) context.lookup(destinationName);
159:                } catch (NameNotFoundException e) {
160:                    if (log.isDebugEnabled()) {
161:                        log.debug("Cannot locate destination : "
162:                                + destinationName + " using " + url);
163:                    }
164:                } catch (NamingException e) {
165:                    handleException("Cannot locate destination : "
166:                            + destinationName + " using " + url, e);
167:                }
168:                return null;
169:            }
170:
171:            /**
172:             * Look up for the given destination
173:             * @param replyDest
174:             * @return
175:             */
176:            public Destination getReplyDestination(String replyDest) {
177:                try {
178:                    return (Destination) jmsConnectionFactory.getContext()
179:                            .lookup(replyDest);
180:                } catch (NameNotFoundException e) {
181:                    if (log.isDebugEnabled()) {
182:                        log.debug("Cannot locate reply destination : "
183:                                + replyDest, e);
184:                    }
185:                } catch (NamingException e) {
186:                    handleException("Cannot locate reply destination : "
187:                            + replyDest, e);
188:                }
189:                return null;
190:            }
191:
192:            private void handleException(String s) {
193:                log.error(s);
194:                throw new AxisJMSException(s);
195:            }
196:
197:            private void handleException(String s, Exception e) {
198:                log.error(s, e);
199:                throw new AxisJMSException(s, e);
200:            }
201:
202:            public Destination getDestination() {
203:                return destination;
204:            }
205:
206:            public ConnectionFactory getConnectionFactory() {
207:                return connectionFactory;
208:            }
209:
210:            public JMSConnectionFactory getJmsConnectionFactory() {
211:                return jmsConnectionFactory;
212:            }
213:
214:            public void setContentType(String contentType) {
215:                this .contentType = contentType;
216:            }
217:
218:            public Hashtable getProperties() {
219:                return properties;
220:            }
221:
222:            public String getTargetEPR() {
223:                return targetEPR;
224:            }
225:
226:            public String getDestinationType() {
227:                return destinationType;
228:            }
229:
230:            public void setDestinationType(String destinationType) {
231:                if (destinationType != null) {
232:                    this.destinationType = destinationType;
233:                }
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.