cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CXF-5863 Fixed the issue that JettyHTTPServerEngineFactoryHolder does not support Handlers
Date Wed, 09 Jul 2014 14:59:28 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 38a9b6614 -> 3812fe232


CXF-5863 Fixed the issue that JettyHTTPServerEngineFactoryHolder does not support Handlers


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3812fe23
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3812fe23
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3812fe23

Branch: refs/heads/master
Commit: 3812fe2327b06d06ba60fe80fc466e4b39c915d6
Parents: 38a9b66
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Jul 9 22:47:48 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Jul 9 22:58:02 2014 +0800

----------------------------------------------------------------------
 .../JettyHTTPServerEngineFactoryHolder.java     | 39 ++++++++++++--
 .../JettyServerEngineFactoryParser.java         | 54 +++++++++++++++++++-
 2 files changed, 89 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3812fe23/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyHTTPServerEngineFactoryHolder.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyHTTPServerEngineFactoryHolder.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyHTTPServerEngineFactoryHolder.java
index c56083f..a4dd160 100644
--- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyHTTPServerEngineFactoryHolder.java
+++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyHTTPServerEngineFactoryHolder.java
@@ -26,11 +26,13 @@ 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;
@@ -47,6 +49,8 @@ import org.apache.cxf.transports.http_jetty.configuration.JettyHTTPServerEngineF
 import org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType;
 import org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersIdentifiedType;
 import org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersType;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
 
 public class JettyHTTPServerEngineFactoryHolder {
 
@@ -54,6 +58,10 @@ public class JettyHTTPServerEngineFactoryHolder {
 
     private String parsedElement;
     private JettyHTTPServerEngineFactory factory;
+    
+    private Map<String, Connector> connectorMap;
+    
+    private Map<String, List<Handler>> handlersMap;
 
     private JAXBContext jaxbContext;
     private Set<Class<?>> jaxbClasses;
@@ -111,13 +119,30 @@ public class JettyHTTPServerEngineFactoryHolder {
             List<JettyHTTPServerEngine> engineList = new ArrayList<JettyHTTPServerEngine>();
             for (JettyHTTPServerEngineConfigType engine : config.getEngine()) {
                 JettyHTTPServerEngine eng = new JettyHTTPServerEngine();
-                //eng.setConnector(engine.getConnector());
+                if (engine.getConnector() != null && connectorMap != null) {
+                    // we need to setup the Connector from the connectorMap
+                    Connector connector = connectorMap.get(engine.getPort().toString());
+                    if (connector != null) {
+                        eng.setConnector(connector);
+                    } else {
+                        throw new RuntimeException("Could not find the connector instance
for engine with port"
+                            + engine.getPort().toString());
+                    }
+                }
+                if (engine.getHandlers() != null && handlersMap != null) {
+                    List<Handler> handlers = handlersMap.get(engine.getPort().toString());
+                    if (handlers != null) {
+                        eng.setHandlers(handlers);
+                    } else {
+                        throw new RuntimeException("Could not find the handlers instance
for engine with port"
+                            + engine.getPort().toString());
+                    }
+                }
 
                 if (engine.isContinuationsEnabled() != null) {
                     eng.setContinuationsEnabled(engine.isContinuationsEnabled());
                 }
-                // eng.setHandlers(engine.getHandlers());
-
+ 
                 if (engine.getHost() != null && !StringUtils.isEmpty(engine.getHost()))
{
                     eng.setHost(engine.getHost());
                 }
@@ -180,6 +205,14 @@ public class JettyHTTPServerEngineFactoryHolder {
     public void setParsedElement(String parsedElement) {
         this.parsedElement = parsedElement;
     }
+    
+    public void setConnectorMap(Map<String, Connector> connectorMap) {
+        this.connectorMap = connectorMap;
+    }
+    
+    public void setHandlersMap(Map<String, List<Handler>> handlersMap) {
+        this.handlersMap = handlersMap;
+    }
 
     protected Object getJaxbObject(Element parent, Class<?> c) {
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/3812fe23/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyServerEngineFactoryParser.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyServerEngineFactoryParser.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyServerEngineFactoryParser.java
index 6a6cf39..8e8c470 100644
--- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyServerEngineFactoryParser.java
+++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/blueprint/JettyServerEngineFactoryParser.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.transport.http_jetty.blueprint;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.StringTokenizer;
 import java.util.UUID;
 
@@ -25,11 +27,16 @@ import org.w3c.dom.Element;
 
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.reflect.MapEntryImpl;
+import org.apache.aries.blueprint.reflect.MapMetadataImpl;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.configuration.blueprint.AbstractBPBeanDefinitionParser;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.MapEntry;
 import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
 
 public class JettyServerEngineFactoryParser extends AbstractBPBeanDefinitionParser {
 
@@ -63,17 +70,62 @@ public class JettyServerEngineFactoryParser extends AbstractBPBeanDefinitionPars
         }
         ef.setRuntimeClass(JettyHTTPServerEngineFactoryHolder.class);
 
+        // setup the ConnectorMap and HandlersMap property for the JettyHTTPServerEngineFactoryHolder
+        
         try {
             // Print the DOM node
-
             String xmlString = StaxUtils.toString(element);
             ef.addProperty("parsedElement", createValue(context, xmlString));
             ef.setInitMethod("init");
             ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
             ef.setDestroyMethod("destroy");
+            // setup the EngineConnector
+            ef.addProperty("connectorMap", parseEngineConnector(element, ef, context));
+            ef.addProperty("handlersMap", parseEngineHandlers(element, ef, context));
             return ef;
         } catch (Exception e) {
             throw new RuntimeException("Could not process configuration.", e);
         }
     }
+    
+    protected Metadata parseEngineConnector(Element element, ComponentMetadata enclosingComponent,
+                                            ParserContext context) {
+        List<MapEntry> entries = new ArrayList<MapEntry>();
+        // create an empty map first
+        List<Element> engines = DOMUtils
+            .getChildrenWithName(element, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT,
"engine");
+        for (Element engine : engines) {
+            String port = engine.getAttribute("port");
+            ValueMetadata keyValue = createValue(context, port);
+            Element connector = DOMUtils
+                .getFirstChildWithName(engine, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT,
+                                       "connector");
+            if (connector != null) {
+                Element first = DOMUtils.getFirstElement(connector);
+                Metadata valValue = context.parseElement(Metadata.class, enclosingComponent,
first);
+                entries.add(new MapEntryImpl(keyValue, valValue));
+            }
+        }
+
+        return new MapMetadataImpl("java.lang.String", "org.eclipse.jetty.server.Connector",
entries);
+    }
+    
+    protected Metadata parseEngineHandlers(Element element, ComponentMetadata enclosingComponent,

+                                           ParserContext context) {
+        List<MapEntry> entries = new ArrayList<MapEntry>();
+        List<Element> engines = DOMUtils
+            .getChildrenWithName(element, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT,
"engine");
+        for (Element engine : engines) {
+            String port = engine.getAttribute("port");
+            ValueMetadata keyValue = createValue(context, port);
+            Element handlers = DOMUtils
+                .getFirstChildWithName(engine, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT,
+                                       "handlers");
+            if (handlers != null) {
+                Metadata valValue = parseListData(context, enclosingComponent, handlers);
+                entries.add(new MapEntryImpl(keyValue, valValue));
+            }
+        }
+        return new MapMetadataImpl("java.lang.String", "java.util.List", entries);
+    }
 }


Mime
View raw message