001/** 002 * 003 * Copyright 2020 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.util.rce; 018 019import org.jivesoftware.smack.util.ToStringUtil; 020 021import org.minidns.dnsname.DnsName; 022 023public abstract class RemoteConnectionEndpointLookupFailure { 024 025 private final String description; 026 private final Exception exception; 027 028 public RemoteConnectionEndpointLookupFailure(String description, Exception exception) { 029 this.description = description; 030 this.exception = exception; 031 } 032 033 public final String getDescription() { 034 return description; 035 } 036 037 public final Exception getException() { 038 return exception; 039 } 040 041 public String getErrorMessage() { 042 return description + " because: " + exception; 043 } 044 045 private transient String toStringCache; 046 047 @Override 048 public String toString() { 049 if (toStringCache == null) { 050 toStringCache = ToStringUtil.builderFor(RemoteConnectionEndpointLookupFailure.class) 051 .addValue("description", description) 052 .addValue("exception", exception) 053 .build(); 054 } 055 return toStringCache; 056 } 057 058 public static class DnsLookupFailure extends RemoteConnectionEndpointLookupFailure { 059 private final DnsName dnsName; 060 061 public DnsLookupFailure(DnsName dnsName, Exception exception) { 062 super("DNS lookup exception for " + dnsName, exception); 063 this.dnsName = dnsName; 064 } 065 066 public DnsName getDnsName() { 067 return dnsName; 068 } 069 } 070}