001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2012-2014 ForgeRock AS. 026 */ 027package org.opends.dsml.protocol; 028 029import java.io.IOException; 030import java.util.List; 031 032import org.forgerock.i18n.LocalizableMessage; 033 034import org.opends.server.protocols.ldap.AbandonRequestProtocolOp; 035import org.opends.server.protocols.ldap.LDAPMessage; 036import org.opends.server.protocols.ldap.LDAPResultCode; 037import org.opends.server.protocols.ldap.ProtocolOp; 038import org.opends.server.tools.LDAPConnection; 039import org.opends.server.types.LDAPException; 040 041 042 043/** 044 * This class provides the functionality for the performing an 045 * LDAP ABANDON operation based on the specified DSML request. 046 */ 047public class DSMLAbandonOperation 048{ 049 private LDAPConnection connection; 050 051 /** 052 * Create an instance with the specified LDAP connection. 053 * 054 * @param connection The LDAP connection to send the request on. 055 */ 056 public DSMLAbandonOperation(LDAPConnection connection) 057 { 058 this.connection = connection; 059 } 060 061 /** 062 * Perform the LDAP ABANDON operation and send the result back to the 063 * client. 064 * 065 * @param objFactory The object factory for this operation. 066 * @param abandonRequest The abandon request for this operation. 067 * @param controls Any required controls (e.g. for proxy authz). 068 * 069 * @return The result of the abandon operation. 070 * 071 * @throws IOException If an I/O problem occurs. 072 * 073 * @throws LDAPException If an error occurs while interacting with an LDAP 074 * element. 075 */ 076 public LDAPResult doOperation(ObjectFactory objFactory, 077 AbandonRequest abandonRequest, 078 List<org.opends.server.types.Control> controls) 079 throws LDAPException, IOException 080 { 081 LDAPResult abandonResponse = objFactory.createLDAPResult(); 082 083 String abandonIdStr = abandonRequest.getAbandonID(); 084 int abandonId = 0; 085 try 086 { 087 abandonId = Integer.parseInt(abandonIdStr); 088 } catch (NumberFormatException nfe) 089 { 090 throw new LDAPException(LDAPResultCode.UNWILLING_TO_PERFORM, 091 LocalizableMessage.raw(nfe.getMessage())); 092 } 093 094 // Create and send an LDAP request to the server. 095 ProtocolOp op = new AbandonRequestProtocolOp(abandonId); 096 LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op, 097 controls); 098 connection.getLDAPWriter().writeMessage(msg); 099 100 return abandonResponse; 101 } 102 103} 104