");
christian@5008:
raimund@2494: if (result == null) {
raimund@2494: logger.warn("FileUpload service returned no result.");
christian@5008: respWriter.write("FileUpload service returned no result");
raimund@2494: }
christian@5008: else {
christian@5008: String status = result.getElementsByTagName("status")
christian@5008: .item(0).getTextContent();
christian@5008: respWriter.write(status);
christian@5008: }
christian@5008:
christian@5008: respWriter.write("
");
christian@5008: respWriter.flush();
raimund@2494:
raimund@2494: return;
raimund@2494: }
raimund@2494: catch (ConnectionException ce) {
raimund@2494: logger.error(ce, ce);
raimund@2494: }
christian@5008: catch (IOException e) {
christian@5008: logger.error(e, e);
christian@5008: }
raimund@2494: }
raimund@2494:
raimund@2494:
raimund@2494: protected Document createFileXML(HttpServletRequest req) {
raimund@2494: ServletFileUpload upload = new ServletFileUpload();
raimund@2494:
raimund@2494: try{
raimund@2494: FileItemIterator iter = upload.getItemIterator(req);
raimund@2494:
raimund@2494: while (iter.hasNext()) {
raimund@2494: FileItemStream item = iter.next();
raimund@2494: InputStream stream = item.openStream();
raimund@2494:
raimund@2494: // Process the input stream
raimund@2494: ByteArrayOutputStream out = new ByteArrayOutputStream();
raimund@2494: int len;
raimund@2494: byte[] buffer = new byte[stream.available()];
raimund@2494: while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
raimund@2494: out.write(buffer, 0, len);
raimund@2494: }
raimund@2494:
christian@2954: buffer = Base64.encodeBase64(buffer);
christian@2954: String b64File = new String(buffer);
raimund@2494:
raimund@2494: Document fileDoc = XMLUtils.newDocument();
raimund@2494:
raimund@2494: ElementCreator ec = new ElementCreator(fileDoc, null, null);
raimund@2494: Element root = ec.create("upload");
raimund@2494: Element id = ec.create("artifact-uuid");
raimund@2494: id.setTextContent(req.getParameter("uuid"));
raimund@2494:
raimund@2494: Element data = ec.create("data");
raimund@2494: data.setTextContent(b64File);
raimund@2494:
raimund@2494: fileDoc.appendChild(root);
raimund@2494: root.appendChild(id);
raimund@2494: root.appendChild(data);
raimund@2494:
raimund@2494: return fileDoc;
raimund@2494: }
raimund@2494: }
raimund@2494: catch(Exception e){
raimund@2494: logger.debug("Failed to create xml document containing the file.");
raimund@2494: logger.debug(e, e);
raimund@2494: }
raimund@2494: return null;
raimund@2494: }
raimund@2494: }