001/*
002 * Copyright 2010-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 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.logs;
022
023
024
025import java.util.Collections;
026import java.util.LinkedList;
027import java.util.List;
028import java.util.StringTokenizer;
029
030import com.unboundid.util.NotMutable;
031import com.unboundid.util.ThreadSafety;
032import com.unboundid.util.ThreadSafetyLevel;
033
034
035
036/**
037 * This class provides a data structure that holds information about a log
038 * message that may appear in the Directory Server access log about an
039 * intermediate response returned to a client.
040 * <BR>
041 * <BLOCKQUOTE>
042 *   <B>NOTE:</B>  This class, and other classes within the
043 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
044 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
045 *   server products.  These classes provide support for proprietary
046 *   functionality or for external specifications that are not considered stable
047 *   or mature enough to be guaranteed to work in an interoperable way with
048 *   other types of LDAP servers.
049 * </BLOCKQUOTE>
050 */
051@NotMutable()
052@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
053public final class IntermediateResponseAccessLogMessage
054       extends OperationRequestAccessLogMessage
055{
056  /**
057   * The serial version UID for this serializable class.
058   */
059  private static final long serialVersionUID = 4480365381503945078L;
060
061
062
063  // The operation type for this access log message.
064  private final AccessLogOperationType operationType;
065
066  // The list of response control OIDs for the operation.
067  private final List<String> responseControlOIDs;
068
069  // A human-readable version of the intermediate response name.
070  private final String name;
071
072  // The OID of the intermediate response.
073  private final String oid;
074
075  // A human-readable version of the intermediate response value.
076  private final String value;
077
078
079
080  /**
081   * Creates a new intermediate response access log message from the provided
082   * message string.
083   *
084   * @param  s  The string to be parsed as an intermediate response access log
085   *            message.
086   *
087   * @throws  LogException  If the provided string cannot be parsed as a valid
088   *                        log message.
089   */
090  public IntermediateResponseAccessLogMessage(final String s)
091         throws LogException
092  {
093    this(new LogMessage(s));
094  }
095
096
097
098  /**
099   * Creates a new intermediate response access log message from the provided
100   * log message.
101   *
102   * @param  m  The log message to be parsed as an intermediate response access
103   *            log message.
104   */
105  public IntermediateResponseAccessLogMessage(final LogMessage m)
106  {
107    super(m);
108
109    oid   = getNamedValue("oid");
110    name  = getNamedValue("name");
111    value = getNamedValue("value");
112
113    final String controlStr = getNamedValue("responseControls");
114    if (controlStr == null)
115    {
116      responseControlOIDs = Collections.emptyList();
117    }
118    else
119    {
120      final LinkedList<String> controlList = new LinkedList<String>();
121      final StringTokenizer t = new StringTokenizer(controlStr, ",");
122      while (t.hasMoreTokens())
123      {
124        controlList.add(t.nextToken());
125      }
126      responseControlOIDs = Collections.unmodifiableList(controlList);
127    }
128
129    if (m.hasUnnamedValue(AccessLogOperationType.ADD.getLogIdentifier()))
130    {
131      operationType = AccessLogOperationType.ADD;
132    }
133    else if (m.hasUnnamedValue(AccessLogOperationType.BIND.getLogIdentifier()))
134    {
135      operationType = AccessLogOperationType.BIND;
136    }
137    else if (m.hasUnnamedValue(AccessLogOperationType.
138         COMPARE.getLogIdentifier()))
139    {
140      operationType = AccessLogOperationType.COMPARE;
141    }
142    else if (m.hasUnnamedValue(AccessLogOperationType.
143         DELETE.getLogIdentifier()))
144    {
145      operationType = AccessLogOperationType.DELETE;
146    }
147    else if (m.hasUnnamedValue(AccessLogOperationType.
148         EXTENDED.getLogIdentifier()))
149    {
150      operationType = AccessLogOperationType.EXTENDED;
151    }
152    else if (m.hasUnnamedValue(AccessLogOperationType.
153         MODIFY.getLogIdentifier()))
154    {
155      operationType = AccessLogOperationType.MODIFY;
156    }
157    else if (m.hasUnnamedValue(AccessLogOperationType.MODDN.getLogIdentifier()))
158    {
159      operationType = AccessLogOperationType.MODDN;
160    }
161    else if (m.hasUnnamedValue(
162         AccessLogOperationType.SEARCH.getLogIdentifier()))
163    {
164      operationType = AccessLogOperationType.SEARCH;
165    }
166    else
167    {
168      // This shouldn't happen, but we'll assume it's extended.
169      operationType = AccessLogOperationType.EXTENDED;
170    }
171  }
172
173
174
175  /**
176   * Retrieves the OID of the intermediate response.
177   *
178   * @return  The OID of the intermediate response, or {@code null} if it is
179   *          not included in the log message.
180   */
181  public String getOID()
182  {
183    return oid;
184  }
185
186
187
188  /**
189   * Retrieves a human-readable name for the intermediate response.
190   *
191   * @return  A human-readable name for the intermediate response, or
192   *          {@code null} if it is not included in the log message.
193   */
194  public String getIntermediateResponseName()
195  {
196    return name;
197  }
198
199
200
201  /**
202   * Retrieves a human-readable representation of the intermediate response
203   * value.
204   *
205   * @return  A human-readable representation of the intermediate response
206   *          value, or {@code null} if it is not included in the log message.
207   */
208  public String getValueString()
209  {
210    return value;
211  }
212
213
214
215  /**
216   * Retrieves the OIDs of any response controls contained in the log message.
217   *
218   * @return  The OIDs of any response controls contained in the log message, or
219   *          an empty list if it is not included in the log message.
220   */
221  public List<String> getResponseControlOIDs()
222  {
223    return responseControlOIDs;
224  }
225
226
227
228  /**
229   * {@inheritDoc}
230   */
231  @Override()
232  public AccessLogMessageType getMessageType()
233  {
234    return AccessLogMessageType.INTERMEDIATE_RESPONSE;
235  }
236
237
238
239  /**
240   * {@inheritDoc}
241   */
242  @Override()
243  public AccessLogOperationType getOperationType()
244  {
245    return operationType;
246  }
247}