Repository: cxf
Updated Branches:
  refs/heads/2.6.x-fixes 915cabf8b -> b6d8e0fbf
  refs/heads/2.7.x-fixes beb6b97ae -> 22b612ffc


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/22b612ff
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/22b612ff
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/22b612ff

Branch: refs/heads/2.7.x-fixes
Commit: 22b612ffcb2540dc59f9b48e947ed86ac2489686
Parents: beb6b97
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Wed Jul 9 22:47:48 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Wed Jul 9 23:23:03 2014 +0800

----------------------------------------------------------------------
 .../JettyHTTPServerEngineFactoryHolder.java     | 39 ++++++++++-
 .../JettyServerEngineFactoryParser.java         | 72 +++++++++++++++-----
 2 files changed, 91 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/22b612ff/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/22b612ff/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 8b4b2e0..c595757 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,22 +18,24 @@
  */
 package org.apache.cxf.transport.http_jetty.blueprint;
 
-import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
 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.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 {
 
@@ -67,27 +69,63 @@ public class JettyServerEngineFactoryParser extends 
AbstractBPBeanDefinitionPars
         }
         ef.setRuntimeClass(JettyHTTPServerEngineFactoryHolder.class);
 
-        try {
+        // setup the ConnectorMap and HandlersMap property for the 
JettyHTTPServerEngineFactoryHolder
 
-            TransformerFactory transfac = TransformerFactory.newInstance();
-            Transformer trans = transfac.newTransformer();
-            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "YES");
-            //trans.setOutputProperty(OutputKeys.INDENT, "yes");
+        try {
 
             // 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();
+            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);
+    }
 }

Reply via email to