Source Code Cross Referenced for MustUnderstandInterceptorTest.java in  » Web-Services-apache-cxf-2.0.1 » bindings » org » apache » cxf » binding » soap » 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 » bindings » org.apache.cxf.binding.soap 
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.binding.soap;
019:
020:        import java.net.URI;
021:        import java.util.HashSet;
022:        import java.util.Set;
023:
024:        import javax.activation.DataHandler;
025:        import javax.mail.util.ByteArrayDataSource;
026:        import javax.xml.namespace.QName;
027:        import javax.xml.stream.XMLInputFactory;
028:        import javax.xml.stream.XMLStreamReader;
029:
030:        import org.apache.cxf.Bus;
031:        import org.apache.cxf.BusFactory;
032:        import org.apache.cxf.attachment.AttachmentImpl;
033:        import org.apache.cxf.attachment.AttachmentUtil;
034:        import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
035:        import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
036:        import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
037:        import org.apache.cxf.message.Attachment;
038:        import org.apache.cxf.service.model.BindingInfo;
039:        import org.apache.cxf.service.model.BindingOperationInfo;
040:        import org.apache.cxf.service.model.ServiceInfo;
041:        import org.junit.Before;
042:        import org.junit.Test;
043:
044:        public class MustUnderstandInterceptorTest extends TestBase {
045:
046:            private static final QName RESERVATION = new QName(
047:                    "http://travelcompany.example.org/reservation",
048:                    "reservation");
049:            private static final QName PASSENGER = new QName(
050:                    "http://mycompany.example.com/employees", "passenger");
051:
052:            private MustUnderstandInterceptor mui;
053:            private DummySoapInterceptor dsi;
054:            private ReadHeadersInterceptor rhi;
055:
056:            @Before
057:            public void setUp() throws Exception {
058:
059:                super .setUp();
060:
061:                Bus bus = BusFactory.getDefaultBus();
062:
063:                rhi = new ReadHeadersInterceptor(bus, "phase1");
064:                chain.add(rhi);
065:
066:                mui = new MustUnderstandInterceptor("phase2");
067:                chain.add(mui);
068:
069:                dsi = new DummySoapInterceptor("phase3");
070:                chain.add(dsi);
071:            }
072:
073:            @Test
074:            public void testHandleMessageSucc() throws Exception {
075:                prepareSoapMessage();
076:                dsi.getUnderstoodHeaders().add(RESERVATION);
077:                dsi.getUnderstoodHeaders().add(PASSENGER);
078:
079:                soapMessage.getInterceptorChain().doIntercept(soapMessage);
080:                assertEquals("DummaySoapInterceptor getRoles has been called!",
081:                        true, dsi.isCalledGetRoles());
082:                assertEquals(
083:                        "DummaySoapInterceptor getUnderstood has been called!",
084:                        true, dsi.isCalledGetUnderstood());
085:            }
086:
087:            @Test
088:            public void testHandleMessageFail() throws Exception {
089:                prepareSoapMessage();
090:
091:                dsi.getUnderstoodHeaders().add(RESERVATION);
092:
093:                soapMessage.getInterceptorChain().doIntercept(soapMessage);
094:
095:                assertEquals("DummaySoapInterceptor getRoles has been called!",
096:                        true, dsi.isCalledGetRoles());
097:                assertEquals(
098:                        "DummaySoapInterceptor getUnderstood has been called!",
099:                        true, dsi.isCalledGetUnderstood());
100:
101:                SoapFault ie = (SoapFault) soapMessage
102:                        .getContent(Exception.class);
103:                if (ie == null) {
104:                    fail("InBound Exception Missing! Exception should be Can't understands QNames: "
105:                            + PASSENGER);
106:                } else {
107:                    assertEquals(soapMessage.getVersion().getMustUnderstand(),
108:                            ie.getFaultCode());
109:                    assertEquals("Can not understand QNames: " + PASSENGER, ie
110:                            .getMessage().toString());
111:                }
112:            }
113:
114:            @Test
115:            public void testHandleMessageWithHeaderParam() throws Exception {
116:                prepareSoapMessage();
117:                dsi.getUnderstoodHeaders().add(RESERVATION);
118:                ServiceInfo serviceInfo = getMockedServiceModel(getClass()
119:                        .getResource("test-soap-header.wsdl").toString());
120:
121:                BindingInfo binding = serviceInfo.getBinding(new QName(
122:                        "http://org.apache.cxf/headers",
123:                        "headerTesterSOAPBinding"));
124:                BindingOperationInfo bop = binding.getOperation(new QName(
125:                        "http://org.apache.cxf/headers", "inHeader"));
126:                soapMessage.getExchange().put(BindingOperationInfo.class, bop);
127:
128:                soapMessage.getInterceptorChain().doIntercept(soapMessage);
129:                assertEquals("DummaySoapInterceptor getRoles has been called!",
130:                        true, dsi.isCalledGetRoles());
131:                assertEquals(
132:                        "DummaySoapInterceptor getUnderstood has been called!",
133:                        true, dsi.isCalledGetUnderstood());
134:            }
135:
136:            private void prepareSoapMessage() throws Exception {
137:
138:                soapMessage = TestUtil.createEmptySoapMessage(Soap12
139:                        .getInstance(), chain);
140:                ByteArrayDataSource bads = new ByteArrayDataSource(
141:                        this .getClass().getResourceAsStream(
142:                                "test-soap-header.xml"), "Application/xop+xml");
143:                String cid = AttachmentUtil
144:                        .createContentID("http://cxf.apache.org");
145:                soapMessage.setContent(Attachment.class, new AttachmentImpl(
146:                        cid, new DataHandler(bads)));
147:                soapMessage.setContent(XMLStreamReader.class, XMLInputFactory
148:                        .newInstance().createXMLStreamReader(
149:                                bads.getInputStream()));
150:
151:            }
152:
153:            private class DummySoapInterceptor extends AbstractSoapInterceptor {
154:
155:                private boolean calledGetRoles;
156:                private boolean calledGetUnderstood;
157:
158:                private Set<URI> roles = new HashSet<URI>();
159:                private Set<QName> understood = new HashSet<QName>();
160:
161:                public DummySoapInterceptor() {
162:                    super ("");
163:                }
164:
165:                public DummySoapInterceptor(String phase) {
166:                    super (phase);
167:                }
168:
169:                public void handleMessage(SoapMessage messageParam) {
170:                }
171:
172:                public Set<URI> getRoles() {
173:                    calledGetRoles = true;
174:                    if (roles.size() == 0) {
175:                        try {
176:                            roles
177:                                    .add(new URI(
178:                                            "http://www.w3.org/2003/05/soap-envelope/role/next"));
179:                            roles
180:                                    .add(new URI(
181:                                            "http://www.w3.org/2003/05/soap-envelope/role/none"));
182:                            roles
183:                                    .add(new URI(
184:                                            "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
185:                        } catch (Exception e) {
186:                            return null;
187:                        }
188:                    }
189:                    return roles;
190:                }
191:
192:                public Set<QName> getUnderstoodHeaders() {
193:                    calledGetUnderstood = true;
194:                    return understood;
195:                }
196:
197:                public boolean isCalledGetRoles() {
198:                    return calledGetRoles;
199:                }
200:
201:                public boolean isCalledGetUnderstood() {
202:                    return calledGetUnderstood;
203:                }
204:
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.