View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.server.ldap.handlers.extended;
21  
22  
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest;
28  import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponse;
29  import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponseImpl;
30  import org.apache.directory.api.ldap.model.message.ExtendedRequest;
31  import org.apache.directory.api.ldap.model.message.ExtendedResponse;
32  import org.apache.directory.server.core.api.CoreSession;
33  import org.apache.directory.server.ldap.ExtendedOperationHandler;
34  import org.apache.directory.server.ldap.LdapServer;
35  import org.apache.directory.server.ldap.LdapSession;
36  import org.slf4j.Logger;
37  import org.slf4j.LoggerFactory;
38  
39  
40  /**
41   * An handler to manage the EndTransaction extended request operation
42   *
43   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
44   */
45  public class EndTransactionHandler implements ExtendedOperationHandler<ExtendedRequest, ExtendedResponse>
46  {
47      private static final Logger LOG = LoggerFactory.getLogger( EndTransactionHandler.class );
48      public static final Set<String> EXTENSION_OIDS;
49  
50      static
51      {
52          Set<String> set = new HashSet<>( 2 );
53          set.add( EndTransactionRequest.EXTENSION_OID );
54          set.add( EndTransactionResponse.EXTENSION_OID );
55          EXTENSION_OIDS = Collections.unmodifiableSet( set );
56      }
57  
58  
59      /**
60       * {@inheritDoc}
61       */
62      public String getOid()
63      {
64          return EndTransactionRequest.EXTENSION_OID;
65      }
66  
67  
68      /**
69       * {@inheritDoc}
70       */
71      public void handleExtendedOperation( LdapSession session, ExtendedRequest req ) throws Exception
72      {
73          LOG.debug( "EndTransaction requested" );
74          
75          // We need to create a new transaction ID for the current session.
76          // If the current session is already processing a transaction, we will return an error
77          CoreSession coreSession = session.getCoreSession();
78          coreSession.endSessionTransaction( ( ( EndTransactionRequest ) req ).getCommit() );
79  
80          EndTransactionResponse endTransactionResponse = new EndTransactionResponseImpl( req.getMessageId() );
81  
82          // Store the StartTransaction request name in the response, to be able to
83          // encode the response properly.
84          // Kurt Zeilenga should have set a responseName to make it easier to 
85          // implement in RFC 5805 :/
86          endTransactionResponse.setResponseName( EndTransactionRequest.EXTENSION_OID );
87  
88          // write the response
89          session.getIoSession().write( endTransactionResponse );
90      }
91  
92  
93      /**
94       * {@inheritDoc}
95       */
96      public Set<String> getExtensionOids()
97      {
98          return EXTENSION_OIDS;
99      }
100 
101 
102     /**
103      * {@inheritDoc}
104      */
105     public void setLdapServer( LdapServer ldapServer )
106     {
107     }
108 }