001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.server.ldap.handlers.request; 021 022 023import org.apache.directory.api.ldap.model.message.LdapResult; 024import org.apache.directory.api.ldap.model.message.ModifyRequest; 025import org.apache.directory.api.ldap.model.message.ModifyResponse; 026import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 027import org.apache.directory.server.core.api.CoreSession; 028import org.apache.directory.server.ldap.LdapSession; 029import org.apache.directory.server.ldap.handlers.LdapRequestHandler; 030 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034 035/** 036 * A single reply MessageReceived handler for {@link ModifyRequest}s. 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public class ModifyRequestHandler extends LdapRequestHandler<ModifyRequest> 041{ 042 private static final Logger LOG = LoggerFactory.getLogger( ModifyRequestHandler.class ); 043 044 045 /** 046 * {@inheritDoc} 047 */ 048 public void handle( LdapSession session, ModifyRequest modifyRequest ) 049 { 050 LOG.debug( "Handling request : {}", modifyRequest ); 051 052 ModifyResponse modifyResponse = ( ModifyResponse ) modifyRequest.getResultResponse(); 053 054 LdapResult result = modifyResponse.getLdapResult(); 055 056 try 057 { 058 // Call the underlying layer to delete the entry 059 CoreSession coreSession = session.getCoreSession(); 060 coreSession.modify( modifyRequest ); 061 062 // If success, here now, otherwise, we would have an exception. 063 result.setResultCode( ResultCodeEnum.SUCCESS ); 064 065 // Write the DeleteResponse message 066 session.getIoSession().write( modifyResponse ); 067 } 068 catch ( Exception e ) 069 { 070 handleException( session, modifyRequest, modifyResponse, e ); 071 } 072 } 073}