directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1085918 - in /directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2: Dsmlv2StatesEnum.java request/Dsmlv2Grammar.java
Date Sun, 27 Mar 2011 12:15:17 GMT
Author: kayyagari
Date: Sun Mar 27 12:15:16 2011
New Revision: 1085918

URL: http://svn.apache.org/viewvc?rev=1085918&view=rev
Log:
o added support for parsing DSML requests present in SOAP envelopes

Modified:
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/Dsmlv2StatesEnum.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/Dsmlv2StatesEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/Dsmlv2StatesEnum.java?rev=1085918&r1=1085917&r2=1085918&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/Dsmlv2StatesEnum.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/Dsmlv2StatesEnum.java
Sun Mar 27 12:15:16 2011
@@ -490,6 +490,24 @@ public enum Dsmlv2StatesEnum
     /** The Search Result Reference Loop state */
     SEARCH_RESULT_REFERENCE_LOOP,
 
+    /** The soap envelop start state */
+    SOAP_ENVELOPE_START_TAG,
+    
+    /** The soap envelop end state */
+    SOAP_ENVELOPE_END_TAG,
+    
+    /** The soap header start state */
+    SOAP_HEADER_START_TAG,
+    
+    /** The soap header end state */
+    SOAP_HEADER_END_TAG,
+    
+    /** The soap body start state */
+    SOAP_BODY_START_TAG,
+    
+    /** The soap body end state */
+    SOAP_BODY_END_TAG,
+    
     /** The Search Result Done End state */
     SEARCH_RESULT_DONE_END
 }

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=1085918&r1=1085917&r2=1085918&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
Sun Mar 27 12:15:16 2011
@@ -1026,6 +1026,54 @@ public final class Dsmlv2Grammar extends
             new GrammarTransition( Dsmlv2StatesEnum.SEARCH_REQUEST_FINAL_END_TAG,
                 Dsmlv2StatesEnum.SEARCH_REQUEST_FILTER_LOOP, substringsFilterClose ) );
 
+        
+        //------------------------------------------ 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,
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: <batchRequest>
+        super.transitions[Dsmlv2StatesEnum.SOAP_BODY_START_TAG.ordinal()].put( new Tag( "batchRequest",
Tag.START ),
+            new GrammarTransition( Dsmlv2StatesEnum.SOAP_BODY_START_TAG, Dsmlv2StatesEnum.BATCHREQUEST_START_TAG,
batchRequestCreation ) );
+
+        // 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 ) );
+
+        //------------------------------------------
+
     } // End of the constructor
 
     
@@ -2847,4 +2895,54 @@ 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