Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 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 io.undertow.server.protocol.http;
 
 import org.xnio.Pool;
 
Open listener for HTTP server. XNIO should be set up to chain the accept handler to post-accept open listeners to this listener which actually initiates HTTP parsing.

Author(s):
David M. Lloyd
 
 public final class HttpOpenListener implements ChannelListener<StreamConnection>, DelegateOpenListener {
 
     private final Pool<ByteBufferbufferPool;
     private final int bufferSize;
 
     private volatile HttpHandler rootHandler;
 
     private volatile OptionMap undertowOptions;
 
     private volatile HttpRequestParser parser;
 
     @Deprecated
     public HttpOpenListener(final Pool<ByteBufferpoolfinal int bufferSize) {
         this(pool.);
     }
 
     @Deprecated
     public HttpOpenListener(final Pool<ByteBufferpoolfinal OptionMap undertowOptionsfinal int bufferSize) {
         this(poolundertowOptions);
     }
 
     public HttpOpenListener(final Pool<ByteBufferpool) {
         this(pool.);
     }
 
     public HttpOpenListener(final Pool<ByteBufferpoolfinal OptionMap undertowOptions) {
         this. = undertowOptions;
         this. = pool;
         Pooled<ByteBufferbuf = pool.allocate();
         this. = buf.getResource().remaining();
         buf.free();
          = HttpRequestParser.instance(undertowOptions);
     }
 
     @Override
     public void handleEvent(StreamConnection channel) {
         handleEvent(channelnull);
     }
     @Override
     public void handleEvent(final StreamConnection channelPooled<ByteBufferbuffer) {
         if (..isTraceEnabled()) {
             ..tracef("Opened connection with %s"channel.getPeerAddress());
         }
 
         //set read and write timeouts
         try {
             Integer readTimeout = channel.getOption(.);
             Integer idleTimeout = .get(.);
             if ((readTimeout == null || readTimeout <= 0) && idleTimeout != null) {
                 readTimeout = idleTimeout;
             } else if (readTimeout != null && idleTimeout != null && idleTimeout > 0) {
                 readTimeout = Math.min(readTimeoutidleTimeout);
             }
             if (readTimeout != null && readTimeout > 0) {
                 channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channelthis));
            }
            Integer writeTimeout = channel.getOption(.);
            if ((writeTimeout == null || writeTimeout <= 0) && idleTimeout != null) {
                writeTimeout = idleTimeout;
            } else if (writeTimeout != null && idleTimeout != null && idleTimeout > 0) {
                writeTimeout = Math.min(writeTimeoutidleTimeout);
            }
            if (writeTimeout != null && writeTimeout > 0) {
                channel.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(channel.getSinkChannel().getConduit(), channelthis));
            }
        } catch (IOException e) {
            IoUtils.safeClose(channel);
            ..ioException(e);
        }
        HttpServerConnection connection = new HttpServerConnection(channel);
        HttpReadListener readListener = new HttpReadListener(connection);
        if(buffer != null) {
            if(buffer.getResource().hasRemaining()) {
                connection.setExtraBytes(buffer);
            } else {
                buffer.free();
            }
        }
        connection.setReadListener(readListener);
        readListener.newRequest();
        channel.getSourceChannel().setReadListener(readListener);
        readListener.handleEvent(channel.getSourceChannel());
    }
    @Override
    public HttpHandler getRootHandler() {
        return ;
    }
    @Override
    public void setRootHandler(final HttpHandler rootHandler) {
        this. = rootHandler;
    }
    @Override
    public OptionMap getUndertowOptions() {
        return ;
    }
    @Override
    public void setUndertowOptions(final OptionMap undertowOptions) {
        if (undertowOptions == null) {
            throw ..argumentCannotBeNull("undertowOptions");
        }
        this. = undertowOptions;
        this. = HttpRequestParser.instance(undertowOptions);
    }
    @Override
    public Pool<ByteBuffergetBufferPool() {
        return ;
    }
New to GrepCode? Check out our FAQ X