| | |
| | | import javax.net.ssl.SSLHandshakeException; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized message for a given properties key an throwable. |
| | | * |
| | | * @param message |
| | | * prefix |
| | | * @param t |
| | | * the throwable for which we want to get a message. |
| | | * @return a localized message for a given properties key and throwable. |
| | | */ |
| | | public static LocalizableMessage getThrowableMsg(final LocalizableMessage message, final Throwable t) { |
| | | final LocalizableMessageBuilder mb = new LocalizableMessageBuilder(message); |
| | | LocalizableMessageDescriptor.Arg1<Object> tag; |
| | | if (isOutOfMemory(t)) { |
| | | tag = INFO_EXCEPTION_OUT_OF_MEMORY_DETAILS; |
| | | } else { |
| | | tag = INFO_EXCEPTION_DETAILS; |
| | | } |
| | | String detail = t.toString(); |
| | | if (detail != null) { |
| | | mb.append(" ").append(tag.get(detail)); |
| | | } |
| | | return mb.toMessage(); |
| | | } |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if we can write on the provided path and <CODE>false</CODE> otherwise. |
| | | * |
| | | * @param path |
| | |
| | | * Returns {@code true} if the the provided string is a DN and {@code false} otherwise. |
| | | * |
| | | * @param dn |
| | | * the String we are analyzing. |
| | | * The String we are analyzing. |
| | | * @return {@code true} if the the provided string is a DN and {@code false} otherwise. |
| | | */ |
| | | public static boolean isDN(String dn) { |
| | |
| | | * The UID to be used to generate the DN. |
| | | * @return The DN of the administrator for the given UID. |
| | | */ |
| | | private static String getAdministratorDN(String uid) { |
| | | public static String getAdministratorDN(String uid) { |
| | | return "cn=" + RDN.valueOf(uid) + ",cn=Administrators, cn=admin data"; |
| | | } |
| | | |
| | | /** |
| | | * Tells whether this throwable has been generated for an out of memory error or not. |
| | | * |
| | | * @param t |
| | | * The throwable to analyze. |
| | | * @return {@code true} if the throwable was generated by an out of memory error and false otherwise. |
| | | */ |
| | | private static boolean isOutOfMemory(Throwable t) { |
| | | boolean isOutOfMemory = false; |
| | | while (!isOutOfMemory && (t != null)) { |
| | | if (t instanceof OutOfMemoryError) { |
| | | isOutOfMemory = true; |
| | | } else if (t instanceof IOException) { |
| | | final String msg = t.toString(); |
| | | if (msg != null) { |
| | | isOutOfMemory = msg.contains("Not enough space"); |
| | | } |
| | | } |
| | | t = t.getCause(); |
| | | } |
| | | return isOutOfMemory; |
| | | } |
| | | } |