cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: More stream work
Date Thu, 28 Apr 2016 10:17:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 50daa4883 -> 895f9b0ff


More stream work


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

Branch: refs/heads/3.1.x-fixes
Commit: 895f9b0ff0b43f775309bfc5d064ca22ec7b2df4
Parents: 50daa48
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Apr 28 11:17:19 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Apr 28 11:17:50 2016 +0100

----------------------------------------------------------------------
 .../jaxws/interceptors/SwAOutInterceptor.java   | 14 ++--
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 21 ++---
 .../provider/datasource/TestProvider.java       |  9 ++-
 .../apache/cxf/tools/util/ToolsStaxUtils.java   | 85 ++++++++++----------
 .../wsdl11/WrapperBeanGeneratorTest.java        | 15 ++--
 .../internal/jaxws/JaxwsServiceBuilderTest.java | 11 ++-
 6 files changed, 78 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/895f9b0f/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
index 7eeb9c2..8b13a6b 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
@@ -183,12 +183,11 @@ public class SwAOutInterceptor extends AbstractSoapInterceptor {
                 // TODO: make this streamable. This is one of my pet
                 // peeves in JAXB RI as well, so if you fix this, submit the 
                 // code to the JAXB RI as well (see RuntimeBuiltinLeafInfoImpl)! - DD
-                ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
                 Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(ct);
                 if (writers.hasNext()) {
                     ImageWriter writer = writers.next();
                     
-                    try {
+                    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) {
                         BufferedImage bimg = convertToBufferedImage((Image) o);
                         ImageOutputStream out = ImageIO.createImageOutputStream(bos); 
                         writer.setOutput(out);
@@ -196,7 +195,7 @@ public class SwAOutInterceptor extends AbstractSoapInterceptor {
                         writer.dispose();
                         out.flush();
                         out.close();
-                        bos.close();
+                        dh = new DataHandler(new ByteDataSource(bos.toByteArray(), ct));
                     } catch (IOException e) {
                         throw new Fault(e);
                     }
@@ -204,8 +203,6 @@ public class SwAOutInterceptor extends AbstractSoapInterceptor {
                     throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED",

                                      LOG, ct));                    
                 }
-                
-                dh = new DataHandler(new ByteDataSource(bos.toByteArray(), ct));
             } else if (o instanceof DataHandler) {
                 dh = (DataHandler) o;
                 ct = dh.getContentType();
@@ -253,9 +250,10 @@ public class SwAOutInterceptor extends AbstractSoapInterceptor {
             StreamSource src = (StreamSource)o;
             try {
                 if (src.getInputStream() != null) {
-                    ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
-                    IOUtils.copy(src.getInputStream(), bos, 1024);
-                    ds = new ByteDataSource(bos.toByteArray(), ct);
+                    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) {
+                        IOUtils.copy(src.getInputStream(), bos, 1024);
+                        ds = new ByteDataSource(bos.toByteArray(), ct);
+                    }
                 } else {
                     ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8),
                                                  ct);                            

http://git-wip-us.apache.org/repos/asf/cxf/blob/895f9b0f/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 5f3aeb0..3a37814 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -1803,16 +1803,17 @@ public class WadlGenerator implements ContainerRequestFilter {
         if (is == null) {
             return;
         }
-        ByteArrayInputStream bis = IOUtils.loadIntoBAIS(is);
-        XMLSource source = new XMLSource(bis);
-        source.setBuffering();
-        String targetNs = source.getValue("/*/@targetNamespace");
-
-        Map<String, String> nsMap = Collections.singletonMap("xs", Constants.URI_2001_SCHEMA_XSD);
-        String[] elementNames = source.getValues("/*/xs:element/@name", nsMap);
-        externalQnamesMap.put(targetNs, Arrays.asList(elementNames));
-        String schemaValue = source.getNode("/xs:schema", nsMap, String.class);
-        externalSchemasCache.add(schemaValue);
+        try (ByteArrayInputStream bis = IOUtils.loadIntoBAIS(is)) {
+            XMLSource source = new XMLSource(bis);
+            source.setBuffering();
+            String targetNs = source.getValue("/*/@targetNamespace");
+
+            Map<String, String> nsMap = Collections.singletonMap("xs", Constants.URI_2001_SCHEMA_XSD);
+            String[] elementNames = source.getValues("/*/xs:element/@name", nsMap);
+            externalQnamesMap.put(targetNs, Arrays.asList(elementNames));
+            String schemaValue = source.getNode("/xs:schema", nsMap, String.class);
+            externalSchemasCache.add(schemaValue);
+        }
     }
 
     public void setUseJaxbContextForQnames(boolean checkJaxbOnly) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/895f9b0f/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
----------------------------------------------------------------------
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
b/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
index d3185a4..46e558a 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
@@ -66,11 +66,12 @@ public class TestProvider extends AbstractProvider<DataSource> implements
Provid
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             IOUtils.copy(req.getInputStream(), baos);
             LOG.info("body [" + new String(baos.toByteArray())  + "]");
-            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-            msg = "<ok/>";
+            try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()))
{
+                msg = "<ok/>";
 
-            MimeMultipart multipart = DataSourceProviderTest.readAttachmentParts(req.getContentType(),
bais);
-            LOG.info("found " + multipart.getCount() + " parts");
+                MimeMultipart multipart = DataSourceProviderTest.readAttachmentParts(req.getContentType(),
bais);
+                LOG.info("found " + multipart.getCount() + " parts");
+            }
             return new ByteArrayDataSource(baos.toByteArray(), req.getContentType());
         } catch (Exception e) {
             e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/cxf/blob/895f9b0f/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java
----------------------------------------------------------------------
diff --git a/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java b/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java
index 2806f26..2a5a35e 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java
@@ -45,56 +45,57 @@ public final class ToolsStaxUtils {
         List<Tag> tags = new ArrayList<Tag>();
         List<String> ignoreEmptyTags = Arrays.asList(new String[]{"sequence"});
 
-        InputStream is = new BufferedInputStream(new FileInputStream(source));
-        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
-        Tag newTag = null;
-        int count = 0;
-        QName checkingPoint = null;
-        
-        Stack<Tag> stack = new Stack<Tag>();
+        try (InputStream is = new BufferedInputStream(new FileInputStream(source))) {
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+            Tag newTag = null;
+            int count = 0;
+            QName checkingPoint = null;
 
-        while (reader.hasNext()) {
-            int event = reader.next();
+            Stack<Tag> stack = new Stack<Tag>();
 
-            if (checkingPoint != null) {
-                count++;
-            }
+            while (reader.hasNext()) {
+                int event = reader.next();
 
-            if (event == XMLStreamReader.START_ELEMENT) {
-                newTag = new Tag();
-                newTag.setName(reader.getName());
-
-                if (ignoreEmptyTags.contains(reader.getLocalName())) {
-                    checkingPoint = reader.getName();
+                if (checkingPoint != null) {
+                    count++;
                 }
 
-                for (int i = 0; i < reader.getAttributeCount(); i++) {
-                    newTag.getAttributes().put(reader.getAttributeName(i), 
-                                               reader.getAttributeValue(i));
+                if (event == XMLStreamReader.START_ELEMENT) {
+                    newTag = new Tag();
+                    newTag.setName(reader.getName());
+
+                    if (ignoreEmptyTags.contains(reader.getLocalName())) {
+                        checkingPoint = reader.getName();
+                    }
+
+                    for (int i = 0; i < reader.getAttributeCount(); i++) {
+                        newTag.getAttributes().put(reader.getAttributeName(i), 
+                                reader.getAttributeValue(i));
+                    }
+                    stack.push(newTag);
+                }
+                if (event == XMLStreamReader.CHARACTERS) {
+                    newTag.setText(reader.getText());
                 }
-                stack.push(newTag);
-            }
-            if (event == XMLStreamReader.CHARACTERS) {
-                newTag.setText(reader.getText());
-            }
 
-            if (event == XMLStreamReader.END_ELEMENT) {
-                Tag startTag = stack.pop();
+                if (event == XMLStreamReader.END_ELEMENT) {
+                    Tag startTag = stack.pop();
 
-                if (checkingPoint != null && checkingPoint.equals(reader.getName()))
{
-                    if (count == 1) {
-                        //Tag is empty, and it's in the ignore collection, so we just skip
this tag
+                    if (checkingPoint != null && checkingPoint.equals(reader.getName()))
{
+                        if (count == 1) {
+                            //Tag is empty, and it's in the ignore collection, so we just
skip this tag
+                        } else {
+                            tags.add(startTag);
+                        }
+                        count = 0;
+                        checkingPoint = null;
                     } else {
                         tags.add(startTag);
                     }
-                    count = 0;
-                    checkingPoint = null;
-                } else {
-                    tags.add(startTag);
                 }
             }
+            reader.close();
         }
-        reader.close();
         return tags;
     }
 
@@ -103,14 +104,16 @@ public final class ToolsStaxUtils {
     }
 
     public static Tag getTagTree(final File source, final List<String> ignoreAttr)
throws Exception {
-        InputStream is = new BufferedInputStream(new FileInputStream(source));
-        return getTagTree(is, ignoreAttr, null);
+        try (InputStream is = new BufferedInputStream(new FileInputStream(source))) {
+            return getTagTree(is, ignoreAttr, null);
+        }
     }
     public static Tag getTagTree(final File source,
                                  final List<String> ignoreAttr,
                                  Map<QName, Set<String>> types) throws Exception
{
-        InputStream is = new BufferedInputStream(new FileInputStream(source));
-        return getTagTree(is, ignoreAttr, types);        
+        try (InputStream is = new BufferedInputStream(new FileInputStream(source))) {
+            return getTagTree(is, ignoreAttr, types);        
+        }
     }    
     public static Tag getTagTree(final InputStream is,
                                  final List<String> ignoreAttr,
@@ -179,4 +182,4 @@ public final class ToolsStaxUtils {
         return a != null && a.contains(attributeName.getLocalPart());
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/895f9b0f/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
----------------------------------------------------------------------
diff --git a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
index 748d517..cd12311 100644
--- a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
+++ b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
@@ -20,14 +20,13 @@
 package org.apache.cxf.tools.java2wsdl.generator.wsdl11;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.lang.reflect.Field;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.file.Files;
 
 import javax.xml.bind.annotation.XmlList;
 
-import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolConstants;
@@ -77,7 +76,7 @@ public class WrapperBeanGeneratorTest extends ProcessorTestBase {
         String pkgBase = "org/apache/cxf";
         File requestWrapperClass = new File(output, pkgBase + "/EchoDataBean.java");
         assertTrue(requestWrapperClass.exists());
-        String contents = IOUtils.toString(new FileInputStream(requestWrapperClass));
+        String contents = new String(Files.readAllBytes(requestWrapperClass.toPath()));
         assertTrue(contents.indexOf("org.apache.cxf.tools.fortest.withannotation.doc") !=
-1);
         
         File responseWrapperClass = new File(output, pkgBase + "/EchoDataBeanResponse.java");
@@ -103,12 +102,12 @@ public class WrapperBeanGeneratorTest extends ProcessorTestBase {
         String pkgBase = "org/apache/cxf/tools/fortest/withannotation/doc/jaxws";
         File requestWrapperClass = new File(output, pkgBase + "/SayIntArray.java");
         assertTrue(requestWrapperClass.exists());
-        String contents = IOUtils.toString(new FileInputStream(requestWrapperClass));
+        String contents = new String(Files.readAllBytes(requestWrapperClass.toPath()));
         assertTrue(contents.indexOf("int[]") != -1);
         
         File responseWrapperClass = new File(output, pkgBase + "/SayIntArrayResponse.java");
         assertTrue(responseWrapperClass.exists());
-        contents = IOUtils.toString(new FileInputStream(responseWrapperClass));
+        contents = new String(Files.readAllBytes(responseWrapperClass.toPath()));
         assertTrue(contents.indexOf("_return") != -1);
         
         requestWrapperClass = new File(output, pkgBase + "/SayStringArray.java");
@@ -120,7 +119,7 @@ public class WrapperBeanGeneratorTest extends ProcessorTestBase {
         assertTrue(requestWrapperClass.exists());
         responseWrapperClass = new File(output, pkgBase + "/SayTestDataBeanArrayResponse.java");
         assertTrue(responseWrapperClass.exists());
-        contents = IOUtils.toString(new FileInputStream(requestWrapperClass));
+        contents = new String(Files.readAllBytes(requestWrapperClass.toPath()));
         assertTrue(contents.indexOf("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]")
!= -1);
     }
     
@@ -154,12 +153,12 @@ public class WrapperBeanGeneratorTest extends ProcessorTestBase {
         String pkgBase = "org/apache/cxf";
         File requestWrapperClass = new File(output, pkgBase + "/EchoGeneric.java");
         assertTrue(requestWrapperClass.exists());
-        String contents = IOUtils.toString(new FileInputStream(requestWrapperClass));
+        String contents = new String(Files.readAllBytes(requestWrapperClass.toPath()));
         assertTrue(contents.indexOf("public java.util.List<java.lang.String> get")
!= -1);
         
         File responseWrapperClass = new File(output, pkgBase + "/EchoGenericResponse.java");
         assertTrue(responseWrapperClass.exists());
-        contents = IOUtils.toString(new FileInputStream(responseWrapperClass));
+        contents = new String(Files.readAllBytes(responseWrapperClass.toPath()));
         assertTrue(contents.indexOf("public java.util.List<java.lang.String> getReturn()")
!= -1);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/895f9b0f/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JaxwsServiceBuilderTest.java
----------------------------------------------------------------------
diff --git a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JaxwsServiceBuilderTest.java
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JaxwsServiceBuilderTest.java
index a97c3ea..009fbcf 100644
--- a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JaxwsServiceBuilderTest.java
+++ b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JaxwsServiceBuilderTest.java
@@ -20,8 +20,8 @@
 package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.net.URI;
+import java.nio.file.Files;
 import java.util.Collection;
 
 import javax.xml.namespace.QName;
@@ -29,7 +29,6 @@ import javax.xml.namespace.QName;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxws.JaxwsServiceBuilder;
 import org.apache.cxf.service.model.BindingInfo;
 import org.apache.cxf.service.model.ServiceInfo;
@@ -307,7 +306,7 @@ public class JaxwsServiceBuilderTest extends ProcessorTestBase {
         generator.generate(output);
         assertTrue(output.exists());
 
-        String s = IOUtils.toString(new FileInputStream(output));
+        String s = new String(Files.readAllBytes(output.toPath()));
         assertTrue(s.indexOf("EchoPort") != -1);
         URI expectedFile = this.getClass()
             .getResource("expected/expected_rpclist_no_sei.wsdl").toURI();
@@ -344,18 +343,18 @@ public class JaxwsServiceBuilderTest extends ProcessorTestBase {
         File schema = new File(output, "HelloService_schema1.xsd");
         assertTrue(schema.exists());
 
-        String s = IOUtils.toString(new FileInputStream(wsdl));
+        String s = new String(Files.readAllBytes(wsdl.toPath()));
         assertTrue(s.indexOf("<wsdl:import namespace=\"http://foo.com/HelloWorld\" "
                              + "location=\"HelloWorld.wsdl\">") != -1);
         assertTrue(s.indexOf("targetNamespace=\"http://foo.com/HelloWorldService\"") != -1);
 
-        s = IOUtils.toString(new FileInputStream(logical));
+        s = new String(Files.readAllBytes(logical.toPath()));
 
         assertTrue(s.indexOf("<import namespace=\"http://foo.com/HelloWorld\"") != -1);
         assertTrue(s.indexOf("schemaLocation=\"HelloService_schema1.xsd\"/>") != -1);
         assertTrue(s.indexOf("targetNamespace=\"http://foo.com/HelloWorld\"") != -1);
 
-        s = IOUtils.toString(new FileInputStream(schema));
+        s = new String(Files.readAllBytes(schema.toPath()));
         assertTrue(s.indexOf("targetNamespace=\"http://foo.com/HelloWorld\"") != -1);
 
         generator.setAllowImports(oldSetting);


Mime
View raw message