cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [cxf] branch master updated: Tidying up the restful_dispatch demo
Date Thu, 24 May 2018 11:44:57 GMT
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 7705952  Tidying up the restful_dispatch demo
7705952 is described below

commit 77059523298743400e5099ba7ff535ed14120a31
Author: Colm O hEigeartaigh <coheigea@apache.org>
AuthorDate: Thu May 24 12:44:34 2018 +0100

    Tidying up the restful_dispatch demo
---
 .../src/main/java/demo/restful/client/Client.java  | 31 ++++++----------------
 .../restful/server/RestSourcePayloadProvider.java  | 16 +++--------
 2 files changed, 11 insertions(+), 36 deletions(-)

diff --git a/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/client/Client.java
b/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/client/Client.java
index ff28e4c..e5f8a43 100644
--- a/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/client/Client.java
+++ b/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/client/Client.java
@@ -19,19 +19,14 @@
 
 package demo.restful.client;
 
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
-import java.util.Properties;
 
 import javax.xml.namespace.QName;
-import javax.xml.transform.OutputKeys;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
@@ -89,23 +84,13 @@ public final class Client {
     }
 
     private static void printSource(Source source) {
-        try {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            StreamResult sr = new StreamResult(bos);
-            TransformerFactory transformerFactory = TransformerFactory.newInstance();
-            transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING,
true);
-            Transformer transformer = transformerFactory.newTransformer();
-            Properties oprops = new Properties();
-            oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
-            transformer.setOutputProperties(oprops);
-            transformer.transform(source, sr);
-            System.out.println("**** Response ******");
-            System.out.println(bos.toString());
-            bos.close();
-            System.out.println();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    	System.out.println("**** Response ******");
+    	try {
+			StaxUtils.copy(source, System.out);
+		} catch (XMLStreamException e) {
+			e.printStackTrace();
+		}
+    	System.out.println();
     }
 
 }
diff --git a/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/server/RestSourcePayloadProvider.java
b/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/server/RestSourcePayloadProvider.java
index ec8d209..3e823ef 100644
--- a/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/server/RestSourcePayloadProvider.java
+++ b/distribution/src/main/release/samples/restful_dispatch/src/main/java/demo/restful/server/RestSourcePayloadProvider.java
@@ -22,8 +22,6 @@ package demo.restful.server;
 import java.io.InputStream;
 
 import javax.annotation.Resource;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.ws.Provider;
 import javax.xml.ws.Service;
@@ -33,8 +31,8 @@ import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.handler.MessageContext;
 
 import org.w3c.dom.Document;
-
 import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
 
 @WebServiceProvider()
 @ServiceMode(value = Service.Mode.PAYLOAD)
@@ -87,18 +85,10 @@ public class RestSourcePayloadProvider implements Provider<DOMSource>
{
     }
 
     private DOMSource createDOMSource(String fileName) {
-        DocumentBuilderFactory factory;
-        DocumentBuilder builder;
-        Document document = null;
         DOMSource response = null;
 
-        try {
-            factory = DocumentBuilderFactory.newInstance();
-            //factory.setValidating(true);
-            builder = factory.newDocumentBuilder();
-            InputStream greetMeResponse = getClass().getResourceAsStream(fileName);
-
-            document = builder.parse(greetMeResponse);
+        try (InputStream greetMeResponse = getClass().getResourceAsStream(fileName)) {
+            Document document = StaxUtils.read(greetMeResponse);
             response = new DOMSource(document);
         } catch (Exception e) {
             e.printStackTrace();

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

Mime
View raw message