just to note that there are a few PMD errors with this commit.

currently core is failing with PMD errors.

2014-07-10 16:51 GMT+02:00 Jason Pell <[email protected]>:
> That definitely sounds good. I am so sick of system properties for
> configuration.
> On 10/07/2014 10:30 PM, "Daniel Kulp" <[email protected]> wrote:
>
>>
>> Alessio,
>>
>> Two thoughts:
>>
>> 1) There is a java.xml.stream.util.StreamReaderDelegate class available
>> from StAX apis, is there really a need for another delegate in CXF?
>>
>> 2) Would it make sense to change the SysPropExpandingStreamReader to a
>> more generic “PropertiesExpandingStreamReader” that takes a Properties
>> object as a constructor param (or better yet, a Map<String, Object> or
>> similar).  That way someone could possibly configure it with some
>> properties object specified in spring or similar.
>>
>>
>> Dan
>>
>>
>> On Jul 9, 2014, at 6:08 PM, [email protected] wrote:
>>
>> > Repository: cxf
>> > Updated Branches:
>> >  refs/heads/master 2c9464299 -> e0b7f3556
>> >
>> >
>> > [CXF-5866] Adding XMLStreamReaderWrapper to WSDLManagerImpl and
>> providing a XMLStreamReader wrapper that resolves system properties
>> >
>> >
>> > Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
>> > Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e0b7f355
>> > Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e0b7f355
>> > Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e0b7f355
>> >
>> > Branch: refs/heads/master
>> > Commit: e0b7f35566bdcb2f364f85caa70c4b100433ed8a
>> > Parents: 2c94642
>> > Author: Alessio Soldano <[email protected]>
>> > Authored: Thu Jul 10 00:04:09 2014 +0200
>> > Committer: Alessio Soldano <[email protected]>
>> > Committed: Thu Jul 10 00:08:08 2014 +0200
>> >
>> > ----------------------------------------------------------------------
>> > .../staxutils/DelegatingXMLStreamReader.java    | 264 +++++++++++++++++++
>> > .../staxutils/SysPropExpandingStreamReader.java |  90 +++++++
>> > .../cxf/staxutils/XMLStreamReaderWrapper.java   |  30 +++
>> > .../SysPropExpandingStreamReaderTest.java       |  63 +++++
>> > .../apache/cxf/staxutils/resources/sysprops.xml |  23 ++
>> > .../org/apache/cxf/wsdl11/WSDLManagerImpl.java  |  26 +-
>> > .../apache/cxf/wsdl11/WSDLManagerImplTest.java  |  28 ++
>> > .../org/apache/cxf/wsdl11/hello_world_wrap.wsdl | 161 +++++++++++
>> > 8 files changed, 680 insertions(+), 5 deletions(-)
>> > ----------------------------------------------------------------------
>> >
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/core/src/main/java/org/apache/cxf/staxutils/DelegatingXMLStreamReader.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/core/src/main/java/org/apache/cxf/staxutils/DelegatingXMLStreamReader.java
>> b/core/src/main/java/org/apache/cxf/staxutils/DelegatingXMLStreamReader.java
>> > new file mode 100644
>> > index 0000000..56564a7
>> > --- /dev/null
>> > +++
>> b/core/src/main/java/org/apache/cxf/staxutils/DelegatingXMLStreamReader.java
>> > @@ -0,0 +1,264 @@
>> > +/**
>> > + * 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.staxutils;
>> > +
>> > +import javax.xml.namespace.NamespaceContext;
>> > +import javax.xml.namespace.QName;
>> > +import javax.xml.stream.Location;
>> > +import javax.xml.stream.XMLStreamException;
>> > +import javax.xml.stream.XMLStreamReader;
>> > +
>> > +/**
>> > + * A XMLStreamReader that delegates to a provided XMLStreamReader
>> instance.
>> > + *
>> > + */
>> > +public class DelegatingXMLStreamReader implements XMLStreamReader {
>> > +
>> > +    private final XMLStreamReader delegate;
>> > +
>> > +    public DelegatingXMLStreamReader(XMLStreamReader reader) {
>> > +        this.delegate = reader;
>> > +    }
>> > +
>> > +    @Override
>> > +    public Object getProperty(String name) throws
>> IllegalArgumentException {
>> > +        return delegate.getProperty(name);
>> > +    }
>> > +
>> > +    @Override
>> > +    public int next() throws XMLStreamException {
>> > +        return delegate.next();
>> > +    }
>> > +
>> > +    @Override
>> > +    public void require(int type, String namespaceURI, String
>> localName) throws XMLStreamException {
>> > +        delegate.require(type, namespaceURI, localName);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getElementText() throws XMLStreamException {
>> > +        return delegate.getElementText();
>> > +    }
>> > +
>> > +    @Override
>> > +    public int nextTag() throws XMLStreamException {
>> > +        return delegate.nextTag();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean hasNext() throws XMLStreamException {
>> > +        return delegate.hasNext();
>> > +    }
>> > +
>> > +    @Override
>> > +    public void close() throws XMLStreamException {
>> > +        delegate.close();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getNamespaceURI(String prefix) {
>> > +        return delegate.getNamespaceURI(prefix);
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean isStartElement() {
>> > +        return delegate.isStartElement();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean isEndElement() {
>> > +        return delegate.isEndElement();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean isCharacters() {
>> > +        return delegate.isCharacters();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean isWhiteSpace() {
>> > +        return delegate.isWhiteSpace();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getAttributeValue(String namespaceURI, String
>> localName) {
>> > +        return delegate.getAttributeValue(namespaceURI, localName);
>> > +    }
>> > +
>> > +    @Override
>> > +    public int getAttributeCount() {
>> > +        return delegate.getAttributeCount();
>> > +    }
>> > +
>> > +    @Override
>> > +    public QName getAttributeName(int index) {
>> > +        return delegate.getAttributeName(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getAttributeNamespace(int index) {
>> > +        return delegate.getAttributeNamespace(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getAttributeLocalName(int index) {
>> > +        return delegate.getAttributeLocalName(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getAttributePrefix(int index) {
>> > +        return delegate.getAttributePrefix(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getAttributeType(int index) {
>> > +        return delegate.getAttributeType(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getAttributeValue(int index) {
>> > +        return delegate.getAttributeValue(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean isAttributeSpecified(int index) {
>> > +        return delegate.isAttributeSpecified(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public int getNamespaceCount() {
>> > +        return delegate.getNamespaceCount();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getNamespacePrefix(int index) {
>> > +        return delegate.getNamespacePrefix(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getNamespaceURI(int index) {
>> > +        return delegate.getNamespaceURI(index);
>> > +    }
>> > +
>> > +    @Override
>> > +    public NamespaceContext getNamespaceContext() {
>> > +        return delegate.getNamespaceContext();
>> > +    }
>> > +
>> > +    @Override
>> > +    public int getEventType() {
>> > +        return delegate.getEventType();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getText() {
>> > +        return delegate.getText();
>> > +    }
>> > +
>> > +    @Override
>> > +    public char[] getTextCharacters() {
>> > +        return delegate.getTextCharacters();
>> > +    }
>> > +
>> > +    @Override
>> > +    public int getTextCharacters(int sourceStart, char[] target, int
>> targetStart, int length)
>> > +        throws XMLStreamException {
>> > +        return delegate.getTextCharacters(sourceStart, target,
>> targetStart, length);
>> > +    }
>> > +
>> > +    @Override
>> > +    public int getTextStart() {
>> > +        return delegate.getTextStart();
>> > +    }
>> > +
>> > +    @Override
>> > +    public int getTextLength() {
>> > +        return delegate.getTextLength();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getEncoding() {
>> > +        return delegate.getEncoding();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean hasText() {
>> > +        return delegate.hasText();
>> > +    }
>> > +
>> > +    @Override
>> > +    public Location getLocation() {
>> > +        return delegate.getLocation();
>> > +    }
>> > +
>> > +    @Override
>> > +    public QName getName() {
>> > +        return delegate.getName();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getLocalName() {
>> > +        return delegate.getLocalName();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean hasName() {
>> > +        return delegate.hasName();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getNamespaceURI() {
>> > +        return delegate.getNamespaceURI();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getPrefix() {
>> > +        return delegate.getPrefix();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getVersion() {
>> > +        return delegate.getVersion();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean isStandalone() {
>> > +        return delegate.isStandalone();
>> > +    }
>> > +
>> > +    @Override
>> > +    public boolean standaloneSet() {
>> > +        return delegate.standaloneSet();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getCharacterEncodingScheme() {
>> > +        return delegate.getCharacterEncodingScheme();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getPITarget() {
>> > +        return delegate.getPITarget();
>> > +    }
>> > +
>> > +    @Override
>> > +    public String getPIData() {
>> > +        return delegate.getPIData();
>> > +    }
>> > +}
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/core/src/main/java/org/apache/cxf/staxutils/SysPropExpandingStreamReader.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/core/src/main/java/org/apache/cxf/staxutils/SysPropExpandingStreamReader.java
>> b/core/src/main/java/org/apache/cxf/staxutils/SysPropExpandingStreamReader.java
>> > new file mode 100644
>> > index 0000000..4987338
>> > --- /dev/null
>> > +++
>> b/core/src/main/java/org/apache/cxf/staxutils/SysPropExpandingStreamReader.java
>> > @@ -0,0 +1,90 @@
>> > +/**
>> > + * 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.staxutils;
>> > +
>> > +import javax.xml.stream.XMLStreamException;
>> > +import javax.xml.stream.XMLStreamReader;
>> > +
>> > +/**
>> > + * A wrapper around XMLStreamReader that expands system property
>> references in element and attribute values.
>> > + *
>> > + */
>> > +public class SysPropExpandingStreamReader extends
>> DelegatingXMLStreamReader {
>> > +
>> > +    public static final String DELIMITER = "@";
>> > +
>> > +    public SysPropExpandingStreamReader(XMLStreamReader reader) {
>> > +        super(reader);
>> > +    }
>> > +
>> > +    protected String expandSystemProperty(String value) {
>> > +        if (!isEmpty(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());
>> > +    }
>> > +}
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/core/src/main/java/org/apache/cxf/staxutils/XMLStreamReaderWrapper.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/core/src/main/java/org/apache/cxf/staxutils/XMLStreamReaderWrapper.java
>> b/core/src/main/java/org/apache/cxf/staxutils/XMLStreamReaderWrapper.java
>> > new file mode 100644
>> > index 0000000..36c582f
>> > --- /dev/null
>> > +++
>> b/core/src/main/java/org/apache/cxf/staxutils/XMLStreamReaderWrapper.java
>> > @@ -0,0 +1,30 @@
>> > +/**
>> > + * 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.staxutils;
>> > +
>> > +import javax.xml.stream.XMLStreamReader;
>> > +
>> > +/**
>> > + * Interface for XMLStreamReader wrappers
>> > + *
>> > + */
>> > +public interface XMLStreamReaderWrapper {
>> > +
>> > +    public XMLStreamReader wrap(XMLStreamReader reader);
>> > +}
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/core/src/test/java/org/apache/cxf/staxutils/SysPropExpandingStreamReaderTest.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/core/src/test/java/org/apache/cxf/staxutils/SysPropExpandingStreamReaderTest.java
>> b/core/src/test/java/org/apache/cxf/staxutils/SysPropExpandingStreamReaderTest.java
>> > new file mode 100644
>> > index 0000000..59a188c
>> > --- /dev/null
>> > +++
>> b/core/src/test/java/org/apache/cxf/staxutils/SysPropExpandingStreamReaderTest.java
>> > @@ -0,0 +1,63 @@
>> > +/**
>> > + * 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.staxutils;
>> > +
>> > +import java.io.InputStream;
>> > +
>> > +import javax.xml.stream.XMLStreamReader;
>> > +
>> > +import org.apache.cxf.helpers.DOMUtils;
>> > +import org.junit.Assert;
>> > +import org.junit.Test;
>> > +import org.w3c.dom.Document;
>> > +import org.w3c.dom.Element;
>> > +
>> > +public class SysPropExpandingStreamReaderTest extends Assert {
>> > +
>> > +    @Test
>> > +    public void testSystemPropertyExpansion() throws Exception {
>> > +        final String barProp = System.setProperty("bar", "BAR-VALUE");
>> > +        final String blahProp = System.setProperty("blah",
>> "BLAH-VALUE");
>> > +        try {
>> > +            XMLStreamReader reader = new
>> SysPropExpandingStreamReader(StaxUtils.createXMLStreamReader(getTestStream("./resources/sysprops.xml")));
>> > +            Document doc = StaxUtils.read(reader);
>> > +            Element abc =
>> DOMUtils.getChildrenWithName(doc.getDocumentElement(), "http://foo/bar";,
>> "abc").iterator().next();
>> > +            assertEquals("fooBAR-VALUEfoo", abc.getTextContent());
>> > +            Element def =
>> DOMUtils.getChildrenWithName(doc.getDocumentElement(), "http://foo/bar";,
>> "def").iterator().next();
>> > +            assertEquals("ggggg", def.getTextContent());
>> > +            assertEquals("BLAH-VALUE2", def.getAttribute("myAttr"));
>> > +        } finally {
>> > +            if (barProp != null) {
>> > +                System.setProperty("bar", barProp);
>> > +            } else {
>> > +                System.clearProperty("bar");
>> > +            }
>> > +            if (blahProp != null) {
>> > +                System.setProperty("blah", blahProp);
>> > +            } else {
>> > +                System.clearProperty("blah");
>> > +            }
>> > +        }
>> > +    }
>> > +
>> > +    private InputStream getTestStream(String resource) {
>> > +        return getClass().getResourceAsStream(resource);
>> > +    }
>> > +}
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/core/src/test/java/org/apache/cxf/staxutils/resources/sysprops.xml
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/core/src/test/java/org/apache/cxf/staxutils/resources/sysprops.xml
>> b/core/src/test/java/org/apache/cxf/staxutils/resources/sysprops.xml
>> > new file mode 100644
>> > index 0000000..7a6ca81
>> > --- /dev/null
>> > +++ b/core/src/test/java/org/apache/cxf/staxutils/resources/sysprops.xml
>> > @@ -0,0 +1,23 @@
>> > +<?xml version="1.0" encoding="UTF-8"?>
>> > +<!--
>> > +  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.
>> > +-->
>> > +<ns:ssss xmlns:ns="http://foo/bar";>
>> > +    <ns:abc>foo@bar@foo</ns:abc>
>> > +    <ns:def myAttr="@blah@2">ggggg</ns:def>
>> > +</ns:ssss>
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
>> b/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
>> > index e4f368a..2f24f9f 100644
>> > --- a/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
>> > +++ b/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
>> > @@ -49,6 +49,9 @@ import org.apache.cxf.common.util.CacheMap;
>> > import org.apache.cxf.configuration.ConfiguredBeanLocator;
>> > import org.apache.cxf.service.model.ServiceSchemaInfo;
>> > import org.apache.cxf.staxutils.StaxUtils;
>> > +import org.apache.cxf.staxutils.DelegatingXMLStreamReader;
>> > +import org.apache.cxf.staxutils.SysPropExpandingStreamReader;
>> > +import org.apache.cxf.staxutils.XMLStreamReaderWrapper;
>> > import org.apache.cxf.wsdl.WSDLConstants;
>> > import org.apache.cxf.wsdl.WSDLExtensionLoader;
>> > import org.apache.cxf.wsdl.WSDLManager;
>> > @@ -71,6 +74,8 @@ public class WSDLManagerImpl implements WSDLManager {
>> >     private boolean disableSchemaCache;
>> >
>> >     private Bus bus;
>> > +
>> > +    private XMLStreamReaderWrapper xmlStreamReaderWrapper;
>> >
>> >     public WSDLManagerImpl() throws BusException {
>> >         this(null);
>> > @@ -130,6 +135,9 @@ public class WSDLManagerImpl implements WSDLManager {
>> >         }
>> >     }
>> >
>> > +    protected Bus getBus() {
>> > +        return bus;
>> > +    }
>> >
>> >     /*
>> >      * (non-Javadoc)
>> > @@ -153,7 +161,11 @@ public class WSDLManagerImpl implements WSDLManager
>> {
>> >                 return definitionsMap.get(url);
>> >             }
>> >         }
>> > -        return loadDefinition(url);
>> > +        Definition def = loadDefinition(url);
>> > +        synchronized (definitionsMap) {
>> > +            definitionsMap.put(url, def);
>> > +        }
>> > +        return def;
>> >     }
>> >
>> >     public Definition getDefinition(Element el) throws WSDLException {
>> > @@ -179,7 +191,7 @@ public class WSDLManagerImpl implements WSDLManager {
>> >         }
>> >     }
>> >
>> > -    private Definition loadDefinition(String url) throws WSDLException {
>> > +    protected Definition loadDefinition(String url) throws
>> WSDLException {
>> >         WSDLReader reader = factory.newWSDLReader();
>> >         reader.setFeature("javax.wsdl.verbose", false);
>> >         reader.setFeature("javax.wsdl.importDocuments", true);
>> > @@ -195,6 +207,9 @@ public class WSDLManagerImpl implements WSDLManager {
>> >             XMLStreamReader xmlReader = null;
>> >             try {
>> >                 xmlReader = StaxUtils.createXMLStreamReader(src);
>> > +                if (xmlStreamReaderWrapper != null) {
>> > +                    xmlReader = xmlStreamReaderWrapper.wrap(xmlReader);
>> > +                }
>> >                 doc = StaxUtils.read(xmlReader, true);
>> >                 if (src.getSystemId() != null) {
>> >                     try {
>> > @@ -217,11 +232,12 @@ public class WSDLManagerImpl implements
>> WSDLManager {
>> >             def = reader.readWSDL(wsdlLocator);
>> >         }
>> >
>> > -        synchronized (definitionsMap) {
>> > -            definitionsMap.put(url, def);
>> > -        }
>> >         return def;
>> >     }
>> > +
>> > +    public void setXMLStreamReaderWrapper(XMLStreamReaderWrapper
>> wrapper) {
>> > +        this.xmlStreamReaderWrapper = wrapper;
>> > +    }
>> >
>> >     private void addExtensionAttributeTypes(ExtensionRegistry extreg) {
>> >         // register types that are not of wsdl4j's default attribute
>> type QName
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/rt/wsdl/src/test/java/org/apache/cxf/wsdl11/WSDLManagerImplTest.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/rt/wsdl/src/test/java/org/apache/cxf/wsdl11/WSDLManagerImplTest.java
>> b/rt/wsdl/src/test/java/org/apache/cxf/wsdl11/WSDLManagerImplTest.java
>> > index e3e5b0a..bcafef1 100644
>> > ---
>> a/rt/wsdl/src/test/java/org/apache/cxf/wsdl11/WSDLManagerImplTest.java
>> > +++
>> b/rt/wsdl/src/test/java/org/apache/cxf/wsdl11/WSDLManagerImplTest.java
>> > @@ -29,7 +29,10 @@ import javax.wsdl.Port;
>> > import javax.wsdl.PortType;
>> > import javax.wsdl.Service;
>> > import javax.xml.namespace.QName;
>> > +import javax.xml.stream.XMLStreamReader;
>> >
>> > +import org.apache.cxf.staxutils.SysPropExpandingStreamReader;
>> > +import org.apache.cxf.staxutils.XMLStreamReaderWrapper;
>> > import org.junit.Assert;
>> > import org.junit.Test;
>> >
>> > @@ -106,4 +109,29 @@ public class WSDLManagerImplTest extends Assert {
>> >         java.io.ByteArrayOutputStream bos = new
>> java.io.ByteArrayOutputStream();
>> >         builder.getWSDLFactory().newWSDLWriter().writeWSDL(def, bos);
>> >     }
>> > +
>> > +    @Test
>> > +    public void testXMLStreamReaderWrapper() throws Exception {
>> > +        final String testProp =
>> System.setProperty("org.apache.cxf.test.wsdl11.port", "99999");
>> > +        try {
>> > +            String wsdlUrl =
>> getClass().getResource("hello_world_wrap.wsdl").toString();
>> > +            WSDLManagerImpl builder = new WSDLManagerImpl();
>> > +            builder.setXMLStreamReaderWrapper(new
>> XMLStreamReaderWrapper() {
>> > +                @Override
>> > +                public XMLStreamReader wrap(XMLStreamReader reader) {
>> > +                    return new SysPropExpandingStreamReader(reader);
>> > +                }
>> > +            });
>> > +            Definition def = builder.getDefinition(wsdlUrl);
>> > +            java.io.ByteArrayOutputStream bos = new
>> java.io.ByteArrayOutputStream();
>> > +            builder.getWSDLFactory().newWSDLWriter().writeWSDL(def,
>> bos);
>> > +            assertTrue(bos.toString().contains("
>> http://localhost:99999/SoapContext/SoapPort";));
>> > +        } finally {
>> > +            if (testProp != null) {
>> > +                System.setProperty("org.apache.cxf.test.wsdl11.port",
>> testProp);
>> > +            } else {
>> > +                System.clearProperty("org.apache.cxf.test.wsdl11.port");
>> > +            }
>> > +        }
>> > +    }
>> > }
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b7f355/rt/wsdl/src/test/resources/org/apache/cxf/wsdl11/hello_world_wrap.wsdl
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/rt/wsdl/src/test/resources/org/apache/cxf/wsdl11/hello_world_wrap.wsdl
>> b/rt/wsdl/src/test/resources/org/apache/cxf/wsdl11/hello_world_wrap.wsdl
>> > new file mode 100644
>> > index 0000000..d2f1d75
>> > --- /dev/null
>> > +++
>> b/rt/wsdl/src/test/resources/org/apache/cxf/wsdl11/hello_world_wrap.wsdl
>> > @@ -0,0 +1,161 @@
>> > +<?xml version="1.0" encoding="UTF-8"?>
>> > +<!--
>> > +  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.
>> > +-->
>> > +<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"; xmlns:tns="
>> http://apache.org/hello_world_soap_http"; xmlns:x1="
>> http://apache.org/hello_world_soap_http/types"; xmlns:wsdl="
>> http://schemas.xmlsoap.org/wsdl/"; xmlns:xsd="
>> http://www.w3.org/2001/XMLSchema"; name="HelloWorld" targetNamespace="
>> http://apache.org/hello_world_soap_http";>
>> > +    <wsdl:types>
>> > +        <schema xmlns="http://www.w3.org/2001/XMLSchema"; xmlns:tns="
>> http://apache.org/hello_world_soap_http/types"; targetNamespace="
>> http://apache.org/hello_world_soap_http/types";
>> elementFormDefault="qualified">
>> > +            <simpleType name="MyStringType">
>> > +                <restriction base="string">
>> > +                    <maxLength value="30"/>
>> > +                </restriction>
>> > +            </simpleType>
>> > +            <element name="sayHi">
>> > +                <complexType/>
>> > +            </element>
>> > +            <element name="sayHiResponse">
>> > +                <complexType>
>> > +                    <sequence>
>> > +                        <element name="responseType" type="string"/>
>> > +                    </sequence>
>> > +                </complexType>
>> > +            </element>
>> > +            <element name="greetMe">
>> > +                <complexType>
>> > +                    <sequence>
>> > +                        <element name="requestType"
>> type="tns:MyStringType"/>
>> > +                    </sequence>
>> > +                </complexType>
>> > +            </element>
>> > +            <element name="greetMeResponse">
>> > +                <complexType>
>> > +                    <sequence>
>> > +                        <element name="responseType" type="string"/>
>> > +                    </sequence>
>> > +                </complexType>
>> > +            </element>
>> > +            <element name="greetMeOneWay">
>> > +                <complexType>
>> > +                    <sequence>
>> > +                        <element name="requestType" type="string"/>
>> > +                    </sequence>
>> > +                </complexType>
>> > +            </element>
>> > +            <element name="pingMe">
>> > +                <complexType/>
>> > +            </element>
>> > +            <element name="pingMeResponse">
>> > +                <complexType/>
>> > +            </element>
>> > +            <element name="faultDetail">
>> > +                <complexType>
>> > +                    <sequence>
>> > +                        <element name="minor" type="short"/>
>> > +                        <element name="major" type="short"/>
>> > +                    </sequence>
>> > +                </complexType>
>> > +            </element>
>> > +        </schema>
>> > +    </wsdl:types>
>> > +    <wsdl:message name="sayHiRequest">
>> > +        <wsdl:part element="x1:sayHi" name="in"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="sayHiResponse">
>> > +        <wsdl:part element="x1:sayHiResponse" name="out"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="greetMeRequest">
>> > +        <wsdl:part element="x1:greetMe" name="in"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="greetMeResponse">
>> > +        <wsdl:part element="x1:greetMeResponse" name="out"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="greetMeOneWayRequest">
>> > +        <wsdl:part element="x1:greetMeOneWay" name="in"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="pingMeRequest">
>> > +        <wsdl:part name="in" element="x1:pingMe"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="pingMeResponse">
>> > +        <wsdl:part name="out" element="x1:pingMeResponse"/>
>> > +    </wsdl:message>
>> > +    <wsdl:message name="pingMeFault">
>> > +        <wsdl:part name="faultDetail" element="x1:faultDetail"/>
>> > +    </wsdl:message>
>> > +    <wsdl:portType name="Greeter">
>> > +        <wsdl:operation name="sayHi">
>> > +            <wsdl:input message="tns:sayHiRequest" name="sayHiRequest"/>
>> > +            <wsdl:output message="tns:sayHiResponse"
>> name="sayHiResponse"/>
>> > +        </wsdl:operation>
>> > +        <wsdl:operation name="greetMe">
>> > +            <wsdl:input message="tns:greetMeRequest"
>> name="greetMeRequest"/>
>> > +            <wsdl:output message="tns:greetMeResponse"
>> name="greetMeResponse"/>
>> > +        </wsdl:operation>
>> > +        <wsdl:operation name="greetMeOneWay">
>> > +            <wsdl:input message="tns:greetMeOneWayRequest"
>> name="greetMeOneWayRequest"/>
>> > +        </wsdl:operation>
>> > +        <wsdl:operation name="pingMe">
>> > +            <wsdl:input name="pingMeRequest"
>> message="tns:pingMeRequest"/>
>> > +            <wsdl:output name="pingMeResponse"
>> message="tns:pingMeResponse"/>
>> > +            <wsdl:fault name="pingMeFault" message="tns:pingMeFault"/>
>> > +        </wsdl:operation>
>> > +    </wsdl:portType>
>> > +    <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
>> > +        <soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
>> style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
>> > +        <wsdl:operation name="sayHi">
>> > +            <soap:operation xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; soapAction="" style="document"/>
>> > +            <wsdl:input name="sayHiRequest">
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:input>
>> > +            <wsdl:output name="sayHiResponse">
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:output>
>> > +        </wsdl:operation>
>> > +        <wsdl:operation name="greetMe">
>> > +            <soap:operation xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; soapAction="" style="document"/>
>> > +            <wsdl:input name="greetMeRequest">
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:input>
>> > +            <wsdl:output name="greetMeResponse">
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:output>
>> > +        </wsdl:operation>
>> > +        <wsdl:operation name="greetMeOneWay">
>> > +            <soap:operation xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; soapAction="" style="document"/>
>> > +            <wsdl:input name="greetMeOneWayRequest">
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:input>
>> > +        </wsdl:operation>
>> > +        <wsdl:operation name="pingMe">
>> > +            <soap:operation xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; style="document"/>
>> > +            <wsdl:input>
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:input>
>> > +            <wsdl:output>
>> > +                <soap:body xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; use="literal"/>
>> > +            </wsdl:output>
>> > +            <wsdl:fault name="pingMeFault">
>> > +                <soap:fault xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/"; name="pingMeFault" use="literal"/>
>> > +            </wsdl:fault>
>> > +        </wsdl:operation>
>> > +    </wsdl:binding>
>> > +    <wsdl:service name="SOAPService">
>> > +        <wsdl:port binding="tns:Greeter_SOAPBinding" name="SoapPort">
>> > +            <soap:address xmlns:soap="
>> http://schemas.xmlsoap.org/wsdl/soap/";
>> location="http://localhost:@org.apache.cxf.test.wsdl11.port
>> @/SoapContext/SoapPort"/>
>> > +        </wsdl:port>
>> > +    </wsdl:service>
>> > +</wsdl:definitions>
>> >
>>
>> --
>> Daniel Kulp
>> [email protected] - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>>
>>

Reply via email to