Source Code Cross Referenced for SerializedMarshaler.java in  » ESB » servicemix » org » apache » servicemix » http » endpoints » 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 » servicemix » org.apache.servicemix.http.endpoints 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.servicemix.http.endpoints;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.ObjectInputStream;
022:        import java.io.ObjectOutputStream;
023:        import java.io.OutputStream;
024:        import java.io.StringWriter;
025:        import java.io.Writer;
026:
027:        import javax.jbi.component.ComponentContext;
028:        import javax.jbi.messaging.MessageExchange;
029:        import javax.jbi.messaging.NormalizedMessage;
030:        import javax.servlet.http.HttpServletRequest;
031:        import javax.servlet.http.HttpServletResponse;
032:        import javax.xml.transform.Source;
033:        import javax.xml.transform.TransformerException;
034:
035:        import com.thoughtworks.xstream.XStream;
036:        import com.thoughtworks.xstream.io.xml.DomDriver;
037:
038:        import org.apache.commons.logging.Log;
039:        import org.apache.commons.logging.LogFactory;
040:        import org.apache.servicemix.jbi.jaxp.SourceTransformer;
041:        import org.apache.servicemix.jbi.jaxp.StringSource;
042:
043:        /**
044:         * A marshaler that handles Java serialized content from the InputStream of the HttpServletRequest object and to the
045:         * OutputStream of the HttpServletResponse object. This class is intended to handle requests initiated by the Spring <a
046:         * href="http://www.springframework.org/docs/api/org/springframework/remoting/httpinvoker/package-summary.html">httpinvoker
047:         * package</a> so the marshaled/unmarshaled XML invocation will be Spring <a
048:         * href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocation.html">RemoteInvocation</a>/
049:         * <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocationResult.html">
050:         * RemoteInvocationResult</a> objects respectively.
051:         * 
052:         * <p>
053:         * This class makes no assumptions about how XML should be marshaled/unmarshaled. I.e., there is currently no way to
054:         * customize the marshaled XML invocation. So this marshaler will need to pass the XML to a component that can transform
055:         * it into some custom XML. The servicemix-saxon component can handle this very easily via XLST.
056:         * 
057:         * @author bsnyder, aco
058:         * @org.apache.xbean.XBean element="serializedMarshaler"
059:         */
060:        public class SerializedMarshaler extends DefaultHttpConsumerMarshaler {
061:
062:            private static Log log = LogFactory
063:                    .getLog(SerializedMarshaler.class);
064:
065:            public MessageExchange createExchange(HttpServletRequest request,
066:                    ComponentContext context) throws Exception {
067:                MessageExchange me = context.getDeliveryChannel()
068:                        .createExchangeFactory()
069:                        .createExchange(getDefaultMep());
070:                NormalizedMessage in = me.createMessage();
071:                in.setContent(marshal(request.getInputStream()));
072:                me.setMessage(in, "in");
073:                return me;
074:            }
075:
076:            public void sendOut(MessageExchange exchange,
077:                    NormalizedMessage outMsg, HttpServletRequest request,
078:                    HttpServletResponse response) throws Exception {
079:                if (outMsg.getContent() != null) {
080:                    unmarshal(response.getOutputStream(), outMsg.getContent());
081:                }
082:            }
083:
084:            /**
085:             * Marshal the byte content of the input stream to an XML source. This method is marshaling the contents of the
086:             * Spring <a
087:             * href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocation.html">RemoteInvocation</a>
088:             * object. Below is an example of what this method emits:
089:             * 
090:             * <pre>
091:             * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;org.springframework.remoting.support.RemoteInvocation&gt;
092:             *   &lt;methodName&gt;login&lt;/methodName&gt;
093:             *     &lt;parameterTypes&gt;
094:             *       &lt;java-class&gt;java.lang.String&lt;/java-class&gt;
095:             *       &lt;java-class&gt;java.lang.String&lt;/java-class&gt;
096:             *     &lt;/parameterTypes&gt;
097:             *     &lt;arguments&gt;
098:             *       &lt;string&gt;foo&lt;/string&gt;
099:             *       &lt;string&gt;bar&lt;/string&gt;
100:             *     &lt;/arguments&gt;
101:             *   &lt;/org.springframework.remoting.support.RemoteInvocation&gt;
102:             * </pre>
103:             * 
104:             * @param is -
105:             *            input stream to read the object from
106:             * @return xml source
107:             * @throws IOException
108:             * @throws ClassNotFoundException
109:             */
110:            private Source marshal(InputStream is) throws IOException,
111:                    ClassNotFoundException {
112:                Object obj = new ObjectInputStream(is).readObject();
113:                Writer w = new StringWriter();
114:                XStream xstream = new XStream(new DomDriver());
115:                xstream.toXML(obj, w);
116:                String request = w.toString();
117:
118:                if (log.isDebugEnabled()) {
119:                    log.debug("Remote invocation request: " + request);
120:                }
121:
122:                return new StringSource(request);
123:            }
124:
125:            /**
126:             * Unmarshal the XML content to the specified output stream. This method is unmarshaling XML into the Spring 
127:             * <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocationResult.html">
128:             * RemoteInvocationResult</a> object. Below is an example of the XML expected by this method:
129:             * 
130:             * <pre>
131:             * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
132:             * &lt;org.springframework.remoting.support.RemoteInvocationResult&gt;
133:             *   &lt;value class=&quot;com.example.foo.bar.Baz&quot;&gt;
134:             *     &lt;firstName&gt;myfirstname&lt;/firstName&gt;
135:             *     &lt;lastName&gt;mylastname&lt;/lastName&gt;
136:             *     &lt;phone&gt;12312312&lt;/phone&gt;
137:             *   &lt;/value&gt;
138:             * &lt;/org.springframework.remoting.support.RemoteInvocationResult&gt;
139:             * </pre>
140:             * 
141:             * @param os -
142:             *            output stream to unmarshal to
143:             * @param content -
144:             *            XML source
145:             * @throws TransformerException
146:             * @throws IOException
147:             */
148:            private void unmarshal(OutputStream os, Source content)
149:                    throws TransformerException, IOException {
150:                SourceTransformer transform = new SourceTransformer();
151:                XStream xstream = new XStream(new DomDriver());
152:                String result = transform.toString(content);
153:
154:                if (log.isDebugEnabled()) {
155:                    log.debug("Remote invocation result: " + result);
156:                }
157:
158:                Object obj = xstream.fromXML(result);
159:                ObjectOutputStream oos = new ObjectOutputStream(os);
160:                oos.writeObject(obj);
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.