mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-09-27 18:19:33 +02:00
2a4d110b22
The exception message now also contains the stream hosts and their exception.
88 lines
2.9 KiB
Java
88 lines
2.9 KiB
Java
/**
|
|
*
|
|
* Copyright 2019 Florian Schmaus.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package org.jivesoftware.smackx.bytestreams.socks5;
|
|
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
import org.jivesoftware.smack.SmackException;
|
|
|
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
|
|
|
public abstract class Socks5Exception extends SmackException {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
protected Socks5Exception(String message) {
|
|
super(message);
|
|
}
|
|
|
|
public static final class NoSocks5StreamHostsProvided extends Socks5Exception {
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
NoSocks5StreamHostsProvided() {
|
|
super("No SOCKS5 stream hosts provided.");
|
|
}
|
|
}
|
|
|
|
public static final class CouldNotConnectToAnyProvidedSocks5Host extends Socks5Exception {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private final Map<StreamHost, Exception> streamHostsExceptions;
|
|
|
|
private CouldNotConnectToAnyProvidedSocks5Host(String message, Map<StreamHost, Exception> streamHostsExceptions) {
|
|
super(message);
|
|
this.streamHostsExceptions = Collections.unmodifiableMap(streamHostsExceptions);
|
|
}
|
|
|
|
public Map<StreamHost, Exception> getStreamHostsExceptions() {
|
|
return streamHostsExceptions;
|
|
}
|
|
|
|
static CouldNotConnectToAnyProvidedSocks5Host construct(Map<StreamHost, Exception> streamHostsExceptions) {
|
|
assert !streamHostsExceptions.isEmpty();
|
|
|
|
StringBuilder sb = new StringBuilder(256);
|
|
sb.append("Could not establish socket with any provided SOCKS5 stream host.");
|
|
Iterator<StreamHost> it = streamHostsExceptions.keySet().iterator();
|
|
while (it.hasNext()) {
|
|
StreamHost streamHost = it.next();
|
|
Exception exception = streamHostsExceptions.get(streamHost);
|
|
|
|
sb.append(' ').append(streamHost).append(" Exception: '").append(exception).append('\'');
|
|
if (it.hasNext()) {
|
|
sb.append(',');
|
|
}
|
|
}
|
|
|
|
String message = sb.toString();
|
|
return new CouldNotConnectToAnyProvidedSocks5Host(message, streamHostsExceptions);
|
|
}
|
|
}
|
|
}
|