public void handle(HttpExchange httpExchange) throws IOException {
Process.currentProcess().setParent(main_thread);
try {
InetSocketAddress ra = httpExchange.getRemoteAddress();
Process cp = Process.currentProcess();
Map<String, Object> prms = new HashMap<String, Object>();
setPrms(cp, prms, "protocol", httpExchange.getProtocol());
setPrms(cp, prms, "method", httpExchange.getRequestMethod());
// setPrms(cp, prms, "remote.hostName", ra.getHostName()); !!!
// TODO
setPrms(cp, prms, "remote.port", ra.getPort());
setPrms(cp, prms, "remote.ip", ra.getAddress().getHostAddress());
setPrms(cp, prms, "query.path", httpExchange.getRequestURI()
.getPath());
String query = httpExchange.getRequestURI().getQuery();
if (query != null) {
String[] eqs = Strings.parseXVSLine(query, '/', '&');
for (int i = 0; i < eqs.length; i++) {
String eq = eqs[i];
int j = eq.indexOf('=');
if (j >= 0)
setPrms(cp, prms, "get." + eq.substring(0, j),
eq.substring(j + 1));
}
setPrms(cp, prms, "query", query);
}
String ct = null;
int cl = 0;
for (Map.Entry<String, List<String>> e : httpExchange
.getRequestHeaders().entrySet()) {
List<String> v = e.getValue();
String k = e.getKey();
if ("Content-type".equals(k))
ct = v.toString();
else if ("Content-length".equals(k))
cl = Strings.parseInteger(v.get(0));
setPrms(cp, prms, "hdrs." + k, v.toString());
}
InputStream is = httpExchange.getRequestBody();
Process tprc = executor.occupyOrNew();
OutputByteBuffer obb = null;
try {
long read_wait = Strings.parseIntegerNvl(
cntx.getPrmByFullName("read_wait"), 10000);// !!!
TimeoutInputStream tis = new TimeoutInputStream(tprc);
tis.setTimeout(read_wait);
tis.setLimitRead(cl);
tis.setCircleBufferSize(50);
tis.startReadSource(is);
obb = (cl <= 0) ? Process.getByteBuffer(8000, tis)
: Process.getByteBuffer(8000, tis, cl);
} catch (SysException e) {
e.printStackTrace();
tprc.interrupt();
throw new SysRuntimeException(e);
} finally {
executor.free(tprc);
}
try {