Source Code Cross Referenced for JaxWsClientTest.java in  » Web-Services-apache-cxf-2.0.1 » frontend » org » apache » cxf » jaxws » 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 
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;
019:
020:        import java.lang.reflect.InvocationHandler;
021:        import java.lang.reflect.Proxy;
022:        import java.net.URL;
023:        import java.util.Map;
024:        import java.util.ResourceBundle;
025:
026:        import javax.xml.namespace.QName;
027:        import javax.xml.ws.BindingProvider;
028:        import javax.xml.ws.WebServiceException;
029:
030:        import org.apache.cxf.endpoint.ClientImpl;
031:        import org.apache.cxf.interceptor.Fault;
032:        import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
033:        import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
034:        import org.apache.cxf.message.Message;
035:        import org.apache.cxf.phase.AbstractPhaseInterceptor;
036:        import org.apache.cxf.phase.Phase;
037:        import org.apache.cxf.service.Service;
038:        import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
039:        import org.apache.cxf.service.invoker.BeanInvoker;
040:        import org.apache.cxf.service.model.BindingOperationInfo;
041:        import org.apache.cxf.service.model.EndpointInfo;
042:        import org.apache.cxf.service.model.MessagePartInfo;
043:        import org.apache.cxf.transport.Destination;
044:        import org.apache.hello_world_soap_http.BadRecordLitFault;
045:        import org.apache.hello_world_soap_http.Greeter;
046:        import org.apache.hello_world_soap_http.GreeterImpl;
047:        import org.junit.Before;
048:        import org.junit.Test;
049:
050:        public class JaxWsClientTest extends AbstractJaxWsTest {
051:
052:            private final QName serviceName = new QName(
053:                    "http://apache.org/hello_world_soap_http", "SOAPService");
054:            private final QName portName = new QName(
055:                    "http://apache.org/hello_world_soap_http", "SoapPort");
056:            private final String address = "http://localhost:9000/SoapContext/SoapPort";
057:            private Destination d;
058:
059:            @Before
060:            public void setUp() throws Exception {
061:                super .setUpBus();
062:
063:                EndpointInfo ei = new EndpointInfo(null,
064:                        "http://schemas.xmlsoap.org/soap/http");
065:                ei.setAddress(address);
066:
067:                d = localTransport.getDestination(ei);
068:            }
069:
070:            @Test
071:            public void testCreate() throws Exception {
072:                javax.xml.ws.Service s = javax.xml.ws.Service.create(new QName(
073:                        "http://apache.org/hello_world_soap_http", "SoapPort"));
074:                assertNotNull(s);
075:
076:                try {
077:                    s = javax.xml.ws.Service.create(new URL(
078:                            "file:/does/not/exist.wsdl"), new QName(
079:                            "http://apache.org/hello_world_soap_http",
080:                            "SoapPort"));
081:                    fail("did not throw exception");
082:                } catch (WebServiceException sce) {
083:                    // ignore, this is expected
084:                }
085:            }
086:
087:            @Test
088:            public void testRequestContext() throws Exception {
089:                URL url = getClass().getResource("/wsdl/hello_world.wsdl");
090:                javax.xml.ws.Service s = javax.xml.ws.Service.create(url,
091:                        serviceName);
092:                Greeter greeter = s.getPort(portName, Greeter.class);
093:                InvocationHandler handler = Proxy.getInvocationHandler(greeter);
094:                BindingProvider bp = null;
095:
096:                if (handler instanceof  BindingProvider) {
097:                    bp = (BindingProvider) handler;
098:                    //System.out.println(bp.toString());
099:                    Map<String, Object> requestContext = bp.getRequestContext();
100:                    String reqAddr = (String) requestContext
101:                            .get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
102:                    assertEquals(
103:                            "the address get from requestContext is not equal",
104:                            address, reqAddr);
105:                } else {
106:                    fail("can't get the requset context");
107:                }
108:            }
109:
110:            @Test
111:            public void testEndpoint() throws Exception {
112:                ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
113:                URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
114:                assertNotNull(resource);
115:                bean.setWsdlURL(resource.toString());
116:                bean.setBus(getBus());
117:                bean.setServiceClass(GreeterImpl.class);
118:                GreeterImpl greeter = new GreeterImpl();
119:                BeanInvoker invoker = new BeanInvoker(greeter);
120:                bean.setInvoker(invoker);
121:
122:                Service service = bean.create();
123:
124:                String namespace = "http://apache.org/hello_world_soap_http";
125:                EndpointInfo ei = service.getServiceInfos().get(0).getEndpoint(
126:                        new QName(namespace, "SoapPort"));
127:                JaxWsEndpointImpl endpoint = new JaxWsEndpointImpl(getBus(),
128:                        service, ei);
129:
130:                ClientImpl client = new ClientImpl(getBus(), endpoint);
131:
132:                BindingOperationInfo bop = ei.getBinding().getOperation(
133:                        new QName(namespace, "sayHi"));
134:                assertNotNull(bop);
135:                bop = bop.getUnwrappedOperation();
136:                assertNotNull(bop);
137:
138:                MessagePartInfo part = bop.getOutput().getMessageParts().get(0);
139:                assertEquals(0, part.getIndex());
140:
141:                d.setMessageObserver(new MessageReplayObserver(
142:                        "sayHiResponse.xml"));
143:                Object ret[] = client.invoke(bop, new Object[] { "hi" }, null);
144:                assertNotNull(ret);
145:                assertEquals("Wrong number of return objects", 1, ret.length);
146:
147:                // test fault handling
148:                bop = ei.getBinding().getOperation(
149:                        new QName(namespace, "testDocLitFault"));
150:                bop = bop.getUnwrappedOperation();
151:                d.setMessageObserver(new MessageReplayObserver(
152:                        "testDocLitFault.xml"));
153:                try {
154:                    client.invoke(bop, new Object[] { "BadRecordLitFault" },
155:                            null);
156:                    fail("Should have returned a fault!");
157:                } catch (BadRecordLitFault fault) {
158:                    assertEquals("foo", fault.getFaultInfo().trim());
159:                    assertEquals("Hadrian did it.", fault.getMessage());
160:                }
161:
162:                try {
163:                    client.getEndpoint().getOutInterceptors().add(
164:                            new NestedFaultThrower());
165:                    client.getEndpoint().getOutInterceptors().add(
166:                            new FaultThrower());
167:                    client.invoke(bop, new Object[] { "BadRecordLitFault" },
168:                            null);
169:                    fail("Should have returned a fault!");
170:                } catch (Fault fault) {
171:                    assertEquals(true, fault.getMessage().indexOf("Foo") >= 0);
172:                }
173:
174:            }
175:
176:            public static class NestedFaultThrower extends
177:                    AbstractPhaseInterceptor<Message> {
178:
179:                public NestedFaultThrower() {
180:                    super (Phase.PRE_LOGICAL);
181:                    addBefore(FaultThrower.class.getName());
182:                }
183:
184:                public void handleMessage(Message message) throws Fault {
185:                    boolean result = message.getInterceptorChain().doIntercept(
186:                            message);
187:                    assertEquals("doIntercept not return false", result, false);
188:                    assertNotNull(message.getContent(Exception.class));
189:                    throw new Fault(message.getContent(Exception.class));
190:                }
191:
192:            }
193:
194:            public static class FaultThrower extends
195:                    AbstractPhaseInterceptor<Message> {
196:
197:                public FaultThrower() {
198:                    super (Phase.PRE_LOGICAL);
199:                }
200:
201:                public void handleMessage(Message message) throws Fault {
202:                    throw new Fault(new org.apache.cxf.common.i18n.Message(
203:                            "Foo", (ResourceBundle) null));
204:                }
205:
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.