001/* 002 * Copyright 2015-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; 022 023 024 025import com.unboundid.asn1.ASN1OctetString; 026import com.unboundid.util.NotExtensible; 027import com.unboundid.util.NotMutable; 028import com.unboundid.util.StaticUtils; 029import com.unboundid.util.ThreadSafety; 030import com.unboundid.util.ThreadSafetyLevel; 031 032 033 034/** 035 * This class defines an exception that can be thrown if the server returns an 036 * extended response that indicates that the operation did not complete 037 * successfully. This may be used to obtain access to any response OID and/or 038 * value that may have been included in the extended result. 039 */ 040@NotExtensible() 041@NotMutable() 042@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 043public class LDAPExtendedOperationException 044 extends LDAPException 045{ 046 /** 047 * The serial version UID for this serializable class. 048 */ 049 private static final long serialVersionUID = -5674215690199642408L; 050 051 052 053 // The extended result for this exception. 054 private final ExtendedResult extendedResult; 055 056 057 058 /** 059 * Creates a new LDAP extended operation exception from the provided extended 060 * result. 061 * 062 * @param extendedResult The extended result to use to create this 063 * exception. 064 */ 065 public LDAPExtendedOperationException(final ExtendedResult extendedResult) 066 { 067 super(extendedResult); 068 069 this.extendedResult = extendedResult; 070 } 071 072 073 074 /** 075 * {@inheritDoc} 076 */ 077 @Override() 078 public LDAPResult toLDAPResult() 079 { 080 return extendedResult; 081 } 082 083 084 085 /** 086 * Retrieves the extended result that was returned by the server. 087 * 088 * @return The extended result that was returned by the server. 089 */ 090 public ExtendedResult getExtendedResult() 091 { 092 return extendedResult; 093 } 094 095 096 097 /** 098 * Retrieves the response OID from the extended result, if any. 099 * 100 * @return The response OID from the extended result, or {@code null} if the 101 * result did not include an OID. 102 */ 103 public String getResponseOID() 104 { 105 return extendedResult.getOID(); 106 } 107 108 109 110 /** 111 * Retrieves the response value from the extended result, if any. 112 * 113 * @return The response value from the extended result, or {@code null} if 114 * the result did not include a value. 115 */ 116 public ASN1OctetString getResponseValue() 117 { 118 return extendedResult.getValue(); 119 } 120 121 122 123 /** 124 * {@inheritDoc} 125 */ 126 @Override() 127 public void toString(final StringBuilder buffer) 128 { 129 super.toString(buffer); 130 } 131 132 133 134 /** 135 * {@inheritDoc} 136 */ 137 @Override() 138 public void toString(final StringBuilder buffer, final boolean includeCause, 139 final boolean includeStackTrace) 140 { 141 buffer.append("LDAPException(resultCode="); 142 buffer.append(getResultCode()); 143 144 final String errorMessage = getMessage(); 145 final String diagnosticMessage = getDiagnosticMessage(); 146 if ((errorMessage != null) && (! errorMessage.equals(diagnosticMessage))) 147 { 148 buffer.append(", errorMessage='"); 149 buffer.append(errorMessage); 150 buffer.append('\''); 151 } 152 153 final String responseOID = getResponseOID(); 154 if (responseOID != null) 155 { 156 buffer.append(", responseOID='"); 157 buffer.append(responseOID); 158 buffer.append('\''); 159 } 160 161 final String responseName = extendedResult.getExtendedResultName(); 162 if ((responseName != null) && (! responseName.equals(responseOID))) 163 { 164 buffer.append(", responseName='"); 165 buffer.append(responseName); 166 buffer.append('\''); 167 } 168 169 if (diagnosticMessage != null) 170 { 171 buffer.append(", diagnosticMessage='"); 172 buffer.append(diagnosticMessage); 173 buffer.append('\''); 174 } 175 176 final String matchedDN = getMatchedDN(); 177 if (matchedDN != null) 178 { 179 buffer.append(", matchedDN='"); 180 buffer.append(matchedDN); 181 buffer.append('\''); 182 } 183 184 final String[] referralURLs = getReferralURLs(); 185 if (referralURLs.length > 0) 186 { 187 buffer.append(", referralURLs={"); 188 189 for (int i=0; i < referralURLs.length; i++) 190 { 191 if (i > 0) 192 { 193 buffer.append(", "); 194 } 195 196 buffer.append('\''); 197 buffer.append(referralURLs[i]); 198 buffer.append('\''); 199 } 200 201 buffer.append('}'); 202 } 203 204 final Control[] responseControls = getResponseControls(); 205 if (responseControls.length > 0) 206 { 207 buffer.append(", responseControls={"); 208 209 for (int i=0; i < responseControls.length; i++) 210 { 211 if (i > 0) 212 { 213 buffer.append(", "); 214 } 215 216 buffer.append(responseControls[i]); 217 } 218 219 buffer.append('}'); 220 } 221 222 if (includeStackTrace) 223 { 224 buffer.append(", trace='"); 225 StaticUtils.getStackTrace(getStackTrace(), buffer); 226 buffer.append('\''); 227 } 228 229 final String ldapSDKVersionString = ", ldapSDKVersion=" + 230 Version.NUMERIC_VERSION_STRING + ", revision=" + Version.REVISION_ID; 231 if (buffer.indexOf(ldapSDKVersionString) < 0) 232 { 233 buffer.append(ldapSDKVersionString); 234 } 235 236 buffer.append(')'); 237 } 238}