示例#1
0
 public static UMODescriptor getDescriptor(String name, String implementation) {
   UMODescriptor descriptor = new MuleDescriptor();
   descriptor.setExceptionListener(new DefaultExceptionStrategy());
   descriptor.setName(name);
   descriptor.setImplementation(implementation);
   return descriptor;
 }
示例#2
0
  /**
   * Usage 2: the implementation reference on the descriptor is to a component in the container
   *
   * @throws Exception
   */
  public void testExternalUMOReference() throws Exception {
    UMOContainerContext container = getContainerContext();
    assertNotNull(container);
    container.initialise();
    UMODescriptor descriptor = getTestDescriptor("some Ejb service", EJB_NAME);
    DummyEjbBean dummyEjbBean =
        (DummyEjbBean) container.getComponent(descriptor.getImplementation());

    assertNotNull(dummyEjbBean);
  }
示例#3
0
  public void testPropertyWithoutOverrides() {

    UMODescriptor d = MuleManager.getInstance().getModel().getDescriptor("test2");
    assertNotNull(d);
    UMOEndpoint endpoint = d.getInboundRouter().getEndpoint("ep1");
    assertNotNull(endpoint);
    assertNotNull(endpoint.getProperties());
    assertEquals(3, endpoint.getProperties().size());
    assertEquals("value1", endpoint.getProperties().get("prop1"));
    assertEquals("overrideValue2", endpoint.getProperties().get("prop2"));
    assertEquals("value3", endpoint.getProperties().get("prop3"));
  }
示例#4
0
  public void testPropertyWithOverrides() {

    UMODescriptor d = MuleManager.getInstance().getModel().getDescriptor("test3");
    assertNotNull(d);
    UMOEndpoint endpoint = d.getInboundRouter().getEndpoint("ep2");
    assertNotNull(endpoint);
    assertEquals("test://embedded", endpoint.getEndpointURI().getUri().toString());
    assertNotNull(endpoint.getProperties());
    assertEquals(3, endpoint.getProperties().size());
    assertEquals("value1", endpoint.getProperties().get("prop1"));
    assertEquals("value2", endpoint.getProperties().get("prop2"));
    assertEquals("value3", endpoint.getProperties().get("prop3"));
  }
示例#5
0
  public void testPropertyMapsListsEtc() {

    UMODescriptor d = MuleManager.getInstance().getModel().getDescriptor("test3");
    assertNotNull(d);
    Map props = (Map) d.getProperties().get("testMap");
    assertNotNull(props);
    assertEquals("foo entry", props.get("foo"));

    List list = (List) d.getProperties().get("testList");
    assertNotNull(list);
    assertEquals("bar entry", list.get(0).toString());

    assertEquals("${this should not be found}", d.getProperties().get("blah"));
    assertEquals("two tags foo entry and bar entry.", d.getProperties().get("foobar"));
  }
示例#6
0
  public void testProperties() {
    assertEquals("blah", MuleManager.getConfiguration().getModel());
    assertEquals("blah", MuleManager.getInstance().getModel().getName());

    AbstractConnector c =
        (AbstractConnector) MuleManager.getInstance().lookupConnector("myTestConnector");
    assertNotNull(c);
    assertTrue(c.getConnectionStrategy() instanceof SimpleRetryConnectionStrategy);
    assertEquals(4, ((SimpleRetryConnectionStrategy) c.getConnectionStrategy()).getRetryCount());

    UMODescriptor d = MuleManager.getInstance().getModel().getDescriptor("test-from-env-props");
    assertNotNull(d);
    assertEquals(d.getInboundEndpoint().getEndpointURI().toString(), "test://test.1");
    assertEquals(d.getOutboundEndpoint().getEndpointURI().toString(), "test://test.2");
  }
示例#7
0
  private boolean registerAsSoap(String endpoint, Object listener) throws UMOException {
    if (endpoint.startsWith("glue") || endpoint.startsWith("soap") || endpoint.startsWith("axis")) {
      UMOEndpointURI ep = new MuleEndpointURI(endpoint);
      QuickConfigurationBuilder builder = new QuickConfigurationBuilder();

      // get the service name from the URI path
      String serviceName = null;
      if (ep.getPath() != null) {
        String path = ep.getPath();
        if (path.endsWith("/")) {
          path = path.substring(0, path.length() - 1);
        }
        int i = path.lastIndexOf("/");
        if (i > -1) {
          serviceName = path.substring(i + 1);
        }
      } else {
        serviceName = descriptor.getName();
      }
      // now strip off the service name
      String newEndpoint = endpoint;
      int i = newEndpoint.indexOf(serviceName);
      newEndpoint = newEndpoint.substring(0, i - 1);
      builder.registerComponentInstance(listener, serviceName, new MuleEndpointURI(newEndpoint));
      return true;
    } else {
      return false;
    }
  }
示例#8
0
 // @java.lang.Override
 public void registerService(UMODescriptor service) throws UMOException {
   String modelName = service.getModelName();
   if (modelName == null) {
     logger.warn("Model name not ser on service, using default: " + UMOModel.DEFAULT_MODEL_NAME);
     modelName = UMOModel.DEFAULT_MODEL_NAME;
     service.setModelName(modelName);
   }
   UMOModel model = lookupModel(modelName);
   if (model == null) {
     // TODO
     throw new IllegalStateException(
         "Service must be associated with an existing model. Not found: " + modelName);
   }
   registerObject(UMODescriptor.class, service.getName(), service);
   model.registerComponent(service);
 }
示例#9
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;
  }
示例#10
0
  public UMOComponent initialiseComponent(
      UMODescriptor descriptor, byte txBeginAction, EventCallback callback) throws Exception {
    JMSMessageToObject inTrans = new JMSMessageToObject();
    ObjectToJMSMessage outTrans = new ObjectToJMSMessage();

    UMOEndpoint endpoint =
        new MuleEndpoint(
            "testIn",
            getInDest(),
            connector,
            inTrans,
            UMOEndpoint.ENDPOINT_TYPE_RECEIVER,
            0,
            null,
            null);

    UMOTransactionConfig txConfig = new MuleTransactionConfig();
    txConfig.setFactory(getTransactionFactory());
    txConfig.setAction(txBeginAction);

    UMOEndpoint outProvider =
        new MuleEndpoint(
            "testOut",
            getOutDest(),
            connector,
            outTrans,
            UMOEndpoint.ENDPOINT_TYPE_SENDER,
            0,
            null,
            null);

    endpoint.setTransactionConfig(txConfig);

    descriptor.setOutboundEndpoint(outProvider);
    descriptor.setInboundEndpoint(endpoint);
    HashMap props = new HashMap();
    props.put("eventCallback", callback);
    descriptor.setProperties(props);
    UMOComponent component = MuleManager.getInstance().getModel().registerComponent(descriptor);
    // MuleManager.getInstance().registerConnector(connector);
    return component;
  }
示例#11
0
  public void testSpecificContainerAddressingForComponents() throws Exception {
    QuickConfigurationBuilder builder = new QuickConfigurationBuilder();
    UMODescriptor d = builder.createDescriptor("Orange", "myOrange", "test://foo", null, null);
    d.setContainer("spring2");
    builder.registerComponent(d);
    UMOComponent c = builder.getManager().getModel().getComponent("myOrange");
    assertNotNull(c);
    Object o = c.getInstance();
    assertTrue(o instanceof Orange);
    Orange orange = (Orange) o;
    assertEquals(10, orange.getSegments().intValue());

    d = builder.createDescriptor("Orange", "myOrange2", "test://bar", null, null);
    d.setContainer("spring1");
    builder.registerComponent(d);
    c = builder.getManager().getModel().getComponent("myOrange2");
    assertNotNull(c);
    o = c.getInstance();
    assertTrue(o instanceof Orange);
    orange = (Orange) o;
    assertEquals(8, orange.getSegments().intValue());
  }
示例#12
0
  protected UMODescriptor getDefaultDescriptor() throws UMOException {
    // When the the beanFactory is refreshed all the beans get
    // reloaded so we need to unregister the component from Mule
    UMOModel model = MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL);
    if (model == null) {
      model = new SedaModel();
      model.setName(ModelHelper.SYSTEM_MODEL);
      MuleManager.getInstance().registerModel(model);
    }
    UMODescriptor descriptor = model.getDescriptor(EVENT_MULTICASTER_DESCRIPTOR_NAME);
    if (descriptor != null) {
      model.unregisterComponent(descriptor);
    }
    descriptor = new MuleDescriptor(EVENT_MULTICASTER_DESCRIPTOR_NAME);
    if (subscriptions == null) {
      logger.info("No receive endpoints have been set, using default '*'");
      descriptor.setInboundEndpoint(new MuleEndpoint("vm://*", true));
    } else {
      // Set multiple inbound subscriptions on the descriptor
      UMOInboundRouterCollection messageRouter = descriptor.getInboundRouter();

      for (int i = 0; i < subscriptions.length; i++) {
        String subscription = subscriptions[i];
        UMOEndpointURI endpointUri = new MuleEndpointURI(subscription);
        UMOEndpoint endpoint =
            MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
        if (!asynchronous) {
          endpoint.setSynchronous(true);
        }
        messageRouter.addEndpoint(endpoint);
      }
    }
    // set the implementation name to this bean so Mule will manage it
    descriptor.setImplementation(
        AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
    return descriptor;
  }