Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * 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 org.apache.coyote.http11;
 
 
 
Abstract the protocol implementation, including threading, etc. Processor is single threaded and specific to stream-based protocols, will not fit Jk protocols like JNI.

Author(s):
Remy Maucherat
Costin Manolache
 
 public class Http11AprProtocol implements ProtocolHandlerMBeanRegistration {
 
     public Http11AprProtocol() {
         //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
     }

    
Pass config info
 
     public void setAttributeString nameObject value ) {
         .put(namevalue);
     }
 
     public Object getAttributeString key ) {
         return .get(key);
     }
 
     public Iterator getAttributeNames() {
         return .keySet().iterator();
     }

    
The adapter, used to call the connector.
 
     protected Adapter adapter;
     public void setAdapter(Adapter adapter) { this. = adapter; }
     public Adapter getAdapter() { return ; }
 
     private boolean canDestroy = false;
 
 
     public boolean hasIoEvents() {
         return true;
     }
 
     public RequestGroupInfo getRequestGroupInfo() {
         return .;
     }


    
Start the protocol
 
     public void init() throws Exception {
        .setName(getName());
        .setHandler();
        try {
            .init();
        } catch (Exception ex) {
            throw ex;
        }
    }
    public void start() throws Exception {
        if (.....) {
            ifthis. != null ) {
                try {
                    =new ObjectName
                            ( + ":" + "type=ThreadPool,name=" + getJmxName());
                    Registry.getRegistry(nullnull)
                    .registerComponent(null );
                } catch (Exception e) {
                    ..errorRegisteringPool(e);
                }
                =new ObjectName
                        ( + ":type=GlobalRequestProcessor,name=" + getJmxName());
                Registry.getRegistry(nullnull).registerComponent
                ( .null );
            }
        }
        try {
            .start();
        } catch (Exception ex) {
            throw ex;
        }
    }
    public void pause() throws Exception {
        try {
            .pause();
        } catch (Exception ex) {
            throw ex;
        }
         = false;
        // Wait for a while until all the processors are idle
        RequestInfo[] states = ..getRequestProcessors();
        int retry = 0;
        boolean done = false;
        while (!done && retry < ....) {
            retry++;
            done = true;
            for (int i = 0; i < states.lengthi++) {
                if (states[i].getStage() == ....) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        ;
                    }
                    done = false;
                    break;
                }
            }
            if (done) {
                 = true;
            }
        }
    }
    public void resume() throws Exception {
        try {
            .resume();
        } catch (Exception ex) {
            throw ex;
        }
    }
    public void destroy() throws Exception {
        if () {
            .destroy();
        } else {
            try {
                RequestInfo[] states = ..getRequestProcessors();
                for (int i = 0; i < states.lengthi++) {
                    if (states[i].getStage() == ....) {
                        // FIXME: Log RequestInfo content
                    }
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
        if (.....) {
            if!=null )
                Registry.getRegistry(nullnull).unregisterComponent();
            if != null )
                Registry.getRegistry(nullnull).unregisterComponent();
        }
    }
    public String getJmxName() {
        String encodedAddr = "";
        if (getAddress() != null) {
            encodedAddr = "" + getAddress();
            encodedAddr = URLEncoder.encode(encodedAddr.replace('/''-').replace(':''_').replace('%''-')) + "-";
        }
        return ("http-" + encodedAddr + .getPort());
    }
    public String getName() {
        String encodedAddr = "";
        if (getAddress() != null) {
            encodedAddr = getAddress() + ":";
        }
        return ("http-" + encodedAddr + .getPort());
    }
    protected AprEndpoint endpoint=new AprEndpoint();
    protected HashMap<StringObjectattributes = new HashMap<StringObject>();
    private Http11ConnectionHandler cHandler = new Http11ConnectionHandler(this);

    
Processor cache.
    protected int processorCache = -1;
    public int getProcessorCache() { return this.; }
    public void setProcessorCache(int processorCache) { this. = processorCache; }
    public Executor getExecutor() { return .getExecutor(); }
    public void setExecutor(Executor executor) { .setExecutor(executor); }
    
    public int getMaxThreads() { return .getMaxThreads(); }
    public void setMaxThreads(int maxThreads) { .setMaxThreads(maxThreads); }
    public int getThreadPriority() { return .getThreadPriority(); }
    public void setThreadPriority(int threadPriority) { .setThreadPriority(threadPriority); }
    public int getBacklog() { return .getBacklog(); }
    public void setBacklog(int backlog) { .setBacklog(backlog); }
    public int getPort() { return .getPort(); }
    public void setPort(int port) { .setPort(port); }
    public InetAddress getAddress() { return .getAddress(); }
    public void setAddress(InetAddress ia) { .setAddress(ia); }
    public boolean getTcpNoDelay() { return .getTcpNoDelay(); }
    public void setTcpNoDelay(boolean tcpNoDelay) { .setTcpNoDelay(tcpNoDelay); }
    public int getSoLinger() { return .getSoLinger(); }
    public void setSoLinger(int soLinger) { .setSoLinger(soLinger); }
    public int getSoTimeout() { return .getSoTimeout(); }
    public void setSoTimeout(int soTimeout) { .setSoTimeout(soTimeout); }
    public boolean getReverseConnection() { return .isReverseConnection(); }
    public void setReverseConnection(boolean reverseConnection) { .setReverseConnection(reverseConnection); }
    public boolean getDeferAccept() { return .getDeferAccept(); }
    public void setDeferAccept(boolean deferAccept) { .setDeferAccept(deferAccept); }

    
The number of seconds Tomcat will wait for a subsequent request before closing the connection.
    public int getKeepAliveTimeout() { return .getKeepAliveTimeout(); }
    public void setKeepAliveTimeout(int timeout) { .setKeepAliveTimeout(timeout); }
    public boolean getUseSendfile() { return .getUseSendfile(); }
    public void setUseSendfile(boolean useSendfile) { .setUseSendfile(useSendfile); }
    public int getPollTime() { return .getPollTime(); }
    public void setPollTime(int pollTime) { .setPollTime(pollTime); }
    public void setPollerSize(int pollerSize) { .setPollerSize(pollerSize); }
    public int getPollerSize() { return .getPollerSize(); }
    public int getSendfileSize() { return .getSendfileSize(); }
    public void setSendfileSize(int sendfileSize) { .setSendfileSize(sendfileSize); }
    
    protected int socketBuffer = 9000;
    public int getSocketBuffer() { return ; }
    public void setSocketBuffer(int socketBuffer) { this. = socketBuffer; }

    
Maximum size of the post which will be saved when processing certain requests, such as a POST.
    protected int maxSavePostSize = 4 * 1024;
    public int getMaxSavePostSize() { return ; }
    public void setMaxSavePostSize(int valueI) {  = valueI; }
    // HTTP
    
Maximum size of the HTTP message header.
    protected int maxHttpHeaderSize = Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.MAX_HEADER_SIZE""8192")).intValue();
    public int getMaxHttpHeaderSize() { return ; }
    public void setMaxHttpHeaderSize(int valueI) {  = valueI; }
    // HTTP
    
If true, the regular socket timeout will be used for the full duration of the connection.
    public boolean getDisableUploadTimeout() { return ; }
    public void setDisableUploadTimeout(boolean isDisabled) {  = isDisabled; }
    // HTTP
    
Integrated compression support.
    protected String compression = System.getProperty("org.apache.coyote.http11.Http11Protocol.COMPRESSION""off");
    public String getCompression() { return ; }
    public void setCompression(String valueS) {  = valueS; }
    
    
    // HTTP
    protected String noCompressionUserAgents = System.getProperty("org.apache.coyote.http11.Http11Protocol.COMPRESSION_RESTRICTED_UA");
    public void setNoCompressionUserAgents(String valueS) {  = valueS; }
    
    // HTTP
    protected String compressableMimeTypes = System.getProperty("org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES""text/html,text/xml,text/plain");
    public String getCompressableMimeType() { return ; }
    public void setCompressableMimeType(String valueS) {  = valueS; }
    
    
    // HTTP
    protected int compressionMinSize = Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIN_SIZE""2048")).intValue();
    public int getCompressionMinSize() { return ; }
    public void setCompressionMinSize(int valueI) {  = valueI; }
    // HTTP
    
User agents regular expressions which should be restricted to HTTP/1.0 support.
    protected String restrictedUserAgents = null;
    public String getRestrictedUserAgents() { return ; }
    public void setRestrictedUserAgents(String valueS) {  = valueS; }
    
    
    // HTTP
    protected String protocol = null;
    public String getProtocol() { return ; }
    public void setProtocol(String protocol) { setSecure(true); this. = protocol; }

    
Maximum number of requests which can be performed over a keepalive connection. The default is the same as for Apache HTTP Server.
    protected int maxKeepAliveRequests = Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.MAX_KEEP_ALIVE_REQUESTS""-1")).intValue();
    public int getMaxKeepAliveRequests() { return ; }
    public void setMaxKeepAliveRequests(int mkar) {  = mkar; }

    
Return the Keep-Alive policy for the connection.
    public boolean getKeepAlive() {
        return (( != 0) && ( != 1));
    }

    
Set the keep-alive policy for this connection.
    public void setKeepAlive(boolean keepAlive) {
        if (!keepAlive) {
            setMaxKeepAliveRequests(1);
        }
    }

    
Server header.
    protected String server = System.getProperty("org.apache.coyote.http11.Http11Protocol.SERVER");
    public void setServerString server ) { this. = server; }
    public String getServer() { return ; }

    
This timeout represents the socket timeout which will be used while the adapter execution is in progress, unless disableUploadTimeout is set to true. The default is the same as for Apache HTTP Server (300 000 milliseconds).
    protected int timeout = 300000;
    public int getTimeout() { return ; }
    public void setTimeout(int timeout) { this. = timeout; }

    
This field indicates if the protocol is secure from the perspective of the client (= https is used).
    protected boolean secure;
    public boolean getSecure() { return ; }
    public void setSecure(boolean b) {  = b; }
    // --------------------  SSL related properties --------------------

    
SSL engine.
    public boolean isSSLEnabled() { return .isSSLEnabled(); }
    public void setSSLEnabled(boolean SSLEnabled) { .setSSLEnabled(SSLEnabled); }


    
SSL protocol.
    public String getSSLProtocol() { return .getSSLProtocol(); }
    public void setSSLProtocol(String SSLProtocol) { .setSSLProtocol(SSLProtocol); }


    
SSL password (if a cert is encrypted, and no password has been provided, a callback will ask for a password).
    public String getSSLPassword() { return .getSSLPassword(); }
    public void setSSLPassword(String SSLPassword) { .setSSLPassword(SSLPassword); }


    
SSL cipher suite.
    public String getSSLCipherSuite() { return .getSSLCipherSuite(); }
    public void setSSLCipherSuite(String SSLCipherSuite) { .setSSLCipherSuite(SSLCipherSuite); }


    
SSL certificate file.
    public String getSSLCertificateFile() { return .getSSLCertificateFile(); }
    public void setSSLCertificateFile(String SSLCertificateFile) { .setSSLCertificateFile(SSLCertificateFile); }


    
SSL certificate key file.
    public void setSSLCertificateKeyFile(String SSLCertificateKeyFile) { .setSSLCertificateKeyFile(SSLCertificateKeyFile); }


    
SSL certificate chain file.
    public void setSSLCertificateChainFile(String SSLCertificateChainFile) { .setSSLCertificateChainFile(SSLCertificateChainFile); }


    
SSL CA certificate path.
    public void setSSLCACertificatePath(String SSLCACertificatePath) { .setSSLCACertificatePath(SSLCACertificatePath); }


    
SSL CA certificate file.
    public void setSSLCACertificateFile(String SSLCACertificateFile) { .setSSLCACertificateFile(SSLCACertificateFile); }


    
SSL CA revocation path.
    public void setSSLCARevocationPath(String SSLCARevocationPath) { .setSSLCARevocationPath(SSLCARevocationPath); }


    
SSL CA revocation file.
    public void setSSLCARevocationFile(String SSLCARevocationFile) { .setSSLCARevocationFile(SSLCARevocationFile); }


    
SSL verify client.
    public String getSSLVerifyClient() { return .getSSLVerifyClient(); }
    public void setSSLVerifyClient(String SSLVerifyClient) { .setSSLVerifyClient(SSLVerifyClient); }


    
SSL verify depth.
    public int getSSLVerifyDepth() { return .getSSLVerifyDepth(); }
    public void setSSLVerifyDepth(int SSLVerifyDepth) { .setSSLVerifyDepth(SSLVerifyDepth); }
    
    // --------------------  Connection handler --------------------
    static class Http11ConnectionHandler implements Handler {
        
        protected Http11AprProtocol proto;
        protected AtomicLong registerCount = new AtomicLong(0);
        protected RequestGroupInfo global = new RequestGroupInfo();
        
        protected ConcurrentHashMap<LongHttp11AprProcessorconnections =
            new ConcurrentHashMap<LongHttp11AprProcessor>();
            new ConcurrentLinkedQueue<Http11AprProcessor>() {
            protected AtomicInteger size = new AtomicInteger(0);
            public boolean offer(Http11AprProcessor processor) {
                boolean offer = (. == -1) ? true : (.get() < .);
                //avoid over growing our cache or add after we have stopped
                boolean result = false;
                if ( offer ) {
                    result = super.offer(processor);
                    if ( result ) {
                        .incrementAndGet();
                    }
                }
                if (!resultunregister(processor);
                return result;
            }
            
            public Http11AprProcessor poll() {
                Http11AprProcessor result = super.poll();
                if ( result != null ) {
                    .decrementAndGet();
                }
                return result;
            }
            
            public void clear() {
                Http11AprProcessor next = poll();
                while ( next != null ) {
                    unregister(next);
                    next = poll();
                }
                super.clear();
                .set(0);
            }
        };
            this. = proto;
        }
        public SocketState event(long socketSocketStatus status) {
            Http11AprProcessor result = .get(socket);
            
            SocketState state = .
            if (result != null) {
                result.startProcessing();
                // Call the appropriate event
                try {
                    state = result.event(status);
                } catch (java.net.SocketException e) {
                    // SocketExceptions are normal
                    ..socketException(e);
                } catch (java.io.IOException e) {
                    // IOExceptions are normal
                    ..socketException(e);
                }
                // Future developers: if you discover any other
                // rare-but-nonfatal exceptions, catch them here, and log as
                // above.
                catch (Throwable e) {
                    // any other exception or error is odd. Here we log it
                    // with "ERROR" level, so it will show up even on
                    // less-than-verbose logs.
                    ..socketError(e);
                } finally {
                    if (state != .) {
                        .remove(socket);
                        .offer(result);
                        if (..isRunning() && state == .) {
                            ..getPoller().add(socket);
                        }
                    } else {
                        if (..isRunning()) {
                            ..getEventPoller().add(socketresult.getTimeout(), 
                                    result.getReadNotifications(), result.getWriteNotification(), result.getResumeNotification(), false);
                        }
                    }
                    result.endProcessing();
                }
            }
            return state;
        }
        
        public SocketState process(long socket) {
            Http11AprProcessor processor = .poll();
            try {
                if (processor == null) {
                    processor = createProcessor();
                }
                SocketState state = processor.process(socket);
                if (state == .) {
                    // Associate the connection with the processor. The next request 
                    // processed by this thread will use either a new or a recycled
                    // processor.
                    .put(socketprocessor);
                    if (processor.getAvailable() && processor.getReadNotifications()) {
                        // Call a read event right away
                        state = event(socket.);
                    } else {
                        ..getEventPoller().add(socketprocessor.getTimeout(), 
                                processor.getReadNotifications(), falseprocessor.getResumeNotification(), false);
                    }
                } else {
                    .offer(processor);
                }
                return state;
            } catch (java.net.SocketException e) {
                // SocketExceptions are normal
                ..socketException(e);
            } catch (java.io.IOException e) {
                // IOExceptions are normal
                ..socketException(e);
            }
            // Future developers: if you discover any other
            // rare-but-nonfatal exceptions, catch them here, and log as
            // above.
            catch (Throwable e) {
                // any other exception or error is odd. Here we log it
                // with "ERROR" level, so it will show up even on
                // less-than-verbose logs.
                ..socketError(e);
            }
            .offer(processor);
            return .;
        }
        protected Http11AprProcessor createProcessor() {
            Http11AprProcessor processor =
                new Http11AprProcessor(..);
            processor.setAdapter(.);
            processor.setMaxKeepAliveRequests(.);
            processor.setTimeout(.);
            processor.setDisableUploadTimeout(.);
            processor.setCompressionMinSize(.);
            processor.setCompression(.);
            processor.setNoCompressionUserAgents(.);
            processor.setCompressableMimeTypes(.);
            processor.setRestrictedUserAgents(.);
            processor.setSocketBuffer(.);
            processor.setMaxSavePostSize(.);
            processor.setServer(.);
            register(processor);
            return processor;
        }
        
        protected void register(Http11AprProcessor processor) {
            RequestInfo rp = processor.getRequest().getRequestProcessor();
            rp.setGlobalProcessor();
            if (..... && .getDomain() != null) {
                synchronized (this) {
                    try {
                        long count = .incrementAndGet();
                        ObjectName rpName = new ObjectName
                            (.getDomain() + ":type=RequestProcessor,worker="
                                + .getJmxName() + ",name=HttpRequest" + count);
                        Registry.getRegistry(nullnull).registerComponent(rprpNamenull);
                        rp.setRpName(rpName);
                    } catch (Exception e) {
                        ..errorRegisteringRequest(e);
                    }
                }
            }
        }
        protected void unregister(Http11AprProcessor processor) {
            RequestInfo rp = processor.getRequest().getRequestProcessor();
            rp.setGlobalProcessor(null);
            if (..... && .getDomain() != null) {
                synchronized (this) {
                    try {
                        ObjectName rpName = rp.getRpName();
                        Registry.getRegistry(nullnull).unregisterComponent(rpName);
                        rp.setRpName(null);
                    } catch (Exception e) {
                        ..errorUnregisteringRequest(e);
                    }
                }
            }
        }
    }
    // -------------------- Various implementation classes --------------------
    protected String domain;
    protected ObjectName oname;
    protected MBeanServer mserver;
    public ObjectName getObjectName() {
        return ;
    }
    public String getDomain() {
        return ;
    }
    public ObjectName preRegister(MBeanServer server,
                                  ObjectName namethrows Exception {
        =name;
        =server;
        =name.getDomain();
        return name;
    }
    public void postRegister(Boolean registrationDone) {
    }
    public void preDeregister() throws Exception {
    }
    public void postDeregister() {
    }
New to GrepCode? Check out our FAQ X