Source Code Cross Referenced for DefaultHttpProviderMarshaler.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.ByteArrayOutputStream;
020:        import java.io.Reader;
021:        import java.net.URI;
022:        import java.util.Map;
023:
024:        import javax.jbi.messaging.ExchangeStatus;
025:        import javax.jbi.messaging.Fault;
026:        import javax.jbi.messaging.InOnly;
027:        import javax.jbi.messaging.InOptionalOut;
028:        import javax.jbi.messaging.InOut;
029:        import javax.jbi.messaging.MessageExchange;
030:        import javax.jbi.messaging.NormalizedMessage;
031:        import javax.xml.transform.stream.StreamResult;
032:        import javax.xml.transform.stream.StreamSource;
033:
034:        import org.apache.commons.httpclient.HttpStatus;
035:        import org.apache.servicemix.expression.Expression;
036:        import org.apache.servicemix.http.jetty.SmxHttpExchange;
037:        import org.apache.servicemix.jbi.jaxp.SourceTransformer;
038:        import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
039:        import org.mortbay.io.ByteArrayBuffer;
040:        import org.mortbay.jetty.HttpHeaders;
041:        import org.mortbay.jetty.HttpMethods;
042:
043:        /**
044:         * Default marshaler used for non-soap provider endpoints.
045:         *
046:         * @author gnodet
047:         * @since 3.2
048:         */
049:        public class DefaultHttpProviderMarshaler implements 
050:                HttpProviderMarshaler {
051:
052:            private SourceTransformer transformer = new StAXSourceTransformer();
053:            private String locationURI;
054:            private Expression locationURIExpression;
055:            private String method;
056:            private Expression methodExpression;
057:            private String contentType = "text/xml";
058:            private Expression contentTypeExpression;
059:            private Map<String, String> headers;
060:
061:            public String getLocationURI() {
062:                return locationURI;
063:            }
064:
065:            public void setLocationURI(String locationUri) {
066:                this .locationURI = locationUri;
067:            }
068:
069:            public Expression getLocationURIExpression() {
070:                return locationURIExpression;
071:            }
072:
073:            public void setLocationURIExpression(
074:                    Expression locationUriExpression) {
075:                this .locationURIExpression = locationUriExpression;
076:            }
077:
078:            public String getMethod() {
079:                return method;
080:            }
081:
082:            public void setMethod(String method) {
083:                this .method = method;
084:            }
085:
086:            public Expression getMethodExpression() {
087:                return methodExpression;
088:            }
089:
090:            public void setMethodExpression(Expression methodExpression) {
091:                this .methodExpression = methodExpression;
092:            }
093:
094:            public String getContentType() {
095:                return contentType;
096:            }
097:
098:            public void setContentType(String contentType) {
099:                this .contentType = contentType;
100:            }
101:
102:            public Expression getContentTypeExpression() {
103:                return contentTypeExpression;
104:            }
105:
106:            public void setContentTypeExpression(
107:                    Expression contentTypeExpression) {
108:                this .contentTypeExpression = contentTypeExpression;
109:            }
110:
111:            public Map<String, String> getHeaders() {
112:                return headers;
113:            }
114:
115:            public void setHeaders(Map<String, String> headers) {
116:                this .headers = headers;
117:            }
118:
119:            protected String getLocationUri(MessageExchange exchange,
120:                    NormalizedMessage inMsg) throws Exception {
121:                String uri = null;
122:                if (locationURIExpression != null) {
123:                    Object o = locationURIExpression.evaluate(exchange, inMsg);
124:                    uri = (o != null) ? o.toString() : null;
125:                }
126:                if (uri == null) {
127:                    uri = locationURI;
128:                }
129:                if (uri == null) {
130:                    throw new IllegalStateException(
131:                            "Unable to find URI for exchange");
132:                }
133:                return uri;
134:            }
135:
136:            protected String getMethod(MessageExchange exchange,
137:                    NormalizedMessage inMsg) throws Exception {
138:                String mth = null;
139:                if (methodExpression != null) {
140:                    Object o = methodExpression.evaluate(exchange, inMsg);
141:                    mth = (o != null) ? o.toString() : null;
142:                }
143:                if (mth == null) {
144:                    mth = method;
145:                }
146:                if (mth == null) {
147:                    if (inMsg.getContent() == null) {
148:                        mth = HttpMethods.GET;
149:                    } else {
150:                        mth = HttpMethods.POST;
151:                    }
152:                }
153:                return mth;
154:            }
155:
156:            protected String getContentType(MessageExchange exchange,
157:                    NormalizedMessage inMsg) throws Exception {
158:                String content = null;
159:                if (contentTypeExpression != null) {
160:                    Object o = contentTypeExpression.evaluate(exchange, inMsg);
161:                    content = (o != null) ? o.toString() : null;
162:                }
163:                if (content == null) {
164:                    content = contentType;
165:                }
166:                if (content == null) {
167:                    throw new IllegalStateException(
168:                            "ContentType must not be null");
169:                }
170:                return content;
171:            }
172:
173:            public void createRequest(final MessageExchange exchange,
174:                    final NormalizedMessage inMsg,
175:                    final SmxHttpExchange httpExchange) throws Exception {
176:                httpExchange.setURL(getLocationUri(exchange, inMsg));
177:
178:                // Temporary fix for bug in jetty-client 6.1.5
179:                // http://fisheye.codehaus.org/browse/jetty-contrib/jetty/trunk/contrib/client/src/main/java/org/mortbay/jetty/client/HttpConnection.java?r1=374&r2=378
180:                httpExchange.addRequestHeader(HttpHeaders.HOST_BUFFER,
181:                        new ByteArrayBuffer(new URI(getLocationUri(exchange,
182:                                inMsg)).getHost()));
183:
184:                httpExchange.setMethod(getMethod(exchange, inMsg));
185:                httpExchange.setRequestHeader(HttpHeaders.CONTENT_TYPE,
186:                        getContentType(exchange, inMsg));
187:                if (getHeaders() != null) {
188:                    for (Map.Entry<String, String> e : getHeaders().entrySet()) {
189:                        httpExchange.setRequestHeader(e.getKey(), e.getValue());
190:                    }
191:                }
192:                if (inMsg.getContent() != null) {
193:                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
194:                    transformer.toResult(inMsg.getContent(), new StreamResult(
195:                            baos));
196:                    httpExchange.setRequestContent(new ByteArrayBuffer(baos
197:                            .toByteArray()));
198:                }
199:            }
200:
201:            public void handleResponse(MessageExchange exchange,
202:                    SmxHttpExchange httpExchange) throws Exception {
203:                int response = httpExchange.getResponseStatus();
204:                if (response != HttpStatus.SC_OK
205:                        && response != HttpStatus.SC_ACCEPTED) {
206:                    if (!(exchange instanceof  InOnly)) {
207:                        Fault fault = exchange.createFault();
208:                        fault.setContent(new StreamSource(httpExchange
209:                                .getResponseReader()));
210:                        exchange.setFault(fault);
211:                    } else {
212:                        throw new Exception("Invalid status response: "
213:                                + response);
214:                    }
215:                } else if (exchange instanceof  InOut) {
216:                    NormalizedMessage msg = exchange.createMessage();
217:                    msg.setContent(new StreamSource(httpExchange
218:                            .getResponseReader()));
219:                    exchange.setMessage(msg, "out");
220:                } else if (exchange instanceof  InOptionalOut) {
221:                    Reader r = httpExchange.getResponseReader();
222:                    if (r != null) {
223:                        NormalizedMessage msg = exchange.createMessage();
224:                        msg.setContent(new StreamSource(r));
225:                        exchange.setMessage(msg, "out");
226:                    } else {
227:                        exchange.setStatus(ExchangeStatus.DONE);
228:                    }
229:                } else {
230:                    exchange.setStatus(ExchangeStatus.DONE);
231:
232:                }
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.