Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You 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.apache.catalina.connector;
 
 import static org.jboss.web.CatalinaMessages.MESSAGES;
 
 
 
Facade class that wraps a Coyote response object. All methods are delegated to the wrapped response.

Author(s):
Remy Maucherat
Jean-Francois Arcand
Version:
$Revision: 2025 $ $Date: 2012-04-16 12:24:28 +0200 (Mon, 16 Apr 2012) $
 
 @SuppressWarnings("deprecation")
 public class ResponseFacade 
 
 
     // ----------------------------------------------------------- DoPrivileged
     
     private final class SetContentTypePrivilegedAction
             implements PrivilegedAction {
 
         private String contentType;
 
         public SetContentTypePrivilegedAction(String contentType){
             this. = contentType;
         }
         
         public Object run() {
             .setContentType();
             return null;
         }            
     }
 
     private final class DateHeaderPrivilegedAction
             implements PrivilegedAction {
 
         private String name;
         private long value;
         private boolean add;
 
         DateHeaderPrivilegedAction(String namelong valueboolean add) {
             this. = name;
             this. = value;
             this. = add;
         }
 
         public Object run() {
             if() {
                 .addDateHeader();
             } else {
                 .setDateHeader();
             }
             return null;
         }
     }
     
     // ----------------------------------------------------------- Constructors
 

    
Construct a wrapper for the specified response.

Parameters:
response The response to be wrapped
    public ResponseFacade(Response response) {
         this. = response;
    }
    // ----------------------------------------------- Class/Instance Variables


    
The wrapped response.
    protected Response response = null;
    // --------------------------------------------------------- Public Methods


    
Clear facade.
    public void clear() {
         = null;
    }


    
Prevent cloning the facade.
    protected Object clone()
        throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }
    public void finish() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        .setSuspended(true);
    }
    public boolean isFinished() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .isSuspended();
    }
    // ------------------------------------------------ ServletResponse Methods
    public String getCharacterEncoding() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getCharacterEncoding();
    }
        throws IOException {
        //        if (isFinished())
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);
        ServletOutputStream sos = .getOutputStream();
        if (isFinished())
            .setSuspended(true);
        return (sos);
    }
    public PrintWriter getWriter()
        throws IOException {
        //        if (isFinished())
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);
        PrintWriter writer = .getWriter();
        if (isFinished())
            .setSuspended(true);
        return (writer);
    }
    public void setContentLength(int len) {
        if (isCommitted())
            return;
        .setContentLength(len);
    }
    public void setContentType(String type) {
        if (isCommitted())
            return;
        
        if (SecurityUtil.isPackageProtectionEnabled()){
            AccessController.doPrivileged(new SetContentTypePrivilegedAction(type));
        } else {
            .setContentType(type);            
        }
    }
    public void setBufferSize(int size) {
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .setBufferSize(size);
    }
    public int getBufferSize() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getBufferSize();
    }
    public void flushBuffer()
        throws IOException {
        if (isFinished())
            //            throw new IllegalStateException
            //                (/*sm.getString("responseFacade.finished")*/);
            return;
        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedExceptionAction(){
                    public Object run() throws IOException{
                        .setAppCommitted(true);
                        .flushBuffer();
                        return null;
                    }
                });
            } catch(PrivilegedActionException e){
                Exception ex = e.getException();
                if (ex instanceof IOException){
                    throw (IOException)ex;
                }
            }
        } else {
            .setAppCommitted(true);
            .flushBuffer();            
        }
    }
    public void resetBuffer() {
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .resetBuffer();
    }
    public boolean isCommitted() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return (.isAppCommitted());
    }
    public void reset() {
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .reset();
    }
    public void setLocale(Locale loc) {
        if (isCommitted())
            return;
        .setLocale(loc);
    }
    public Locale getLocale() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getLocale();
    }
    public void addCookie(Cookie cookie) {
        if (isCommitted())
            return;
        .addCookie(cookie);
    }
    public boolean containsHeader(String name) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .containsHeader(name);
    }
    public String encodeURL(String url) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .encodeURL(url);
    }
    public String encodeRedirectURL(String url) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .encodeRedirectURL(url);
    }
    public String encodeUrl(String url) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .encodeURL(url);
    }
    public String encodeRedirectUrl(String url) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .encodeRedirectURL(url);
    }
    public void sendError(int scString msg)
        throws IOException {
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .setAppCommitted(true);
        .sendError(scmsg);
    }
    public void sendError(int sc)
        throws IOException {
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .setAppCommitted(true);
        .sendError(sc);
    }
    public void sendRedirect(String location)
        throws IOException {
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .setAppCommitted(true);
        .sendRedirect(location);
    }
    public void sendFile(String pathString absolutePathlong startlong end) {
        
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .setAppCommitted(true);
        .sendFile(pathabsolutePathstartend);
    }
    public void startUpgrade() {
        
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .startUpgrade();
    }
    public void sendUpgrade()
            throws IOException {
        
        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);
        .setAppCommitted(true);
        .sendUpgrade();
    }
    public void setDateHeader(String namelong date) {
        if (isCommitted())
            return;
        if(.) {
            AccessController.doPrivileged(new DateHeaderPrivilegedAction
                                             (namedatefalse));
        } else {
            .setDateHeader(namedate);
        }
    }
    public void addDateHeader(String namelong date) {
        if (isCommitted())
            return;
        if(.) {
            AccessController.doPrivileged(new DateHeaderPrivilegedAction
                                             (namedatetrue));
        } else {
            .addDateHeader(namedate);
        }
    }
    public void setHeader(String nameString value) {
        if (isCommitted())
            return;
        .setHeader(namevalue);
    }
    public void addHeader(String nameString value) {
        if (isCommitted())
            return;
        .addHeader(namevalue);
    }
    public void setIntHeader(String nameint value) {
        if (isCommitted())
            return;
        .setIntHeader(namevalue);
    }
    public void addIntHeader(String nameint value) {
        if (isCommitted())
            return;
        .addIntHeader(namevalue);
    }
    public void setStatus(int sc) {
        if (isCommitted())
            return;
        .setStatus(sc);
    }
    public void setStatus(int scString sm) {
        if (isCommitted())
            return;
        .setStatus(scsm);
    }
    public String getContentType() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getContentType();
    }
    public void setCharacterEncoding(String arg0) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        .setCharacterEncoding(arg0);
    }
    public String getHeader(String name) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getHeader(name);
    }
    public Collection<StringgetHeaderNames() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getHeaderNames();
    }
    public Collection<StringgetHeaders(String name) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getHeaders(name);
    }
    public int getStatus() {
        if ( == null) {
            throw .nullResponseFacade();
        }
        return .getStatus();
    }
    public void setContentLengthLong(long contentLength) {
        if ( == null) {
            throw .nullResponseFacade();
        }
        .setContentLengthLong(contentLength);
    }
New to GrepCode? Check out our FAQ X