res = cntx_child
.getPrmByFullName(((grp_out == null) || (grp_out
.length() == 0)) ? "body" : grp_out
+ "/body");
if (res == null) {
Headers hd = httpExchange.getResponseHeaders();
hd.put("Content-Type",
Arrays.asList("text/plain; charset=" + enc));
httpExchange.sendResponseHeaders(503, 0);
OutputStream w = httpExchange.getResponseBody();
w.write("Обработчик не выбран".getBytes(enc));
w.close();
return;
}
} else {
Process.currentProcess().regResourceName(
cntx_child.id_task, "child.id");
long wait = Strings.parseIntegerNvl(
cntx.getPrmByFullName("wait"), 30000);// !!!
cntx.log(false, "Start waiting (", wait, ")");
cntx_child.ta.waitFinished(cntx_child.id_subject,
cntx_child.id_task, wait);
cntx.log(false, "End waiting");
res = cntx_child
.getPrmByFullName(((grp_out == null) || (grp_out
.length() == 0)) ? "body" : grp_out
+ "/body");
}
if (res != null) {
Map<String, Object> result = cntx_child
.getGroupParams(grp_out);
long l = 0;
if (res instanceof FileInputStream) {
is = (FileInputStream) res;
l = ((FileInputStream) is).getChannel().size();
} else if (res instanceof Element) {
Element el = (Element) res;
obb = new OutputByteBuffer(8000);
XMLFileWaiter.putStream(el, obb, "utf-8");
try {
obb.close();
l = obb.getLength();
} catch (IOException e1) {
e1.printStackTrace();
}
is = obb.getIS();
} else if (res instanceof OutputByteBuffer) {
is = ((OutputByteBuffer) res).getIS();
l = ((OutputByteBuffer) res).getLength();
} else if (res instanceof File) {
File f = (File) res;
cntx.log(false, "source file name = ",
f.getCanonicalPath());
is = new FileInputStream(f.getCanonicalPath());
l = f.length();
} else if (res instanceof InputStreamReader) {
InputStreamReader f = (InputStreamReader) res;
File x = File.createTempFile("dbms", "clob");
FileWriter w = new FileWriter(x);
char[] buf = new char[8 * 1024];
int len;
while ((len = f.read(buf)) > 0) {
w.write(buf, 0, len);
}
w.flush();
w.close();
is = new FileInputStream(x);
l = ((FileInputStream) is).getChannel().size();
} else {
byte[] buf = res.toString().getBytes(enc);
is = new ByteArrayInputStream(buf);
l = buf.length;
}
Headers hd = httpExchange.getResponseHeaders();
hd.put("Content-Type",
Arrays.asList("text/plain; charset=" + enc));
hd.put("Content-Length",
Arrays.asList(Long.toString(l)));
String h = cntx.getFullName(grp_out, "hdrs.");
for (Map.Entry<String, Object> e : result.entrySet()) {
String k = e.getKey();
if (k.indexOf(h) == 0) {
k = k.substring(h.length());
Object o = e.getValue();
String v;
if (o != null && o instanceof IDependentParam) {
IDependentParam idp = (IDependentParam) o;
try {
o = idp.getValue(cntx_child);
} catch (CalculateException e1) {
e1.printStackTrace();
}
}
if (o == null)
continue;
v = Strings.getString(o);
hd.put(k, Arrays.asList(v));
}
}
httpExchange.sendResponseHeaders(200, l);
OutputStream w = httpExchange.getResponseBody();
byte[] buf = new byte[8 * 1024];