You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2013/07/03 09:32:06 UTC
svn commit: r1499235 - in /cxf/trunk/rt/transports/http-netty/netty-server:
./ src/main/java/org/apache/cxf/transport/http/netty/server/
src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/
src/main/resources/OSGI-INF/ src/main/resources...
Author: ningjiang
Date: Wed Jul 3 07:32:05 2013
New Revision: 1499235
URL: http://svn.apache.org/r1499235
Log:
CXF-5044 added the blueprint support of netty-server
Added:
cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/
cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/HttpNettyTransportNamespaceHandler.java
cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyHttpServerEngineFactoryHolder.java
cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyServerEngineFactoryParser.java
cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/
cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/blueprint/
cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/blueprint/httpn.xml
Modified:
cxf/trunk/rt/transports/http-netty/netty-server/pom.xml
cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java
Modified: cxf/trunk/rt/transports/http-netty/netty-server/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/pom.xml?rev=1499235&r1=1499234&r2=1499235&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/pom.xml (original)
+++ cxf/trunk/rt/transports/http-netty/netty-server/pom.xml Wed Jul 3 07:32:05 2013
@@ -38,6 +38,8 @@
<cxf.osgi.import>
org.jboss.netty.*;version="${cxf.netty.version.range}",
javax.annotation;version="${cxf.osgi.javax.annotation.version}",
+ org.apache.aries*;version="${cxf.aries.version.range}",
+ org.springframework*;resolution:="optional";version="${cxf.osgi.spring.version}"
</cxf.osgi.import>
<cxf.osgi.export>
org.apache.cxf.*,
@@ -64,6 +66,23 @@
</dependency>
<dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.core</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<optional>true</optional>
Modified: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java?rev=1499235&r1=1499234&r2=1499235&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java (original)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java Wed Jul 3 07:32:05 2013
@@ -241,4 +241,12 @@ public class NettyHttpServerEngine imple
public void setPort(int port) {
this.port = port;
}
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getHost() {
+ return host;
+ }
}
Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/HttpNettyTransportNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/HttpNettyTransportNamespaceHandler.java?rev=1499235&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/HttpNettyTransportNamespaceHandler.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/HttpNettyTransportNamespaceHandler.java Wed Jul 3 07:32:05 2013
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.http.netty.server.blueprint;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.cxf.common.logging.LogUtils;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+public class HttpNettyTransportNamespaceHandler implements NamespaceHandler {
+
+ public static final String NETTY_SERVER_TRANSPORT =
+ "http://cxf.apache.org/transports/http-netty-server/configuration";
+
+ private static final String NETTY_SERVER_ENGINE_FACTORY = "engine-factory";
+
+ private static final Logger LOG = LogUtils.getL7dLogger(HttpNettyTransportNamespaceHandler.class);
+
+ public URL getSchemaLocation(String s) {
+ if (NETTY_SERVER_TRANSPORT.equals(s)) {
+ return getClass().getClassLoader().
+ getResource("schemas/configuration/http-netty-server.xsd");
+ } else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ public Set<Class> getManagedClasses() {
+ return null;
+ }
+
+ public Metadata parse(Element element, ParserContext parserContext) {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Parsing element {{" + element.getNamespaceURI() + "}}{" + element.getLocalName() + "}");
+ }
+
+ if (NETTY_SERVER_ENGINE_FACTORY.equals(element.getLocalName())) {
+
+ return new NettyServerEngineFactoryParser().parse(element, parserContext);
+ }
+
+ return null;
+ }
+
+ public ComponentMetadata decorate(Node node,
+ ComponentMetadata componentMetadata,
+ ParserContext parserContext) {
+ LOG.info("Decorating node " + node + " " + componentMetadata);
+ return componentMetadata;
+ }
+}
Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyHttpServerEngineFactoryHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyHttpServerEngineFactoryHolder.java?rev=1499235&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyHttpServerEngineFactoryHolder.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyHttpServerEngineFactoryHolder.java Wed Jul 3 07:32:05 2013
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.http.netty.server.blueprint;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.logging.Logger;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.common.jaxb.JAXBContextCache;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.configuration.jsse.TLSServerParameters;
+import org.apache.cxf.configuration.jsse.TLSServerParametersConfig;
+import org.apache.cxf.transport.http.netty.server.NettyHttpServerEngine;
+import org.apache.cxf.transport.http.netty.server.NettyHttpServerEngineFactory;
+import org.apache.cxf.transport.http.netty.server.ThreadingParameters;
+import org.apache.cxf.transports.http_netty_server.configuration.NettyHttpServerEngineConfigType;
+import org.apache.cxf.transports.http_netty_server.configuration.NettyHttpServerEngineFactoryConfigType;
+import org.apache.cxf.transports.http_netty_server.configuration.TLSServerParametersIdentifiedType;
+import org.apache.cxf.transports.http_netty_server.configuration.ThreadingParametersIdentifiedType;
+import org.apache.cxf.transports.http_netty_server.configuration.ThreadingParametersType;
+
+public class NettyHttpServerEngineFactoryHolder {
+
+ private static final Logger LOG = LogUtils.getL7dLogger(NettyHttpServerEngineFactoryHolder.class);
+
+ private String parsedElement;
+ private NettyHttpServerEngineFactory factory;
+
+ private JAXBContext jaxbContext;
+ private Set<Class<?>> jaxbClasses;
+
+ public NettyHttpServerEngineFactoryHolder() {
+ }
+
+ public void init() {
+ try {
+
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docFactory.setNamespaceAware(true);
+
+ Element element = docFactory.newDocumentBuilder()
+ .parse(new ByteArrayInputStream(parsedElement.getBytes())).getDocumentElement();
+
+ NettyHttpServerEngineFactoryConfigType config
+ = (NettyHttpServerEngineFactoryConfigType) getJaxbObject(element,
+ NettyHttpServerEngineFactoryConfigType.class);
+
+ factory = new NettyHttpServerEngineFactory();
+
+ Map<String, ThreadingParameters> threadingParametersMap
+ = new TreeMap<String, ThreadingParameters>();
+
+ if (config.getIdentifiedThreadingParameters() != null) {
+ for (ThreadingParametersIdentifiedType threads : config.getIdentifiedThreadingParameters()) {
+ ThreadingParameters rThreads = new ThreadingParameters();
+ String id = threads.getId();
+ rThreads.setThreadPoolSize(threads.getThreadingParameters().getThreadPoolSize());
+ threadingParametersMap.put(id, rThreads);
+ }
+
+ factory.setThreadingParametersMap(threadingParametersMap);
+ }
+
+ //SSL
+ Map<String, TLSServerParameters> sslMap = new TreeMap<String, TLSServerParameters>();
+ if (config.getIdentifiedTLSServerParameters() != null) {
+
+ for (TLSServerParametersIdentifiedType t : config.getIdentifiedTLSServerParameters()) {
+ try {
+ TLSServerParameters parameter
+ = new TLSServerParametersConfig(t.getTlsServerParameters());
+ sslMap.put(t.getId(), parameter);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not configure TLS for id " + t.getId(), e);
+ }
+ }
+ factory.setTlsServerParameters(sslMap);
+ }
+ //Engines
+
+ List<NettyHttpServerEngine> engineList = new ArrayList<NettyHttpServerEngine>();
+ for (NettyHttpServerEngineConfigType engine : config.getEngine()) {
+ NettyHttpServerEngine eng = new NettyHttpServerEngine();
+
+ if (engine.getHost() != null && !StringUtils.isEmpty(engine.getHost())) {
+ eng.setHost(engine.getHost());
+ }
+ if (engine.getReadIdleTime() != null) {
+ eng.setReadIdleTime(engine.getReadIdleTime());
+ }
+ if (engine.getWriteIdleTime() != null) {
+ eng.setWriteIdleTime(engine.getWriteIdleTime());
+ }
+ if (engine.getPort() != null) {
+ eng.setPort(engine.getPort());
+ }
+ if (engine.isSessionSupport() != null) {
+ eng.setSessionSupport(engine.isSessionSupport());
+ }
+ if (engine.getThreadingParameters() != null) {
+ ThreadingParametersType threads = engine.getThreadingParameters();
+ ThreadingParameters rThreads = new ThreadingParameters();
+ rThreads.setThreadPoolSize(threads.getThreadPoolSize());
+ eng.setThreadingParameters(rThreads);
+ }
+
+ //eng.setServer(engine.getTlsServerParameters());
+ if (engine.getTlsServerParameters() != null) {
+ TLSServerParameters parameter = null;
+ try {
+ parameter = new TLSServerParametersConfig(engine.getTlsServerParameters());
+ eng.setTlsServerParameters(parameter);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not configure TLS for engine on "
+ + eng.getHost() + ":" + eng.getPort(), e);
+ }
+ }
+ eng.finalizeConfig();
+
+ engineList.add(eng);
+ }
+ factory.setEnginesList(engineList);
+ //Unravel this completely.
+
+ factory.initComplete();
+ } catch (Exception e) {
+ throw new RuntimeException("Could not process configuration.", e);
+ }
+ }
+
+ public void destroy() {
+ factory.postShutdown();
+ }
+
+ public String getParsedElement() {
+ return parsedElement;
+ }
+
+ public void setParsedElement(String parsedElement) {
+ this.parsedElement = parsedElement;
+ }
+
+ protected Object getJaxbObject(Element parent, Class<?> c) {
+
+ try {
+ Unmarshaller umr = getContext(c).createUnmarshaller();
+ JAXBElement<?> ele = (JAXBElement<?>) umr.unmarshal(parent);
+
+ return ele.getValue();
+ } catch (JAXBException e) {
+ LOG.warning("Unable to parse property due to " + e);
+ return null;
+ }
+ }
+
+ protected synchronized JAXBContext getContext(Class<?> cls) {
+ if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
+ try {
+ Set<Class<?>> tmp = new HashSet<Class<?>>();
+ if (jaxbClasses != null) {
+ tmp.addAll(jaxbClasses);
+ }
+ JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls),
+ cls == null ? getClass().getClassLoader() : cls.getClassLoader());
+ if (cls != null) {
+ boolean hasOf = false;
+ for (Class<?> c : tmp) {
+ if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName())) {
+ hasOf = true;
+ }
+ }
+ if (!hasOf) {
+ tmp.add(cls);
+ }
+ }
+ JAXBContextCache.scanPackages(tmp);
+ JAXBContextCache.CachedContextAndSchemas ccs
+ = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null, false);
+ jaxbClasses = ccs.getClasses();
+ jaxbContext = ccs.getContext();
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return jaxbContext;
+ }
+}
Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyServerEngineFactoryParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyServerEngineFactoryParser.java?rev=1499235&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyServerEngineFactoryParser.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/blueprint/NettyServerEngineFactoryParser.java Wed Jul 3 07:32:05 2013
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.http.netty.server.blueprint;
+
+import java.io.StringWriter;
+import java.util.StringTokenizer;
+import java.util.UUID;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.w3c.dom.Element;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.configuration.blueprint.AbstractBPBeanDefinitionParser;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+public class NettyServerEngineFactoryParser extends AbstractBPBeanDefinitionParser {
+
+ public static String getIdOrName(Element elem) {
+ String id = elem.getAttribute("id");
+
+ if (null == id || "".equals(id)) {
+ String names = elem.getAttribute("name");
+ if (null != names) {
+ StringTokenizer st = new StringTokenizer(names, ",");
+ if (st.countTokens() > 0) {
+ id = st.nextToken();
+ }
+ }
+ }
+ return id;
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+
+ //Endpoint definition
+ MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class);
+ if (!StringUtils.isEmpty(getIdOrName(element))) {
+ ef.setId(getIdOrName(element));
+ } else {
+ ef.setId("netty.engine.factory-holder-" + UUID.randomUUID().toString());
+ }
+ ef.setRuntimeClass(NettyHttpServerEngineFactoryHolder.class);
+
+ try {
+
+ TransformerFactory transfac = TransformerFactory.newInstance();
+ Transformer trans = transfac.newTransformer();
+ trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "YES");
+ //trans.setOutputProperty(OutputKeys.INDENT, "yes");
+
+ // Print the DOM node
+
+ StringWriter sw = new StringWriter();
+ StreamResult result = new StreamResult(sw);
+ DOMSource source = new DOMSource(element);
+ trans.transform(source, result);
+ String xmlString = sw.toString();
+ ef.addProperty("parsedElement", createValue(context, xmlString));
+ ef.setInitMethod("init");
+ ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
+
+ return ef;
+ } catch (Exception e) {
+ throw new RuntimeException("Could not process configuration.", e);
+ }
+ }
+}
Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/blueprint/httpn.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/blueprint/httpn.xml?rev=1499235&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/blueprint/httpn.xml (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/OSGI-INF/blueprint/httpn.xml Wed Jul 3 07:32:05 2013
@@ -0,0 +1,29 @@
+<!--
+ ~ /**
+ ~ * Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ * contributor license agreements. See the NOTICE file distributed with
+ ~ * this work for additional information regarding copyright ownership.
+ ~ * The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ * (the "License"); you may not use this file except in compliance with
+ ~ * the License. You may obtain a copy of the License at
+ ~ *
+ ~ * http://www.apache.org/licenses/LICENSE-2.0
+ ~ *
+ ~ * Unless required by applicable law or agreed to in writing, software
+ ~ * distributed under the License is distributed on an "AS IS" BASIS,
+ ~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ * See the License for the specific language governing permissions and
+ ~ * limitations under the License.
+ ~ */
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+ <service interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://cxf.apache.org/transports/http-netty-server/configuration"/>
+ </service-properties>
+ <bean class="org.apache.cxf.transport.http.netty.server.blueprint.HttpNettyTransportNamespaceHandler"/>
+ </service>
+</blueprint>
\ No newline at end of file