cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject cxf git commit: [CXF-6217] More updates to use secure processing
Date Wed, 01 Jul 2015 17:59:53 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5d5f5e34b -> c322ba957


[CXF-6217] More updates to use secure processing


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

Branch: refs/heads/master
Commit: c322ba957e09c58ccef0fe25b382497b031fdc06
Parents: 5d5f5e3
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Jul 1 12:44:55 2015 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Jul 1 13:59:42 2015 -0400

----------------------------------------------------------------------
 .../jaxrs/provider/atom/AtomPojoProvider.java   |  4 +-
 .../rs/security/saml/sso/MetadataWriter.java    | 22 +++----
 .../org/apache/cxf/wsn/jms/JmsPullPoint.java    |  7 ++-
 .../org/apache/cxf/wsn/jms/JmsSubscription.java | 12 ++--
 .../common/dom/ExtendedDocumentBuilder.java     | 43 +++++++------
 .../cxf/tools/common/toolspec/ToolSpec.java     |  6 +-
 .../toolspec/parser/CommandLineParserTest.java  |  8 ++-
 .../validator/internal/SchemaValidator.java     |  5 +-
 .../tools/validator/internal/ValidatorUtil.java |  2 +
 .../cxf/tools/wsdlto/core/PluginLoader.java     | 25 ++++++--
 .../databinding/jaxb/NamespaceContextImpl.java  | 65 --------------------
 11 files changed, 82 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
index 46823b8..9585994 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AtomPojoProvider.java
@@ -667,9 +667,7 @@ public class AtomPojoProvider extends AbstractConfigurableProvider
                 reportError("Object of type " + cls.getName() + " can not be deserialized
from Entry", ex, 400);
             } finally {
                 try {
-                    if (xreader != null) {
-                        StaxUtils.close(xreader);
-                    }
+                    StaxUtils.close(xreader);
                 } catch (XMLStreamException e) {
                     //ignore
                 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
index 9bb1f16..c094b95 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.rs.security.saml.sso;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
@@ -46,13 +44,13 @@ import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
 import javax.xml.crypto.dsig.keyinfo.X509Data;
 import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
 import javax.xml.crypto.dsig.spec.TransformParameterSpec;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Document;
 
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.xml.security.stax.impl.util.IDGenerator;
 import org.apache.xml.security.utils.Base64;
 import org.slf4j.Logger;
@@ -61,14 +59,8 @@ import org.slf4j.LoggerFactory;
 public class MetadataWriter {
     
     private static final Logger LOG = LoggerFactory.getLogger(MetadataWriter.class);
-    
-    private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance();
-    private static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
     private static final XMLSignatureFactory XML_SIGNATURE_FACTORY = XMLSignatureFactory.getInstance("DOM");
     
-    static {
-        DOC_BUILDER_FACTORY.setNamespaceAware(true);
-    }
 
     //CHECKSTYLE:OFF
     public Document getMetaData(
@@ -80,9 +72,9 @@ public class MetadataWriter {
         boolean wantRequestsSigned
     ) throws Exception {
 
-        ByteArrayOutputStream bout = new ByteArrayOutputStream(4096);
+        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(4096);
         Writer streamWriter = new OutputStreamWriter(bout, "UTF-8");
-        XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(streamWriter);
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(streamWriter);
 
         writer.writeStartDocument("UTF-8", "1.0");
 
@@ -112,12 +104,12 @@ public class MetadataWriter {
             LOG.debug("***************** unsigned ****************");
         }
 
-        InputStream is = new ByteArrayInputStream(bout.toByteArray());
+        InputStream is = bout.createInputStream();
 
         if (signingKey != null) {
             return signMetaInfo(signingCert, signingKey, is, referenceID);
         }
-        return DOC_BUILDER_FACTORY.newDocumentBuilder().parse(is);
+        return StaxUtils.read(is);
     }
     
     private void writeSAMLMetadata(
@@ -248,7 +240,7 @@ public class MetadataWriter {
         KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));
 
         // Instantiate the document to be signed.
-        Document doc = DOC_BUILDER_FACTORY.newDocumentBuilder().parse(metaInfo);
+        Document doc = StaxUtils.read(metaInfo);
 
         // Create a DOMSignContext and specify the RSA PrivateKey and
         // location of the resulting XMLSignature's parent element.

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
----------------------------------------------------------------------
diff --git a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
index 1ac5c00..92d50ae 100644
--- a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
+++ b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
@@ -35,6 +35,7 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.common.logging.LogUtils;
@@ -124,7 +125,11 @@ public class JmsPullPoint extends AbstractPullPoint {
                 StringReader reader = new StringReader(txtMsg.getText());
                 XMLStreamReader xreader = StaxUtils.createXMLStreamReader(reader);
                 Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(xreader);
-                reader.close();
+                try {
+                    xreader.close();
+                } catch (XMLStreamException e) {
+                    //ignoreable
+                }
                 messages.addAll(notify.getNotificationMessage());
             }
             return messages;

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
----------------------------------------------------------------------
diff --git a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
index a7e539e..6420400 100644
--- a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
+++ b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
@@ -31,10 +31,10 @@ import javax.jms.MessageListener;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.Topic;
+import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
@@ -46,6 +46,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.wsn.AbstractSubscription;
 import org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType;
@@ -200,9 +201,7 @@ public abstract class JmsSubscription extends AbstractSubscription implements
Me
                 NotificationMessageHolderType h = ith.next();
                 Object content = h.getMessage().getAny();
                 if (!(content instanceof Element)) {
-                    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                    factory.setNamespaceAware(true);
-                    Document doc = factory.newDocumentBuilder().newDocument();
+                    Document doc = DOMUtils.createDocument();
                     jaxbContext.createMarshaller().marshal(content, doc);
                     content = doc.getDocumentElement();
                 }
@@ -228,6 +227,11 @@ public abstract class JmsSubscription extends AbstractSubscription implements
Me
             }
             try {
                 XPathFactory xpfactory = XPathFactory.newInstance();
+                try {
+                    xpfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
+                } catch (Throwable t) {
+                    //possibly old version, though doesn't really matter as content is already
parsed as an Element
+                }
                 XPath xpath = xpfactory.newXPath();
                 XPathExpression exp = xpath.compile(contentFilter.getContent().get(0).toString());
                 Boolean ret = (Boolean) exp.evaluate(content, XPathConstants.BOOLEAN);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
----------------------------------------------------------------------
diff --git a/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
b/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
index c3017b1..8551225 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
@@ -25,16 +25,22 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
     
+
+
+
 import org.w3c.dom.Document;
+
 import org.xml.sax.SAXException;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.staxutils.StaxUtils;
 
 /**
  * (not thread safe)
@@ -44,15 +50,11 @@ public class ExtendedDocumentBuilder {
 
     private static final Logger LOG = LogUtils.getL7dLogger(ExtendedDocumentBuilder.class);
 
-    private final DocumentBuilderFactory parserFactory;
-    private DocumentBuilder parser;
-
+    private DocumentBuilderFactory parserFactory;
     private SchemaFactory schemaFactory;
     private Schema schema;
 
     public ExtendedDocumentBuilder() {
-        parserFactory = DocumentBuilderFactory.newInstance();
-        parserFactory.setNamespaceAware(true);
     }
 
     private InputStream getSchemaLocation() {
@@ -69,30 +71,33 @@ public class ExtendedDocumentBuilder {
                 LOG.log(Level.SEVERE, "SCHEMA_FACTORY_EXCEPTION_MSG");
             }
             try {
-                this.parserFactory.setSchema(this.schema);                
+                parserFactory = DocumentBuilderFactory.newInstance();
+                try {
+                    parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
+                } catch (ParserConfigurationException e) {
+                    //old version, not supported.
+                }
+                parserFactory.setNamespaceAware(true);
+                parserFactory.setSchema(this.schema);                
             } catch (UnsupportedOperationException e) {
                 LOG.log(Level.WARNING, "DOC_PARSER_NOT_SUPPORTED", e);
             }
         }
     }
 
-
-    private DocumentBuilder getParser() {
-        if (parser == null) {
+    public Document parse(InputStream in) throws SAXException, IOException, XMLStreamException
{
+        if (in == null && LOG.isLoggable(Level.FINE)) {
+            LOG.fine("ExtendedDocumentBuilder trying to parse a null inputstream");
+        }
+        if (parserFactory != null) {
+            //validating, so need to use the validating parser factory
             try {
-                parser = parserFactory.newDocumentBuilder();
+                return parserFactory.newDocumentBuilder().parse(in);
             } catch (javax.xml.parsers.ParserConfigurationException e) {
                 LOG.log(Level.SEVERE, "NEW_DOCUMENT_BUILDER_EXCEPTION_MSG");
             }
         }
-        return parser;
-    }
-    
-    public Document parse(InputStream in) throws SAXException, IOException {
-        if (in == null && LOG.isLoggable(Level.FINE)) {
-            LOG.fine("ExtendedDocumentBuilder trying to parse a null inputstream");
-        }
-        return getParser().parse(in);
+        return StaxUtils.read(in);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
----------------------------------------------------------------------
diff --git a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
index 710e5cc..8bd9457 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
@@ -27,6 +27,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
+import javax.xml.XMLConstants;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
@@ -210,7 +212,9 @@ public class ToolSpec {
     }
 
     public void transform(InputStream stylesheet, OutputStream out) throws TransformerException
{
-        Transformer trans = TransformerFactory.newInstance().newTransformer(new StreamSource(stylesheet));
+        TransformerFactory factory = TransformerFactory.newInstance();
+        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
+        Transformer trans = factory.newTransformer(new StreamSource(stylesheet));
         trans.transform(new DOMSource(doc), new StreamResult(out));
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
----------------------------------------------------------------------
diff --git a/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
b/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
index 93253d0..9ca2489 100644
--- a/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
+++ b/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
@@ -247,8 +247,12 @@ public class CommandLineParserTest extends Assert {
             Class<?> c = Class.forName("org.apache.xerces.impl.Version");
             Object o = c.newInstance();
             String v =  (String) c.getMethod("getVersion").invoke(o);
-            float vn = Float.parseFloat(StringUtils.getFirstFound(v, "(\\d+.\\d+)"));
-            return vn >= 2.7;
+            v = StringUtils.getFirstFound(v, "(\\d+.\\d+)").trim();
+            if (v.charAt(0) >= '3') {
+                return true;
+            }
+            v = v.substring(2);
+            return Integer.parseInt(v) >= 7;
         } catch (Exception e) {
             // ignore
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
----------------------------------------------------------------------
diff --git a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
index fa7c3f7..87bf631 100644
--- a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
+++ b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
@@ -107,6 +107,7 @@ public class SchemaValidator extends AbstractDefinitionValidator {
         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
         try {
             docFactory.setNamespaceAware(true);
+            docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
             docBuilder = docFactory.newDocumentBuilder();
         } catch (ParserConfigurationException e) {
             throw new ToolException(e);
@@ -124,7 +125,7 @@ public class SchemaValidator extends AbstractDefinitionValidator {
         throws SAXException, IOException {
 
         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
+        sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
         SchemaResourceResolver resourceResolver = new SchemaResourceResolver();
 
         sf.setResourceResolver(resourceResolver);
@@ -156,6 +157,7 @@ public class SchemaValidator extends AbstractDefinitionValidator {
     private Schema createSchema(String[] schemas) throws SAXException, IOException {
 
         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
 
         SchemaResourceResolver resourceResolver = new SchemaResourceResolver();
 
@@ -181,6 +183,7 @@ public class SchemaValidator extends AbstractDefinitionValidator {
         try {
             SAXParserFactory saxFactory = SAXParserFactory.newInstance();
             saxFactory.setFeature("http://xml.org/sax/features/namespaces", true);
+            saxFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
             saxParser = saxFactory.newSAXParser();
 
             if (defaultSchemas != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidatorUtil.java
----------------------------------------------------------------------
diff --git a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidatorUtil.java
b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidatorUtil.java
index 305d370..bab3289 100644
--- a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidatorUtil.java
+++ b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidatorUtil.java
@@ -32,6 +32,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.wsdl.Definition;
+import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -148,6 +149,7 @@ public final class ValidatorUtil {
         try {
             DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
             docFactory.setNamespaceAware(true);
+            docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
             docBuilder = docFactory.newDocumentBuilder();
         } catch (ParserConfigurationException e) {
             throw new ToolException(e);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
----------------------------------------------------------------------
diff --git a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
index 8c36cb0..3a90451 100644
--- a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
+++ b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
@@ -35,14 +35,17 @@ import java.util.logging.Level;
 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.stream.XMLStreamException;
+
+import org.w3c.dom.Document;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.jaxb.JAXBUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.tools.common.FrontEndGenerator;
 import org.apache.cxf.tools.common.Processor;
 import org.apache.cxf.tools.common.ToolException;
@@ -64,7 +67,7 @@ public final class PluginLoader {
 
     private Map<String, DataBinding> databindings = new TreeMap<String, DataBinding>();
 
-    private Unmarshaller unmarshaller;
+    private JAXBContext jaxbContext;
 
     private PluginLoader() {
         init();
@@ -72,8 +75,7 @@ public final class PluginLoader {
 
     private void init() {
         try {
-            JAXBContext jc = JAXBContext.newInstance("org.apache.cxf.tools.plugin");
-            unmarshaller = jc.createUnmarshaller();
+            jaxbContext = JAXBContext.newInstance("org.apache.cxf.tools.plugin");
             loadPlugins(ClassLoaderUtils.getResources(PLUGIN_FILE_NAME, getClass()));
         } catch (JAXBException e) {
             Message msg = new Message("JAXB_CONTEXT_INIT_FAIL", LOG);
@@ -230,7 +232,18 @@ public final class PluginLoader {
     }
 
     private Plugin getPlugin(InputStream is) throws JAXBException {
-        return (Plugin) ((JAXBElement<?>)unmarshaller.unmarshal(is)).getValue();
+        try {
+            Document doc = StaxUtils.read(is);
+            return JAXBUtils.unmarshall(jaxbContext, doc.getDocumentElement(), Plugin.class).getValue();
+        } catch (XMLStreamException xse) {
+            throw new JAXBException(xse);
+        } finally {
+            try {
+                is.close();
+            } catch (IOException e) {
+                //ignore
+            }
+        }
     }
 
     public FrontEnd getFrontEnd(String name) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c322ba95/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/NamespaceContextImpl.java
----------------------------------------------------------------------
diff --git a/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/NamespaceContextImpl.java
b/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/NamespaceContextImpl.java
deleted file mode 100644
index eff5759..0000000
--- a/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/NamespaceContextImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.tools.wsdlto.databinding.jaxb;
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.xml.sax.SAXException;
-
-public class NamespaceContextImpl implements NamespaceContext {
-    private Element element;
-
-    public NamespaceContextImpl(File file) {
-        Document document = null;
-        DocumentBuilderFactory docFact = DocumentBuilderFactory.newInstance();
-        docFact.setNamespaceAware(true);
-        try {
-            document = docFact.newDocumentBuilder().parse(file);
-            element = document.getDocumentElement();
-        } catch (SAXException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        } catch (ParserConfigurationException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public String getNamespaceURI(String prefix) {
-        return element.lookupNamespaceURI(prefix);
-
-    }
-
-    public String getPrefix(String namespaceURI) {
-        return element.lookupPrefix(namespaceURI);
-    }
-
-    public Iterator<?> getPrefixes(String namespaceURI) {
-        return null;
-    }
-
-}


Mime
View raw message