001/*
002 * Copyright 2008-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2020 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) 2015-2020 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.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051
052import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
053
054
055
056/**
057 * This class provides an implementation of the get connection ID extended
058 * operation as used in the Ping Identity, UnboundID, and Nokia/Alcatel-Lucent
059 * 8661 Directory Server.  It may be used to obtain the connection ID associated
060 * with the current connection.  This is primarily useful for debugging
061 * purposes, and the {@link IntermediateClientRequestControl} may also be used
062 * to obtain this (along with other information).
063 * <BR>
064 * <BLOCKQUOTE>
065 *   <B>NOTE:</B>  This class, and other classes within the
066 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
067 *   supported for use against Ping Identity, UnboundID, and
068 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
069 *   for proprietary functionality or for external specifications that are not
070 *   considered stable or mature enough to be guaranteed to work in an
071 *   interoperable way with other types of LDAP servers.
072 * </BLOCKQUOTE>
073 * <BR>
074 * This extended request has an OID of 1.3.6.1.4.1.30221.1.6.2.  It does not
075 * have a value.
076 * <BR>
077 * <H2>Example</H2>
078 * The following example demonstrates the process for using the get connection
079 * ID extended operation:
080 * <PRE>
081 * GetConnectionIDExtendedResult result =
082 *      (GetConnectionIDExtendedResult) connection.processExtendedOperation(
083 *           new GetConnectionIDExtendedRequest());
084 *
085 * // NOTE:  The processExtendedOperation method will generally only throw an
086 * // exception if a problem occurs while trying to send the request or read
087 * // the response.  It will not throw an exception because of a non-success
088 * // response.
089 *
090 * if (result.getResultCode() == ResultCode.SUCCESS)
091 * {
092 *   long connectionID = result.getConnectionID();
093 * }
094 * </PRE>
095 */
096@NotMutable()
097@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
098public final class GetConnectionIDExtendedRequest
099       extends ExtendedRequest
100{
101  /**
102   * The OID (1.3.6.1.4.1.30221.1.6.2) for the get connection ID extended
103   * request.
104   */
105  public static final String GET_CONNECTION_ID_REQUEST_OID =
106       "1.3.6.1.4.1.30221.1.6.2";
107
108
109
110  /**
111   * The serial version UID for this serializable class.
112   */
113  private static final long serialVersionUID = 4787797927715098127L;
114
115
116
117  /**
118   * Creates a new get connection ID extended request with no controls.
119   */
120  public GetConnectionIDExtendedRequest()
121  {
122    this((Control[]) null);
123  }
124
125
126
127  /**
128   * Creates a new get connection ID extended request with the provided set of
129   * controls.
130   *
131   * @param  controls  The set of controls to include in the request.
132   */
133  public GetConnectionIDExtendedRequest(final Control[] controls)
134  {
135    super(GET_CONNECTION_ID_REQUEST_OID, null, controls);
136  }
137
138
139
140  /**
141   * Creates a new get connection ID extended request from the provided generic
142   * extended request.
143   *
144   * @param  extendedRequest  The generic extended request to use to create this
145   *                          get connection ID extended request.
146   *
147   * @throws  LDAPException  If a problem occurs while decoding the request.
148   */
149  public GetConnectionIDExtendedRequest(final ExtendedRequest extendedRequest)
150         throws LDAPException
151  {
152    super(extendedRequest);
153
154    if (extendedRequest.hasValue())
155    {
156      throw new LDAPException(ResultCode.DECODING_ERROR,
157                              ERR_GET_CONN_ID_REQUEST_HAS_VALUE.get());
158    }
159  }
160
161
162
163  /**
164   * {@inheritDoc}
165   */
166  @Override()
167  public GetConnectionIDExtendedResult process(final LDAPConnection connection,
168                                               final int depth)
169         throws LDAPException
170  {
171    final ExtendedResult extendedResponse = super.process(connection, depth);
172    return new GetConnectionIDExtendedResult(extendedResponse);
173  }
174
175
176
177  /**
178   * {@inheritDoc}
179   */
180  @Override()
181  public GetConnectionIDExtendedRequest duplicate()
182  {
183    return duplicate(getControls());
184  }
185
186
187
188  /**
189   * {@inheritDoc}
190   */
191  @Override()
192  public GetConnectionIDExtendedRequest duplicate(final Control[] controls)
193  {
194    final GetConnectionIDExtendedRequest r =
195         new GetConnectionIDExtendedRequest(controls);
196    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
197    return r;
198  }
199
200
201
202  /**
203   * {@inheritDoc}
204   */
205  @Override()
206  public String getExtendedRequestName()
207  {
208    return INFO_EXTENDED_REQUEST_NAME_GET_CONNECTION_ID.get();
209  }
210
211
212
213  /**
214   * {@inheritDoc}
215   */
216  @Override()
217  public void toString(final StringBuilder buffer)
218  {
219    buffer.append("GetConnectionIDExtendedRequest(");
220
221    final Control[] controls = getControls();
222    if (controls.length > 0)
223    {
224      buffer.append("controls={");
225      for (int i=0; i < controls.length; i++)
226      {
227        if (i > 0)
228        {
229          buffer.append(", ");
230        }
231
232        buffer.append(controls[i]);
233      }
234      buffer.append('}');
235    }
236
237    buffer.append(')');
238  }
239}