@Test
  public void testResolveJmsEndpoint() throws Exception {
    reset(applicationContext);

    expect(applicationContext.getBeansOfType(EndpointComponent.class))
        .andReturn(Collections.<String, EndpointComponent>emptyMap())
        .once();
    expect(applicationContext.containsBean("connectionFactory")).andReturn(true).once();
    expect(applicationContext.getBean("connectionFactory", ConnectionFactory.class))
        .andReturn(EasyMock.createMock(ConnectionFactory.class))
        .once();

    replay(applicationContext);

    TestContext context = new TestContext();
    context.setApplicationContext(applicationContext);

    DefaultEndpointFactory factory = new DefaultEndpointFactory();
    Endpoint endpoint = factory.create("jms:Sample.Queue.Name", context);

    Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class);
    Assert.assertEquals(
        ((JmsEndpoint) endpoint).getEndpointConfiguration().getDestinationName(),
        "Sample.Queue.Name");

    verify(applicationContext);
  }
Exemple #2
0
  /**
   * Returns the EndpointFactory implementation for given endpoint configuration. Throws a
   * SynapseException, if there is no EndpointFactory for given configuration.
   *
   * @param configElement Endpoint configuration.
   * @return EndpointFactory implementation.
   */
  private static EndpointFactory getEndpointFactory(OMElement configElement) {

    if (configElement.getAttribute(new QName("key")) != null) {
      return IndirectEndpointFactory.getInstance();
    }

    if (configElement.getAttribute(new QName("key-expression")) != null) {
      return ResolvingEndpointFactory.getInstance();
    }

    if (configElement.getAttribute(new QName("template")) != null) {
      return new TemplateEndpointFactory();
    }

    OMElement addressElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "address"));
    if (addressElement != null) {
      return AddressEndpointFactory.getInstance();
    }

    OMElement wsdlElement =
        configElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "wsdl"));
    if (wsdlElement != null) {
      return WSDLEndpointFactory.getInstance();
    }

    OMElement defaultElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "default"));
    if (defaultElement != null) {
      return DefaultEndpointFactory.getInstance();
    }

    OMElement lbElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));
    if (lbElement != null) {
      OMElement sessionElement =
          configElement.getFirstChildWithName(
              new QName(SynapseConstants.SYNAPSE_NAMESPACE, "session"));
      if (sessionElement != null) {
        return SALoadbalanceEndpointFactory.getInstance();
      } else {
        return LoadbalanceEndpointFactory.getInstance();
      }
    }

    OMElement dlbElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dynamicLoadbalance"));
    if (dlbElement != null) {
      return DynamicLoadbalanceEndpointFactory.getInstance();
    }

    OMElement sdlbElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "serviceDynamicLoadbalance"));
    if (sdlbElement != null) {
      return ServiceDynamicLoadbalanceEndpointFactory.getInstance();
    }

    OMElement foElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "failover"));
    if (foElement != null) {
      return FailoverEndpointFactory.getInstance();
    }

    OMElement rcplElement =
        configElement.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "recipientlist"));
    if (rcplElement != null) {
      return RecipientListEndpointFactory.getInstance();
    }

    OMElement httpElement =
        configElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "http"));
    if (httpElement != null) {
      return HTTPEndpointFactory.getInstance();
    }

    OMElement classElement =
        configElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "class"));
    if (classElement != null) {
      return ClassEndpointFactory.getInstance();
    }

    handleException("Invalid endpoint configuration.");
    // just to make the compiler happy : never executes
    return null;
  }