001/* 002 * Copyright 2008-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.extensions; 022 023 024 025import com.unboundid.ldap.sdk.Control; 026import com.unboundid.ldap.sdk.ExtendedRequest; 027import com.unboundid.ldap.sdk.ExtendedResult; 028import com.unboundid.ldap.sdk.LDAPConnection; 029import com.unboundid.ldap.sdk.LDAPException; 030import com.unboundid.ldap.sdk.ResultCode; 031import com.unboundid.ldap.sdk.unboundidds.controls. 032 IntermediateClientRequestControl; 033import com.unboundid.util.NotMutable; 034import com.unboundid.util.ThreadSafety; 035import com.unboundid.util.ThreadSafetyLevel; 036 037import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 038 039 040 041/** 042 * This class provides an implementation of the get connection ID extended 043 * operation as used in the Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 044 * 8661 Directory Server. It may be used to obtain the connection ID associated 045 * with the current connection. This is primarily useful for debugging 046 * purposes, and the {@link IntermediateClientRequestControl} may also be used 047 * to obtain this (along with other information). 048 * <BR> 049 * <BLOCKQUOTE> 050 * <B>NOTE:</B> This class, and other classes within the 051 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 052 * supported for use against Ping Identity, UnboundID, and 053 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 054 * for proprietary functionality or for external specifications that are not 055 * considered stable or mature enough to be guaranteed to work in an 056 * interoperable way with other types of LDAP servers. 057 * </BLOCKQUOTE> 058 * <BR> 059 * This extended request has an OID of 1.3.6.1.4.1.30221.1.6.2. It does not 060 * have a value. 061 * <BR> 062 * <H2>Example</H2> 063 * The following example demonstrates the process for using the get connection 064 * ID extended operation: 065 * <PRE> 066 * GetConnectionIDExtendedResult result = 067 * (GetConnectionIDExtendedResult) connection.processExtendedOperation( 068 * new GetConnectionIDExtendedRequest()); 069 * 070 * // NOTE: The processExtendedOperation method will generally only throw an 071 * // exception if a problem occurs while trying to send the request or read 072 * // the response. It will not throw an exception because of a non-success 073 * // response. 074 * 075 * if (result.getResultCode() == ResultCode.SUCCESS) 076 * { 077 * long connectionID = result.getConnectionID(); 078 * } 079 * </PRE> 080 */ 081@NotMutable() 082@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 083public final class GetConnectionIDExtendedRequest 084 extends ExtendedRequest 085{ 086 /** 087 * The OID (1.3.6.1.4.1.30221.1.6.2) for the get connection ID extended 088 * request. 089 */ 090 public static final String GET_CONNECTION_ID_REQUEST_OID = 091 "1.3.6.1.4.1.30221.1.6.2"; 092 093 094 095 /** 096 * The serial version UID for this serializable class. 097 */ 098 private static final long serialVersionUID = 4787797927715098127L; 099 100 101 102 /** 103 * Creates a new get connection ID extended request with no controls. 104 */ 105 public GetConnectionIDExtendedRequest() 106 { 107 this((Control[]) null); 108 } 109 110 111 112 /** 113 * Creates a new get connection ID extended request with the provided set of 114 * controls. 115 * 116 * @param controls The set of controls to include in the request. 117 */ 118 public GetConnectionIDExtendedRequest(final Control[] controls) 119 { 120 super(GET_CONNECTION_ID_REQUEST_OID, null, controls); 121 } 122 123 124 125 /** 126 * Creates a new get connection ID extended request from the provided generic 127 * extended request. 128 * 129 * @param extendedRequest The generic extended request to use to create this 130 * get connection ID extended request. 131 * 132 * @throws LDAPException If a problem occurs while decoding the request. 133 */ 134 public GetConnectionIDExtendedRequest(final ExtendedRequest extendedRequest) 135 throws LDAPException 136 { 137 super(extendedRequest); 138 139 if (extendedRequest.hasValue()) 140 { 141 throw new LDAPException(ResultCode.DECODING_ERROR, 142 ERR_GET_CONN_ID_REQUEST_HAS_VALUE.get()); 143 } 144 } 145 146 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override() 152 public GetConnectionIDExtendedResult process(final LDAPConnection connection, 153 final int depth) 154 throws LDAPException 155 { 156 final ExtendedResult extendedResponse = super.process(connection, depth); 157 return new GetConnectionIDExtendedResult(extendedResponse); 158 } 159 160 161 162 /** 163 * {@inheritDoc} 164 */ 165 @Override() 166 public GetConnectionIDExtendedRequest duplicate() 167 { 168 return duplicate(getControls()); 169 } 170 171 172 173 /** 174 * {@inheritDoc} 175 */ 176 @Override() 177 public GetConnectionIDExtendedRequest duplicate(final Control[] controls) 178 { 179 final GetConnectionIDExtendedRequest r = 180 new GetConnectionIDExtendedRequest(controls); 181 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); 182 return r; 183 } 184 185 186 187 /** 188 * {@inheritDoc} 189 */ 190 @Override() 191 public String getExtendedRequestName() 192 { 193 return INFO_EXTENDED_REQUEST_NAME_GET_CONNECTION_ID.get(); 194 } 195 196 197 198 /** 199 * {@inheritDoc} 200 */ 201 @Override() 202 public void toString(final StringBuilder buffer) 203 { 204 buffer.append("GetConnectionIDExtendedRequest("); 205 206 final Control[] controls = getControls(); 207 if (controls.length > 0) 208 { 209 buffer.append("controls={"); 210 for (int i=0; i < controls.length; i++) 211 { 212 if (i > 0) 213 { 214 buffer.append(", "); 215 } 216 217 buffer.append(controls[i]); 218 } 219 buffer.append('}'); 220 } 221 222 buffer.append(')'); 223 } 224}