Пример #1
0
  /**
   * Retrieve the payload from the message.<br>
   * The default receiver stores the payload as a files at the particular place specified in the
   * configuration.
   */
  public void onResponse() throws Exception {
    EBMSMessageData d = (EBMSMessageData) this.properties;
    // Get the first element with tagname is "hasMessage".
    String result = this.getResponseElementText("hasMessage", NS_URI, 0);

    if (log != null) {
      this.log.log("Received Message id: " + this.messageId);
      this.log.log("Has payload ?      : " + result);
    }

    if (Boolean.valueOf(result).booleanValue()) {
      // Retreive the actual file path.

      File outputFolder = new File(this.getOutputDirectory());
      if (!outputFolder.exists()) outputFolder.mkdirs();

      // Get payload.
      Payload[] payloads = this.getResponsePayloads();

      // For each payload, we get the input stream
      // from the payload and read it to buffer.
      // then open the output file path and write the buffer.
      for (int i = 0; i < payloads.length; i++) {
        String filename = "ebms." + this.messageId + ".Payload." + i;

        File outputFile = new File(outputFolder.getAbsolutePath() + File.separator + filename);
        // Pipe the payload to the designated file.
        NIOHandler.pipe(payloads[i].getInputStream(), new FileOutputStream(outputFile));
      }
    }
  }