Source Code Cross Referenced for SendMessageMarshaller.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » http » marshallers » 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 » cbesb 1.2 » com.bostechcorp.cbesb.runtime.component.http.marshallers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         * 		Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2007 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id: SendMessageMarshaller.java 11875 2008-02-04 14:20:31Z mpreston $
023:         */
024:        package com.bostechcorp.cbesb.runtime.component.http.marshallers;
025:
026:        import java.io.UnsupportedEncodingException;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.Set;
030:
031:        import javax.activation.DataHandler;
032:        import javax.jbi.messaging.MessageExchange;
033:        import javax.jbi.messaging.MessagingException;
034:        import javax.jbi.messaging.NormalizedMessage;
035:        import javax.xml.transform.Source;
036:        import javax.xml.transform.dom.DOMSource;
037:
038:        import org.apache.axiom.om.OMElement;
039:        import org.apache.axiom.om.OMNamespace;
040:        import org.apache.axiom.om.OMNode;
041:        import org.apache.axiom.soap.SOAPBody;
042:        import org.apache.axiom.soap.SOAPEnvelope;
043:        import org.apache.axiom.soap.SOAPFactory;
044:        import org.apache.axis2.context.MessageContext;
045:        import org.apache.commons.codec.binary.Base64;
046:        import org.w3c.dom.Element;
047:
048:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.ServiceDescriptionHandler;
049:        import com.bostechcorp.cbesb.runtime.ccsl.lib.ISoapConsumerMarshaller;
050:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.ByteArraySource;
051:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
052:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.StringSource;
053:        import com.bostechcorp.cbesb.runtime.component.http.marshallers.axiom.AxiomBuilderFactory;
054:        import com.bostechcorp.cbesb.runtime.component.http.marshallers.axiom.DOMBuilderFactory;
055:        import com.bostechcorp.cbesb.runtime.component.http.marshallers.axiom.IAxiomBuilder;
056:        import com.bostechcorp.cbesb.runtime.component.http.marshallers.axiom.IDOMBuilder;
057:
058:        public class SendMessageMarshaller extends StandardSoapMarshaller
059:                implements  ISoapConsumerMarshaller {
060:
061:            private static final String SENDMESSAGE_NAMESPACE_URL = "http://cbesb.bostechcorp.com/soap/sendmessage/1.0";
062:
063:            /**
064:             * 
065:             */
066:            public SendMessageMarshaller() {
067:
068:            }
069:
070:            /* (non-Javadoc)
071:             * @see com.bostechcorp.cbesb.runtime.component.http.marshallers.AbstractSoapMarshaller#SoapToNormalizedMessage(org.apache.axis2.context.MessageContext, javax.jbi.messaging.NormalizedMessage, javax.jbi.messaging.MessageExchange, com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.ServiceDescriptionHandler)
072:             */
073:            public void SoapToNormalizedMessage(MessageContext soapMsgContext,
074:                    NormalizedMessage message, MessageExchange msgExchange,
075:                    ServiceDescriptionHandler svcDescHandler, boolean useMTOM,
076:                    boolean useSwA) throws MessagingException {
077:                logger.debug("Converting SendMessage request to DataEnvelope");
078:
079:                String messageType = null;
080:                NormalizedMessageHandler nmh = new NormalizedMessageHandler(
081:                        message, svcDescHandler);
082:
083:                SOAPBody soapBody = soapMsgContext.getEnvelope().getBody();
084:                if (soapBody == null) {
085:                    throw new MessagingException(
086:                            "SoapEnvelope does not contain Body.");
087:                }
088:                OMElement root = soapBody.getFirstElement();
089:
090:                if (root != null
091:                        && SENDMESSAGE_NAMESPACE_URL.equals(root.getNamespace()
092:                                .getNamespaceURI())
093:                        && "sendMessage".equals(root.getLocalName())) {
094:                    for (Iterator children = root.getChildElements(); children
095:                            .hasNext();) {
096:                        OMElement child = (OMElement) children.next();
097:                        if ("messageType".equals(child.getLocalName())) {
098:                            messageType = child.getText();
099:
100:                        } else if ("message".equals(child.getLocalName())) {
101:                            if (messageType == null) {
102:                                //Missing messageType
103:                                throw new MessagingException(
104:                                        "Missing required 'messageType' element");
105:                            }
106:                            if (messageType.equalsIgnoreCase("STRING")) {
107:                                StringSource source = new StringSource(child
108:                                        .getText());
109:                                nmh.addRecord(source);
110:
111:                            } else if (messageType.equalsIgnoreCase("BASE64")) {
112:                                try {
113:                                    byte[] binaryBytes = Base64
114:                                            .decodeBase64(child.getText()
115:                                                    .getBytes("utf-8"));
116:                                    ByteArraySource bas = new ByteArraySource(
117:                                            binaryBytes);
118:                                    nmh.addRecord(bas);
119:                                } catch (UnsupportedEncodingException e) {
120:                                    //Will never happen. we always specify utf-8
121:                                }
122:
123:                            } else if (messageType.equalsIgnoreCase("XML")) {
124:                                try {
125:                                    OMElement payload = child.getFirstElement();
126:
127:                                    IDOMBuilder domBuilder = DOMBuilderFactory
128:                                            .newDOMBuilder(useMTOM);
129:
130:                                    Element payloadRoot = domBuilder
131:                                            .getElement(
132:                                                    payload,
133:                                                    getAttachments(soapMsgContext),
134:                                                    useMTOM, useSwA);
135:
136:                                    nmh.addRecord(new DOMSource(payloadRoot));
137:
138:                                    if (useMTOM || useSwA) {
139:                                        HashMap<String, DataHandler> attachments = domBuilder
140:                                                .getOutputAttachments();
141:                                        Set set = attachments.keySet();
142:                                        for (Object object : set) {
143:                                            String id = (String) object;
144:                                            DataHandler dh = attachments
145:                                                    .get(id);
146:                                            message.addAttachment(id, dh);
147:                                        }
148:                                    }
149:
150:                                } catch (Exception e) {
151:                                    throw new MessagingException(e);
152:                                }
153:
154:                            } else {
155:                                //Unsupported MessageType
156:                                throw new MessagingException(
157:                                        "Unrecognized value in 'messageType': "
158:                                                + messageType);
159:                            }
160:
161:                        } else if ("properties".equals(child.getLocalName())) {
162:                            for (Iterator properties = child.getChildElements(); properties
163:                                    .hasNext();) {
164:                                OMElement property = (OMElement) properties
165:                                        .next();
166:                                if ("property".equals(property.getLocalName())) {
167:                                    String name = null;
168:                                    String value = null;
169:                                    OMElement nameElement = property
170:                                            .getFirstElement();
171:                                    if (nameElement != null
172:                                            && "name".equals(nameElement
173:                                                    .getLocalName())) {
174:                                        name = nameElement.getText();
175:                                        OMNode sibling = nameElement
176:                                                .getNextOMSibling();
177:                                        if (sibling instanceof  OMElement) {
178:                                            OMElement valueElement = (OMElement) sibling;
179:                                            value = valueElement.getText();
180:                                        }
181:                                    }
182:                                    if (name != null && !name.equals("")) {
183:                                        msgExchange.setProperty(name, value);
184:                                    }
185:                                }
186:                            }
187:                        }
188:                    }
189:
190:                    nmh.generateMessageContent();
191:
192:                } else {
193:                    throw new MessagingException("SoapBody does not contain {"
194:                            + SENDMESSAGE_NAMESPACE_URL
195:                            + "}sendMessage element");
196:                }
197:            }
198:
199:            /* (non-Javadoc)
200:             * @see com.bostechcorp.cbesb.runtime.component.http.marshallers.AbstractSoapMarshaller#NormalizedMessageToSoap(javax.jbi.messaging.NormalizedMessage, org.apache.axis2.context.MessageContext, javax.jbi.messaging.MessageExchange, org.apache.axiom.soap.SOAPFactory)
201:             */
202:            public void NormalizedMessageToSoap(NormalizedMessage message,
203:                    MessageContext soapMsgContext, MessageExchange msgExchange,
204:                    SOAPFactory soapFactory, boolean useMTOM, boolean useSwA)
205:                    throws MessagingException {
206:                logger
207:                        .debug("Converting DataEnvelope into SendMessageResponse");
208:                try {
209:                    NormalizedMessageHandler nmh = new NormalizedMessageHandler(
210:                            message);
211:                    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
212:                    soapMsgContext.setEnvelope(envelope);
213:                    SOAPBody body = soapFactory.createSOAPBody(envelope);
214:                    OMNamespace sendMessageNS = soapFactory.createOMNamespace(
215:                            SENDMESSAGE_NAMESPACE_URL, "sm");
216:                    OMElement sendMessageResponse = soapFactory
217:                            .createOMElement("sendMessageResponse",
218:                                    sendMessageNS);
219:                    body.addChild(sendMessageResponse);
220:                    if (nmh.getRecordCount() > 0) {
221:                        Source record = nmh.getRecordAtIndex(0);
222:                        if (record instanceof  StringSource) {
223:                            OMElement messageType = soapFactory
224:                                    .createOMElement("messageType",
225:                                            sendMessageNS);
226:                            messageType.setText("STRING");
227:                            sendMessageResponse.addChild(messageType);
228:                            OMElement messageElem = soapFactory
229:                                    .createOMElement("message", sendMessageNS);
230:                            messageElem.setText(((StringSource) record)
231:                                    .getText());
232:                            sendMessageResponse.addChild(messageElem);
233:
234:                        } else if (record instanceof  ByteArraySource) {
235:                            OMElement messageType = soapFactory
236:                                    .createOMElement("messageType",
237:                                            sendMessageNS);
238:                            messageType.setText("BASE64");
239:                            sendMessageResponse.addChild(messageType);
240:                            OMElement messageElem = soapFactory
241:                                    .createOMElement("message", sendMessageNS);
242:                            byte[] rawBytes = ((ByteArraySource) record)
243:                                    .getBytes();
244:                            byte[] encodedBytes = Base64.encodeBase64(rawBytes);
245:                            String encodedString = new String(encodedBytes,
246:                                    "utf-8");
247:                            messageElem.setText(encodedString);
248:                            sendMessageResponse.addChild(messageElem);
249:
250:                        } else {
251:                            OMElement messageType = soapFactory
252:                                    .createOMElement("messageType",
253:                                            sendMessageNS);
254:                            messageType.setText("XML");
255:                            sendMessageResponse.addChild(messageType);
256:                            OMElement messageElem = soapFactory
257:                                    .createOMElement("message", sendMessageNS);
258:
259:                            IAxiomBuilder axiomBuilder = AxiomBuilderFactory
260:                                    .newAxiomBuilder(record);
261:
262:                            OMElement payload = axiomBuilder.getOMTree(record,
263:                                    getAttachments(message), useMTOM, useSwA);
264:
265:                            messageElem.addChild(payload);
266:                            sendMessageResponse.addChild(messageElem);
267:
268:                            if (useSwA) {
269:                                HashMap<String, DataHandler> attachments = axiomBuilder
270:                                        .getOutputAttachments();
271:                                Set set = attachments.keySet();
272:                                for (Object object : set) {
273:                                    String id = (String) object;
274:                                    DataHandler dh = attachments.get(id);
275:                                    soapMsgContext.addAttachment(id, dh);
276:                                }
277:                            }
278:
279:                        }
280:                    } else {
281:                        //SendMessage requires 1 record
282:                        throw new MessagingException(
283:                                "No records found in DataEnvelope");
284:                    }
285:
286:                    // now add the properties
287:                    Set<String> properties = message.getPropertyNames();
288:                    if (properties.size() > 0) {
289:                        OMElement propertiesElem = soapFactory.createOMElement(
290:                                "properties", sendMessageNS);
291:                        sendMessageResponse.addChild(propertiesElem);
292:                        for (String propertyName : properties) {
293:                            Object value = message.getProperty(propertyName);
294:                            OMElement property = soapFactory.createOMElement(
295:                                    "property", sendMessageNS);
296:                            OMElement name = soapFactory.createOMElement(
297:                                    "name", sendMessageNS);
298:                            name.setText(propertyName);
299:                            property.addChild(name);
300:                            OMElement valueElem = soapFactory.createOMElement(
301:                                    "value", sendMessageNS);
302:                            valueElem.setText(value.toString());
303:                            property.addChild(valueElem);
304:                            propertiesElem.addChild(property);
305:                        }
306:                    }
307:
308:                } catch (Exception e) {
309:                    throw new MessagingException(
310:                            "Exception converting NormalizedMesage into SOAP Envelope",
311:                            e);
312:                }
313:            }
314:
315:        }
w__ww__.__ja___v__a__2___s___._c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.