org.mule.transport.http
Class HttpServerConnection

java.lang.Object
  extended by org.mule.transport.http.HttpServerConnection
All Implemented Interfaces:
EventListener, HandshakeCompletedListener

public class HttpServerConnection
extends Object
implements HandshakeCompletedListener

A connection to the SimpleHttpServer.


Constructor Summary
HttpServerConnection(Socket socket, String encoding, HttpConnector connector)
           
 
Method Summary
 void close()
           
protected  HttpRequest createHttpRequest()
           
 String getFullUri()
           
 InputStream getInputStream()
           
 Certificate[] getLocalCertificateChain()
           
 OutputStream getOutputStream()
           
 Certificate[] getPeerCertificateChain()
           
 String getRemoteClientAddress()
           
 RequestLine getRequestLine()
           
 int getSocketReceiveBufferSize()
          Gets the value of the SO_RCVBUF for the underlying socket.
 int getSocketTimeout()
          Returns the value of the SO_TIMEOUT for the underlying socket.
 Latch getSslSocketHandshakeCompleteLatch()
           
 String getUrlWithoutRequestParams()
          Returns the path of the http request without the http parameters encoded in the URL
 ResponseWriter getWriter()
          Returns the ResponseWriter used to write the output to the socket.
 void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent)
           
 boolean isKeepAlive()
           
 boolean isOpen()
           
 boolean isSocketKeepAlive()
          Tests if SO_KEEPALIVE is enabled in the underlying socket.
 boolean isSocketTcpNoDelay()
          Tests if TCP_NODELAY is enabled in the underlying socket.
 HttpRequest readRequest()
           
 HttpResponse readResponse()
           
 void reset()
          Clean up cached values.
 void setKeepAlive(boolean b)
           
 void setSocketTimeout(int timeout)
           
 void writeFailureResponse(int statusCode, String description)
          Sends to the customer a Failure response.
 void writeFailureResponse(int statusCode, String description, Map<String,String> headers)
          Sends a customer a failure response but also adds the headers in the headers map
 void writeRequest(HttpRequest request)
           
 void writeResponse(HttpResponse response)
           
 void writeResponse(HttpResponse response, Map<String,String> headers)
          Write an HttpResponse and add the map entries as headers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServerConnection

public HttpServerConnection(Socket socket,
                            String encoding,
                            HttpConnector connector)
                     throws IOException
Throws:
IOException
Method Detail

close

public void close()

isOpen

public boolean isOpen()

setKeepAlive

public void setKeepAlive(boolean b)

isKeepAlive

public boolean isKeepAlive()

getInputStream

public InputStream getInputStream()

getOutputStream

public OutputStream getOutputStream()

getWriter

public ResponseWriter getWriter()
                         throws UnsupportedEncodingException
Returns the ResponseWriter used to write the output to the socket.

Returns:
This connection's ResponseWriter
Throws:
UnsupportedEncodingException

readRequest

public HttpRequest readRequest()
                        throws IOException
Throws:
IOException

createHttpRequest

protected HttpRequest createHttpRequest()
                                 throws IOException
Throws:
IOException

readResponse

public HttpResponse readResponse()
                          throws IOException
Throws:
IOException

writeRequest

public void writeRequest(HttpRequest request)
                  throws IOException
Throws:
IOException

writeResponse

public void writeResponse(HttpResponse response)
                   throws IOException
Throws:
IOException

writeResponse

public void writeResponse(HttpResponse response,
                          Map<String,String> headers)
                   throws IOException
Write an HttpResponse and add the map entries as headers

Parameters:
response - http response with the content of the response
headers - headers to add to the http response besides the one already contained in the HttpResponse object
Throws:
IOException

getUrlWithoutRequestParams

public String getUrlWithoutRequestParams()
                                  throws IOException
Returns the path of the http request without the http parameters encoded in the URL

Returns:
Throws:
IOException

getRemoteClientAddress

public String getRemoteClientAddress()

writeFailureResponse

public void writeFailureResponse(int statusCode,
                                 String description)
                          throws IOException
Sends to the customer a Failure response.

Parameters:
statusCode - http status code to send to the client
description - description to send as the body of the response
Throws:
IOException - when it's not possible to write the response back to the client.

writeFailureResponse

public void writeFailureResponse(int statusCode,
                                 String description,
                                 Map<String,String> headers)
                          throws IOException
Sends a customer a failure response but also adds the headers in the headers map

Parameters:
statusCode - status code of the failure response
description - message to be send as the body
headers - headers to send with the failure response
Throws:
IOException

getFullUri

public String getFullUri()
                  throws IOException
Returns:
the uri for the request including scheme, host, port and path. i.e: http://192.168.1.1:7777/service/orders
Throws:
IOException

getSocketTimeout

public int getSocketTimeout()
                     throws SocketException
Returns the value of the SO_TIMEOUT for the underlying socket.

Returns:
The value of the SO_TIMEOUT for the underlying socket.
Throws:
SocketException - If there is an error in the underlying protocol.

setSocketTimeout

public void setSocketTimeout(int timeout)
                      throws SocketException
Throws:
SocketException

isSocketKeepAlive

public boolean isSocketKeepAlive()
                          throws SocketException
Tests if SO_KEEPALIVE is enabled in the underlying socket.

Returns:
a boolean indicating whether or not SO_KEEPALIVE is enabled.
Throws:
SocketException - If there is an error in the underlying protocol.

isSocketTcpNoDelay

public boolean isSocketTcpNoDelay()
                           throws SocketException
Tests if TCP_NODELAY is enabled in the underlying socket.

Returns:
a boolean indicating whether or not TCP_NODELAY is enabled.
Throws:
SocketException - If there is an error in the underlying protocol.

getSocketReceiveBufferSize

public int getSocketReceiveBufferSize()
                               throws SocketException
Gets the value of the SO_RCVBUF for the underlying socket.

Returns:
The value of the SO_RCVBUF for the underlying socket.
Throws:
SocketException - If there is an error in the underlying protocol.

getSslSocketHandshakeCompleteLatch

public Latch getSslSocketHandshakeCompleteLatch()

reset

public void reset()
           throws IOException
Clean up cached values.

Must be called if a new request from the same socket associated with the instance is going to be processed.

Throws:
IOException

handshakeCompleted

public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent)
Specified by:
handshakeCompleted in interface HandshakeCompletedListener

getLocalCertificateChain

public Certificate[] getLocalCertificateChain()

getPeerCertificateChain

public Certificate[] getPeerCertificateChain()

getRequestLine

public RequestLine getRequestLine()
                           throws IOException
Throws:
IOException


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.