Home | History | Annotate | Download | only in jsse
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package org.apache.harmony.xnet.provider.jsse;
     19 
     20 import javax.net.ssl.SSLException;
     21 
     22 /**
     23  * This exception is used to signal that a fatal alert has occurred while working through the
     24  * protocol.
     25  */
     26 public class AlertException extends RuntimeException {
     27 
     28     private static final long serialVersionUID = -4448327177165687581L;
     29     // SSLException to be thrown to application side
     30     private final SSLException reason;
     31     // alert description code
     32     private final byte description;
     33 
     34     /**
     35      * Constructs the instance.
     36      *
     37      * @param description The alert description code from {@link AlertProtocol}
     38      * @param reason The SSLException to be thrown to application side after alert processing
     39      *            (sending the record with alert, shutdown work, etc).
     40      * @see AlertProtocol
     41      */
     42     protected AlertException(byte description, SSLException reason) {
     43         super(reason);
     44         this.reason = reason;
     45         this.description = description;
     46     }
     47 
     48     /**
     49      * Returns the reason of alert. This reason should be rethrown after alert processing.
     50      *
     51      * @return the reason of alert.
     52      */
     53     protected SSLException getReason() {
     54         return reason;
     55     }
     56 
     57     /**
     58      * Returns alert's description code.
     59      *
     60      * @return alert description code from {@link AlertProtocol}
     61      * @see AlertProtocol for more information about possible reason codes.
     62      */
     63     protected byte getDescriptionCode() {
     64         return description;
     65     }
     66 }
     67