Ejemplo n.º 1
0
 /**
  * Will attempt to do a receive from a directory, if the endpointUri resolves to a file name the
  * file will be returned, otherwise the first file in the directory according to the filename
  * filter configured on the connector.
  *
  * @param endpointUri a path to a file or directory
  * @param timeout this is ignored when doing a receive on this dispatcher
  * @return a message containing file contents or null if there was notthing to receive
  * @throws Exception
  */
 public UMOMessage receive(UMOEndpointURI endpointUri, long timeout) throws Exception {
   File file = new File(endpointUri.getAddress());
   File result = null;
   if (file.exists()) {
     if (file.isFile()) {
       result = file;
     } else if (file.isDirectory()) {
       result = getNextFile(endpointUri.getAddress());
     }
     if (result != null) {
       MuleMessage message = new MuleMessage(connector.getMessageAdapter(result));
       if (connector.getMoveToDirectory() != null) {
         {
           File destinationFile = new File(connector.getMoveToDirectory(), result.getName());
           if (!result.renameTo(destinationFile)) {
             logger.error(
                 "Failed to move file: "
                     + result.getAbsolutePath()
                     + " to "
                     + destinationFile.getAbsolutePath());
           }
         }
       }
       result.delete();
       return message;
     }
   }
   return null;
 }
Ejemplo n.º 2
0
  /** Test polling frequency set on a connector. */
  public void testConnectorPollingFrequency() throws Exception {
    FileConnector connector = (FileConnector) getConnector();
    connector.setPollingFrequency(POLLING_FREQUENCY);

    UMOEndpoint endpoint = getTestEndpoint("simple", UMOImmutableEndpoint.ENDPOINT_TYPE_RECEIVER);
    UMOComponent component = getTestComponent(getDescriptor());
    UMOMessageReceiver receiver = connector.createReceiver(component, endpoint);
    assertEquals(
        "Connector's polling frequency must not be ignored.",
        POLLING_FREQUENCY,
        ((FileMessageReceiver) receiver).getFrequency());
  }
Ejemplo n.º 3
0
  public void testOnlySingleDispatcherPerEndpoint() {
    // MULE-1773 implies that we must only have one dispatcher per endpoint
    FileConnector connector = (FileConnector) getConnector();

    assertEquals(1, connector.getMaxDispatchersActive());

    try {
      connector.setMaxDispatchersActive(2);
      fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException iax) {
      // OK - expected
    }

    // value must be unchanged
    assertEquals(1, connector.getMaxDispatchersActive());
  }
Ejemplo n.º 4
0
  /** Test polling frequency overridden at an endpoint level. */
  public void testPollingFrequencyEndpointOverride() throws Exception {
    FileConnector connector = (FileConnector) getConnector();
    // set some connector-level value which we are about to override
    connector.setPollingFrequency(-1);

    UMOEndpoint endpoint = getTestEndpoint("simple", UMOImmutableEndpoint.ENDPOINT_TYPE_RECEIVER);

    Properties props = new Properties();
    // Endpoint wants String-typed properties
    props.put(FileConnector.PROPERTY_POLLING_FREQUENCY, String.valueOf(POLLING_FREQUENCY_OVERRIDE));
    endpoint.setProperties(props);

    UMOComponent component = getTestComponent(getDescriptor());
    UMOMessageReceiver receiver = connector.createReceiver(component, endpoint);
    assertEquals(
        "Polling frequency endpoint override must not be ignored.",
        POLLING_FREQUENCY_OVERRIDE,
        ((FileMessageReceiver) receiver).getFrequency());
  }
Ejemplo n.º 5
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);
    }
  }
  /* (non-Javadoc)
   * @see org.bedework.synch.ConnectorInstance#getItemsInfo()
   */
  @Override
  public SynchItemsInfo getItemsInfo() throws SynchException {
    SynchItemsInfo sii = new SynchItemsInfo();
    sii.items = new ArrayList<ItemInfo>();
    sii.setStatus(StatusType.OK);

    getIcal();

    if (sub.changed()) {
      cnctr.getSyncher().updateSubscription(sub);
    }

    for (MapEntry me : uidMap.values()) {
      sii.items.add(new ItemInfo(me.uid, me.lastMod, null)); // lastSynch
    }

    return sii;
  }
  /* (non-Javadoc)
   * @see org.bedework.synch.cnctrs.ConnectorInstance#fetchItem(java.lang.String)
   */
  @Override
  public FetchItemResponseType fetchItem(final String uid) throws SynchException {
    getIcal();

    if (sub.changed()) {
      cnctr.getSyncher().updateSubscription(sub);
    }

    MapEntry me = uidMap.get(uid);

    FetchItemResponseType fir = new FetchItemResponseType();

    if (me == null) {
      fir.setStatus(StatusType.NOT_FOUND);
      return fir;
    }

    fir.setHref(info.getUri() + "#" + uid);
    fir.setChangeToken(info.getChangeToken());

    IcalendarType ical = new IcalendarType();
    VcalendarType vcal = new VcalendarType();

    ical.getVcalendar().add(vcal);

    vcal.setProperties(new ArrayOfProperties());
    List<JAXBElement<? extends BasePropertyType>> pl = vcal.getProperties().getBasePropertyOrTzid();

    ProdidPropType prod = new ProdidPropType();
    prod.setText(prodid);
    pl.add(of.createProdid(prod));

    VersionPropType vers = new VersionPropType();
    vers.setText("2.0");
    pl.add(of.createVersion(vers));

    ArrayOfComponents aoc = new ArrayOfComponents();
    vcal.setComponents(aoc);

    aoc.getBaseComponent().addAll(me.comps);
    fir.setIcalendar(ical);

    return fir;
  }
  private DavClient getClient() throws SynchException {
    if (client != null) {
      return client;
    }

    DavClient cl = null;

    try {
      cl = new DavClient(15 * 1000);

      if (info.getPrincipalHref() != null) {
        cl.setCredentials(info.getPrincipalHref(), cnctr.getSyncher().decrypt(info.getPassword()));
      }

      client = cl;

      return cl;
    } catch (DavioException de) {
      throw new SynchException(de);
    }
  }
Ejemplo n.º 9
0
 private String generateFilename(UMOEvent event, String pattern) {
   if (pattern == null) {
     pattern = connector.getOutputPattern();
   }
   return connector.getFilenameParser().getFilename(event, pattern);
 }