re = (ResponseElement) i.next();
internationalize(re, messages);
/* Now make a dynabean for the given element */
ResponseElementDynaBean reAsBean = new ResponseElementDynaBean(re);
wreq.setAttribute(re.getName(), reAsBean);
if (re instanceof Input)
{
inputs.add(reAsBean);
}
else if (re instanceof Output)
{
// HACK: For the moment, if re is output file, write to stream
// here, as not being written otherwise
final String outputType = (String) re.getAttribute("type");
if ((outputType != null) && outputType.equals("binary"))
{
// Binary data, so dump to output stream now....
log.debug("File Data is available");
final BinaryWrapper data = (BinaryWrapper) ((Output) re).getContent();
// hres.setContentLength(new
// Integer(((Long)re.getAttribute("ContentLength")).toString()).intValue());
final long dataSize = data.getSize();
if ((dataSize > 0) && (dataSize < Integer.MAX_VALUE))
{
// Have a valid content length.
hres.setContentLength((int) data.getSize());
}
hres.setContentType(data.getContentType());
hres.setHeader("Content-Disposition", (String) re.getAttribute("Content-Disposition"));
// String encodings = hreq.getHeader ("Accept-Encoding");
BufferedOutputStream buffOut = null;
try
{
// BUG #844574:Writing using GZip compression is very
// slow
// HACK: Disable GZip compression until speed/threading
// issues are worked out.
// if (encodings != null && encodings.indexOf ("gzip") != -1)
// {
// log.info ("Writing data using GZip compression");
//
// final OutputStream out = hres.getOutputStream ();
//
// buffOut = new BufferedOutputStream(
// new GZIPOutputStream(out), BUFFER_SIZE);
// hres.setHeader ("Content-Encoding", "gzip");
// }
// else
// {
log.info("Writing data with no compression");
OutputStream out = hres.getOutputStream();
buffOut = new BufferedOutputStream(out, BUFFER_SIZE);
// }
data.writeTo(buffOut);
log.trace("Wrote Buffer.");
}
catch (IOException e)
{
e.printStackTrace();
log.error("Exception during file read/write:", e);
throw new ClientException("Exception during file read/write", e);
}
finally
{
// Flush all streams, and close input streams
try
{
data.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
try
{
buffOut.flush();
}
catch (IOException e2)
{
e2.printStackTrace();
}
// Do NOT close the Output stream here, as the
// underlying output stream is/should be closed later.
}
}
else
{
outputs.add(reAsBean);
}
}
else if (re instanceof Command)
{
commands.add(reAsBean);
}
}
wreq.setAttribute("inputs", inputs);
wreq.setAttribute("outputs", outputs);
wreq.setAttribute("commands", commands);
int inputCount = 0;
DynaProperty[] dps = new DynaProperty[inputs.size()];
ResponseElementDynaBean oneInput = null;
for (Iterator ii = inputs.iterator(); ii.hasNext();)
{
oneInput = (ResponseElementDynaBean) ii.next();
Object defValue = oneInput.get("defaultValue");
DynaProperty dp = null;
if (defValue != null)
{
dp = new DynaProperty((String) oneInput.get("name"), oneInput.get("defaultValue").getClass());
}
else
{
try
{
dp = new DynaProperty((String) oneInput.get("name"), Class.forName("java.lang.String"));
}
catch (ClassNotFoundException e)
{
throw new ClientException("Cannot create String dynaproperty", e);
}
}
dps[inputCount++] = dp;
}
BasicDynaClass bd;
try
{
bd = new BasicDynaClass(modelName, Class.forName("org.apache.commons.beanutils.BasicDynaBean"), dps);
BasicDynaBean newForm = (BasicDynaBean) bd.newInstance();
// Now populate the newForm's properties
for (Iterator i2 = inputs.iterator(); i2.hasNext();)
{
oneInput = (ResponseElementDynaBean) i2.next();
newForm.set((String) oneInput.get("name"), oneInput.get("defaultValue"));
}
wreq.setAttribute("default", newForm);
}
catch (ClassNotFoundException e)