KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > ssl > SSLException


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.ssl;
21
22 import java.text.MessageFormat JavaDoc;
23
24 /**
25  * An exception thrown by the API
26  *
27  * @author Lee David Painter <a HREF="mailto:lee@3sp.com">&lt;lee@3sp.com&gt;</a>
28  */

29 public class SSLException extends Exception JavaDoc {
30
31     /**
32      * Status codes defined by the specification
33      */

34     public static final int CLOSE_NOTIFY = 0;
35     public static final int UNEXPECTED_MESSAGE = 10;
36     public static final int BAD_RECORD_MAC = 20;
37     public static final int DECOMPRESSION_FAILURE = 30;
38     public static final int HANDSHAKE_FAILURE = 40;
39     public static final int NO_CERTIFICATE = 41;
40     public static final int BAD_CERTIFICATE = 42;
41     public static final int UNSUPPORTED_CERTIFICATE = 43;
42     public static final int CERTIFICATE_REVOKED = 44;
43     public static final int CERTIFICATE_EXPIRED = 45;
44     public static final int CERTIFICATE_UNKNOWN = 46;
45
46     /**
47      * Maverick SSL status codes
48      */

49     public static final int PROTOCOL_VIOLATION = 999;
50     public static final int UNSUPPORTED_OPERATION = 998;
51     public static final int INTERNAL_ERROR = 997;
52     public static final int UNEXPECTED_TERMINATION = 996;
53     public static final int READ_TIMEOUT = 997;
54
55     int status;
56
57     public SSLException(int status) {
58         super(getDescription(status));
59         this.status = status;
60     }
61
62     public SSLException(int status, String JavaDoc msg) {
63         super(msg);
64         this.status = status;
65     }
66
67     public int getStatus() {
68         return status;
69     }
70
71     public static String JavaDoc getDescription(int status) {
72         switch (status) {
73             case CLOSE_NOTIFY:
74                 return Messages.getString("SSLException.remoteSideClosedConnection"); //$NON-NLS-1$
75
case UNEXPECTED_MESSAGE:
76                 return Messages.getString("SSLException.unexpectedMessage"); //$NON-NLS-1$
77
case BAD_RECORD_MAC:
78                 return Messages.getString("SSLException.badRecordMAC"); //$NON-NLS-1$
79
case DECOMPRESSION_FAILURE:
80                 return Messages.getString("SSLException.decompressionFailure"); //$NON-NLS-1$
81
case HANDSHAKE_FAILURE:
82                 return Messages.getString("SSLException.handshakeFailure"); //$NON-NLS-1$
83
case NO_CERTIFICATE:
84                 return Messages.getString("SSLException.noCert"); //$NON-NLS-1$
85
case BAD_CERTIFICATE:
86                 return Messages.getString("SSLException.badCert"); //$NON-NLS-1$
87
case UNSUPPORTED_CERTIFICATE:
88                 return Messages.getString("SSLException.unsupportedCert"); //$NON-NLS-1$
89
case CERTIFICATE_REVOKED:
90                 return Messages.getString("SSLException.certRevoked"); //$NON-NLS-1$
91
case CERTIFICATE_EXPIRED:
92                 return Messages.getString("SSLException.certExpired"); //$NON-NLS-1$
93
case CERTIFICATE_UNKNOWN:
94                 return Messages.getString("SSLException.certUnknown"); //$NON-NLS-1$
95
case PROTOCOL_VIOLATION:
96                 return Messages.getString("SSLException.protocolViolation"); //$NON-NLS-1$
97
case READ_TIMEOUT:
98                 return Messages.getString("SSLException.readTimeout"); //$NON-NLS-1$
99
default:
100                 return MessageFormat.format(Messages.getString("SSLException.unexpectedStatusError"), new Object JavaDoc[] { new Integer JavaDoc(status) }); //$NON-NLS-1$
101

102         }
103     }
104
105 }
106
Popular Tags