directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1343583 - in /directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2: ParserUtils.java reponse/Dsmlv2ResponseGrammar.java request/Dsmlv2Grammar.java
Date Tue, 29 May 2012 07:39:33 GMT
Author: kayyagari
Date: Tue May 29 07:39:32 2012
New Revision: 1343583

URL: http://svn.apache.org/viewvc?rev=1343583&view=rev
Log:
o added support for parsing responses present in a soap envelope
o moved the soap header parsing code to ParserUtils

Modified:
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/Dsmlv2ResponseGrammar.java
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java?rev=1343583&r1=1343582&r2=1343583&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
Tue May 29 07:39:32 2012
@@ -20,6 +20,7 @@
 package org.apache.directory.shared.dsmlv2;
 
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
 
@@ -319,4 +320,55 @@ public final class ParserUtils
         Document transformedDoc = result.getDocument();
         return transformedDoc;
     }
+    
+    
+    /**
+     * GrammarAction that reads the SOAP header data
+     */
+    public static final GrammarAction readSoapHeader = new GrammarAction( "Reads SOAP header"
)
+    {
+        public void action( Dsmlv2Container container ) throws XmlPullParserException
+        {
+            try
+            {
+                XmlPullParser xpp = container.getParser();
+                StringBuilder sb = new StringBuilder();
+
+                String startTag = xpp.getText();
+                sb.append( startTag );
+
+                // string '<' and '>'
+                startTag = startTag.substring( 1, startTag.length() - 1 );
+
+                int tagType = -1;
+                String endTag = "";
+
+                // continue parsing till we get to the end tag of SOAP header
+                // and match the tag values including the namespace
+                while ( !startTag.equals( endTag ) )
+                {
+                    tagType = xpp.next();
+                    endTag = xpp.getText();
+                    sb.append( endTag );
+
+                    if ( tagType == XmlPullParser.END_TAG )
+                    {
+                        // strip '<', '/' and '>'
+                        endTag = endTag.substring( 2, endTag.length() - 1 );
+                    }
+                }
+
+                // change the state to header end
+                container.setState( Dsmlv2StatesEnum.SOAP_HEADER_END_TAG );
+
+                //System.out.println( sb );
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace();
+            }
+
+        }
+    };
+    
 }

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/Dsmlv2ResponseGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/Dsmlv2ResponseGrammar.java?rev=1343583&r1=1343582&r2=1343583&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/Dsmlv2ResponseGrammar.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/Dsmlv2ResponseGrammar.java
Tue May 29 07:39:32 2012
@@ -72,7 +72,6 @@ import org.apache.directory.shared.util.
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
-
 /**
  * This Class represents the DSMLv2 Response Grammar
  * 
@@ -814,6 +813,59 @@ public final class Dsmlv2ResponseGrammar
             Tag.START ),
             new GrammarTransition( Dsmlv2StatesEnum.SEARCH_RESULT_REFERENCE_LOOP, Dsmlv2StatesEnum.LDAP_RESULT,
                 searchResultDoneCreation ) );
+        
+        //------------------------------------------ handle SOAP envelopes --------------------------
+        super.transitions[Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG.ordinal()] = new HashMap<Tag,
GrammarTransition>();
+        super.transitions[Dsmlv2StatesEnum.SOAP_HEADER_START_TAG.ordinal()] = new HashMap<Tag,
GrammarTransition>();
+        super.transitions[Dsmlv2StatesEnum.SOAP_HEADER_END_TAG.ordinal()] = new HashMap<Tag,
GrammarTransition>();
+        super.transitions[Dsmlv2StatesEnum.SOAP_BODY_START_TAG.ordinal()] = new HashMap<Tag,
GrammarTransition>();
+        super.transitions[Dsmlv2StatesEnum.SOAP_BODY_END_TAG.ordinal()] = new HashMap<Tag,
GrammarTransition>();
+
+        super.transitions[Dsmlv2StatesEnum.GRAMMAR_END.ordinal()] = new HashMap<Tag, GrammarTransition>();
+
+        // State: [INIT_GRAMMAR_STATE] - Tag: <envelope>
+        super.transitions[Dsmlv2StatesEnum.INIT_GRAMMAR_STATE.ordinal()].put( new Tag( "envelope",
Tag.START ),
+            new GrammarTransition( Dsmlv2StatesEnum.INIT_GRAMMAR_STATE, Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG,
+                null ) );
+
+        // state: [SOAP_ENVELOPE_START_TAG] -> Tag: <header>
+        super.transitions[Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG.ordinal()].put( new Tag(
"header", Tag.START ),
+            new GrammarTransition( Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG, Dsmlv2StatesEnum.SOAP_HEADER_START_TAG,
+            		ParserUtils.readSoapHeader ) );
+
+        // state: [SOAP_HEADER_START_TAG] -> Tag: </header>
+        super.transitions[Dsmlv2StatesEnum.SOAP_HEADER_START_TAG.ordinal()]
+            .put( new Tag( "header", Tag.END ),
+                new GrammarTransition( Dsmlv2StatesEnum.SOAP_HEADER_START_TAG, Dsmlv2StatesEnum.SOAP_HEADER_END_TAG,
+                    null ) );
+
+        // state: [SOAP_HEADER_END_TAG] -> Tag: <body>
+        super.transitions[Dsmlv2StatesEnum.SOAP_HEADER_END_TAG.ordinal()].put( new Tag( "body",
Tag.START ),
+            new GrammarTransition( Dsmlv2StatesEnum.SOAP_HEADER_END_TAG, Dsmlv2StatesEnum.SOAP_BODY_START_TAG,
null ) );
+
+        // state: [SOAP_BODY_START_TAG] -> Tag: <batchResponse>
+        super.transitions[Dsmlv2StatesEnum.SOAP_BODY_START_TAG.ordinal()].put( new Tag( "batchResponse",
Tag.START ),
+            new GrammarTransition( Dsmlv2StatesEnum.SOAP_BODY_START_TAG, Dsmlv2StatesEnum.BATCH_RESPONSE_LOOP,
+                batchResponseCreation ) );
+
+        // the optional transition if no soap header is present
+        // state: [SOAP_ENVELOPE_START_TAG] -> Tag: <body>
+        super.transitions[Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG.ordinal()]
+            .put( new Tag( "body", Tag.START ),
+                new GrammarTransition( Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG, Dsmlv2StatesEnum.SOAP_BODY_START_TAG,
+                    null ) );
+
+        // the below two transitions are a bit unconventional, technically the container's
state is set to GRAMMAR_END
+        // when the </batchRequest> tag is encountered by the parser and the corresponding
action gets executed but in
+        // a SOAP envelop we still have two more end tags(</body> and </envelope>)
are left so we set those corresponding
+        // current and next transition states always to GRAMMAR_END
+        super.transitions[Dsmlv2StatesEnum.GRAMMAR_END.ordinal()].put( new Tag( "body", Tag.END
),
+            new GrammarTransition( Dsmlv2StatesEnum.GRAMMAR_END, Dsmlv2StatesEnum.GRAMMAR_END,
null ) );
+
+        super.transitions[Dsmlv2StatesEnum.GRAMMAR_END.ordinal()].put( new Tag( "envelope",
Tag.END ),
+            new GrammarTransition( Dsmlv2StatesEnum.GRAMMAR_END, Dsmlv2StatesEnum.GRAMMAR_END,
null ) );
+
+        //------------------------------------------
     }
 
     /**

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java?rev=1343583&r1=1343582&r2=1343583&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
Tue May 29 07:39:32 2012
@@ -73,6 +73,7 @@ import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
 
+
 /**
  * This Class represents the DSMLv2 Request Grammar
  *
@@ -1138,7 +1139,7 @@ public final class Dsmlv2Grammar extends
         // state: [SOAP_ENVELOPE_START_TAG] -> Tag: <header>
         super.transitions[Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG.ordinal()].put( new Tag(
"header", Tag.START ),
             new GrammarTransition( Dsmlv2StatesEnum.SOAP_ENVELOPE_START_TAG, Dsmlv2StatesEnum.SOAP_HEADER_START_TAG,
-                readSoapHeader ) );
+                ParserUtils.readSoapHeader ) );
 
         // state: [SOAP_HEADER_START_TAG] -> Tag: </header>
         super.transitions[Dsmlv2StatesEnum.SOAP_HEADER_START_TAG.ordinal()]
@@ -1190,7 +1191,7 @@ public final class Dsmlv2Grammar extends
     //*************************
 
     /**
-     * GrammarAction that creates an Abandon Request
+     * GrammarAction that creates a Batch Request
      */
     private final GrammarAction batchRequestCreation = new GrammarAction( "Create Batch Request"
)
     {
@@ -2993,53 +2994,4 @@ public final class Dsmlv2Grammar extends
             }
         }
     };
-
-    /**
-     * GrammarAction that reads the SOAP header data
-     */
-    private final GrammarAction readSoapHeader = new GrammarAction( "Reads SOAP header" )
-    {
-        public void action( Dsmlv2Container container ) throws XmlPullParserException
-        {
-            try
-            {
-                XmlPullParser xpp = container.getParser();
-                StringBuilder sb = new StringBuilder();
-
-                String startTag = xpp.getText();
-                sb.append( startTag );
-
-                // string '<' and '>'
-                startTag = startTag.substring( 1, startTag.length() - 1 );
-
-                int tagType = -1;
-                String endTag = "";
-
-                // continue parsing till we get to the end tag of SOAP header
-                // and match the tag values including the namespace
-                while ( !startTag.equals( endTag ) )
-                {
-                    tagType = xpp.next();
-                    endTag = xpp.getText();
-                    sb.append( endTag );
-
-                    if ( tagType == XmlPullParser.END_TAG )
-                    {
-                        // strip '<', '/' and '>'
-                        endTag = endTag.substring( 2, endTag.length() - 1 );
-                    }
-                }
-
-                // change the state to header end
-                container.setState( Dsmlv2StatesEnum.SOAP_HEADER_END_TAG );
-
-                //System.out.println( sb );
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();
-            }
-
-        }
-    };
 }



Mime
View raw message