org.restlet.engine.http.connector

## Class ServerConnection

- java.lang.Object
- - org.restlet.engine.http.connector.Connection<Server>
  - - org.restlet.engine.http.connector.ServerConnection

All Implemented Interfaces:
  Notifiable

    public class ServerConnection
    extends Connection<Server>

Generic HTTP-like server connection.

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`ServerConnection(BaseHelper<Server> helper, java.net.Socket socket, java.nio.channels.SocketChannel socketChannel)` Constructor.

### Method Summary

Methods
`protected void` `addResponseHeaders(Response response, Series<Parameter> headers)` Adds the response headers.
`boolean` `canRead()` Indicates if the connection's socket can be read for inbound data.
`void` `commit(Response response)` Asks the server connector to immediately commit the given response associated to this request, making it ready to be sent back to the client.
`protected ConnectedRequest` `createRequest(Context context, ServerConnection connection, java.lang.String methodName, java.lang.String resourceUri, java.lang.String version, Series<Parameter> headers, Representation entity, boolean confidential, java.security.Principal userPrincipal)` Creates a new request.
`protected void` `readMessage()` Reads the next request sent by the client if available.
`protected void` `writeMessage(Response response)` Write the given response on the socket.
`protected void` `writeMessageHeadLine(Response response, java.io.OutputStream headStream)` Writes the message head line to the given output stream.

### Methods inherited from class org.restlet.engine.http.connector.Connection

`addEntityHeaders, addGeneralHeaders, canWrite, close, createInboundEntity, getAddress, getHelper, getInboundEntityChannel, getInboundEntityStream, getInboundMessages, getInboundStream, getLogger, getOutboundEntityChannel, getOutboundEntityStream, getOutboundMessages, getOutboundStream, getPort, getRepresentation, getRepresentation, getSocket, getSocketChannel, getSslCipherSuite, getSslClientCertificates, getSslKeySize, getState, isBusy, isClientSide, isInboundBusy, isOutboundBusy, isPersistent, isPipelining, isServerSide, onEndReached, onError, open, readMessages, setInboundBusy, setOutboundBusy, setPersistent, setPipelining, setState, shouldBeChunked, writeMessage, writeMessageBody, writeMessageHead, writeMessageHead, writeMessages`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ServerConnection

    public ServerConnection(BaseHelper<Server> helper,
                    java.net.Socket socket,
                    java.nio.channels.SocketChannel socketChannel)
                     throws java.io.IOException

Constructor.

Parameters:
  `helper` - The parent connector helper.
  `socket` - The underlying BIO socket.
  `socketChannel` - The underlying NIO socket channel.
Throws:
  `java.io.IOException`

### Method Detail

#### addResponseHeaders

    protected void addResponseHeaders(Response response,
                          Series<Parameter> headers)

Adds the response headers.

Parameters:
  `response` - The response to inspect.
  `headers` - The headers series to update.

#### canRead

    public boolean canRead()

Description copied from class: `Connection`
Indicates if the connection's socket can be read for inbound data.

Overrides:
  `canRead` in class `Connection<Server>`
Returns:
  True if the connection's socket can be read for inbound data.

#### commit

    public void commit(Response response)

Asks the server connector to immediately commit the given response associated to this request, making it ready to be sent back to the client. Note that all server connectors don't necessarily support this feature.

Parameters:
  `response` - The response to commit.

#### createRequest

    protected ConnectedRequest createRequest(Context context,
                                 ServerConnection connection,
                                 java.lang.String methodName,
                                 java.lang.String resourceUri,
                                 java.lang.String version,
                                 Series<Parameter> headers,
                                 Representation entity,
                                 boolean confidential,
                                 java.security.Principal userPrincipal)

Creates a new request.

Parameters:
  `context` - The current context.
  `connection` - The associated connection.
  `methodName` - The method name.
  `resourceUri` - The target resource URI.
  `version` - The protocol version.
  `headers` - The request headers.
  `entity` - The request entity.
  `confidential` - True if received confidentially.
  `userPrincipal` - The user principal.
Returns:
  The created request.

#### readMessage

    protected void readMessage()
                        throws java.io.IOException

Reads the next request sent by the client if available. Note that the optional entity is not fully read.

Specified by:
  `readMessage` in class `Connection<Server>`
Throws:
  `java.io.IOException`

#### writeMessage

    protected void writeMessage(Response response)

Write the given response on the socket.

Specified by:
  `writeMessage` in class `Connection<Server>`
Parameters:
  `response` - The response to write.

#### writeMessageHeadLine

    protected void writeMessageHeadLine(Response response,
                            java.io.OutputStream headStream)
                                 throws java.io.IOException

Description copied from class: `Connection`
Writes the message head line to the given output stream.

Specified by:
  `writeMessageHeadLine` in class `Connection<Server>`
Parameters:
  `response` - The source message.
  `headStream` - The target stream.
Throws:
  `java.io.IOException`