cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1506415 - in /cxf/trunk/rt: core/src/main/java/org/apache/cxf/configuration/blueprint/ transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/
Date Wed, 24 Jul 2013 06:53:06 GMT
Author: ffang
Date: Wed Jul 24 06:53:06 2013
New Revision: 1506415

URL: http://svn.apache.org/r1506415
Log:
[CXF-5148]add HTTPServerPolicyHolder for http:server blueprint configuration

Added:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HttpDestinationBPBeanDefinitionParser.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java?rev=1506415&r1=1506414&r2=1506415&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
Wed Jul 24 06:53:06 2013
@@ -335,7 +335,7 @@ public abstract class AbstractBPBeanDefi
         }
     }
 
-    private synchronized JAXBContext getContext(Class<?> cls) {
+    protected synchronized JAXBContext getContext(Class<?> cls) {
         if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
             try {
                 Set<Class<?>> tmp = new HashSet<Class<?>>();

Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java?rev=1506415&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
(added)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
Wed Jul 24 06:53:06 2013
@@ -0,0 +1,137 @@
+/**
+ * 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.blueprint;
+
+import java.io.ByteArrayInputStream;
+import java.util.HashSet;
+import java.util.Set;
+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.transports.http.configuration.HTTPServerPolicy;
+
+
+public class HTTPServerPolicyHolder extends HTTPServerPolicy {
+    private static final Logger LOG = LogUtils.getL7dLogger(HTTPServerPolicyHolder.class);
+
+    private String parsedElement;
+    private HTTPServerPolicy serverPolicy;
+
+    private JAXBContext jaxbContext;
+    private Set<Class<?>> jaxbClasses;
+
+    public HTTPServerPolicyHolder() {
+    }
+
+    public void init() {
+        try {
+
+            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+            docFactory.setNamespaceAware(true);
+
+            Element element = docFactory.newDocumentBuilder()
+                .parse(new ByteArrayInputStream(parsedElement.getBytes())).getDocumentElement();
+
+            serverPolicy = (HTTPServerPolicy)getJaxbObject(element, HTTPServerPolicy.class);
+            this.setCacheControl(serverPolicy.getCacheControl());
+            this.setContentEncoding(serverPolicy.getContentEncoding());
+            this.setContentLocation(serverPolicy.getContentLocation());
+            this.setContentType(serverPolicy.getContentType());
+            this.setHonorKeepAlive(serverPolicy.isHonorKeepAlive());
+            this.setKeepAliveParameters(serverPolicy.getKeepAliveParameters());
+            this.setReceiveTimeout(serverPolicy.getReceiveTimeout());
+            this.setRedirectURL(serverPolicy.getRedirectURL());
+            this.setServerType(serverPolicy.getServerType());
+            this.setSuppressClientReceiveErrors(serverPolicy.isSuppressClientReceiveErrors());
+            this.setSuppressClientSendErrors(serverPolicy.isSuppressClientSendErrors());
+            
+        } catch (Exception e) {
+            throw new RuntimeException("Could not process configuration.", e);
+        }
+    }
+
+    public void destroy() {
+        
+    }
+
+    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;
+    }
+   
+       
+}

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HttpDestinationBPBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HttpDestinationBPBeanDefinitionParser.java?rev=1506415&r1=1506414&r2=1506415&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HttpDestinationBPBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HttpDestinationBPBeanDefinitionParser.java
Wed Jul 24 06:53:06 2013
@@ -19,18 +19,28 @@
 
 package org.apache.cxf.transport.http.blueprint;
 
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Element;
 
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.blueprint.AbstractBPBeanDefinitionParser;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
-import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.Metadata;
 
 public class HttpDestinationBPBeanDefinitionParser extends AbstractBPBeanDefinitionParser
{
+    private static final Logger LOG = LogUtils.getL7dLogger(HttpDestinationBPBeanDefinitionParser.class);
+    
     private static final String HTTP_NS =
         "http://cxf.apache.org/transports/http/configuration";
 
@@ -39,12 +49,11 @@ public class HttpDestinationBPBeanDefini
         
         bean.setRuntimeClass(AbstractHTTPDestination.class);
 
-        mapElementToJaxbProperty(context, bean, element,
-                new QName(HTTP_NS, "server"), "server", HTTPServerPolicy.class);
-        mapElementToJaxbProperty(context, bean, element,
-                new QName(HTTP_NS, "fixedParameterOrder"), "fixedParameterOrder", Boolean.class);

-        mapElementToJaxbProperty(context, bean, element,
-                new QName(HTTP_NS, "contextMatchStrategy"), "contextMatchStrategy", String.class);
+        mapElementToServerPoliy(context, bean, element, new QName(HTTP_NS, "server"), "server");
+        mapElementToJaxbProperty(context, bean, element, new QName(HTTP_NS, "fixedParameterOrder"),
+                                 "fixedParameterOrder", Boolean.class);
+        mapElementToJaxbProperty(context, bean, element, new QName(HTTP_NS, "contextMatchStrategy"),
+                                 "contextMatchStrategy", String.class);
         
         parseAttributes(element, context, bean);
         parseChildElements(element, context, bean);
@@ -59,4 +68,47 @@ public class HttpDestinationBPBeanDefini
                                         String val) {
         bean.setId(val);
     }
+    
+    @Override
+    protected void mapElementToJaxbProperty(ParserContext ctx,
+                                            MutableBeanMetadata bean, Element data, 
+                                            String propertyName, 
+                                            Class<?> c) {
+        try {
+            Unmarshaller unmarshaller = getContext(c).createUnmarshaller();
+            MutableValueMetadata value = ctx.createMetadata(MutableValueMetadata.class);
+            value.setStringValue(unmarshaller.unmarshal(data, c).getValue().toString());
+            bean.addProperty(propertyName, value);
+        } catch (JAXBException e) {
+            LOG.warning("Unable to parse property " + propertyName + " due to " + e);
+        }
+    }
+    
+    private void mapElementToServerPoliy(ParserContext ctx,
+                                            MutableBeanMetadata bean, Element parent, 
+                                            QName name,
+                                            String propertyName) {
+        Element data = DOMUtils.getFirstChildWithName(parent, name);
+        if (data == null) {
+            return;
+        }
+        MutableBeanMetadata ef = ctx.createMetadata(MutableBeanMetadata.class);
+        
+        ef.setRuntimeClass(HTTPServerPolicyHolder.class);
+
+        try {
+            // Print the DOM node
+
+            String xmlString = StaxUtils.toString(data);
+            ef.addProperty("parsedElement", createValue(ctx, xmlString));
+            ef.setInitMethod("init");
+
+            ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
+            bean.addProperty(propertyName, ef);
+            
+        } catch (Exception e) {
+            throw new RuntimeException("Could not process configuration.", e);
+        }
+        
+    }
 }



Mime
View raw message