Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce JSchProxyException to replace generic JschException in Proxy implementations #467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/com/jcraft/jsch/JSchProxyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jcraft.jsch;

public class JSchProxyException extends JSchException {
private static final long serialVersionUID = -1L;

public JSchProxyException(String s) {
super(s);
}

public JSchProxyException(String s, Throwable e) {
super(s, e);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/jcraft/jsch/ProxyHTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
} catch (Exception eee) {
}
String message = "ProxyHTTP: " + e.toString();
throw new JSchException(message, e);
throw new JSchProxyException(message, e);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/jcraft/jsch/ProxySOCKS4.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
buf[index++] = byteAddress[i];
}
} catch (UnknownHostException uhe) {
throw new JSchException("ProxySOCKS4: " + uhe.toString(), uhe);
throw new JSchProxyException("ProxySOCKS4: " + uhe.toString(), uhe);
}

if (user != null) {
Expand Down Expand Up @@ -156,20 +156,20 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
while (s < len) {
int i = in.read(buf, s, len - s);
if (i <= 0) {
throw new JSchException("ProxySOCKS4: stream is closed");
throw new JSchProxyException("ProxySOCKS4: stream is closed");
}
s += i;
}
if (buf[0] != 0) {
throw new JSchException("ProxySOCKS4: server returns VN " + buf[0]);
throw new JSchProxyException("ProxySOCKS4: server returns VN " + buf[0]);
}
if (buf[1] != 90) {
try {
socket.close();
} catch (Exception eee) {
}
String message = "ProxySOCKS4: server returns CD " + buf[1];
throw new JSchException(message);
throw new JSchProxyException(message);
}
} catch (RuntimeException e) {
throw e;
Expand All @@ -179,7 +179,7 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
socket.close();
} catch (Exception eee) {
}
throw new JSchException("ProxySOCKS4: " + e.toString(), e);
throw new JSchProxyException("ProxySOCKS4: " + e.toString(), e);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jcraft/jsch/ProxySOCKS5.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
socket.close();
} catch (Exception eee) {
}
throw new JSchException("fail in SOCKS5 proxy");
throw new JSchProxyException("fail in SOCKS5 proxy");
}

/*
Expand Down Expand Up @@ -239,7 +239,7 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
socket.close();
} catch (Exception eee) {
}
throw new JSchException("ProxySOCKS5: server returns " + buf[1]);
throw new JSchProxyException("ProxySOCKS5: server returns " + buf[1]);
}

switch (buf[3] & 0xff) {
Expand Down Expand Up @@ -268,7 +268,7 @@ public void connect(SocketFactory socket_factory, String host, int port, int tim
} catch (Exception eee) {
}
String message = "ProxySOCKS5: " + e.toString();
throw new JSchException(message, e);
throw new JSchProxyException(message, e);
}
}

Expand Down Expand Up @@ -312,7 +312,7 @@ private void fill(InputStream in, byte[] buf, int len) throws JSchException, IOE
while (s < len) {
int i = in.read(buf, s, len - s);
if (i <= 0) {
throw new JSchException("ProxySOCKS5: stream is closed");
throw new JSchProxyException("ProxySOCKS5: stream is closed");
}
s += i;
}
Expand Down