示例#1
0
 public static void fixProviderUrl(Properties props) throws IOException {
   String providerUrl = props.getProperty(Context.PROVIDER_URL);
   if (providerUrl != null && !providerUrl.startsWith("file:") && providerUrl.indexOf(':') < 0) {
     String path = Utility.getResourcePath(providerUrl, JmsTestUtils.class);
     if (path == null) throw new FileNotFoundException(providerUrl);
     providerUrl = "file:" + File.separator + path;
     System.out.println("Setting provider url to: " + providerUrl);
     props.setProperty(Context.PROVIDER_URL, providerUrl);
   }
 }
示例#2
0
  /* (non-Javadoc)
   * @see org.mule.umo.provider.UMOConnectorSession#dispatch(org.mule.umo.UMOEvent)
   */
  public void doDispatch(UMOEvent event) throws Exception {
    try {
      String endpoint = event.getEndpoint().getEndpointURI().getAddress();
      Object data = event.getTransformedMessage();
      String filename = (String) event.getProperty(FileConnector.PROPERTY_FILENAME);

      if (filename == null) {
        String outPattern = (String) event.getProperty(FileConnector.PROPERTY_OUTPUT_PATTERN);
        if (outPattern == null) {
          outPattern = connector.getOutputPattern();
        }
        filename = generateFilename(event, outPattern);
      }

      if (filename == null) {
        throw new IOException("Filename is null");
      }

      File file = Utility.createFile(endpoint + "/" + filename);
      byte[] buf;
      if (data instanceof byte[]) {
        buf = (byte[]) data;
      } else {
        buf = data.toString().getBytes();
      }

      logger.info("Writing file to: " + file.getAbsolutePath());
      FileOutputStream fos = new FileOutputStream(file, connector.isOutputAppend());
      try {
        fos.write(buf);
      } finally {
        fos.close();
      }
    } catch (Exception e) {
      getConnector().handleException(e);
    }
  }