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


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.transport.jms;
020:
021:        import org.apache.axis2.transport.OutTransportInfo;
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:
025:        import javax.jms.ConnectionFactory;
026:        import javax.jms.Destination;
027:        import javax.naming.Context;
028:        import javax.naming.InitialContext;
029:        import javax.naming.NameNotFoundException;
030:        import javax.naming.NamingException;
031:        import java.util.Hashtable;
032:
033:        /**
034:         * The JMS OutTransportInfo
035:         */
036:        public class JMSOutTransportInfo implements  OutTransportInfo {
037:
038:            private static final Log log = LogFactory
039:                    .getLog(JMSOutTransportInfo.class);
040:
041:            private ConnectionFactory connectionFactory = null;
042:            private String connectionFactoryUser = null;
043:            private String connectionFactoryPassword = null;
044:            private Destination destination = null;
045:
046:            private String contentType = null;
047:
048:            /**
049:             * Creates an instance using the given connection factory and destination
050:             *
051:             * @param connectionFactory the connection factory
052:             * @param dest              the destination
053:             */
054:            JMSOutTransportInfo(ConnectionFactory connectionFactory,
055:                    Destination dest) {
056:                this .connectionFactory = connectionFactory;
057:                this .destination = dest;
058:            }
059:
060:            /**
061:             * Creates an instance using the given connection factory and destination
062:             *
063:             * @param connectionFactory the connection factory
064:             * @param dest              the destination
065:             */
066:            JMSOutTransportInfo(ConnectionFactory connectionFactory,
067:                    String connectionFactoryUser,
068:                    String connectionFactoryPassword, Destination dest) {
069:                this .connectionFactory = connectionFactory;
070:                this .connectionFactoryUser = connectionFactoryUser;
071:                this .connectionFactoryPassword = connectionFactoryPassword;
072:                this .destination = dest;
073:            }
074:
075:            /**
076:             * Creates and instance using the given URL
077:             *
078:             * @param url the URL
079:             */
080:            JMSOutTransportInfo(String url) {
081:                if (!url.startsWith(JMSConstants.JMS_PREFIX)) {
082:                    handleException("Invalid JMS URL : " + url
083:                            + " Must begin with the prefix "
084:                            + JMSConstants.JMS_PREFIX);
085:                } else {
086:                    Context context = null;
087:                    Hashtable props = JMSUtils.getProperties(url);
088:                    try {
089:                        context = new InitialContext(props);
090:                    } catch (NamingException e) {
091:                        handleException("Could not get the initial context", e);
092:                    }
093:
094:                    connectionFactory = getConnectionFactory(context, props);
095:                    connectionFactoryUser = getConnectionFactoryUser(context,
096:                            props);
097:                    connectionFactoryPassword = getConnectionFactoryPass(
098:                            context, props);
099:                    destination = getDestination(context, url);
100:                }
101:            }
102:
103:            /**
104:             * Get the referenced ConnectionFactory using the properties from the context
105:             *
106:             * @param context the context to use for lookup
107:             * @param props   the properties which contains the JNDI name of the factory
108:             * @return the connection factory
109:             */
110:            private ConnectionFactory getConnectionFactory(Context context,
111:                    Hashtable props) {
112:                try {
113:
114:                    String conFacJndiName = (String) props
115:                            .get(JMSConstants.CONFAC_JNDI_NAME_PARAM);
116:                    if (conFacJndiName != null) {
117:                        return (ConnectionFactory) context
118:                                .lookup(conFacJndiName);
119:                    } else {
120:                        throw new NamingException(
121:                                "JMS Connection Factory JNDI name cannot be determined from url");
122:                    }
123:                } catch (NamingException e) {
124:                    handleException(
125:                            "Cannot get JMS Connection factory with props : "
126:                                    + props, e);
127:                }
128:                return null;
129:            }
130:
131:            /**
132:             * Get the referenced ConnectionFactory Username (if supplied) using the properties from the context
133:             *
134:             * @param context the context to use for lookup
135:             * @param props   the properties which contains the JNDI name of the factory username
136:             * @return the connection factory username (or null if one is not in the JNDI tree)
137:             */
138:            private String getConnectionFactoryUser(Context context,
139:                    Hashtable props) {
140:                try {
141:
142:                    String conFacJndiUser = (String) props
143:                            .get(JMSConstants.CONFAC_JNDI_NAME_USER);
144:                    if (conFacJndiUser != null) {
145:                        return (String) context.lookup(conFacJndiUser);
146:                    } else {
147:                        return null;
148:                    }
149:                } catch (NamingException e) {
150:                    handleException(
151:                            "Cannot get JMS Connection factory username with props : "
152:                                    + props, e);
153:                }
154:                return null;
155:            }
156:
157:            /**
158:             * Get the referenced ConnectionFactory Password (if supplied) using the properties from the context
159:             *
160:             * @param context the context to use for lookup
161:             * @param props   the properties which contains the JNDI name of the factory password
162:             * @return the connection factory password (or null if one is not in the JNDI tree)
163:             */
164:            private String getConnectionFactoryPass(Context context,
165:                    Hashtable props) {
166:                try {
167:
168:                    String conFacJndiPass = (String) props
169:                            .get(JMSConstants.CONFAC_JNDI_NAME_PASS);
170:                    if (conFacJndiPass != null) {
171:                        return (String) context.lookup(conFacJndiPass);
172:                    } else {
173:                        return null;
174:                    }
175:                } catch (NamingException e) {
176:                    handleException(
177:                            "Cannot get JMS Connection factory password with props : "
178:                                    + props, e);
179:                }
180:                return null;
181:            }
182:
183:            /**
184:             * Get the JMS destination specified by the given URL from the context
185:             *
186:             * @param context the Context to lookup
187:             * @param url     URL
188:             * @return the JMS destination, or null if it does not exist
189:             */
190:            private Destination getDestination(Context context, String url) {
191:                String destinationName = JMSUtils.getDestination(url);
192:                try {
193:                    return (Destination) context.lookup(destinationName);
194:
195:                } catch (NameNotFoundException e) {
196:                    log.warn("Cannot get or lookup JMS destination : "
197:                            + destinationName + " from url : " + url + " : "
198:                            + e.getMessage());
199:
200:                } catch (NamingException e) {
201:                    handleException("Cannot get JMS destination : "
202:                            + destinationName + " from url : " + url, e);
203:                }
204:                return null;
205:            }
206:
207:            private void handleException(String s) {
208:                log.error(s);
209:                throw new AxisJMSException(s);
210:            }
211:
212:            private void handleException(String s, Exception e) {
213:                log.error(s, e);
214:                throw new AxisJMSException(s, e);
215:            }
216:
217:            public Destination getDestination() {
218:                return destination;
219:            }
220:
221:            public ConnectionFactory getConnectionFactory() {
222:                return connectionFactory;
223:            }
224:
225:            public String getConnectionFactoryPassword() {
226:                return connectionFactoryPassword;
227:            }
228:
229:            public String getConnectionFactoryUser() {
230:                return connectionFactoryUser;
231:            }
232:
233:            public void setContentType(String contentType) {
234:                this.contentType = contentType;
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.