/**
   * Actual processing of the file/folder
   *
   * @param file
   * @return
   * @throws synapseException
   */
  private FileObject processFile(FileObject file) throws SynapseException {
    try {
      FileContent content = file.getContent();
      String fileName = file.getName().getBaseName();
      String filePath = file.getName().getPath();
      String fileURI = file.getName().getURI();

      if (injectHandler != null) {
        Map<String, Object> transportHeaders = new HashMap<String, Object>();
        transportHeaders.put(VFSConstants.FILE_PATH, filePath);
        transportHeaders.put(VFSConstants.FILE_NAME, fileName);
        transportHeaders.put(VFSConstants.FILE_URI, fileURI);

        try {
          transportHeaders.put(VFSConstants.FILE_LENGTH, content.getSize());
          transportHeaders.put(VFSConstants.LAST_MODIFIED, content.getLastModifiedTime());
        } catch (FileSystemException e) {
          log.warn("Unable to set file length or last modified date header.", e);
        }

        injectHandler.setTransportHeaders(transportHeaders);
        // injectHandler
        if (!injectHandler.invoke(file)) {
          return null;
        }
      }

    } catch (FileSystemException e) {
      log.error("Error reading file content or attributes : " + file, e);
    }
    return file;
  }
  public FileContentInfo create(FileContent fileContent) throws FileSystemException {
    MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
    Part part = mimeFile.getPart();

    String contentTypeString = null;
    String charset = null;

    try {
      // special handling for multipart
      if (mimeFile.isMultipart()) {
        // get the original content type, but ...
        contentTypeString = part.getContentType();

        // .... we deliver the preamble instead of an inupt string
        // the preamble will be delivered in UTF-8 - fixed
        charset = MimeFileSystem.PREAMBLE_CHARSET;
      }
    } catch (MessagingException e) {
      throw new FileSystemException(e);
    }

    if (contentTypeString == null) {
      // normal message ... get the content type
      try {
        contentTypeString = part.getContentType();
      } catch (MessagingException e) {
        throw new FileSystemException(e);
      }
    }

    ContentType contentType;
    try {
      contentType = new ContentType(contentTypeString);
    } catch (MessagingException e) {
      throw new FileSystemException(e);
    }

    if (charset == null) {
      // charset might already be set by the multipart message stuff, else
      // extract it from the contentType now
      charset = contentType.getParameter("charset"); // NON-NLS
    }

    return new DefaultFileContentInfo(contentType.getBaseType(), charset);
  }
 @Override
 public OutputStream getOutputStream() throws FileSystemException {
   return fileContent.getOutputStream();
 }
 @Override
 public void removeAttribute(final String s) throws FileSystemException {
   fileContent.removeAttribute(s);
 }
 @Override
 public Certificate[] getCertificates() throws FileSystemException {
   return fileContent.getCertificates();
 }
 @Override
 public Object getAttribute(final String s) throws FileSystemException {
   return fileContent.getAttribute(s);
 }
 @Override
 public void setAttribute(final String s, final Object o) throws FileSystemException {
   fileContent.setAttribute(s, o);
 }
Ejemplo n.º 8
0
 private InputStream inputStreamFrom(final FileContent content) throws FileSystemException {
   return content.getInputStream();
 }
 @Override
 public void close() throws FileSystemException {
   fileContent.close();
 }
 @Override
 public void setLastModifiedTime(final long l) throws FileSystemException {
   fileContent.setLastModifiedTime(l);
 }
 @Override
 public boolean hasAttribute(final String s) throws FileSystemException {
   return fileContent.hasAttribute(s);
 }
 @Override
 public long getSize() throws FileSystemException {
   return fileContent.getSize();
 }
 @Override
 public long getLastModifiedTime() throws FileSystemException {
   return fileContent.getLastModifiedTime();
 }
 @Override
 public FileObject getFile() {
   return fileContent.getFile();
 }
 @Override
 public boolean isOpen() {
   return fileContent.isOpen();
 }
 @Override
 public FileContentInfo getContentInfo() throws FileSystemException {
   return fileContent.getContentInfo();
 }
Ejemplo n.º 17
0
  /**
   * Process a single file through Axis2
   *
   * @param entry the PollTableEntry for the file (or its parent directory or archive)
   * @param file the file that contains the actual message pumped into Axis2
   * @throws AxisFault on error
   */
  private void processFile(PollTableEntry entry, FileObject file) throws AxisFault {

    try {
      FileContent content = file.getContent();
      String fileName = file.getName().getBaseName();
      String filePath = file.getName().getPath();

      metrics.incrementBytesReceived(content.getSize());

      Map<String, Object> transportHeaders = new HashMap<String, Object>();
      transportHeaders.put(VFSConstants.FILE_PATH, filePath);
      transportHeaders.put(VFSConstants.FILE_NAME, fileName);

      try {
        transportHeaders.put(VFSConstants.FILE_LENGTH, content.getSize());
        transportHeaders.put(VFSConstants.LAST_MODIFIED, content.getLastModifiedTime());
      } catch (FileSystemException ignore) {
      }

      MessageContext msgContext = entry.createMessageContext();

      String contentType = entry.getContentType();
      if (BaseUtils.isBlank(contentType)) {
        if (file.getName().getExtension().toLowerCase().endsWith(".xml")) {
          contentType = "text/xml";
        } else if (file.getName().getExtension().toLowerCase().endsWith(".txt")) {
          contentType = "text/plain";
        }
      } else {
        // Extract the charset encoding from the configured content type and
        // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
        String charSetEnc = null;
        try {
          if (contentType != null) {
            charSetEnc = new ContentType(contentType).getParameter("charset");
          }
        } catch (ParseException ex) {
          // ignore
        }
        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
      }

      // if the content type was not found, but the service defined it.. use it
      if (contentType == null) {
        if (entry.getContentType() != null) {
          contentType = entry.getContentType();
        } else if (VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE) != null) {
          contentType = VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE);
        }
      }

      // does the service specify a default reply file URI ?
      String replyFileURI = entry.getReplyFileURI();
      if (replyFileURI != null) {
        msgContext.setProperty(
            Constants.OUT_TRANSPORT_INFO,
            new VFSOutTransportInfo(replyFileURI, entry.isFileLockingEnabled()));
      }

      // Determine the message builder to use
      Builder builder;
      if (contentType == null) {
        log.debug("No content type specified. Using SOAP builder.");
        builder = new SOAPBuilder();
      } else {
        int index = contentType.indexOf(';');
        String type = index > 0 ? contentType.substring(0, index) : contentType;
        builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
        if (builder == null) {
          if (log.isDebugEnabled()) {
            log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
          }
          builder = new SOAPBuilder();
        }
      }

      // set the message payload to the message context
      InputStream in;
      ManagedDataSource dataSource;
      if (builder instanceof DataSourceMessageBuilder && entry.isStreaming()) {
        in = null;
        dataSource = ManagedDataSourceFactory.create(new FileObjectDataSource(file, contentType));
      } else {
        in = new AutoCloseInputStream(content.getInputStream());
        dataSource = null;
      }

      try {
        OMElement documentElement;
        if (in != null) {
          documentElement = builder.processDocument(in, contentType, msgContext);
        } else {
          documentElement =
              ((DataSourceMessageBuilder) builder)
                  .processDocument(dataSource, contentType, msgContext);
        }
        msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));

        handleIncomingMessage(
            msgContext,
            transportHeaders,
            null, // * SOAP Action - not applicable *//
            contentType);
      } finally {
        if (dataSource != null) {
          dataSource.destroy();
        }
      }

      if (log.isDebugEnabled()) {
        log.debug("Processed file : " + file + " of Content-type : " + contentType);
      }

    } catch (FileSystemException e) {
      handleException("Error reading file content or attributes : " + file, e);

    } finally {
      try {
        file.close();
      } catch (FileSystemException warn) {
        //  log.warn("Cannot close file after processing : " + file.getName().getPath(), warn);
        // ignore the warning, since we handed over the stream close job to AutocloseInputstream..
      }
    }
  }
 @Override
 public RandomAccessContent getRandomAccessContent(final RandomAccessMode randomAccessMode)
     throws FileSystemException {
   return fileContent.getRandomAccessContent(randomAccessMode);
 }
Ejemplo n.º 19
0
 private ZipEntry entryFor(final String name, final FileContent content)
     throws FileSystemException {
   final ZipEntry entry = new ZipEntry(name);
   entry.setTime(content.getLastModifiedTime());
   return entry;
 }
 @Override
 public String[] getAttributeNames() throws FileSystemException {
   return fileContent.getAttributeNames();
 }
 @Override
 public Map getAttributes() throws FileSystemException {
   return fileContent.getAttributes();
 }
 @Override
 public OutputStream getOutputStream(final boolean b) throws FileSystemException {
   return fileContent.getOutputStream(b);
 }