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.spring;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.xml.sax.SAXParseException;
023:
024: import org.apache.cxf.Bus;
025: import org.apache.cxf.BusFactory;
026: import org.apache.cxf.configuration.Configurer;
027: import org.apache.cxf.configuration.spring.ConfigurerImpl;
028: import org.apache.cxf.service.model.EndpointInfo;
029: import org.apache.cxf.service.model.ServiceInfo;
030: import org.apache.cxf.test.TestApplicationContext;
031: import org.apache.cxf.transport.ConduitInitiator;
032: import org.apache.cxf.transport.ConduitInitiatorManager;
033: import org.apache.cxf.transport.Destination;
034: import org.apache.cxf.transport.DestinationFactory;
035: import org.apache.cxf.transport.DestinationFactoryManager;
036: import org.apache.cxf.transport.http.HTTPConduit;
037: import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
038: import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
039: import org.junit.AfterClass;
040: import org.junit.Assert;
041: import org.junit.BeforeClass;
042: import org.junit.Test;
043: import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
044:
045: public class ApplicationContextTest extends Assert {
046:
047: private static final String S1 = ApplicationContextTest.class
048: .getResource("/META-INF/cxf/cxf.xml").toString();
049: private static final String S2 = ApplicationContextTest.class
050: .getResource("/META-INF/cxf/cxf-extension-http.xml")
051: .toString();
052: private static final String S3 = ApplicationContextTest.class
053: .getResource("/META-INF/cxf/cxf-extension-http-jetty.xml")
054: .toString();
055:
056: @BeforeClass
057: public static void classUp() {
058: BusFactory.setDefaultBus(null);
059: }
060:
061: @AfterClass
062: public static void classDown() {
063: BusFactory.setDefaultBus(null);
064: }
065:
066: @Test
067: public void testInvalid() throws Exception {
068: String s4 = getClass()
069: .getResource(
070: "/org/apache/cxf/transport/http_jetty/spring/invalid-beans.xml")
071: .toString();
072:
073: try {
074: new TestApplicationContext(new String[] { S1, S2, S3, s4 });
075: fail("Expected XmlBeanDefinitionStoreException not thrown.");
076: } catch (XmlBeanDefinitionStoreException ex) {
077: assertTrue(ex.getCause() instanceof SAXParseException);
078: }
079: }
080:
081: // This test fails because I think it is trying to read the http-conf.xsd
082: // twice, failing on a duplicate name for
083: //http://cxf.apache.org/transports/http/configuration,authorization
084:
085: @Test
086: public void testContext() throws Exception {
087: String s4 = getClass()
088: .getResource(
089: "/org/apache/cxf/transport/http_jetty/spring/beans.xml")
090: .toString();
091:
092: TestApplicationContext ctx = new TestApplicationContext(
093: new String[] { S1, S2, S3, s4 });
094:
095: //ctx.refresh();
096:
097: ConfigurerImpl cfg = new ConfigurerImpl(ctx);
098:
099: EndpointInfo info = getEndpointInfo("bla", "Foo",
100: "http://localhost:9000");
101:
102: Bus bus = (Bus) ctx.getBean(Bus.DEFAULT_BUS_ID);
103: bus.setExtension(cfg, Configurer.class);
104:
105: DestinationFactoryManager dfm = bus
106: .getExtension(DestinationFactoryManager.class);
107: DestinationFactory factory = dfm
108: .getDestinationFactory("http://schemas.xmlsoap.org/soap/http");
109: Destination d = factory.getDestination(info);
110: assertTrue(d instanceof JettyHTTPDestination);
111: JettyHTTPDestination jd = (JettyHTTPDestination) d;
112: assertEquals("foobar", jd.getServer().getContentEncoding());
113:
114: JettyHTTPServerEngine engine = (JettyHTTPServerEngine) jd
115: .getEngine();
116: assertEquals(111, engine.getThreadingParameters()
117: .getMinThreads());
118: assertEquals(120, engine.getThreadingParameters()
119: .getMaxThreads());
120:
121: ConduitInitiatorManager cim = bus
122: .getExtension(ConduitInitiatorManager.class);
123: ConduitInitiator ci = cim
124: .getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
125: HTTPConduit conduit = (HTTPConduit) ci.getConduit(info);
126: assertEquals(97, conduit.getClient().getConnectionTimeout());
127:
128: info.setName(new QName("urn:test:ns", "Bar"));
129: conduit = (HTTPConduit) ci.getConduit(info);
130: assertEquals(79, conduit.getClient().getConnectionTimeout());
131:
132: JettyHTTPDestination jd2 = (JettyHTTPDestination) factory
133: .getDestination(getEndpointInfo("foo", "bar",
134: "http://localhost:9001"));
135:
136: engine = (JettyHTTPServerEngine) jd2.getEngine();
137: assertEquals(99, engine.getThreadingParameters()
138: .getMinThreads());
139: assertEquals(777, engine.getThreadingParameters()
140: .getMaxThreads());
141: assertTrue("The engine should support session manager", engine
142: .isSessionSupport());
143: assertNotNull("The handlers should not be null", engine
144: .getHandlers());
145: assertEquals(1, engine.getHandlers().size());
146: assertTrue(
147: "The connector should be instance of org.mortbay.jetty.bio.SocketConnector",
148: engine.getConnector() instanceof org.mortbay.jetty.bio.SocketConnector);
149:
150: JettyHTTPDestination jd3 = (JettyHTTPDestination) factory
151: .getDestination(getEndpointInfo("sna", "foo",
152: "https://localhost:9002"));
153:
154: engine = (JettyHTTPServerEngine) jd3.getEngine();
155: assertEquals(111, engine.getThreadingParameters()
156: .getMinThreads());
157: assertEquals(120, engine.getThreadingParameters()
158: .getMaxThreads());
159: assertEquals(engine.getTlsServerParameters()
160: .getClientAuthentication().isWant(), true);
161: assertEquals(engine.getTlsServerParameters()
162: .getClientAuthentication().isRequired(), true);
163:
164: JettyHTTPDestination jd4 = (JettyHTTPDestination) factory
165: .getDestination(getEndpointInfo("sna", "foo2",
166: "https://localhost:9003"));
167:
168: engine = (JettyHTTPServerEngine) jd4.getEngine();
169: assertEquals(engine.getTlsServerParameters()
170: .getClientAuthentication().isWant(), false);
171: assertEquals(engine.getTlsServerParameters()
172: .getClientAuthentication().isRequired(), false);
173: }
174:
175: private EndpointInfo getEndpointInfo(String serviceNS,
176: String endpointLocal, String address) {
177: ServiceInfo serviceInfo2 = new ServiceInfo();
178: serviceInfo2.setName(new QName(serviceNS, "Service"));
179: EndpointInfo info2 = new EndpointInfo(serviceInfo2, "");
180: info2.setName(new QName("urn:test:ns", endpointLocal));
181: info2.setAddress(address);
182: return info2;
183: }
184: }
|