Beispiel #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);
    }
  }
Beispiel #2
0
  /**
   * Exception safe version of BeanUtils.populate()
   *
   * @param object the object to set the properties on
   * @param props the map of properties to set
   * @param logWarnings whether exception warnings should be logged
   */
  public static void populateWithoutFail(Object object, Map props, boolean logWarnings) {
    // Check to see if our object has a setProperties method where the properties
    // map should be set
    if (ClassUtils.getMethod(object.getClass(), SET_PROPERTIES_METHOD, new Class[] {Map.class})
        != null) {
      try {
        BeanUtils.setProperty(object, "properties", props);
      } catch (Exception e) {
        // this should never happen since we explicitly check for the method
        // above
        if (logWarnings) {
          logger.warn(
              "Property: "
                  + SET_PROPERTIES_METHOD
                  + "="
                  + Map.class.getName()
                  + " not found on object: "
                  + object.getClass().getName());
        }
      }
    } else {
      for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iterator.next();

        try {
          BeanUtils.setProperty(object, entry.getKey().toString(), entry.getValue());
        } catch (Exception e) {
          if (logWarnings) {
            logger.warn(
                "Property: "
                    + entry.getKey()
                    + "="
                    + entry.getValue()
                    + " not found on object: "
                    + object.getClass().getName());
          }
        }
      }
    }
  }
  @Override
  public Object transformMessage(MuleMessage message, String outputEncoding)
      throws TransformerException {
    try {
      ProcessInstance processInstance = new ProcessInstance();
      Map<String, Object> rootAsMap =
          this.getMapper().readValue(message.getPayloadAsString(), Map.class);
      BeanUtils.populateWithoutFail(processInstance, rootAsMap, false);

      return processInstance;
    } catch (Exception e) {
      throw new TransformerException(ActivitiMessages.failToProcessJson(), e);
    }
  }
Beispiel #4
0
  /** Creates an initialized object instance based on the class and sets any properties. */
  public Object getInstance() throws Exception {
    if (objectClass == null) {
      throw new InitialisationException(
          MessageFactory.createStaticMessage("Object factory has not been initialized."), this);
    }

    Object object = ClassUtils.instanciateClass(objectClass, ClassUtils.NO_ARGS);

    if (properties != null) {
      BeanUtils.populate(object, properties);
    }

    fireInitialisationCallbacks(object);

    return object;
  }
Beispiel #5
0
 /**
  * This will overlay a map of properties on a bean. This method will validate that all properties
  * are available on the bean before setting the properties
  *
  * @param bean the bean on which to set the properties
  * @param props a Map of properties to set on the bean
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  */
 public static void populate(Object bean, Map props)
     throws IllegalAccessException, InvocationTargetException {
   // Check to see if our object has a setProperties method where the properties
   // map should be set
   if (ClassUtils.getMethod(bean.getClass(), SET_PROPERTIES_METHOD, new Class[] {Map.class})
       != null) {
     BeanUtils.setProperty(bean, "properties", props);
   } else {
     Map master = describe(bean);
     for (Iterator iterator = props.keySet().iterator(); iterator.hasNext(); ) {
       Object o = iterator.next();
       if (!master.containsKey(o)) {
         throw new IllegalArgumentException(
             CoreMessages.propertyDoesNotExistOnObject(o.toString(), bean).getMessage());
       }
     }
     org.apache.commons.beanutils.BeanUtils.populate(bean, props);
   }
 }
Beispiel #6
0
  /**
   * Creates a component based on its descriptor.
   *
   * @param descriptor the descriptor to create the component from
   * @return The newly created component
   * @throws UMOException
   */
  public static Object createService(UMODescriptor descriptor) throws UMOException {
    Object component;
    try {
      component = descriptor.getServiceFactory().create();

      // TODO MULE-1933 Would be nice to remove this eventually.
      BeanUtils.populate(component, descriptor.getProperties());
    } catch (Exception e) {
      throw new LifecycleException(
          MessageFactory.createStaticMessage("Unable to create component"), e, descriptor);
    }

    // Call any custom initialisers
    if (descriptor instanceof MuleDescriptor) {
      ((MuleDescriptor) descriptor).fireInitialisationCallbacks(component);
    }

    return component;
  }
Beispiel #7
0
 // @java.lang.Override
 public UMOTransformer lookupTransformer(String name) {
   UMOTransformer transformer = super.lookupTransformer(name);
   if (transformer != null) {
     try {
       if (transformer.getEndpoint() != null) {
         throw new IllegalStateException("Endpoint cannot be set");
       }
       //                Map props = BeanUtils.describe(transformer);
       //                props.remove("endpoint");
       //                props.remove("strategy");
       //                transformer =
       // (UMOTransformer)ClassUtils.instanciateClass(transformer.getClass(), ClassUtils.NO_ARGS);
       // TODO: friggin' cloning
       transformer = (UMOTransformer) BeanUtils.cloneBean(transformer);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return transformer;
 }
  /** Returns an initialized connector. */
  public Connector getOrCreateConnectorByProtocol(EndpointURI uri)
      throws TransportFactoryException {
    String connectorName = uri.getConnectorName();
    if (null != connectorName) {
      // TODO this lookup fails currently on Mule 2.x! MuleAdminAgentTestCase
      Connector connector = muleContext.getRegistry().lookupConnector(connectorName);
      if (connector != null) {
        return connector;
      }
    }

    Connector connector = getConnectorByProtocol(uri.getFullScheme());
    if (connector == null) {
      connector = createConnector(uri);
      try {
        BeanUtils.populate(connector, uri.getParams());
        muleContext.getRegistry().registerConnector(connector);
      } catch (Exception e) {
        throw new TransportFactoryException(e);
      }
    }
    return connector;
  }
Beispiel #9
0
 public void initialiseFromUrl(UMOEndpointURI endpointUri) throws InitialisationException {
   if (!supportsProtocol(endpointUri.getFullScheme())) {
     throw new InitialisationException(
         new Message(
             Messages.SCHEME_X_NOT_COMPATIBLE_WITH_CONNECTOR_X,
             endpointUri.getFullScheme(),
             getClass().getName()),
         this);
   }
   Properties props = new Properties();
   props.putAll(endpointUri.getParams());
   // auto set username and password
   if (endpointUri.getUserInfo() != null) {
     props.setProperty("username", endpointUri.getUsername());
     String passwd = endpointUri.getPassword();
     if (passwd != null) {
       props.setProperty("password", passwd);
     }
   }
   String host = endpointUri.getHost();
   if (host != null) {
     props.setProperty("hostname", host);
     props.setProperty("host", host);
   }
   if (endpointUri.getPort() > -1) {
     props.setProperty("port", String.valueOf(endpointUri.getPort()));
   }
   // try
   // {
   BeanUtils.populateWithoutFail(this, props, true);
   // } catch (InvocationTargetException e)
   // {
   // throw new InitialisationException(new
   // Message(Messages.FAILED_TO_SET_PROPERTIES_ON_X, "Connector"), e,
   // this);
   // }
 }