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


001:        /*
002:         * $Id: JmsReplyToHandler.java 11373 2008-03-15 05:03:10Z dfeist $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:
011:        package org.mule.transport.jms;
012:
013:        import org.mule.api.MuleEvent;
014:        import org.mule.api.MuleException;
015:        import org.mule.api.MuleMessage;
016:        import org.mule.api.transformer.Transformer;
017:        import org.mule.api.transport.DispatchException;
018:        import org.mule.transport.DefaultReplyToHandler;
019:        import org.mule.transport.jms.i18n.JmsMessages;
020:        import org.mule.util.StringMessageUtils;
021:
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import javax.jms.DeliveryMode;
026:        import javax.jms.Destination;
027:        import javax.jms.Message;
028:        import javax.jms.MessageProducer;
029:        import javax.jms.Queue;
030:        import javax.jms.Session;
031:        import javax.jms.Topic;
032:
033:        /**
034:         * <code>JmsReplyToHandler</code> will process a JMS replyTo or hand off to the
035:         * default replyTo handler if the replyTo is a URL
036:         */
037:        public class JmsReplyToHandler extends DefaultReplyToHandler {
038:            private final JmsConnector connector;
039:
040:            public JmsReplyToHandler(JmsConnector connector, List transformers) {
041:                super (transformers);
042:                this .connector = connector;
043:            }
044:
045:            public void processReplyTo(MuleEvent event,
046:                    MuleMessage returnMessage, Object replyTo)
047:                    throws MuleException {
048:                Destination replyToDestination = null;
049:                MessageProducer replyToProducer = null;
050:                Session session = null;
051:                try {
052:                    // now we need to send the response
053:                    if (replyTo instanceof  Destination) {
054:                        replyToDestination = (Destination) replyTo;
055:                    }
056:                    if (replyToDestination == null) {
057:                        super .processReplyTo(event, returnMessage, replyTo);
058:                        return;
059:                    }
060:
061:                    //This is a work around for JmsTransformers where the current endpoint needs
062:                    //to be set on the transformer so that a JMSMEssage can be created correctly
063:                    Class srcType = returnMessage.getPayload().getClass();
064:                    for (Iterator iterator = getTransformers().iterator(); iterator
065:                            .hasNext();) {
066:                        Transformer t = (Transformer) iterator.next();
067:                        if (t.isSourceTypeSupported(srcType)) {
068:                            if (t.getEndpoint() == null) {
069:                                t.setEndpoint(getEndpoint(event,
070:                                        "jms://temporary"));
071:                                break;
072:                            }
073:                        }
074:                    }
075:                    returnMessage.applyTransformers(getTransformers());
076:                    Object payload = returnMessage.getPayload();
077:
078:                    if (replyToDestination instanceof  Topic
079:                            && replyToDestination instanceof  Queue
080:                            && connector.getJmsSupport() instanceof  Jms102bSupport) {
081:                        logger
082:                                .error(StringMessageUtils
083:                                        .getBoilerPlate("ReplyTo destination implements both Queue and Topic "
084:                                                + "while complying with JMS 1.0.2b specification. "
085:                                                + "Please report your application server or JMS vendor name and version "
086:                                                + "to dev<_at_>mule.codehaus.org or http://mule.mulesource.org/jira"));
087:                    }
088:
089:                    final boolean topic = connector.getTopicResolver().isTopic(
090:                            replyToDestination);
091:                    session = connector.getSession(false, topic);
092:                    Message replyToMessage = JmsMessageUtils.toMessage(payload,
093:                            session);
094:
095:                    replyToMessage.setJMSReplyTo(null);
096:                    if (logger.isDebugEnabled()) {
097:                        logger
098:                                .debug("Sending jms reply to: "
099:                                        + replyToDestination
100:                                        + "("
101:                                        + replyToDestination.getClass()
102:                                                .getName() + ")");
103:                    }
104:                    replyToProducer = connector.getJmsSupport().createProducer(
105:                            session, replyToDestination, topic);
106:
107:                    // QoS support
108:                    MuleMessage eventMsg = event.getMessage();
109:                    String ttlString = (String) eventMsg
110:                            .removeProperty(JmsConstants.TIME_TO_LIVE_PROPERTY);
111:                    String priorityString = (String) eventMsg
112:                            .removeProperty(JmsConstants.PRIORITY_PROPERTY);
113:                    String persistentDeliveryString = (String) eventMsg
114:                            .removeProperty(JmsConstants.PERSISTENT_DELIVERY_PROPERTY);
115:
116:                    if (ttlString == null && priorityString == null
117:                            && persistentDeliveryString == null) {
118:                        connector.getJmsSupport().send(replyToProducer,
119:                                replyToMessage, topic);
120:                    } else {
121:                        long ttl = Message.DEFAULT_TIME_TO_LIVE;
122:                        int priority = Message.DEFAULT_PRIORITY;
123:
124:                        // TODO this first assignment is ignored anyway, review and remove if need to
125:                        boolean persistent = Message.DEFAULT_DELIVERY_MODE == DeliveryMode.PERSISTENT;
126:
127:                        if (ttlString != null) {
128:                            ttl = Long.parseLong(ttlString);
129:                        }
130:                        if (priorityString != null) {
131:                            priority = Integer.parseInt(priorityString);
132:                        }
133:                        // TODO StringUtils.notBlank() would be more robust here
134:                        persistent = persistentDeliveryString != null ? Boolean
135:                                .valueOf(persistentDeliveryString)
136:                                .booleanValue() : connector
137:                                .isPersistentDelivery();
138:
139:                        connector.getJmsSupport().send(replyToProducer,
140:                                replyToMessage, persistent, priority, ttl,
141:                                topic);
142:                    }
143:
144:                    // connector.getJmsSupport().send(replyToProducer, replyToMessage,
145:                    // replyToDestination);
146:                    logger.info("Reply Message sent to: " + replyToDestination);
147:                    event.getService().getComponent().getStatistics()
148:                            .incSentReplyToEvent();
149:                } catch (Exception e) {
150:                    throw new DispatchException(
151:                            JmsMessages
152:                                    .failedToCreateAndDispatchResponse(replyToDestination),
153:                            returnMessage, null, e);
154:                } finally {
155:                    connector.closeQuietly(replyToProducer);
156:                    connector.closeQuietly(session);
157:                }
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.