Hello again Joakim,
with some help, I could move forward , yay !
So why I ended up doing is make my TerracottaConnector extend LocalConnector and then read from the socket a String (basically the HTTP request forwarded by the Terracotta Server), and pass it to the LocalConnector getResponse().
Then, I retrieve the response, write it to the socket and flush it.
In code terms, it's more or less :
public class TerracottaConnector extends LocalConnector {
public void handleSocketFromDSO(Socket s, byte[] data) throws IOException {
PushbackInputStream pis = new PushbackInputStream(s.getInputStream(), data.length);
pis.unread(data);
InputStreamReader inputStreamReader = new InputStreamReader(pis);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String readLineFromBuffer = bufferedReader.readLine();
StringWriter writer = new StringWriter();
do {
writer.write(readLineFromBuffer);
writer.write("\r\n");
readLineFromBuffer = bufferedReader.readLine();
}
while (!readLineFromBuffer.equals(""));
writer.write("\r\n");
String theString = writer.toString();
try {
String response = this.getResponse(theString);
s.getOutputStream().write(response.getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
} finally {
s.getOutputStream().flush();
}
}
}
It's not perfect, since I had to change some servlets (although we don't have many anyway) to specifically close the connection, and prevent jetty to chunk the output :
OutputStream out = response.getOutputStream();
int bytesCopied = IOUtils.copy(documentToSend.newInputStream(), out);
response.setHeader("Connection", "close");
response.setContentLength(bytesCopied);
response.flushBuffer();
But I think that's a start.
To answer your previous questions :
> How do you handle the HTTP persistence layer?
I don't think we do
> Do you have any plans to support HTTP/2?
no
> Do you expect Jetty to handle the HTTP conversation entirely on from the active connection?
> (parsing the request headers + body contents, generating the response headers + body contents)?
Yes, this is what we use Jetty for : the Terracotta Server found out the request is HTTP, it passes the socket to Jetty and expects Jetty to finish dealing with it.
> Is it possible to have a non-HTTP request after the active HTTP request on the same connection?
I don't think so, it's OK if a new connection is opened after the HTTP exchange.
Thanks again for all your help.
I have other parts of the system to migrate, but this one was clearly the most perilous...
I also need to figure out if LocalConnector is the best candidate.
Anthony