You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2021/12/24 14:58:12 UTC

[GitHub] [cxf] reta opened a new pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

reta opened a new pull request #887:
URL: https://github.com/apache/cxf/pull/887


   StaxTransformFeature deep-dropping doesn't work with any element


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #887:
URL: https://github.com/apache/cxf/pull/887#discussion_r775245355



##########
File path: core/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
##########
@@ -69,6 +69,116 @@ public void testReplaceSimpleElement() throws Exception {
         String value = bos.toString();
         assertEquals("<ns:test xmlns:ns=\"http://bar\"><ns:a>1 2 3</ns:a></ns:test>", value);
     }
+    
+    @Test

Review comment:
       Thank you for suggestion @hypervisorfdi , there is a large chunk of code which deals with namespaces, the tests exercise both flows: elements with / without namespaces.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #887:
URL: https://github.com/apache/cxf/pull/887#discussion_r775185383



##########
File path: core/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
##########
@@ -262,12 +262,22 @@ private void handleDefaultMode(QName name, QName expected) {
 
     private void handleDeepDrop() throws XMLStreamException {
         final int depth = getDepth();
-        while (depth != getDepth() || super.next() != XMLStreamConstants.END_ELEMENT) {
-            // get to the matching end element event
+        int read = 0;
+        while (depth != getDepth() || hasNext()) {

Review comment:
       👍 thank you




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] hypervisorfdi commented on a change in pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
hypervisorfdi commented on a change in pull request #887:
URL: https://github.com/apache/cxf/pull/887#discussion_r775178308



##########
File path: core/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
##########
@@ -262,12 +262,22 @@ private void handleDefaultMode(QName name, QName expected) {
 
     private void handleDeepDrop() throws XMLStreamException {
         final int depth = getDepth();
-        while (depth != getDepth() || super.next() != XMLStreamConstants.END_ELEMENT) {
-            // get to the matching end element event
+        int read = 0;
+        while (depth != getDepth() || hasNext()) {

Review comment:
       think you can drop `depth != depth()` condition along side depth declaration. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] hypervisorfdi commented on a change in pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
hypervisorfdi commented on a change in pull request #887:
URL: https://github.com/apache/cxf/pull/887#discussion_r775216735



##########
File path: core/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
##########
@@ -69,6 +69,116 @@ public void testReplaceSimpleElement() throws Exception {
         String value = bos.toString();
         assertEquals("<ns:test xmlns:ns=\"http://bar\"><ns:a>1 2 3</ns:a></ns:test>", value);
     }
+    
+    @Test

Review comment:
       The namespace is not adding any additional benefit other than taking space, small refactor could help.
   here is a suggestion:
   
   ```
       @Test
       public void testDropComplexElement() throws Exception {
           String template = "<greetMe>%s<email>alex.just@nowhere</email></greetMe>";
           String expected = String.format(template, "<age>35</age>");
           String inXml = String.format(template, "<skippedElement><age>35</age></skippedElement>");
           verifyTransformation(expected, inXml, null, Collections.singletonList("skippedElement"));
       }
   
       @Test
       public void testDropComplexElementByReplacement() throws Exception {
           String template = "<greetMe><firstname>Alex</firstname>%s<email>alex.just@nowhere</email></greetMe>";
           String expected = String.format(template, "");
           String inXml = String.format(template, "<skippedElement><age>35</age></skippedElement>");
           verifyTransformation(expected, inXml, Collections.singletonMap("skippedElement", ""), null);
       }
   
       @Test
       public void testDropComplexElementLastByReplacement() throws Exception {
           String template = "<greetMe><firstname>Alex</firstname><lastname>Just</lastname>%s</greetMe>";
           String expected = String.format(template, "");
           String inXml = String.format(template, "<skippedElement><age>35</age></skippedElement>");
           verifyTransformation(expected, inXml, Collections.singletonMap("skippedElement", ""), null);
       }
   
       @Test
       public void testDropSimpleElementByReplacement() throws Exception {
           String template = "<greetMe><firstname>Alex</firstname><lastname>Just</lastname>%s</greetMe>";
           String expected = String.format(template, "<skippedElement/>");
           String inXml = String.format(template, "<skippedElement><age>35</age></skippedElement>");
           verifyTransformation(expected, inXml, Collections.singletonMap("age", ""), null);
       }
   
       private void verifyTransformation(String expected, 
       		String inXml, 
       		Map<String, String> inEMap, 
       		List<String> dropESet) throws XMLStreamException {
   
           InputStream is = new ByteArrayInputStream(inXml.getBytes());
           XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
           reader = new InTransformReader(reader,
                                           inEMap,
                                           null,
                                           dropESet,
                                           null, false);
   
           ByteArrayOutputStream bos = new ByteArrayOutputStream();
           StaxUtils.copy(reader, bos);
           String value = bos.toString();
           assertEquals(expected, value);
       }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #887:
URL: https://github.com/apache/cxf/pull/887#discussion_r775245477



##########
File path: core/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
##########
@@ -261,13 +261,22 @@ private void handleDefaultMode(QName name, QName expected) {
     }
 
     private void handleDeepDrop() throws XMLStreamException {
-        final int depth = getDepth();
-        while (depth != getDepth() || super.next() != XMLStreamConstants.END_ELEMENT) {
-            // get to the matching end element event
+        int read = 0;
+        while (hasNext()) {
+            // get to the matching end element event (accounting for all inner elements)
+            final int event = super.next();
+            if (event == XMLStreamConstants.START_ELEMENT) {
+                ++read;
+            } else if (event == XMLStreamConstants.END_ELEMENT) {
+                if (read == 0) {

Review comment:
       Matter of preferences, I will keep it the way it is now




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] hypervisorfdi commented on a change in pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
hypervisorfdi commented on a change in pull request #887:
URL: https://github.com/apache/cxf/pull/887#discussion_r775216802



##########
File path: core/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
##########
@@ -261,13 +261,22 @@ private void handleDefaultMode(QName name, QName expected) {
     }
 
     private void handleDeepDrop() throws XMLStreamException {
-        final int depth = getDepth();
-        while (depth != getDepth() || super.next() != XMLStreamConstants.END_ELEMENT) {
-            // get to the matching end element event
+        int read = 0;
+        while (hasNext()) {
+            // get to the matching end element event (accounting for all inner elements)
+            final int event = super.next();
+            if (event == XMLStreamConstants.START_ELEMENT) {
+                ++read;
+            } else if (event == XMLStreamConstants.END_ELEMENT) {
+                if (read == 0) {

Review comment:
       since break never executes else:
   
   ```
                   if (read == 0) {
                       break; 
                   }
                   read--;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta merged pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
reta merged pull request #887:
URL: https://github.com/apache/cxf/pull/887


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on pull request #887: CXF-8632: StaxTransformFeature deep-dropping doesn't work with any element

Posted by GitBox <gi...@apache.org>.
reta commented on pull request #887:
URL: https://github.com/apache/cxf/pull/887#issuecomment-1000907663


   @coheigea @ffang @dkulp guys not sure who is familiar with this code, but would really appreciate if someone glances through, essentially fixing endless loop, thank you!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org