httpcore-nio-4.1.1

16:36:44.556 INFO  jd.cli.Main - Decompiling httpcore-nio-4.1.1.jar
package org.apache.http.impl.nio;

import java.io.IOException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import org.apache.http.HttpRequestFactory;
import org.apache.http.impl.DefaultHttpRequestFactory;
import org.apache.http.impl.nio.reactor.SSLIOSession;
import org.apache.http.impl.nio.reactor.SSLIOSessionHandler;
import org.apache.http.impl.nio.reactor.SSLMode;
import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.NHttpServiceHandler;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
import org.apache.http.params.HttpParams;

@Deprecated
public class SSLServerIOEventDispatch
  implements IOEventDispatch
{
  private static final String SSL_SESSION = "SSL_SESSION";
  protected final NHttpServiceHandler handler;
  protected final SSLContext sslcontext;
  protected final SSLIOSessionHandler sslHandler;
  protected final HttpParams params;
  
  public SSLServerIOEventDispatch(NHttpServiceHandler handler, SSLContext sslcontext, SSLIOSessionHandler sslHandler, HttpParams params)
  {
    if (handler == null) {
      throw new IllegalArgumentException("HTTP service handler may not be null");
    }
    if (sslcontext == null) {
      throw new IllegalArgumentException("SSL context may not be null");
    }
    if (params == null) {
      throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.handler = handler;
    this.params = params;
    this.sslcontext = sslcontext;
    this.sslHandler = sslHandler;
  }
  
  public SSLServerIOEventDispatch(NHttpServiceHandler handler, SSLContext sslcontext, HttpParams params)
  {
    this(handler, sslcontext, null, params);
  }
  
  protected ByteBufferAllocator createByteBufferAllocator()
  {
    return new HeapByteBufferAllocator();
  }
  
  protected HttpRequestFactory createHttpRequestFactory()
  {
    return new DefaultHttpRequestFactory();
  }
  
  protected NHttpServerIOTarget createConnection(IOSession session)
  {
    return new DefaultNHttpServerConnection(session, createHttpRequestFactory(), createByteBufferAllocator(), params);
  }
  
  protected SSLIOSession createSSLIOSession(IOSession session, SSLContext sslcontext, SSLIOSessionHandler sslHandler)
  {
    return new SSLIOSession(session, sslcontext, sslHandler);
  }
  
  public void connected(IOSession session)
  {
    SSLIOSession sslSession = createSSLIOSession(session, sslcontext, sslHandler);
    
    NHttpServerIOTarget conn = createConnection(sslSession);
    
    session.setAttribute("http.connection", conn);
    session.setAttribute("SSL_SESSION", sslSession);
    
    handler.connected(conn);
    try
    {
      sslSession.bind(SSLMode.SERVER, params);
    }
    catch (SSLException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void disconnected(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    if (conn != null) {
      handler.closed(conn);
    }
  }
  
  public void inputReady(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("SSL_SESSION");
    try
    {
      if (sslSession.isAppInputReady()) {
        conn.consumeInput(handler);
      }
      sslSession.inboundTransport();
    }
    catch (IOException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void outputReady(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("SSL_SESSION");
    try
    {
      if (sslSession.isAppOutputReady()) {
        conn.produceOutput(handler);
      }
      sslSession.outboundTransport();
    }
    catch (IOException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void timeout(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("SSL_SESSION");
    
    handler.timeout(conn);
    synchronized (sslSession)
    {
      if ((sslSession.isOutboundDone()) && (!sslSession.isInboundDone())) {
        sslSession.shutdown();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.SSLServerIOEventDispatch
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio.ssl;

import java.io.IOException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import org.apache.http.HttpRequestFactory;
import org.apache.http.impl.DefaultHttpRequestFactory;
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.reactor.SSLIOSession;
import org.apache.http.impl.nio.reactor.SSLMode;
import org.apache.http.impl.nio.reactor.SSLSetupHandler;
import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.NHttpServiceHandler;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
import org.apache.http.params.HttpParams;

public class SSLServerIOEventDispatch
  implements IOEventDispatch
{
  private static final String SSL_SESSION = "http.nio.ssl-session";
  private final NHttpServiceHandler handler;
  private final SSLContext sslcontext;
  private final SSLSetupHandler sslHandler;
  private final HttpParams params;
  
  public SSLServerIOEventDispatch(NHttpServiceHandler handler, SSLContext sslcontext, SSLSetupHandler sslHandler, HttpParams params)
  {
    if (handler == null) {
      throw new IllegalArgumentException("HTTP service handler may not be null");
    }
    if (sslcontext == null) {
      throw new IllegalArgumentException("SSL context may not be null");
    }
    if (params == null) {
      throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.handler = handler;
    this.params = params;
    this.sslcontext = sslcontext;
    this.sslHandler = sslHandler;
  }
  
  public SSLServerIOEventDispatch(NHttpServiceHandler handler, SSLContext sslcontext, HttpParams params)
  {
    this(handler, sslcontext, null, params);
  }
  
  protected ByteBufferAllocator createByteBufferAllocator()
  {
    return new HeapByteBufferAllocator();
  }
  
  protected HttpRequestFactory createHttpRequestFactory()
  {
    return new DefaultHttpRequestFactory();
  }
  
  protected NHttpServerIOTarget createConnection(IOSession session)
  {
    return new DefaultNHttpServerConnection(session, createHttpRequestFactory(), createByteBufferAllocator(), params);
  }
  
  protected SSLIOSession createSSLIOSession(IOSession session, SSLContext sslcontext, SSLSetupHandler sslHandler)
  {
    return new SSLIOSession(session, sslcontext, sslHandler);
  }
  
  public void connected(IOSession session)
  {
    SSLIOSession sslSession = createSSLIOSession(session, sslcontext, sslHandler);
    
    NHttpServerIOTarget conn = createConnection(sslSession);
    
    session.setAttribute("http.connection", conn);
    session.setAttribute("http.nio.ssl-session", sslSession);
    
    handler.connected(conn);
    try
    {
      sslSession.bind(SSLMode.SERVER, params);
    }
    catch (SSLException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void disconnected(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    if (conn != null) {
      handler.closed(conn);
    }
  }
  
  private void ensureNotNull(NHttpServerIOTarget conn)
  {
    if (conn == null) {
      throw new IllegalStateException("HTTP connection is null");
    }
  }
  
  private void ensureNotNull(SSLIOSession ssliosession)
  {
    if (ssliosession == null) {
      throw new IllegalStateException("SSL I/O session is null");
    }
  }
  
  public void inputReady(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("http.nio.ssl-session");
    
    ensureNotNull(sslSession);
    try
    {
      if (sslSession.isAppInputReady()) {
        conn.consumeInput(handler);
      }
      sslSession.inboundTransport();
    }
    catch (IOException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void outputReady(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("http.nio.ssl-session");
    
    ensureNotNull(sslSession);
    try
    {
      if (sslSession.isAppOutputReady()) {
        conn.produceOutput(handler);
      }
      sslSession.outboundTransport();
    }
    catch (IOException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void timeout(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("http.nio.ssl-session");
    
    ensureNotNull(sslSession);
    
    handler.timeout(conn);
    synchronized (sslSession)
    {
      if ((sslSession.isOutboundDone()) && (!sslSession.isInboundDone())) {
        sslSession.shutdown();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.ssl.SSLServerIOEventDispatch
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio.ssl;

import java.io.IOException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import org.apache.http.HttpResponseFactory;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
import org.apache.http.impl.nio.reactor.SSLIOSession;
import org.apache.http.impl.nio.reactor.SSLMode;
import org.apache.http.impl.nio.reactor.SSLSetupHandler;
import org.apache.http.nio.NHttpClientHandler;
import org.apache.http.nio.NHttpClientIOTarget;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
import org.apache.http.params.HttpParams;

public class SSLClientIOEventDispatch
  implements IOEventDispatch
{
  private static final String SSL_SESSION = "http.nio.ssl-session";
  private final NHttpClientHandler handler;
  private final SSLContext sslcontext;
  private final SSLSetupHandler sslHandler;
  private final HttpParams params;
  
  public SSLClientIOEventDispatch(NHttpClientHandler handler, SSLContext sslcontext, SSLSetupHandler sslHandler, HttpParams params)
  {
    if (handler == null) {
      throw new IllegalArgumentException("HTTP client handler may not be null");
    }
    if (sslcontext == null) {
      throw new IllegalArgumentException("SSL context may not be null");
    }
    if (params == null) {
      throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.handler = handler;
    this.params = params;
    this.sslcontext = sslcontext;
    this.sslHandler = sslHandler;
  }
  
  public SSLClientIOEventDispatch(NHttpClientHandler handler, SSLContext sslcontext, HttpParams params)
  {
    this(handler, sslcontext, null, params);
  }
  
  protected ByteBufferAllocator createByteBufferAllocator()
  {
    return new HeapByteBufferAllocator();
  }
  
  protected HttpResponseFactory createHttpResponseFactory()
  {
    return new DefaultHttpResponseFactory();
  }
  
  protected NHttpClientIOTarget createConnection(IOSession session)
  {
    return new DefaultNHttpClientConnection(session, createHttpResponseFactory(), createByteBufferAllocator(), params);
  }
  
  protected SSLIOSession createSSLIOSession(IOSession session, SSLContext sslcontext, SSLSetupHandler sslHandler)
  {
    return new SSLIOSession(session, sslcontext, sslHandler);
  }
  
  public void connected(IOSession session)
  {
    SSLIOSession sslSession = createSSLIOSession(session, sslcontext, sslHandler);
    
    NHttpClientIOTarget conn = createConnection(sslSession);
    
    session.setAttribute("http.connection", conn);
    session.setAttribute("http.nio.ssl-session", sslSession);
    
    Object attachment = session.getAttribute("http.session.attachment");
    handler.connected(conn, attachment);
    try
    {
      sslSession.bind(SSLMode.CLIENT, params);
    }
    catch (SSLException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void disconnected(IOSession session)
  {
    NHttpClientIOTarget conn = (NHttpClientIOTarget)session.getAttribute("http.connection");
    if (conn != null) {
      handler.closed(conn);
    }
  }
  
  private void ensureNotNull(NHttpClientIOTarget conn)
  {
    if (conn == null) {
      throw new IllegalStateException("HTTP connection is null");
    }
  }
  
  private void ensureNotNull(SSLIOSession ssliosession)
  {
    if (ssliosession == null) {
      throw new IllegalStateException("SSL I/O session is null");
    }
  }
  
  public void inputReady(IOSession session)
  {
    NHttpClientIOTarget conn = (NHttpClientIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("http.nio.ssl-session");
    
    ensureNotNull(sslSession);
    try
    {
      if (sslSession.isAppInputReady()) {
        conn.consumeInput(handler);
      }
      sslSession.inboundTransport();
    }
    catch (IOException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void outputReady(IOSession session)
  {
    NHttpClientIOTarget conn = (NHttpClientIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("http.nio.ssl-session");
    
    ensureNotNull(sslSession);
    try
    {
      if (sslSession.isAppOutputReady()) {
        conn.produceOutput(handler);
      }
      sslSession.outboundTransport();
    }
    catch (IOException ex)
    {
      handler.exception(conn, ex);
      sslSession.shutdown();
    }
  }
  
  public void timeout(IOSession session)
  {
    NHttpClientIOTarget conn = (NHttpClientIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    SSLIOSession sslSession = (SSLIOSession)session.getAttribute("http.nio.ssl-session");
    
    ensureNotNull(sslSession);
    
    handler.timeout(conn);
    synchronized (sslSession)
    {
      if ((sslSession.isOutboundDone()) && (!sslSession.isInboundDone())) {
        sslSession.shutdown();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.ssl.SSLClientIOEventDispatch
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestFactory;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.impl.HttpConnectionMetricsImpl;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.codecs.DefaultHttpRequestParser;
import org.apache.http.impl.nio.codecs.DefaultHttpResponseWriter;
import org.apache.http.impl.nio.reactor.SessionInputBufferImpl;
import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpMessageParser;
import org.apache.http.nio.NHttpMessageWriter;
import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.NHttpServiceHandler;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.nio.reactor.SessionOutputBuffer;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.params.HttpParams;

public class DefaultNHttpServerConnection
  extends NHttpConnectionBase
  implements NHttpServerIOTarget
{
  protected final NHttpMessageParser<HttpRequest> requestParser;
  protected final NHttpMessageWriter<HttpResponse> responseWriter;
  
  public DefaultNHttpServerConnection(IOSession session, HttpRequestFactory requestFactory, ByteBufferAllocator allocator, HttpParams params)
  {
    super(session, allocator, params);
    if (requestFactory == null) {
      throw new IllegalArgumentException("Request factory may not be null");
    }
    requestParser = createRequestParser(inbuf, requestFactory, params);
    responseWriter = createResponseWriter(outbuf, params);
  }
  
  protected NHttpMessageParser<HttpRequest> createRequestParser(SessionInputBuffer buffer, HttpRequestFactory requestFactory, HttpParams params)
  {
    return new DefaultHttpRequestParser(buffer, null, requestFactory, params);
  }
  
  protected NHttpMessageWriter<HttpResponse> createResponseWriter(SessionOutputBuffer buffer, HttpParams params)
  {
    return new DefaultHttpResponseWriter(buffer, null, params);
  }
  
  public void resetInput()
  {
    request = null;
    contentDecoder = null;
    requestParser.reset();
  }
  
  public void resetOutput()
  {
    response = null;
    contentEncoder = null;
    responseWriter.reset();
  }
  
  public void consumeInput(NHttpServiceHandler handler)
  {
    if (status != 0)
    {
      session.clearEvent(1);
      return;
    }
    try
    {
      if (request == null)
      {
        int bytesRead;
        do
        {
          bytesRead = requestParser.fillBuffer(session.channel());
          if (bytesRead > 0) {
            inTransportMetrics.incrementBytesTransferred(bytesRead);
          }
          request = ((HttpRequest)requestParser.parse());
        } while ((bytesRead > 0) && (request == null));
        if (request != null)
        {
          if ((request instanceof HttpEntityEnclosingRequest))
          {
            HttpEntity entity = prepareDecoder(request);
            ((HttpEntityEnclosingRequest)request).setEntity(entity);
          }
          connMetrics.incrementRequestCount();
          handler.requestReceived(this);
          if (contentDecoder == null) {
            resetInput();
          }
        }
        if (bytesRead == -1) {
          close();
        }
      }
      if (contentDecoder != null)
      {
        handler.inputReady(this, contentDecoder);
        if (contentDecoder.isCompleted()) {
          resetInput();
        }
      }
    }
    catch (IOException ex)
    {
      handler.exception(this, ex);
    }
    catch (HttpException ex)
    {
      resetInput();
      handler.exception(this, ex);
    }
    finally
    {
      hasBufferedInput = inbuf.hasData();
    }
  }
  
  public void produceOutput(NHttpServiceHandler handler)
  {
    try
    {
      if (outbuf.hasData())
      {
        int bytesWritten = outbuf.flush(session.channel());
        if (bytesWritten > 0) {
          outTransportMetrics.incrementBytesTransferred(bytesWritten);
        }
      }
      if (!outbuf.hasData())
      {
        if (status == 1)
        {
          session.close();
          status = 2;
          resetOutput(); return;
        }
        if (contentEncoder != null)
        {
          handler.outputReady(this, contentEncoder);
          if (contentEncoder.isCompleted()) {
            resetOutput();
          }
        }
        if ((contentEncoder == null) && (!outbuf.hasData()))
        {
          if (status == 1)
          {
            session.close();
            status = 2;
          }
          if (status != 2)
          {
            session.clearEvent(4);
            handler.responseReady(this);
          }
        }
      }
    }
    catch (IOException ex)
    {
      handler.exception(this, ex);
    }
    finally
    {
      hasBufferedOutput = outbuf.hasData();
    }
  }
  
  public void submitResponse(HttpResponse response)
    throws IOException, HttpException
  {
    if (response == null) {
      throw new IllegalArgumentException("HTTP response may not be null");
    }
    assertNotClosed();
    if (this.response != null) {
      throw new HttpException("Response already submitted");
    }
    responseWriter.write(response);
    hasBufferedOutput = outbuf.hasData();
    if (response.getStatusLine().getStatusCode() >= 200)
    {
      connMetrics.incrementResponseCount();
      if (response.getEntity() != null)
      {
        this.response = response;
        prepareEncoder(response);
      }
    }
    session.setEvent(4);
  }
  
  public boolean isResponseSubmitted()
  {
    return response != null;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.DefaultNHttpServerConnection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio;

import org.apache.http.HttpRequestFactory;
import org.apache.http.impl.DefaultHttpRequestFactory;
import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.NHttpServiceHandler;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
import org.apache.http.params.HttpParams;

public class DefaultServerIOEventDispatch
  implements IOEventDispatch
{
  protected final ByteBufferAllocator allocator;
  protected final NHttpServiceHandler handler;
  protected final HttpParams params;
  
  public DefaultServerIOEventDispatch(NHttpServiceHandler handler, HttpParams params)
  {
    if (handler == null) {
      throw new IllegalArgumentException("HTTP service handler may not be null");
    }
    if (params == null) {
      throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    allocator = createByteBufferAllocator();
    this.handler = handler;
    this.params = params;
  }
  
  protected ByteBufferAllocator createByteBufferAllocator()
  {
    return new HeapByteBufferAllocator();
  }
  
  protected HttpRequestFactory createHttpRequestFactory()
  {
    return new DefaultHttpRequestFactory();
  }
  
  protected NHttpServerIOTarget createConnection(IOSession session)
  {
    return new DefaultNHttpServerConnection(session, createHttpRequestFactory(), allocator, params);
  }
  
  public void connected(IOSession session)
  {
    NHttpServerIOTarget conn = createConnection(session);
    session.setAttribute("http.connection", conn);
    handler.connected(conn);
  }
  
  public void disconnected(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    if (conn != null) {
      handler.closed(conn);
    }
  }
  
  private void ensureNotNull(NHttpServerIOTarget conn)
  {
    if (conn == null) {
      throw new IllegalStateException("HTTP connection is null");
    }
  }
  
  public void inputReady(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    conn.consumeInput(handler);
  }
  
  public void outputReady(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    conn.produceOutput(handler);
  }
  
  public void timeout(IOSession session)
  {
    NHttpServerIOTarget conn = (NHttpServerIOTarget)session.getAttribute("http.connection");
    
    ensureNotNull(conn);
    handler.timeout(conn);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.DefaultServerIOEventDispatch
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import org.apache.http.ConnectionClosedException;
import org.apache.http.Header;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpInetConnection;
import org.apache.http.HttpMessage;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.HttpConnectionMetricsImpl;
import org.apache.http.impl.entity.LaxContentLengthStrategy;
import org.apache.http.impl.entity.StrictContentLengthStrategy;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.codecs.ChunkDecoder;
import org.apache.http.impl.nio.codecs.ChunkEncoder;
import org.apache.http.impl.nio.codecs.IdentityDecoder;
import org.apache.http.impl.nio.codecs.IdentityEncoder;
import org.apache.http.impl.nio.codecs.LengthDelimitedDecoder;
import org.apache.http.impl.nio.codecs.LengthDelimitedEncoder;
import org.apache.http.impl.nio.reactor.SessionInputBufferImpl;
import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpConnection;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionBufferStatus;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.nio.reactor.SessionOutputBuffer;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

public class NHttpConnectionBase
  implements NHttpConnection, HttpInetConnection, SessionBufferStatus
{
  protected final ContentLengthStrategy incomingContentStrategy;
  protected final ContentLengthStrategy outgoingContentStrategy;
  protected final SessionInputBufferImpl inbuf;
  protected final SessionOutputBufferImpl outbuf;
  protected final HttpTransportMetricsImpl inTransportMetrics;
  protected final HttpTransportMetricsImpl outTransportMetrics;
  protected final HttpConnectionMetricsImpl connMetrics;
  protected HttpContext context;
  protected IOSession session;
  protected SocketAddress remote;
  protected volatile ContentDecoder contentDecoder;
  protected volatile boolean hasBufferedInput;
  protected volatile ContentEncoder contentEncoder;
  protected volatile boolean hasBufferedOutput;
  protected volatile HttpRequest request;
  protected volatile HttpResponse response;
  protected volatile int status;
  
  public NHttpConnectionBase(IOSession session, ByteBufferAllocator allocator, HttpParams params)
  {
    if (session == null) {
      throw new IllegalArgumentException("I/O session may not be null");
    }
    if (params == null) {
      throw new IllegalArgumentException("HTTP params may not be null");
    }
    int buffersize = HttpConnectionParams.getSocketBufferSize(params);
    int linebuffersize = buffersize;
    if (linebuffersize > 512) {
      linebuffersize = 512;
    }
    inbuf = new SessionInputBufferImpl(buffersize, linebuffersize, allocator, params);
    outbuf = new SessionOutputBufferImpl(buffersize, linebuffersize, allocator, params);
    
    incomingContentStrategy = new LaxContentLengthStrategy();
    outgoingContentStrategy = new StrictContentLengthStrategy();
    
    inTransportMetrics = createTransportMetrics();
    outTransportMetrics = createTransportMetrics();
    connMetrics = createConnectionMetrics(inTransportMetrics, outTransportMetrics);
    
    setSession(session);
    status = 0;
  }
  
  private void setSession(IOSession session)
  {
    this.session = session;
    context = new SessionHttpContext(this.session);
    this.session.setBufferStatus(this);
    remote = this.session.getRemoteAddress();
  }
  
  protected HttpTransportMetricsImpl createTransportMetrics()
  {
    return new HttpTransportMetricsImpl();
  }
  
  protected HttpConnectionMetricsImpl createConnectionMetrics(HttpTransportMetrics inTransportMetric, HttpTransportMetrics outTransportMetric)
  {
    return new HttpConnectionMetricsImpl(inTransportMetric, outTransportMetric);
  }
  
  public int getStatus()
  {
    return status;
  }
  
  public HttpContext getContext()
  {
    return context;
  }
  
  public HttpRequest getHttpRequest()
  {
    return request;
  }
  
  public HttpResponse getHttpResponse()
  {
    return response;
  }
  
  public void requestInput()
  {
    session.setEvent(1);
  }
  
  public void requestOutput()
  {
    session.setEvent(4);
  }
  
  public void suspendInput()
  {
    session.clearEvent(1);
  }
  
  public void suspendOutput()
  {
    session.clearEvent(4);
  }
  
  protected HttpEntity prepareDecoder(HttpMessage message)
    throws HttpException
  {
    BasicHttpEntity entity = new BasicHttpEntity();
    long len = incomingContentStrategy.determineLength(message);
    contentDecoder = createContentDecoder(len, session.channel(), inbuf, inTransportMetrics);
    if (len == -2L)
    {
      entity.setChunked(true);
      entity.setContentLength(-1L);
    }
    else if (len == -1L)
    {
      entity.setChunked(false);
      entity.setContentLength(-1L);
    }
    else
    {
      entity.setChunked(false);
      entity.setContentLength(len);
    }
    Header contentTypeHeader = message.getFirstHeader("Content-Type");
    if (contentTypeHeader != null) {
      entity.setContentType(contentTypeHeader);
    }
    Header contentEncodingHeader = message.getFirstHeader("Content-Encoding");
    if (contentEncodingHeader != null) {
      entity.setContentEncoding(contentEncodingHeader);
    }
    return entity;
  }
  
  protected ContentDecoder createContentDecoder(long len, ReadableByteChannel channel, SessionInputBuffer buffer, HttpTransportMetricsImpl metrics)
  {
    if (len == -2L) {
      return new ChunkDecoder(channel, buffer, metrics);
    }
    if (len == -1L) {
      return new IdentityDecoder(channel, buffer, metrics);
    }
    return new LengthDelimitedDecoder(channel, buffer, metrics, len);
  }
  
  protected void prepareEncoder(HttpMessage message)
    throws HttpException
  {
    long len = outgoingContentStrategy.determineLength(message);
    contentEncoder = createContentEncoder(len, session.channel(), outbuf, outTransportMetrics);
  }
  
  protected ContentEncoder createContentEncoder(long len, WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)
  {
    if (len == -2L) {
      return new ChunkEncoder(channel, buffer, metrics);
    }
    if (len == -1L) {
      return new IdentityEncoder(channel, buffer, metrics);
    }
    return new LengthDelimitedEncoder(channel, buffer, metrics, len);
  }
  
  public boolean hasBufferedInput()
  {
    return hasBufferedInput;
  }
  
  public boolean hasBufferedOutput()
  {
    return hasBufferedOutput;
  }
  
  protected void assertNotClosed()
    throws ConnectionClosedException
  {
    if (status != 0) {
      throw new ConnectionClosedException("Connection is closed");
    }
  }
  
  public void close()
    throws IOException
  {
    if (status != 0) {
      return;
    }
    status = 1;
    if (outbuf.hasData())
    {
      session.setEvent(4);
    }
    else
    {
      session.close();
      status = 2;
    }
  }
  
  public boolean isOpen()
  {
    return (status == 0) && (!session.isClosed());
  }
  
  public boolean isStale()
  {
    return session.isClosed();
  }
  
  public InetAddress getLocalAddress()
  {
    SocketAddress address = session.getLocalAddress();
    if ((address instanceof InetSocketAddress)) {
      return ((InetSocketAddress)address).getAddress();
    }
    return null;
  }
  
  public int getLocalPort()
  {
    SocketAddress address = session.getLocalAddress();
    if ((address instanceof InetSocketAddress)) {
      return ((InetSocketAddress)address).getPort();
    }
    return -1;
  }
  
  public InetAddress getRemoteAddress()
  {
    SocketAddress address = session.getRemoteAddress();
    if ((address instanceof InetSocketAddress)) {
      return ((InetSocketAddress)address).getAddress();
    }
    return null;
  }
  
  public int getRemotePort()
  {
    SocketAddress address = session.getRemoteAddress();
    if ((address instanceof InetSocketAddress)) {
      return ((InetSocketAddress)address).getPort();
    }
    return -1;
  }
  
  public void setSocketTimeout(int timeout)
  {
    session.setSocketTimeout(timeout);
  }
  
  public int getSocketTimeout()
  {
    return session.getSocketTimeout();
  }
  
  public void shutdown()
    throws IOException
  {
    status = 2;
    session.shutdown();
  }
  
  public HttpConnectionMetrics getMetrics()
  {
    return connMetrics;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("[");
    buffer.append(remote);
    if (status == 2) {
      buffer.append("(closed)");
    }
    buffer.append("]");
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.NHttpConnectionBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio.codecs;

import java.io.IOException;
import java.util.Iterator;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpMessage;
import org.apache.http.message.BasicLineFormatter;
import org.apache.http.message.LineFormatter;
import org.apache.http.nio.NHttpMessageWriter;
import org.apache.http.nio.reactor.SessionOutputBuffer;
import org.apache.http.params.HttpParams;
import org.apache.http.util.CharArrayBuffer;

public abstract class AbstractMessageWriter<T extends HttpMessage>
  implements NHttpMessageWriter<T>
{
  protected final SessionOutputBuffer sessionBuffer;
  protected final CharArrayBuffer lineBuf;
  protected final LineFormatter lineFormatter;
  
  public AbstractMessageWriter(SessionOutputBuffer buffer, LineFormatter formatter, HttpParams params)
  {
    if (buffer == null) {
      throw new IllegalArgumentException("Session input buffer may not be null");
    }
    sessionBuffer = buffer;
    lineBuf = new CharArrayBuffer(64);
    lineFormatter = (formatter != null ? formatter : BasicLineFormatter.DEFAULT);
  }
  
  public void reset() {}
  
  protected abstract void writeHeadLine(T paramT)
    throws IOException;
  
  public void write(T message)
    throws IOException, HttpException
  {
    if (message == null) {
      throw new IllegalArgumentException("HTTP message may not be null");
    }
    writeHeadLine(message);
    for (Iterator<?> it = message.headerIterator(); it.hasNext();)
    {
      Header header = (Header)it.next();
      sessionBuffer.writeLine(lineFormatter.formatHeader(lineBuf, header));
    }
    lineBuf.clear();
    sessionBuffer.writeLine(lineBuf);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.codecs.AbstractMessageWriter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio.codecs;

import java.io.IOException;
import java.nio.channels.WritableByteChannel;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.reactor.SessionOutputBuffer;

public abstract class AbstractContentEncoder
  implements ContentEncoder
{
  protected final WritableByteChannel channel;
  protected final SessionOutputBuffer buffer;
  protected final HttpTransportMetricsImpl metrics;
  protected boolean completed;
  
  public AbstractContentEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)
  {
    if (channel == null) {
      throw new IllegalArgumentException("Channel may not be null");
    }
    if (buffer == null) {
      throw new IllegalArgumentException("Session input buffer may not be null");
    }
    if (metrics == null) {
      throw new IllegalArgumentException("Transport metrics may not be null");
    }
    this.buffer = buffer;
    this.channel = channel;
    this.metrics = metrics;
  }
  
  public boolean isCompleted()
  {
    return completed;
  }
  
  public void complete()
    throws IOException
  {
    completed = true;
  }
  
  protected void assertNotCompleted()
  {
    if (completed) {
      throw new IllegalStateException("Encoding process already completed");
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.codecs.AbstractContentEncoder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio.codecs;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.io.BufferInfo;
import org.apache.http.nio.reactor.SessionOutputBuffer;
import org.apache.http.util.CharArrayBuffer;

public class ChunkEncoder
  extends AbstractContentEncoder
{
  private final CharArrayBuffer lineBuffer;
  private final BufferInfo bufferinfo;
  
  public ChunkEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)
  {
    super(channel, buffer, metrics);
    lineBuffer = new CharArrayBuffer(16);
    if ((buffer instanceof BufferInfo)) {
      bufferinfo = ((BufferInfo)buffer);
    } else {
      bufferinfo = null;
    }
  }
  
  public int write(ByteBuffer src)
    throws IOException
  {
    if (src == null) {
      return 0;
    }
    assertNotCompleted();
    int chunk = src.remaining();
    if (chunk == 0) {
      return 0;
    }
    long bytesWritten = buffer.flush(channel);
    if (bytesWritten > 0L) {
      metrics.incrementBytesTransferred(bytesWritten);
    }
    int avail;
    int avail;
    if (bufferinfo != null) {
      avail = bufferinfo.available();
    } else {
      avail = 4096;
    }
    avail -= 12;
    if (avail <= 0) {
      return 0;
    }
    if (avail < chunk)
    {
      chunk = avail;
      lineBuffer.clear();
      lineBuffer.append(Integer.toHexString(chunk));
      buffer.writeLine(lineBuffer);
      int oldlimit = src.limit();
      src.limit(src.position() + chunk);
      buffer.write(src);
      src.limit(oldlimit);
    }
    else
    {
      lineBuffer.clear();
      lineBuffer.append(Integer.toHexString(chunk));
      buffer.writeLine(lineBuffer);
      buffer.write(src);
    }
    lineBuffer.clear();
    buffer.writeLine(lineBuffer);
    return chunk;
  }
  
  public void complete()
    throws IOException
  {
    assertNotCompleted();
    lineBuffer.clear();
    lineBuffer.append("0");
    buffer.writeLine(lineBuffer);
    lineBuffer.clear();
    buffer.writeLine(lineBuffer);
    completed = true;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("[chunk-coded; completed: ");
    buffer.append(completed);
    buffer.append("]");
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.nio.codecs.ChunkEncoder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.nio.codecs;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.nio.FileContentEnco
1 2 3 4 5 6 7 8 9

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd