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 java.util.List;
021: import java.util.Map;
022:
023: import org.w3c.dom.Element;
024: import org.w3c.dom.Node;
025: import org.w3c.dom.NodeList;
026:
027: import org.apache.cxf.configuration.jsse.TLSServerParameters;
028: import org.apache.cxf.configuration.jsse.spring.TLSServerParametersConfig;
029: import org.apache.cxf.configuration.security.TLSServerParametersType;
030: import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
031: import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
032: import org.apache.cxf.transport.http_jetty.ThreadingParameters;
033: import org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType;
034: import org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersIdentifiedType;
035: import org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersType;
036: import org.springframework.beans.MutablePropertyValues;
037: import org.springframework.beans.PropertyValue;
038: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
039: import org.springframework.beans.factory.xml.ParserContext;
040:
041: public class JettyHTTPServerEngineBeanDefinitionParser extends
042: AbstractBeanDefinitionParser {
043:
044: public void doParse(Element element, ParserContext ctx,
045: BeanDefinitionBuilder bean) {
046:
047: String portStr = element.getAttribute("port");
048: int port = Integer.valueOf(portStr);
049: bean.addPropertyValue("port", port);
050:
051: MutablePropertyValues engineFactoryProperties = ctx
052: .getContainingBeanDefinition().getPropertyValues();
053: PropertyValue busValue = engineFactoryProperties
054: .getPropertyValue("bus");
055:
056: // get the property value from paranets
057: try {
058:
059: NodeList children = element.getChildNodes();
060: for (int i = 0; i < children.getLength(); i++) {
061: Node n = children.item(i);
062: if (n.getNodeType() == Node.ELEMENT_NODE) {
063: String name = n.getLocalName();
064: if ("tlsServerParameters".equals(name)) {
065:
066: TLSServerParametersType parametersType = JAXBHelper
067: .parseElement((Element) n, bean,
068: TLSServerParametersType.class);
069:
070: TLSServerParametersConfig param = new TLSServerParametersConfig(
071: parametersType);
072:
073: bean.addPropertyValue("tlsServerParameters",
074: param);
075:
076: } else if ("tlsServerParametersRef".equals(name)) {
077:
078: TLSServerParametersIdentifiedType parameterTypeRef = JAXBHelper
079: .parseElement(
080: (Element) n,
081: bean,
082: TLSServerParametersIdentifiedType.class);
083:
084: TLSServerParameters param = getTlsServerParameters(
085: engineFactoryProperties,
086: parameterTypeRef.getId());
087: bean.addPropertyValue("tlsServerParameters",
088: param);
089:
090: } else if ("threadingParameters".equals(name)) {
091: ThreadingParametersType parametersType = JAXBHelper
092: .parseElement((Element) n, bean,
093: ThreadingParametersType.class);
094:
095: ThreadingParameters param = toThreadingParameters(parametersType);
096: bean.addPropertyValue("threadingParameters",
097: param);
098:
099: } else if ("threadingParametersRef".equals(name)) {
100: ThreadingParametersIdentifiedType parametersTypeRef = JAXBHelper
101: .parseElement(
102: (Element) n,
103: bean,
104: ThreadingParametersIdentifiedType.class);
105: ThreadingParameters param = getThreadingParameters(
106: engineFactoryProperties,
107: parametersTypeRef.getId());
108: bean.addPropertyValue("threadingParameters",
109: param);
110:
111: } else if ("connector".equals(name)) {
112: // only deal with the one connector here
113: List list = ctx.getDelegate().parseListElement(
114: (Element) n, bean.getBeanDefinition());
115: bean.addPropertyValue("connector", list.get(0));
116: } else if ("handlers".equals(name)) {
117: List handlers = ctx.getDelegate()
118: .parseListElement((Element) n,
119: bean.getBeanDefinition());
120: bean.addPropertyValue("handlers", handlers);
121: } else if ("sessionSupport".equals(name)) {
122: String text = n.getTextContent();
123: System.out.println("sessionSupport is "
124: + Boolean.valueOf(text));
125: bean.addPropertyValue(name, Boolean
126: .valueOf(text));
127: }
128:
129: }
130: }
131: } catch (Exception e) {
132: throw new RuntimeException(
133: "Could not process configuration.", e);
134: }
135:
136: bean.addPropertyValue("bus", busValue.getValue());
137:
138: bean.setLazyInit(false);
139:
140: }
141:
142: private TLSServerParameters getTlsServerParameters(
143: MutablePropertyValues engineFactoryProperties,
144: String reference) {
145: TLSServerParameters result = null;
146: PropertyValue tlsParameterMapValue = engineFactoryProperties
147: .getPropertyValue("tlsServerParametersMap");
148: if (null == tlsParameterMapValue) {
149: throw new RuntimeException(
150: "Could not find the tlsServerParametersMap "
151: + "from the JettyHTTPServerEngineFactory!");
152: } else {
153: Map tlsServerParametersMap = (Map) tlsParameterMapValue
154: .getValue();
155: result = (TLSServerParameters) tlsServerParametersMap
156: .get(reference);
157: if (result == null) {
158: throw new RuntimeException(
159: "Could not find the tlsServerParametersMap reference ["
160: + reference
161: + "]'s mapping tlsParameter");
162: }
163: }
164: return result;
165: }
166:
167: private ThreadingParameters getThreadingParameters(
168: MutablePropertyValues engineFactoryProperties,
169: String reference) {
170: ThreadingParameters result = null;
171: PropertyValue threadingParametersMapValue = engineFactoryProperties
172: .getPropertyValue("threadingParametersMap");
173: if (null == threadingParametersMapValue) {
174: throw new RuntimeException(
175: "Could not find the threadingParametersMap "
176: + "from the JettyHTTPServerEngineFactory!");
177: } else {
178: Map threadingParametersMap = (Map) threadingParametersMapValue
179: .getValue();
180: result = (ThreadingParameters) threadingParametersMap
181: .get(reference);
182: if (result == null) {
183: throw new RuntimeException(
184: "Could not find the threadingParametersMap reference ["
185: + reference
186: + "]'s mapping threadingParameters");
187: }
188: }
189:
190: return result;
191: }
192:
193: private ThreadingParameters toThreadingParameters(
194: ThreadingParametersType paramtype) {
195: ThreadingParameters params = new ThreadingParameters();
196: params.setMaxThreads(paramtype.getMaxThreads());
197: params.setMinThreads(paramtype.getMinThreads());
198: return params;
199: }
200:
201: /*
202: * We do not require an id from the configuration.
203: *
204: * (non-Javadoc)
205: * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#shouldGenerateId()
206: */
207: @Override
208: protected boolean shouldGenerateId() {
209: return true;
210: }
211:
212: @Override
213: protected Class getBeanClass(Element arg0) {
214: return JettyHTTPServerEngine.class;
215: }
216:
217: }
|