Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   * 
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   * 
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  * 
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  * Sun designates this particular file as subject to the "Classpath" exception
  * as provided by Sun in the GPL Version 2 section of the License file that
  * accompanied this code.  If applicable, add the following below the License
  * Header, with the fields enclosed by brackets [] replaced by your own
  * identifying information: "Portions Copyrighted [year]
  * [name of copyright owner]"
  * 
  * Contributor(s):
  * 
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 /*
  *  Copyright 1999-2004 The Apache Software Foundation
  *
  *  Licensed 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 com.sun.enterprise.web.connector.grizzly.blocking;
 
Process HTTP request. This class is based on org.apache.coyote.http11.Http11Processor. This class must be used when NIO Blocking is enabled.

Author(s):
Jean-Francois Arcand
 
 public class ProcessorBlockingTask extends DefaultProcessorTask {
   
    
    
The wrapper used to support SSL.
 
     protected SSLImplementation sslImplementation = null;
    
     // ----------------------------------------------------- Constructor ---- //
 
     public ProcessorBlockingTask(){
         this(true);
     }
         
     public ProcessorBlockingTask(boolean init){    
         
          = ;
         if (init) {
             initialize();
         }
     }

    
    
Initialize the stream and the buffer used to parse the request.
    @Override
    public void initialize(){
         = true;   
         = new Request();
         = new Response();
        .setHook(this);
        
                                                 , true);
        
       
        .setResponse();
        initializeFilters();
    }
    // ----------------------------------------------------- Thread run ---- //
    
    
     
Execute the HTTP request by parsing the header/body, and then by delegating the process to the Catalina container.
    @Override
    public void doTask() throws IOException{
        try {
            process(.getInputStream(),.getOutputStream());
        } catch(Throwable ex){
            ex.printStackTrace();
            SelectorThread.logger().log(.,
                    "processorTask.errorProcessingRequest"ex);
        } finally {
            terminateProcess();        
        }
    }
 
     // --------------------------------------------------------- TaskEvent ---// 
        
     
    @Override
    public void taskEvent(TaskEvent event){
        if ( event.getStatus() == .) {
             = (TaskContext)event.attachement();
            if (   == null ) {
                 = new TaskEvent<TaskContext>();
            }
            
            .attach();
            execute();
        }
    }
    
    // -------------------------------------------------------------------- //
    
    
    
Process pipelined HTTP requests using the specified input and output streams.

Parameters:
input stream from which the HTTP requests will be read
output stream which will be used to output the HTTP responses
Returns:
true is an error occured.
Throws:
java.lang.Exception error during an I/O operation
    @Override
    public boolean process(InputStream inputOutputStream output)
            throws Exception {
        preProcess(input,output);            
        if ( != null) {
             = .getSSLSupport();
        }        
        doProcess(input,output);
        postProcess(input,output);
        return ;
    }
    
    
    
Pre process the request by decoding the request line and the header.

Parameters:
input the InputStream to read bytes
output the OutputStream to write bytes
     
    @Override
    public void preProcess(InputStream inputOutputStream output)
                                                            throws Exception {        
        // Make sure this object has been initialized.
        if ( ! ){
            initialize();
        }               
        // Setting up the I/O
        .setInputStream(input);
        .setOutputStream(output);  
        configPreProcess();
    }
    
    
    
Process an HTTP request using a blocking socket

Parameters:
input the InputStream to read bytes
output the OutputStream to write bytes
      
    @Override
    protected boolean doProcess(InputStream inputOutputStream output)
                                                            throws Exception {
        boolean keptAlive = false;    
        while ( && ! && ) {                
            boolean exitWhile = parseRequest(input,output,keptAlive);
            if (exitWhilebreak;                     
            invokeAdapter();            
            postResponse();
        }      
        return true;
    }
     

    
Notify the TaskListener that the request has been fully processed.
    @Override
    public void terminateProcess(){
        try{
            fireTaskEvent();
        } finally {
            clearTaskListeners();
        }
    }
    
    
    // -------------------------------------------------------------------- //
    

    
    
Set the maximum number of Keep-Alive requests to honor. This is to safeguard from DoS attacks. Setting to a negative value disables the check.
    public void setMaxKeepAliveRequests(int maxKeepAliveRequests) {
        this. = maxKeepAliveRequests;
    }


    
Return the number of Keep-Alive requests that we will honor.
    public int getMaxKeepAliveRequests() {
        return ;
    }
    
    
    
Return the number of blocking keep-alive connection
    public int countBlockingKeepAlive(){
        if ( == -1) return -1;
                
        return  - 
    }
    
    
    
    
Return the current SSLImplementation this Thread
        return ;
    }


    
Set the SSLImplementation used by this thread.It usually means HTTPS will be used.
    public void setSSLImplementationSSLImplementation sslImplementation) {
        this. = sslImplementation;
    }
    
    
    
Recyle this object.
    @Override
    public void recycle(){
         = null;
         = false;
    }
New to GrepCode? Check out our FAQ X