Source Code Cross Referenced for JettyHTTPDestinationTest.java in  » Web-Services-apache-cxf-2.0.1 » transports » org » apache » cxf » transport » http_jetty » 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 » transports » org.apache.cxf.transport.http_jetty 
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.transport.http_jetty;
019:
020:        import java.io.IOException;
021:        import java.io.OutputStream;
022:        import java.net.URL;
023:        import java.util.ArrayList;
024:        import java.util.HashMap;
025:        import java.util.List;
026:        import java.util.Map;
027:
028:        import javax.servlet.ServletInputStream;
029:        import javax.servlet.ServletOutputStream;
030:        import javax.xml.bind.JAXBElement;
031:        import javax.xml.namespace.QName;
032:
033:        import org.apache.cxf.Bus;
034:        import org.apache.cxf.bus.CXFBusImpl;
035:        import org.apache.cxf.common.util.Base64Utility;
036:        import org.apache.cxf.common.util.StringUtils;
037:        import org.apache.cxf.configuration.security.AuthorizationPolicy;
038:        import org.apache.cxf.endpoint.EndpointResolverRegistry;
039:        import org.apache.cxf.helpers.CastUtils;
040:        import org.apache.cxf.io.AbstractWrappedOutputStream;
041:        import org.apache.cxf.message.ExchangeImpl;
042:        import org.apache.cxf.message.Message;
043:        import org.apache.cxf.message.MessageImpl;
044:        import org.apache.cxf.security.transport.TLSSessionInfo;
045:        import org.apache.cxf.service.model.EndpointInfo;
046:        import org.apache.cxf.service.model.ServiceInfo;
047:        import org.apache.cxf.transport.Conduit;
048:        import org.apache.cxf.transport.Destination;
049:        import org.apache.cxf.transport.MessageObserver;
050:        import org.apache.cxf.transport.http.WSDLQueryHandler;
051:        import org.apache.cxf.transports.http.QueryHandler;
052:        import org.apache.cxf.transports.http.QueryHandlerRegistry;
053:        import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
054:        import org.apache.cxf.ws.addressing.AddressingProperties;
055:        import org.apache.cxf.ws.addressing.EndpointReferenceType;
056:        import org.apache.cxf.ws.policy.PolicyEngine;
057:        import org.apache.cxf.wsdl.EndpointReferenceUtils;
058:        import org.easymock.classextension.EasyMock;
059:        import org.junit.After;
060:        import org.junit.Assert;
061:        import org.junit.Test;
062:        import org.mortbay.jetty.HttpFields;
063:        import org.mortbay.jetty.Request;
064:        import org.mortbay.jetty.Response;
065:
066:        import static org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND;
067:
068:        public class JettyHTTPDestinationTest extends Assert {
069:            protected static final String AUTH_HEADER = "Authorization";
070:            protected static final String USER = "copernicus";
071:            protected static final String PASSWD = "epicycles";
072:            protected static final String BASIC_AUTH = "Basic "
073:                    + Base64Utility.encode((USER + ":" + PASSWD).getBytes());
074:
075:            private static final String NOWHERE = "http://nada.nothing.nowhere.null/";
076:            private static final String PAYLOAD = "message payload";
077:            private static final String CHALLENGE_HEADER = "WWW-Authenticate";
078:            private static final String BASIC_CHALLENGE = "Basic realm=terra";
079:            private static final String DIGEST_CHALLENGE = "Digest realm=luna";
080:            private static final String CUSTOM_CHALLENGE = "Custom realm=sol";
081:            private Bus bus;
082:            private Conduit decoupledBackChannel;
083:            private EndpointInfo endpointInfo;
084:            private EndpointReferenceType address;
085:            private EndpointReferenceType replyTo;
086:            private JettyHTTPServerEngine engine;
087:            private HTTPServerPolicy policy;
088:            private JettyHTTPDestination destination;
089:            private Request request;
090:            private Response response;
091:            private Message inMessage;
092:            private Message outMessage;
093:            private MessageObserver observer;
094:            private ServletInputStream is;
095:            private ServletOutputStream os;
096:            private WSDLQueryHandler wsdlQueryHandler;
097:            private QueryHandlerRegistry queryHandlerRegistry;
098:            private List<QueryHandler> queryHandlerList;
099:            private JettyHTTPTransportFactory transportFactory;
100:
101:            /**
102:             * This class replaces the engine in the Jetty Destination.
103:             */
104:            private class EasyMockJettyHTTPDestination extends
105:                    JettyHTTPDestination {
106:
107:                public EasyMockJettyHTTPDestination(Bus b,
108:                        JettyHTTPTransportFactory ci,
109:                        EndpointInfo endpointInfo,
110:                        JettyHTTPServerEngine easyMockEngine)
111:                        throws IOException {
112:                    super (b, ci, endpointInfo);
113:                    engine = easyMockEngine;
114:                }
115:
116:                @Override
117:                public void retrieveEngine() {
118:                    // Leave engine alone.
119:                }
120:            }
121:
122:            @After
123:            public void tearDown() {
124:
125:                bus = null;
126:                transportFactory = null;
127:                decoupledBackChannel = null;
128:                address = null;
129:                replyTo = null;
130:                engine = null;
131:                request = null;
132:                response = null;
133:                inMessage = null;
134:                outMessage = null;
135:                is = null;
136:                os = null;
137:                destination = null;
138:            }
139:
140:            @Test
141:            public void testGetAddress() throws Exception {
142:                destination = setUpDestination();
143:                EndpointReferenceType ref = destination.getAddress();
144:                assertNotNull("unexpected null address", ref);
145:                assertEquals("unexpected address", EndpointReferenceUtils
146:                        .getAddress(ref), StringUtils
147:                        .addDefaultPortIfMissing(EndpointReferenceUtils
148:                                .getAddress(address)));
149:                assertEquals("unexpected service name local part",
150:                        EndpointReferenceUtils.getServiceName(ref)
151:                                .getLocalPart(), "Service");
152:                assertEquals("unexpected portName", EndpointReferenceUtils
153:                        .getPortName(ref), "Port");
154:            }
155:
156:            @Test
157:            public void testGetMultiple() throws Exception {
158:                transportFactory = new JettyHTTPTransportFactory();
159:                transportFactory.setBus(new CXFBusImpl());
160:
161:                ServiceInfo serviceInfo = new ServiceInfo();
162:                serviceInfo.setName(new QName("bla", "Service"));
163:                EndpointInfo ei = new EndpointInfo(serviceInfo, "");
164:                ei.setName(new QName("bla", "Port"));
165:                ei.setAddress("http://foo");
166:                Destination d1 = transportFactory.getDestination(ei);
167:
168:                Destination d2 = transportFactory.getDestination(ei);
169:                assertEquals(d1, d2);
170:
171:                d2.shutdown();
172:
173:                Destination d3 = transportFactory.getDestination(ei);
174:                assertNotSame(d1, d3);
175:            }
176:
177:            @Test
178:            public void testRemoveServant() throws Exception {
179:                destination = setUpDestination();
180:                setUpRemoveServant();
181:                destination.setMessageObserver(null);
182:            }
183:
184:            @Test
185:            public void testDoServiceRedirectURL() throws Exception {
186:                destination = setUpDestination(false, false);
187:                setUpDoService(true);
188:                destination.doService(request, response);
189:
190:            }
191:
192:            @Test
193:            public void testDoService() throws Exception {
194:                destination = setUpDestination(false, false);
195:                setUpDoService(false);
196:                destination.doService(request, response);
197:                verifyDoService();
198:            }
199:
200:            @Test
201:            public void testDoServiceWithHttpGET() throws Exception {
202:                destination = setUpDestination(false, false);
203:                setUpDoService(false, false, false, "GET",
204:                        "?customerId=abc&cutomerAdd=def", 200);
205:                destination.doService(request, response);
206:
207:                assertNotNull("unexpected null message", inMessage);
208:                assertEquals("unexpected method", inMessage
209:                        .get(Message.HTTP_REQUEST_METHOD), "GET");
210:                assertEquals("unexpected path", inMessage
211:                        .get(Message.PATH_INFO), "/bar/foo");
212:                assertEquals("unexpected query", inMessage
213:                        .get(Message.QUERY_STRING),
214:                        "?customerId=abc&cutomerAdd=def");
215:
216:            }
217:
218:            @Test
219:            public void testDoServiceWithHttpGETandQueryWSDL() throws Exception {
220:                destination = setUpDestination(false, true);
221:                setUpDoService(false, false, false, "GET", "?wsdl", 200);
222:
223:                destination.doService(request, response);
224:                assertNotNull("unexpected null response", response);
225:
226:            }
227:
228:            @Test
229:            public void testGetAnonBackChannel() throws Exception {
230:                destination = setUpDestination(false, false);
231:                setUpDoService(false);
232:                destination.doService(request, response);
233:                setUpInMessage();
234:                Conduit backChannel = destination.getBackChannel(inMessage,
235:                        null, null);
236:
237:                assertNotNull("expected back channel", backChannel);
238:                assertNull("unexpected backchannel-backchannel", backChannel
239:                        .getBackChannel());
240:                assertEquals("unexpected target",
241:                        EndpointReferenceUtils.ANONYMOUS_ADDRESS, backChannel
242:                                .getTarget().getAddress().getValue());
243:            }
244:
245:            @Test
246:            public void testGetBackChannelSend() throws Exception {
247:                destination = setUpDestination(false, false);
248:                setUpDoService(false, true);
249:                destination.doService(request, response);
250:                setUpInMessage();
251:                Conduit backChannel = destination.getBackChannel(inMessage,
252:                        null, null);
253:                outMessage = setUpOutMessage();
254:                backChannel.prepare(outMessage);
255:                verifyBackChannelSend(backChannel, outMessage, 200);
256:            }
257:
258:            @Test
259:            public void testGetBackChannelSendFault() throws Exception {
260:                destination = setUpDestination(false, false);
261:                setUpDoService(false, true, 500);
262:                destination.doService(request, response);
263:                setUpInMessage();
264:                Conduit backChannel = destination.getBackChannel(inMessage,
265:                        null, null);
266:                outMessage = setUpOutMessage();
267:                backChannel.prepare(outMessage);
268:                verifyBackChannelSend(backChannel, outMessage, 500);
269:            }
270:
271:            @Test
272:            public void testGetBackChannelSendOneway() throws Exception {
273:                destination = setUpDestination(false, false);
274:                setUpDoService(false, true, 500);
275:                destination.doService(request, response);
276:                setUpInMessage();
277:                Conduit backChannel = destination.getBackChannel(inMessage,
278:                        null, null);
279:                outMessage = setUpOutMessage();
280:                backChannel.prepare(outMessage);
281:                verifyBackChannelSend(backChannel, outMessage, 500, true);
282:            }
283:
284:            @Test
285:            public void testGetBackChannelSendDecoupled() throws Exception {
286:                destination = setUpDestination(false, false);
287:                replyTo = getEPR(NOWHERE + "response/foo");
288:                setUpDoService(false, true, true, 202);
289:                destination.doService(request, response);
290:                setUpInMessage();
291:
292:                Message partialResponse = setUpOutMessage();
293:                Conduit partialBackChannel = destination.getBackChannel(
294:                        inMessage, partialResponse, replyTo);
295:                assertEquals("unexpected response code", 202, partialResponse
296:                        .get(Message.RESPONSE_CODE));
297:                partialBackChannel.prepare(partialResponse);
298:                verifyBackChannelSend(partialBackChannel, partialResponse, 202);
299:
300:                outMessage = setUpOutMessage();
301:                Conduit fullBackChannel = destination.getBackChannel(inMessage,
302:                        null, replyTo);
303:                assertSame("unexpected back channel", fullBackChannel,
304:                        decoupledBackChannel);
305:                fullBackChannel.prepare(outMessage);
306:            }
307:
308:            @Test
309:            public void testServerPolicyInServiceModel() throws Exception {
310:                policy = new HTTPServerPolicy();
311:                address = getEPR("bar/foo");
312:                bus = new CXFBusImpl();
313:
314:                transportFactory = new JettyHTTPTransportFactory();
315:                transportFactory.setBus(bus);
316:
317:                ServiceInfo serviceInfo = new ServiceInfo();
318:                serviceInfo.setName(new QName("bla", "Service"));
319:                endpointInfo = new EndpointInfo(serviceInfo, "");
320:                endpointInfo.setName(new QName("bla", "Port"));
321:                endpointInfo.addExtensor(policy);
322:
323:                engine = EasyMock.createMock(JettyHTTPServerEngine.class);
324:                EasyMock.replay();
325:                endpointInfo.setAddress(NOWHERE + "bar/foo");
326:
327:                JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(
328:                        bus, transportFactory, endpointInfo, engine);
329:                assertEquals(policy, dest.getServer());
330:            }
331:
332:            @Test
333:            public void testMultiplexGetAddressWithId() throws Exception {
334:                destination = setUpDestination();
335:                final String id = "ID2";
336:                EndpointReferenceType refWithId = destination
337:                        .getAddressWithId(id);
338:                assertNotNull(refWithId);
339:                assertNotNull(refWithId.getReferenceParameters());
340:                assertNotNull(refWithId.getReferenceParameters().getAny());
341:                assertTrue(
342:                        "it is an element",
343:                        refWithId.getReferenceParameters().getAny().get(0) instanceof  JAXBElement);
344:                JAXBElement el = (JAXBElement) refWithId
345:                        .getReferenceParameters().getAny().get(0);
346:                assertEquals("match our id", el.getValue(), id);
347:            }
348:
349:            @Test
350:            public void testMultiplexGetAddressWithIdForAddress()
351:                    throws Exception {
352:                destination = setUpDestination();
353:                destination.setMultiplexWithAddress(true);
354:
355:                final String id = "ID3";
356:                EndpointReferenceType refWithId = destination
357:                        .getAddressWithId(id);
358:                assertNotNull(refWithId);
359:                assertNull(refWithId.getReferenceParameters());
360:                assertTrue("match our id", EndpointReferenceUtils.getAddress(
361:                        refWithId).indexOf(id) != -1);
362:            }
363:
364:            @Test
365:            public void testMultiplexGetIdForAddress() throws Exception {
366:                destination = setUpDestination();
367:                destination.setMultiplexWithAddress(true);
368:
369:                final String id = "ID3";
370:                EndpointReferenceType refWithId = destination
371:                        .getAddressWithId(id);
372:                String pathInfo = EndpointReferenceUtils.getAddress(refWithId);
373:
374:                Map<String, Object> context = new HashMap<String, Object>();
375:                assertNull("fails with no context", destination.getId(context));
376:
377:                context.put(Message.PATH_INFO, pathInfo);
378:                String result = destination.getId(context);
379:                assertNotNull(result);
380:                assertEquals("match our id", result, id);
381:            }
382:
383:            @Test
384:            public void testMultiplexGetId() throws Exception {
385:                destination = setUpDestination();
386:
387:                final String id = "ID3";
388:                EndpointReferenceType refWithId = destination
389:                        .getAddressWithId(id);
390:
391:                Map<String, Object> context = new HashMap<String, Object>();
392:                assertNull("fails with no context", destination.getId(context));
393:
394:                AddressingProperties maps = EasyMock
395:                        .createMock(AddressingProperties.class);
396:                maps.getToEndpointReference();
397:                EasyMock.expectLastCall().andReturn(refWithId);
398:                EasyMock.replay(maps);
399:                context.put(SERVER_ADDRESSING_PROPERTIES_INBOUND, maps);
400:                String result = destination.getId(context);
401:                assertNotNull(result);
402:                assertEquals("match our id", result, id);
403:            }
404:
405:            private JettyHTTPDestination setUpDestination() throws Exception {
406:                return setUpDestination(false, false);
407:            };
408:
409:            private JettyHTTPDestination setUpDestination(
410:                    boolean contextMatchOnStem, boolean mockedBus)
411:                    throws Exception {
412:                policy = new HTTPServerPolicy();
413:                address = getEPR("bar/foo");
414:
415:                transportFactory = new JettyHTTPTransportFactory() {
416:                    JettyHTTPServerEngineFactory serverEngineFactory;
417:
418:                    @Override
419:                    public JettyHTTPServerEngineFactory getJettyHTTPServerEngineFactory() {
420:                        if (serverEngineFactory == null) {
421:                            serverEngineFactory = new JettyHTTPServerEngineFactory();
422:                        }
423:                        return serverEngineFactory;
424:                    }
425:
426:                    @Override
427:                    public Conduit getConduit(EndpointInfo epi,
428:                            EndpointReferenceType target) throws IOException {
429:                        return decoupledBackChannel;
430:                    }
431:                };
432:
433:                if (!mockedBus) {
434:                    bus = new CXFBusImpl();
435:                } else {
436:                    bus = EasyMock.createMock(Bus.class);
437:                    bus.getExtension(EndpointResolverRegistry.class);
438:                    EasyMock.expectLastCall().andReturn(null);
439:                    bus.getExtension(PolicyEngine.class);
440:                    EasyMock.expectLastCall().andReturn(null);
441:                    EasyMock.replay(bus);
442:                }
443:
444:                engine = EasyMock.createMock(JettyHTTPServerEngine.class);
445:                ServiceInfo serviceInfo = new ServiceInfo();
446:                serviceInfo.setName(new QName("bla", "Service"));
447:                endpointInfo = new EndpointInfo(serviceInfo, "");
448:                endpointInfo.setName(new QName("bla", "Port"));
449:                endpointInfo.setAddress(NOWHERE + "bar/foo");
450:
451:                endpointInfo.addExtensor(policy);
452:                engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")),
453:                        EasyMock.isA(JettyHTTPHandler.class));
454:                EasyMock.expectLastCall();
455:                EasyMock.replay(engine);
456:
457:                JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(
458:                        bus, transportFactory, endpointInfo, engine);
459:                dest.retrieveEngine();
460:                policy = dest.getServer();
461:                observer = new MessageObserver() {
462:                    public void onMessage(Message m) {
463:                        inMessage = m;
464:                    }
465:                };
466:                dest.setMessageObserver(observer);
467:                return dest;
468:            }
469:
470:            private void setUpRemoveServant() throws Exception {
471:                EasyMock.reset(engine);
472:                engine.removeServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")));
473:                EasyMock.expectLastCall();
474:                EasyMock.replay(engine);
475:            }
476:
477:            private void setUpDoService(boolean setRedirectURL)
478:                    throws Exception {
479:                setUpDoService(setRedirectURL, false);
480:            }
481:
482:            private void setUpDoService(boolean setRedirectURL,
483:                    boolean sendResponse) throws Exception {
484:                setUpDoService(setRedirectURL, sendResponse, false);
485:            }
486:
487:            private void setUpDoService(boolean setRedirectURL,
488:                    boolean sendResponse, int status) throws Exception {
489:                String method = "POST";
490:                String query = "?name";
491:                setUpDoService(setRedirectURL, sendResponse, false, method,
492:                        query, status);
493:            }
494:
495:            private void setUpDoService(boolean setRedirectURL,
496:                    boolean sendResponse, boolean decoupled, int status)
497:                    throws Exception {
498:                String method = "POST";
499:                String query = "?name";
500:                setUpDoService(setRedirectURL, sendResponse, decoupled, method,
501:                        query, status);
502:            }
503:
504:            private void setUpDoService(boolean setRedirectURL,
505:                    boolean sendResponse, boolean decoupled) throws Exception {
506:                String method = "POST";
507:                String query = "?name";
508:                setUpDoService(setRedirectURL, sendResponse, decoupled, method,
509:                        query, 200);
510:            }
511:
512:            private void setUpDoService(boolean setRedirectURL,
513:                    boolean sendResponse, boolean decoupled, String method,
514:                    String query, int status) throws Exception {
515:
516:                is = EasyMock.createMock(ServletInputStream.class);
517:                os = EasyMock.createMock(ServletOutputStream.class);
518:                request = EasyMock.createMock(Request.class);
519:                response = EasyMock.createMock(Response.class);
520:                request.getMethod();
521:                EasyMock.expectLastCall().andReturn(method);
522:
523:                if (setRedirectURL) {
524:                    policy.setRedirectURL(NOWHERE + "foo/bar");
525:                    response.sendRedirect(EasyMock.eq(NOWHERE + "foo/bar"));
526:                    EasyMock.expectLastCall();
527:                    response.flushBuffer();
528:                    EasyMock.expectLastCall();
529:                    request.setHandled(true);
530:                    EasyMock.expectLastCall();
531:                } else {
532:                    //getQueryString for if statement
533:                    request.getQueryString();
534:                    EasyMock.expectLastCall().andReturn(query);
535:
536:                    if ("GET".equals(method) && "?wsdl".equals(query)) {
537:                        verifyGetWSDLQuery();
538:                    } else { // test for the post
539:                        EasyMock.expect(request.getMethod()).andReturn(method);
540:                        EasyMock.expect(request.getInputStream()).andReturn(is);
541:                        EasyMock.expect(request.getContextPath()).andReturn(
542:                                "/bar");
543:                        EasyMock.expect(request.getPathInfo())
544:                                .andReturn("/foo");
545:                        EasyMock.expect(request.getQueryString()).andReturn(
546:                                query);
547:                        EasyMock.expect(request.getContentType()).andReturn(
548:                                "text/xml charset=utf8");
549:
550:                        HttpFields httpFields = new HttpFields();
551:                        httpFields.add("content-type", "text/xml");
552:                        httpFields.add("content-type", "charset=utf8");
553:                        httpFields.put(JettyHTTPDestinationTest.AUTH_HEADER,
554:                                JettyHTTPDestinationTest.BASIC_AUTH);
555:
556:                        EasyMock.expect(request.getHeaderNames()).andReturn(
557:                                httpFields.getFieldNames());
558:                        request.getHeaders("content-type");
559:                        EasyMock.expectLastCall().andReturn(
560:                                httpFields.getValues("content-type"));
561:                        request
562:                                .getHeaders(JettyHTTPDestinationTest.AUTH_HEADER);
563:                        EasyMock
564:                                .expectLastCall()
565:                                .andReturn(
566:                                        httpFields
567:                                                .getValues(JettyHTTPDestinationTest.AUTH_HEADER));
568:
569:                        EasyMock.expect(request.getInputStream()).andReturn(is);
570:                        request.setHandled(true);
571:                        EasyMock.expectLastCall();
572:                        response.flushBuffer();
573:                        EasyMock.expectLastCall();
574:                        if (sendResponse) {
575:                            response.setStatus(status);
576:                            EasyMock.expectLastCall();
577:                            response.setContentType("text/xml charset=utf8");
578:                            EasyMock.expectLastCall();
579:                            response.addHeader(EasyMock.isA(String.class),
580:                                    EasyMock.isA(String.class));
581:                            EasyMock.expectLastCall().anyTimes();
582:                            response.getOutputStream();
583:                            EasyMock.expectLastCall().andReturn(os);
584:                            response.getStatus();
585:                            EasyMock.expectLastCall().andReturn(status)
586:                                    .anyTimes();
587:                            response.flushBuffer();
588:                            EasyMock.expectLastCall();
589:                        }
590:                        request
591:                                .getAttribute("javax.servlet.request.cipher_suite");
592:                        EasyMock.expectLastCall().andReturn(
593:                                "anythingwilldoreally");
594:                        request.getAttribute("javax.net.ssl.session");
595:                        EasyMock.expectLastCall().andReturn(null);
596:                        request
597:                                .getAttribute("javax.servlet.request.X509Certificate");
598:                        EasyMock.expectLastCall().andReturn(null);
599:                    }
600:                }
601:
602:                if (decoupled) {
603:                    decoupledBackChannel = EasyMock.createMock(Conduit.class);
604:                    decoupledBackChannel.setMessageObserver(EasyMock
605:                            .isA(MessageObserver.class));
606:                    decoupledBackChannel.prepare(EasyMock.isA(Message.class));
607:                    EasyMock.expectLastCall();
608:                    EasyMock.replay(decoupledBackChannel);
609:                }
610:                EasyMock.replay(response);
611:                EasyMock.replay(request);
612:            }
613:
614:            private void setUpInMessage() {
615:                inMessage.setExchange(new ExchangeImpl());
616:            }
617:
618:            private Message setUpOutMessage() {
619:                Message outMsg = new MessageImpl();
620:                outMsg.putAll(inMessage);
621:                outMsg.setExchange(new ExchangeImpl());
622:                outMsg.put(Message.PROTOCOL_HEADERS,
623:                        new HashMap<String, List<String>>());
624:                return outMsg;
625:            }
626:
627:            private void setUpResponseHeaders(Message outMsg) {
628:                Map<String, List<String>> responseHeaders = CastUtils
629:                        .cast((Map<?, ?>) outMsg.get(Message.PROTOCOL_HEADERS));
630:                assertNotNull("expected response headers", responseHeaders);
631:                List<String> challenges = new ArrayList<String>();
632:                challenges.add(BASIC_CHALLENGE);
633:                challenges.add(DIGEST_CHALLENGE);
634:                challenges.add(CUSTOM_CHALLENGE);
635:                responseHeaders.put(CHALLENGE_HEADER, challenges);
636:            }
637:
638:            private void verifyGetWSDLQuery() throws Exception {
639:                wsdlQueryHandler = EasyMock.createMock(WSDLQueryHandler.class);
640:                queryHandlerRegistry = EasyMock
641:                        .createMock(QueryHandlerRegistry.class);
642:                queryHandlerList = new ArrayList<QueryHandler>();
643:                queryHandlerList.add(wsdlQueryHandler);
644:                EasyMock.reset(bus);
645:                bus.getExtension(QueryHandlerRegistry.class);
646:                EasyMock.expectLastCall().andReturn(queryHandlerRegistry);
647:                queryHandlerRegistry.getHandlers();
648:                EasyMock.expectLastCall().andReturn(queryHandlerList);
649:                request.getRequestURL();
650:                EasyMock.expectLastCall().andReturn(
651:                        new StringBuffer("http://localhost/bar/foo")).times(2);
652:                request.getPathInfo();
653:                EasyMock.expectLastCall().andReturn("/bar/foo");
654:                request.getQueryString();
655:                EasyMock.expectLastCall().andReturn("wsdl");
656:                response.setContentType("text/xml");
657:                EasyMock.expectLastCall();
658:                response.getOutputStream();
659:                EasyMock.expectLastCall().andReturn(os).anyTimes();
660:                request.setHandled(true);
661:                EasyMock.expectLastCall();
662:                wsdlQueryHandler.isRecognizedQuery(
663:                        "http://localhost/bar/foo?wsdl", "/bar/foo",
664:                        endpointInfo);
665:                EasyMock.expectLastCall().andReturn(true);
666:                wsdlQueryHandler.getResponseContentType(
667:                        "http://localhost/bar/foo?wsdl", "/bar/foo");
668:                EasyMock.expectLastCall().andReturn("text/xml");
669:                wsdlQueryHandler.writeResponse("http://localhost/bar/foo?wsdl",
670:                        "/bar/foo", endpointInfo, os);
671:                EasyMock.expectLastCall().once();
672:                EasyMock.replay(bus);
673:                EasyMock.replay(queryHandlerRegistry);
674:                EasyMock.replay(wsdlQueryHandler);
675:            }
676:
677:            private void verifyDoService() throws Exception {
678:                assertNotNull("unexpected null message", inMessage);
679:                assertSame("unexpected HTTP request", inMessage
680:                        .get(JettyHTTPDestination.HTTP_REQUEST), request);
681:                assertSame("unexpected HTTP response", inMessage
682:                        .get(JettyHTTPDestination.HTTP_RESPONSE), response);
683:                assertEquals("unexpected method", inMessage
684:                        .get(Message.HTTP_REQUEST_METHOD), "POST");
685:                assertEquals("unexpected path", inMessage
686:                        .get(Message.PATH_INFO), "/bar/foo");
687:                assertEquals("unexpected query", inMessage
688:                        .get(Message.QUERY_STRING), "?name");
689:                assertNotNull("unexpected query", inMessage
690:                        .get(TLSSessionInfo.class));
691:                verifyRequestHeaders();
692:
693:            }
694:
695:            private void verifyRequestHeaders() throws Exception {
696:                Map<String, List<String>> requestHeaders = CastUtils
697:                        .cast((Map<?, ?>) inMessage
698:                                .get(Message.PROTOCOL_HEADERS));
699:                assertNotNull("expected request headers", requestHeaders);
700:                List<String> values = requestHeaders.get("content-type");
701:                assertNotNull("expected field", values);
702:                assertEquals("unexpected values", 2, values.size());
703:                assertTrue("expected value", values.contains("text/xml"));
704:                assertTrue("expected value", values.contains("charset=utf8"));
705:                values = requestHeaders.get(AUTH_HEADER);
706:                assertNotNull("expected field", values);
707:                assertEquals("unexpected values", 1, values.size());
708:                assertTrue("expected value", values.contains(BASIC_AUTH));
709:
710:                AuthorizationPolicy authpolicy = inMessage
711:                        .get(AuthorizationPolicy.class);
712:                assertNotNull("Expected some auth tokens", policy);
713:                assertEquals("expected user", USER, authpolicy.getUserName());
714:                assertEquals("expected passwd", PASSWD, authpolicy
715:                        .getPassword());
716:            }
717:
718:            private void verifyResponseHeaders(Message outMsg) throws Exception {
719:                Map<String, List<String>> responseHeaders = CastUtils
720:                        .cast((Map<?, ?>) outMsg.get(Message.PROTOCOL_HEADERS));
721:                assertNotNull("expected response headers", responseHeaders);
722:                //REVISIT CHALLENGE_HEADER's mean
723:                /*assertEquals("expected addField",
724:                             3,
725:                             response.getAddFieldCallCount());
726:                Enumeration e = response.getFieldValues(CHALLENGE_HEADER);
727:                List<String> challenges = new ArrayList<String>();
728:                while (e.hasMoreElements()) {
729:                    challenges.add((String)e.nextElement());
730:                }
731:                assertTrue("expected challenge",
732:                           challenges.contains(BASIC_CHALLENGE));
733:                assertTrue("expected challenge",
734:                           challenges.contains(DIGEST_CHALLENGE));
735:                assertTrue("expected challenge",
736:                           challenges.contains(CUSTOM_CHALLENGE));*/
737:            }
738:
739:            private void verifyBackChannelSend(Conduit backChannel,
740:                    Message outMsg, int status) throws Exception {
741:                verifyBackChannelSend(backChannel, outMsg, status, false);
742:            }
743:
744:            private void verifyBackChannelSend(Conduit backChannel,
745:                    Message outMsg, int status, boolean oneway)
746:                    throws Exception {
747:                outMsg.getExchange().setOneWay(oneway);
748:
749:                assertTrue(
750:                        "unexpected back channel type",
751:                        backChannel instanceof  JettyHTTPDestination.BackChannelConduit);
752:                assertTrue("unexpected content formats", outMsg
753:                        .getContentFormats().contains(OutputStream.class));
754:                OutputStream responseOS = outMsg.getContent(OutputStream.class);
755:                assertNotNull("expected output stream", responseOS);
756:                assertTrue("unexpected output stream type",
757:                        responseOS instanceof  AbstractWrappedOutputStream);
758:
759:                outMsg.put(Message.RESPONSE_CODE, status);
760:                responseOS.write(PAYLOAD.getBytes());
761:
762:                setUpResponseHeaders(outMsg);
763:
764:                responseOS.flush();
765:                assertEquals("unexpected status", status, response.getStatus());
766:                /*if (status == 500) {
767:                    assertEquals("unexpected status message",
768:                                 "Internal Server Error",
769:                                 response.getReason());
770:                }*/
771:                verifyResponseHeaders(outMsg);
772:
773:                if (oneway) {
774:                    assertNull("unexpected HTTP response", outMsg
775:                            .get(JettyHTTPDestination.HTTP_RESPONSE));
776:                } else {
777:                    assertNotNull("expected HTTP response", outMsg
778:                            .get(JettyHTTPDestination.HTTP_RESPONSE));
779:                    responseOS.close();
780:                }
781:            }
782:
783:            static EndpointReferenceType getEPR(String s) {
784:                return EndpointReferenceUtils.getEndpointReference(NOWHERE + s);
785:            }
786:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.