You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2022/07/27 03:07:34 UTC

[directory-ldap-api] branch master updated: * Added a test for ResponseError without RequestID * Fixed the DSML parser to deal with missing the optional RequestID field

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new a800c2593 * Added a test for ResponseError without RequestID * Fixed the DSML parser to deal with missing the optional RequestID field
a800c2593 is described below

commit a800c25936e51b51c8294521395f9f3694377c6b
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Wed Jul 27 05:07:15 2022 +0200

    * Added a test for ResponseError without RequestID
    * Fixed the DSML parser to deal with missing the optional RequestID
    field
---
 .../api/dsmlv2/response/Dsmlv2ResponseGrammar.java | 72 +++++++++++++++++++++-
 .../dsmlv2/batchResponse/BatchResponseTest.java    | 41 ++++++++++++
 .../response_with_empty_ID_ErrorResponse.xml       | 34 ++++++++++
 3 files changed, 146 insertions(+), 1 deletion(-)

diff --git a/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/response/Dsmlv2ResponseGrammar.java b/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/response/Dsmlv2ResponseGrammar.java
index c8b6cfff3..8c938e28f 100644
--- a/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/response/Dsmlv2ResponseGrammar.java
+++ b/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/response/Dsmlv2ResponseGrammar.java
@@ -148,6 +148,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -155,6 +156,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 batchResponse.setRequestID( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                batchResponse.setRequestID( -1 );
+            }
         }
     };
 
@@ -179,6 +185,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -186,6 +193,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 addResponse.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                addResponse.setMessageId( -1 );
+            }
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
@@ -225,6 +237,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -233,6 +246,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
                 bindResponse.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
 
             }
+            else
+            {
+                // The request ID is optional 
+                bindResponse.setMessageId( -1 );
+            }
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
@@ -272,6 +290,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -279,6 +298,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 compareResponse.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                compareResponse.setMessageId( -1 );
+            }
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
@@ -318,6 +342,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -325,6 +350,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 delResponse.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                delResponse.setMessageId( -1 );
+            }
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
@@ -364,6 +394,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -371,6 +402,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 modifyResponse.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                modifyResponse.setMessageId( -1 );
+            }
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
@@ -410,6 +446,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -417,6 +454,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 modDNResponse.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                modDNResponse.setMessageId( -1 );
+            }
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
@@ -515,6 +557,14 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
                 container.getBatchResponse().addResponse( errorResponse );
             }
+            else
+            {
+                // No request ID: no problem, it's optional
+                errorResponse = new ErrorResponse( -1, null );
+
+                container.getBatchResponse().addResponse( errorResponse );
+
+            }
 
             // type
             attributeValue = xpp.getAttributeValue( "", "type" );
@@ -929,7 +979,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             }
             else
             {
-                searchResponse = new SearchResponse();
+                searchResponse = new SearchResponse( -1 );
             }
 
             container.getBatchResponse().addResponse( new SearchResponseDsml(
@@ -960,6 +1010,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the request's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -967,6 +1018,11 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 searchResultEntry.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                searchResultEntry.setMessageId( -1 );
+            }
 
             // dn
             attributeValue = xpp.getAttributeValue( "", "dn" );
@@ -1015,6 +1071,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the request's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -1022,6 +1079,12 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 searchResultReference.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                searchResultReference.setMessageId( -1 );
+            }
+
         }
     };
 
@@ -1049,6 +1112,7 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
 
             // Checking and adding the batchRequest's attributes
             String attributeValue;
+            
             // requestID
             attributeValue = xpp.getAttributeValue( "", "requestID" );
 
@@ -1056,6 +1120,12 @@ public final class Dsmlv2ResponseGrammar extends AbstractGrammar implements Gram
             {
                 searchResultDone.setMessageId( ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) );
             }
+            else
+            {
+                // The request ID is optional 
+                searchResultDone.setMessageId( -1 );
+            }
+
 
             // MatchedDN
             attributeValue = xpp.getAttributeValue( "", "matchedDN" );
diff --git a/dsml/parser/src/test/java/org/apache/directory/api/dsmlv2/batchResponse/BatchResponseTest.java b/dsml/parser/src/test/java/org/apache/directory/api/dsmlv2/batchResponse/BatchResponseTest.java
index 47aa5b7cb..9b3a1c91a 100644
--- a/dsml/parser/src/test/java/org/apache/directory/api/dsmlv2/batchResponse/BatchResponseTest.java
+++ b/dsml/parser/src/test/java/org/apache/directory/api/dsmlv2/batchResponse/BatchResponseTest.java
@@ -30,6 +30,7 @@ import org.apache.directory.api.dsmlv2.DsmlDecorator;
 import org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser;
 import org.apache.directory.api.dsmlv2.response.BatchResponseDsml;
 import org.apache.directory.api.dsmlv2.response.ErrorResponse;
+import org.apache.directory.api.dsmlv2.response.ErrorResponse.ErrorResponseType;
 import org.apache.directory.api.dsmlv2.response.SearchResponse;
 import org.apache.directory.api.ldap.model.message.AddResponse;
 import org.apache.directory.api.ldap.model.message.BindResponse;
@@ -797,4 +798,44 @@ public class BatchResponseTest extends AbstractResponseTest
             fail();
         }
     }
+    
+    
+    /**
+     * Test parsing of a Response with the 2 SearchResponse
+     */
+    @Test
+    public void testResponseWithEmptyIDErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser( getCodec() );
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_empty_ID_ErrorResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            fail( e.getMessage() );
+        }
+
+        BatchResponseDsml batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ErrorResponse )
+        {
+            assertTrue( true );
+            assertEquals( ErrorResponseType.COULD_NOT_CONNECT, ((ErrorResponse)response).getErrorType());
+        }
+        else
+        {
+            fail();
+        }
+    }
 }
diff --git a/dsml/parser/src/test/resources/org/apache/directory/api/dsmlv2/batchResponse/response_with_empty_ID_ErrorResponse.xml b/dsml/parser/src/test/resources/org/apache/directory/api/dsmlv2/batchResponse/response_with_empty_ID_ErrorResponse.xml
new file mode 100644
index 000000000..61556f631
--- /dev/null
+++ b/dsml/parser/src/test/resources/org/apache/directory/api/dsmlv2/batchResponse/response_with_empty_ID_ErrorResponse.xml
@@ -0,0 +1,34 @@
+<?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
+
+    https://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.
+-->
+<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
+  <soap:Header>
+    <Action xmlns="http://www.w3.org/2005/08/addressing">urn:ihe:iti:2010:ProviderInformationFeedResponse</Action>
+    <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:e7b4def8-0ad7-46d9-b9db-3389b6c3c7f7</MessageID>
+    <To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
+    <RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:e529d797-d54f-41c0-8cea-d5e2c194afbf</RelatesTo>
+  </soap:Header>
+  <soap:Body>
+    <batchResponse xmlns="urn:oasis:names:tc:DSML:2:0:core" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+      <errorResponse type="couldNotConnect">
+        <message>ERR_04110_CANNOT_CONNECT_TO_SERVER Cannot connect to the server: Connection refused</message>
+      </errorResponse>
+    </batchResponse>
+  </soap:Body>
+</soap:Envelope>