// Handle response based on "responseTemplate"
EntityTemplate body = null;
if (server.getResponseTemplate() == null
|| server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_OK_XML)) {
response.setStatusCode(HttpStatus.SC_OK);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write("<Response>ok<Response>");
writer.flush();
}
});
response.setEntity(body);
} else if (server.getResponseTemplate().equals(
BasicHttpServer.RESPONSE_HTTP_OK_LOOP_BACK)) {
response.setStatusCode(HttpStatus.SC_OK);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write(new String(server.getContent()));
writer.flush();
}
});
} else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_404)) {
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write("<html><body><h1>");
writer.write(" not found - 404");
writer.write("</h1></body></html>");
writer.flush();
}
});
} else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_200)) {
response.setStatusCode(HttpStatus.SC_OK);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write("<Response> SC_ACCEPTED 202 <Response>");
writer.flush();
}
});
} else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_201)) {
response.setStatusCode(HttpStatus.SC_CREATED);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
//writer.write("<Response> SC_ACCEPTED 202 <Response>");
writer.flush();
}
});
} else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_202)) {
response.setStatusCode(HttpStatus.SC_ACCEPTED);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
//writer.write("<Response> SC_ACCEPTED 202 <Response>");
writer.flush();
}
});
} else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_400)) {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
//writer.write("<Response> SC_ACCEPTED 202 <Response>");
writer.flush();
}
});
} else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_500)) {
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write(" Server Error");
writer.flush();
}