001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.exp;
020
021import java.net.URL;
022
023import lucee.runtime.config.Config;
024import lucee.runtime.type.util.KeyConstants;
025
026/**
027 * Exception class for the HTTP Handling
028 */
029public final class HTTPException extends ApplicationException {
030
031    private int statusCode;
032    private String statusText;
033        private URL url;
034
035    
036    /**
037     * Constructor of the class
038     * @param message
039     * @param detail
040     * @param statusCode
041     */
042    public HTTPException(String message, String detail, int statusCode,String statusText,URL url) {
043        super(message,detail);
044        this.statusCode=statusCode;
045        this.statusText=statusText;
046        this.url=url;
047
048        setAdditional(KeyConstants._statuscode, new Double(statusCode));
049                setAdditional(KeyConstants._statustext, statusText);
050                if(url!=null)setAdditional(KeyConstants._url, url.toExternalForm());
051    }
052
053        /**
054     * @return Returns the statusCode.
055     */
056    public int getStatusCode() {
057        return statusCode;
058    }
059
060        /**
061     * @return Returns the status text.
062     */
063    public String getStatusText() {
064        return statusText;
065    }
066    
067    public URL getURL(){
068        return url;
069    }
070
071    @Override
072        public CatchBlock getCatchBlock(Config config) {
073                CatchBlock sct = super.getCatchBlock(config);
074        sct.setEL("statusCode",statusCode+"");
075        sct.setEL("statusText",statusText);
076        if(url!=null)sct.setEL("url",url.toExternalForm());
077        return sct;
078    }
079}