private void writeJobXML(String experimentID, Message message) throws Exception { try { String inputLocation = properties.getProperty(ServiceConstants.INPUTLOCATION); if (inputLocation == null) { inputLocation = "."; } File file = new File(inputLocation + File.separatorChar + experimentID); log.info("Input Location " + file.getAbsolutePath()); if (file != null && !file.exists()) { file.mkdir(); } File jobFile = new File(file.getAbsolutePath() + File.separator + "jobxmlfile.xml"); String filePath = "file://" + jobFile.getAbsolutePath(); Parameters parameters = new Parameters(); parameters.setName("jobxml"); parameters.setValue(filePath); message.getBody().getInput().getParameters().add(parameters); log.info("Job File Location " + jobFile.getAbsolutePath()); BufferedWriter out = new BufferedWriter(new FileWriter(jobFile)); out.write(MessageUtil.readRequestMessage(message)); out.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
private Message readMulipartData(MultiPart multiPart) throws Exception { Message message = multiPart.getBodyParts().get(0).getEntityAs(Message.class); InputStream inputStream = null; FileOutputStream outputStream = null; try { if (message.getHeader().getExperimentid() == null || message.getHeader().getExperimentid().isEmpty()) { String newexpID = createExperimentID(); message.getHeader().setExperimentid(newexpID); } String expID = message.getHeader().getExperimentid(); BodyPartEntity entity = (BodyPartEntity) multiPart.getBodyParts().get(1).getEntity(); List<String> list = multiPart.getBodyParts().get(1).getHeaders().get("Content-Transfer-Encoding"); if (list != null && list.contains("base64")) { log.info("Encoded data recieved from the server"); inputStream = new Base64InputStream(entity.getInputStream()); } else { log.info("Data recieved from the server"); inputStream = entity.getInputStream(); } String inputLocation = properties.getProperty(ServiceConstants.INPUTLOCATION); if (inputLocation == null) { inputLocation = "."; } File file = new File(inputLocation + File.separatorChar + expID); log.info("Input Location " + file.getAbsolutePath()); if (file != null && !file.exists()) { file.mkdir(); } File tarfile = new File(file.getAbsolutePath() + File.separator + "hpcinput.tar"); outputStream = new FileOutputStream(tarfile); int i; while ((i = inputStream.read()) != -1) { outputStream.write(i); } String filePath = "file://" + tarfile.getAbsolutePath(); Parameters parameters = new Parameters(); parameters.setName("inputData"); parameters.setValue(filePath); message.getBody().getInput().getParameters().add(parameters); writeJobXML(expID, message); } finally { if (multiPart != null) { multiPart.cleanup(); multiPart.close(); } if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.flush(); outputStream.close(); } } return message; }