@Path("/resubmitasync")
 @POST
 @Consumes("application/xml")
 @Produces("application/xml")
 public MessageResponse submitRecoverJobAsync(Message message) {
   MessageResponse response = new MessageResponse();
   String messageXML = MessageUtil.readRequestMessage(message);
   String expID = message.getHeader().getExperimentid();
   log.info(
       "Async Resuest recived from client at :"
           + new Date()
           + " : and assigned experiment id :"
           + expID
           + "with message "
           + messageXML);
   try {
     submitAsyncRequest(message);
   } catch (Exception e) {
     try {
       response.setMessage("Failed to submit job to gfac");
     } catch (Exception e1) {
       response.setStatus(ServiceConstants.ERROR);
       response.setMessage(e1.getLocalizedMessage());
     }
     response.setStatus(ServiceConstants.ERROR);
     response.setMessage(e.getLocalizedMessage());
   }
   response.setExperimentid(message.getHeader().getExperimentid());
   return response;
 }
  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;
  }
 @Path("/sync")
 @POST
 @Consumes("application/xml")
 @Produces("application/xml")
 public MessageResponse submitJobSync(Message message) {
   if (message.getHeader().getExperimentid() == null
       || message.getHeader().getExperimentid().isEmpty()) {
     String newexpID = createExperimentID();
     message.getHeader().setExperimentid(newexpID);
   }
   String expID = message.getHeader().getExperimentid();
   MessageResponse response = new MessageResponse();
   String messageXML = MessageUtil.readRequestMessage(message);
   log.info(
       "Sync Resuest recived from client at :"
           + new Date()
           + " : and assigned experiment id :"
           + expID
           + "with message"
           + messageXML);
   try {
     insertExperimentStatus(
         expID,
         ServiceConstants.SUBMITTED,
         messageXML,
         message.getHeader().getCluster(),
         message.getHeader().getUs3Db());
     submitSyncRequest(message);
   } catch (Exception e) {
     try {
       updateExperimentStatus(expID, ServiceConstants.FAILED, e.getLocalizedMessage());
       response.setMessage("Failed to submit job to gfac");
     } catch (Exception e1) {
       response.setStatus(ServiceConstants.ERROR);
       response.setMessage(e1.getLocalizedMessage());
     }
     response.setStatus(ServiceConstants.ERROR);
     response.setMessage(e.getLocalizedMessage());
   }
   response.setExperimentid(expID);
   return response;
 }
 @Path("/async")
 @POST
 @Consumes("multipart/mixed")
 @Produces("application/xml")
 public MessageResponse submitJobAsync(MultiPart multiPart) {
   String messageXML = null;
   String expID = null;
   MessageResponse response = new MessageResponse();
   try {
     Message message = readMulipartData(multiPart);
     expID = message.getHeader().getExperimentid();
     messageXML = MessageUtil.readRequestMessage(message);
     log.info(
         "Async multipart resuest recived from client at :"
             + new Date()
             + " : and assigned experiment id :"
             + message.getHeader().getExperimentid()
             + "with message "
             + messageXML);
     insertExperimentStatus(
         expID,
         ServiceConstants.SUBMITTED,
         messageXML,
         message.getHeader().getCluster(),
         message.getHeader().getUs3Db());
     submitAsyncRequest(message);
   } catch (Exception e) {
     e.printStackTrace();
     try {
       updateExperimentStatus(
           expID, ServiceConstants.FAILED, "Failed to submit job :" + e.getMessage());
       response.setMessage("Failed to submit job to gfac" + e.getMessage());
     } catch (Exception e1) {
       response.setStatus(ServiceConstants.ERROR);
       response.setMessage(e.getLocalizedMessage());
     }
     response.setStatus(ServiceConstants.ERROR);
     response.setMessage(e.getLocalizedMessage());
   }
   response.setExperimentid(expID);
   return response;
 }