Source Code Cross Referenced for LogicalHandlerOutInterceptor.java in  » Web-Services-apache-cxf-2.0.1 » frontend » org » apache » cxf » jaxws » handler » logical » 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 apache cxf 2.0.1 » frontend » org.apache.cxf.jaxws.handler.logical 
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:         */package org.apache.cxf.jaxws.handler.logical;
019:
020:        import javax.xml.parsers.ParserConfigurationException;
021:        import javax.xml.soap.SOAPMessage;
022:        import javax.xml.stream.XMLStreamException;
023:        import javax.xml.stream.XMLStreamReader;
024:        import javax.xml.stream.XMLStreamWriter;
025:        import javax.xml.transform.Source;
026:        import javax.xml.transform.dom.DOMSource;
027:        import javax.xml.ws.Binding;
028:
029:        import org.w3c.dom.Document;
030:        import org.w3c.dom.Node;
031:
032:        import org.apache.cxf.endpoint.Endpoint;
033:        import org.apache.cxf.helpers.XMLUtils;
034:        import org.apache.cxf.interceptor.Fault;
035:        import org.apache.cxf.jaxws.handler.AbstractJAXWSHandlerInterceptor;
036:        import org.apache.cxf.jaxws.handler.HandlerChainInvoker;
037:        import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
038:        import org.apache.cxf.message.Message;
039:        import org.apache.cxf.phase.Phase;
040:        import org.apache.cxf.phase.PhaseInterceptorChain;
041:        import org.apache.cxf.staxutils.StaxUtils;
042:        import org.apache.cxf.staxutils.W3CDOMStreamWriter;
043:        import org.apache.cxf.transport.MessageObserver;
044:
045:        public class LogicalHandlerOutInterceptor<T extends Message> extends
046:                AbstractJAXWSHandlerInterceptor<T> {
047:
048:            public static final String ORIGINAL_WRITER = "original_writer";
049:            private LogicalHandlerOutEndingInterceptor<T> ending;
050:
051:            public LogicalHandlerOutInterceptor(Binding binding) {
052:                super (binding, Phase.PRE_MARSHAL);
053:                ending = new LogicalHandlerOutEndingInterceptor<T>(binding);
054:            }
055:
056:            public void handleMessage(T message) throws Fault {
057:                HandlerChainInvoker invoker = getInvoker(message);
058:                if (invoker.getLogicalHandlers().isEmpty()) {
059:                    return;
060:                }
061:
062:                try {
063:
064:                    XMLStreamWriter origWriter = message
065:                            .getContent(XMLStreamWriter.class);
066:                    Document document = XMLUtils.newDocument();
067:                    message.setContent(Node.class, document);
068:                    W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document);
069:
070:                    // Replace stax writer with DomStreamWriter
071:                    message.setContent(XMLStreamWriter.class, writer);
072:                    message.put(ORIGINAL_WRITER, origWriter);
073:
074:                    message.getInterceptorChain().add(ending);
075:                } catch (ParserConfigurationException e) {
076:                    throw new Fault(e);
077:                }
078:            }
079:
080:            private class LogicalHandlerOutEndingInterceptor<X extends Message>
081:                    extends AbstractJAXWSHandlerInterceptor<X> {
082:
083:                public LogicalHandlerOutEndingInterceptor(Binding binding) {
084:                    super (binding, Phase.POST_MARSHAL);
085:                }
086:
087:                public void handleMessage(X message) throws Fault {
088:                    W3CDOMStreamWriter domWriter = (W3CDOMStreamWriter) message
089:                            .getContent(XMLStreamWriter.class);
090:                    XMLStreamWriter origWriter = (XMLStreamWriter) message
091:                            .get(LogicalHandlerOutInterceptor.ORIGINAL_WRITER);
092:
093:                    HandlerChainInvoker invoker = getInvoker(message);
094:                    LogicalMessageContextImpl lctx = new LogicalMessageContextImpl(
095:                            message);
096:                    invoker.setLogicalMessageContext(lctx);
097:                    boolean requestor = isRequestor(message);
098:
099:                    ContextPropertiesMapping.mapCxf2Jaxws(
100:                            message.getExchange(), lctx, requestor);
101:
102:                    XMLStreamReader reader = (XMLStreamReader) message
103:                            .get("LogicalHandlerInterceptor.INREADER");
104:                    SOAPMessage origMessage = null;
105:                    if (reader != null) {
106:                        origMessage = message.getContent(SOAPMessage.class);
107:                        message.setContent(XMLStreamReader.class, reader);
108:                        message.removeContent(SOAPMessage.class);
109:                    } else if (domWriter.getDocument().getDocumentElement() != null) {
110:                        Source source = new DOMSource(domWriter.getDocument());
111:                        message.setContent(Source.class, source);
112:                        message
113:                                .setContent(XMLStreamReader.class, StaxUtils
114:                                        .createXMLStreamReader(domWriter
115:                                                .getDocument()));
116:                    }
117:
118:                    if (!invoker.invokeLogicalHandlers(requestor, lctx)) {
119:                        if (requestor) {
120:                            // client side - abort
121:                            message.getInterceptorChain().abort();
122:                            Endpoint e = message.getExchange().get(
123:                                    Endpoint.class);
124:                            Message responseMsg = e.getBinding()
125:                                    .createMessage();
126:
127:                            MessageObserver observer = (MessageObserver) message
128:                                    .getExchange().get(MessageObserver.class);
129:                            if (observer != null) {
130:                                //client side outbound, the request message becomes the response message
131:                                responseMsg
132:                                        .setContent(
133:                                                XMLStreamReader.class,
134:                                                message
135:                                                        .getContent(XMLStreamReader.class));
136:
137:                                message.getExchange().setInMessage(responseMsg);
138:                                responseMsg
139:                                        .put(
140:                                                PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
141:                                                LogicalHandlerInInterceptor.class
142:                                                        .getName());
143:                                observer.onMessage(responseMsg);
144:                            }
145:                        } else {
146:                            // server side - abort
147:                            //System.out.println("Logical handler server side aborting");
148:                        }
149:                        return;
150:                    }
151:                    if (origMessage != null) {
152:                        message.setContent(SOAPMessage.class, origMessage);
153:                    }
154:
155:                    try {
156:                        reader = message.getContent(XMLStreamReader.class);
157:                        message.removeContent(XMLStreamReader.class);
158:                        if (reader != null) {
159:                            StaxUtils.copy(reader, origWriter);
160:                        } else if (domWriter.getDocument().getDocumentElement() != null) {
161:                            StaxUtils.copy(domWriter.getDocument(), origWriter);
162:                        }
163:                        message.setContent(XMLStreamWriter.class, origWriter);
164:                    } catch (XMLStreamException e) {
165:                        throw new Fault(e);
166:                    }
167:                }
168:
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.