[jbossws-commits] JBossWS SVN: r18804 - stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Mon Jul 21 12:15:08 EDT 2014


Author: asoldano
Date: 2014-07-21 12:15:08 -0400 (Mon, 21 Jul 2014)
New Revision: 18804

Added:
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/SysPropExpandingStreamReader.java
Modified:
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
Log:
[JBWS-3628] Add property expansion capability to .wsdl files


Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java	2014-07-21 10:47:43 UTC (rev 18803)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java	2014-07-21 16:15:08 UTC (rev 18804)
@@ -26,6 +26,8 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import javax.xml.stream.XMLStreamReader;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.buslifecycle.BusLifeCycleListener;
 import org.apache.cxf.buslifecycle.BusLifeCycleManager;
@@ -40,6 +42,7 @@
 import org.apache.cxf.resource.ResourceResolver;
 import org.apache.cxf.service.factory.FactoryBeanListener;
 import org.apache.cxf.service.factory.FactoryBeanListenerManager;
+import org.apache.cxf.staxutils.XMLStreamReaderWrapper;
 import org.apache.cxf.workqueue.AutomaticWorkQueue;
 import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
 import org.apache.cxf.workqueue.WorkQueueManager;
@@ -47,6 +50,8 @@
 import org.apache.cxf.ws.policy.AlternativeSelector;
 import org.apache.cxf.ws.policy.PolicyEngine;
 import org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.WSDLManagerImpl;
 import org.jboss.ws.api.annotation.PolicySets;
 import org.jboss.ws.api.binding.BindingCustomization;
 import org.jboss.wsf.spi.SPIProvider;
@@ -109,6 +114,7 @@
       bus.setProperty(org.jboss.wsf.stack.cxf.client.Constants.DEPLOYMENT_BUS, true);
       busHolderListener = new BusHolderLifeCycleListener();
       bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(busHolderListener);
+      setWSDLManagerStreamWrapper(bus);
       
       if (configurer != null)
       {
@@ -282,6 +288,18 @@
       }
    }
    
+   private static void setWSDLManagerStreamWrapper(Bus bus)
+   {
+      ((WSDLManagerImpl) bus.getExtension(WSDLManager.class)).setXMLStreamReaderWrapper(new XMLStreamReaderWrapper()
+      {
+         @Override
+         public XMLStreamReader wrap(XMLStreamReader reader)
+         {
+            return new SysPropExpandingStreamReader(reader);
+         }
+      });
+   }
+   
    private static AlternativeSelector getAlternativeSelector(Map<String, String> props) {
       //default to MaximalAlternativeSelector on server side [JBWS-3149]
       AlternativeSelector selector = new MaximalAlternativeSelector();

Added: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/SysPropExpandingStreamReader.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/SysPropExpandingStreamReader.java	                        (rev 0)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/SysPropExpandingStreamReader.java	2014-07-21 16:15:08 UTC (rev 18804)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.configuration;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+/**
+ * A StreamReaderDelegate that expands system property references in element and attribute values.
+ * 
+ */
+public class SysPropExpandingStreamReader extends StreamReaderDelegate
+{
+   public static final String DELIMITER = "@";
+
+   public SysPropExpandingStreamReader(XMLStreamReader reader)
+   {
+      super(reader);
+   }
+
+   protected String expandSystemProperty(String value)
+   {
+      if (isEmpty(value))
+      {
+         return value;
+      }
+      final int startIndx = value.indexOf(DELIMITER);
+      if (startIndx > -1)
+      {
+         final int endIndx = value.lastIndexOf(DELIMITER);
+         if (endIndx > -1 && startIndx + 1 < endIndx)
+         {
+            final String propName = value.substring(startIndx + 1, endIndx);
+            if (!isEmpty(propName))
+            {
+               final String envValue = System.getProperty(propName);
+               if (!isEmpty(envValue))
+               {
+                  StringBuilder sb = new StringBuilder();
+                  sb.append(value.substring(0, startIndx));
+                  sb.append(envValue);
+                  sb.append(value.substring(endIndx + 1));
+                  value = sb.toString();
+               }
+            }
+         }
+      }
+
+      return value;
+   }
+
+   private static boolean isEmpty(String str)
+   {
+      if (str != null)
+      {
+         int len = str.length();
+         for (int x = 0; x < len; ++x)
+         {
+            if (str.charAt(x) > ' ')
+            {
+               return false;
+            }
+         }
+      }
+      return true;
+   }
+
+   @Override
+   public String getElementText() throws XMLStreamException
+   {
+      return expandSystemProperty(super.getElementText());
+   }
+
+   @Override
+   public String getAttributeValue(String namespaceURI, String localName)
+   {
+      return expandSystemProperty(super.getAttributeValue(namespaceURI, localName));
+   }
+
+   @Override
+   public String getAttributeValue(int index)
+   {
+      return expandSystemProperty(super.getAttributeValue(index));
+   }
+
+   @Override
+   public String getText()
+   {
+      return expandSystemProperty(super.getText());
+   }
+}


Property changes on: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/SysPropExpandingStreamReader.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native



More information about the jbossws-commits mailing list