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