Esempio n. 1
0
  protected synchronized void initFromServiceDescriptor() throws InitialisationException {
    try {
      serviceDescriptor =
          ConnectorFactory.getServiceDescriptor(getProtocol().toLowerCase(), serviceOverrides);

      if (serviceDescriptor.getDispatcherFactory() != null) {
        logger.info("Loading DispatcherFactory: " + serviceDescriptor.getDispatcherFactory());
        dispatcherFactory = serviceDescriptor.createDispatcherFactory();
      }

      defaultInboundTransformer = serviceDescriptor.createInboundTransformer();
      defaultOutboundTransformer = serviceDescriptor.createOutboundTransformer();
      defaultResponseTransformer = serviceDescriptor.createResponseTransformer();

      sessionHandler = serviceDescriptor.createSessionHandler();
      // set any manager default properties for the connector
      // these are set on the Manager with a protocol i.e.
      // jms.specification=1.1
      // This provides a really convenient way to set properties on object form unit
      // tests
      Map props = new HashMap();
      PropertiesHelper.getPropertiesWithPrefix(
          MuleManager.getInstance().getProperties(), getProtocol().toLowerCase(), props);
      if (props.size() > 0) {
        props = PropertiesHelper.removeNamspaces(props);
        org.mule.util.BeanUtils.populateWithoutFail(this, props, true);
      }
    } catch (Exception e) {
      throw new InitialisationException(e, this);
    }
  }
Esempio n. 2
0
  protected Properties getPropertiesForURI(URI uri) {
    Properties properties = PropertiesHelper.getPropertiesFromQueryString(uri.getQuery());

    String tempEndpointName = (String) properties.remove(PROPERTY_ENDPOINT_NAME);
    if (tempEndpointName != null) {
      this.endpointName = tempEndpointName;
    }
    // override the endpointUri if set
    String endpoint = (String) properties.remove(PROPERTY_ENDPOINT_URI);
    if (endpoint != null) {
      this.address = endpoint;
    }

    String cnnName = (String) properties.remove(PROPERTY_CONNECTOR_NAME);
    if (cnnName != null) {
      this.connectorName = cnnName;
    }

    String create = (String) properties.remove(PROPERTY_CREATE_CONNECTOR);
    if (create != null) {
      if ("0".equals(create)) {
        this.createConnector = ConnectorFactory.GET_OR_CREATE_CONNECTOR;
      } else if ("1".equals(create)) {
        this.createConnector = ConnectorFactory.ALWAYS_CREATE_CONNECTOR;
      } else if ("2".equals(create)) {
        this.createConnector = ConnectorFactory.NEVER_CREATE_CONNECTOR;
      } else if ("IF_NEEDED".equals(create)) {
        this.createConnector = ConnectorFactory.GET_OR_CREATE_CONNECTOR;
      } else if ("ALWAYS".equals(create)) {
        this.createConnector = ConnectorFactory.ALWAYS_CREATE_CONNECTOR;
      } else if ("NEVER".equals(create)) {
        this.createConnector = ConnectorFactory.NEVER_CREATE_CONNECTOR;
      } else if (connectorName == null) {
        this.createConnector = ConnectorFactory.USE_CONNECTOR;
        connectorName = create;
      }
    }

    transformers = (String) properties.remove(PROPERTY_TRANSFORMERS);
    if (transformers != null) {
      transformers = transformers.replaceAll(" ", ",");
    }
    return properties;
  }
Esempio n. 3
0
  /*
   * (non-Javadoc)
   *
   * @see org.mule.transformers.AbstractTransformer#doTransform(java.lang.Object)
   */
  public Object transform(Object src, UMOEventContext context) throws TransformerException {
    String endpointAddress = endpoint.getEndpointURI().getAddress();
    SmtpConnector connector = (SmtpConnector) endpoint.getConnector();
    String to = context.getStringProperty(MailProperties.TO_ADDRESSES_PROPERTY, endpointAddress);
    String cc =
        context.getStringProperty(MailProperties.CC_ADDRESSES_PROPERTY, connector.getCcAddresses());
    String bcc =
        context.getStringProperty(
            MailProperties.BCC_ADDRESSES_PROPERTY, connector.getBccAddresses());
    String from =
        context.getStringProperty(MailProperties.FROM_ADDRESS_PROPERTY, connector.getFromAddress());
    String replyTo =
        context.getStringProperty(
            MailProperties.REPLY_TO_ADDRESSES_PROPERTY, connector.getReplyToAddresses());
    String subject =
        context.getStringProperty(MailProperties.SUBJECT_PROPERTY, connector.getSubject());

    String contentType =
        context.getStringProperty(MailProperties.CONTENT_TYPE_PROPERTY, connector.getContentType());

    Properties headers = new Properties();
    if (connector.getCustomHeaders() != null) headers.putAll(connector.getCustomHeaders());
    Properties otherHeaders =
        (Properties) context.getProperty(MailProperties.CUSTOM_HEADERS_MAP_PROPERTY);
    if (otherHeaders != null) {
      Map props = new HashMap(MuleManager.getInstance().getProperties());
      props.putAll(context.getProperties());
      headers.putAll(templateParser.parse(props, otherHeaders));
    }

    if (logger.isDebugEnabled()) {
      StringBuffer buf = new StringBuffer();
      buf.append("Constucting email using:\n");
      buf.append("To: ").append(to);
      buf.append("From: ").append(from);
      buf.append("CC: ").append(cc);
      buf.append("BCC: ").append(bcc);
      buf.append("Subject: ").append(subject);
      buf.append("ReplyTo: ").append(replyTo);
      buf.append("Content type: ").append(contentType);
      buf.append("Payload type: ").append(src.getClass().getName());
      buf.append("Custom Headers: ").append(PropertiesHelper.propertiesToString(headers, false));
      logger.debug(buf.toString());
    }

    try {
      Message msg =
          new MimeMessage(
              (Session)
                  endpoint.getConnector().getDispatcher(endpointAddress).getDelegateSession());

      msg.setRecipients(Message.RecipientType.TO, MailUtils.stringToInternetAddresses(to));

      // sent date
      msg.setSentDate(Calendar.getInstance().getTime());

      if (from != null && !Utility.EMPTY_STRING.equals(from)) {
        msg.setFrom(MailUtils.stringToInternetAddresses(from)[0]);
      }

      if (cc != null && !Utility.EMPTY_STRING.equals(cc)) {
        msg.setRecipients(Message.RecipientType.CC, MailUtils.stringToInternetAddresses(cc));
      }

      if (bcc != null && !Utility.EMPTY_STRING.equals(bcc)) {
        msg.setRecipients(Message.RecipientType.BCC, MailUtils.stringToInternetAddresses(bcc));
      }

      if (replyTo != null && !Utility.EMPTY_STRING.equals(replyTo)) {
        msg.setReplyTo(MailUtils.stringToInternetAddresses(replyTo));
      }

      msg.setSubject(subject);

      Map.Entry entry;
      for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext(); ) {
        entry = (Map.Entry) iterator.next();
        msg.setHeader(entry.getKey().toString(), entry.getValue().toString());
      }

      setContent(src, msg, contentType, context);

      return msg;
    } catch (Exception e) {
      throw new TransformerException(this, e);
    }
  }