org.apache.activemq.util.URISupport Java Examples

The following examples show how to use org.apache.activemq.util.URISupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmsFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private static boolean isSSL(URI uri) {
    try {
        CompositeData compositeData = URISupport.parseComposite(uri);
        if ("ssl".equals(compositeData.getScheme())) {
            return true;
        }
        for(URI component : compositeData.getComponents()){
            if ("ssl".equals(component.getScheme())) {
                return true;
            }
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Attempting to initiate JMS with invalid composite URI [" + uri + "]", e);
    }
    return false;
}
 
Example #2
Source File: ActiveMQConnectionFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private static URI createURI(String brokerURL) {
   try {
      URI uri = new URI(brokerURL);
      String scheme = uri.getScheme();
      if ("vm".equals(scheme)) {
         Map<String, String> params = URISupport.parseParameters(uri);
         //EMPTY_MAP is immutable, so use a normal map instead.
         if (params == Collections.EMPTY_MAP) {
            params = new HashMap<>();
         }
         params.put("invmBrokerId", uri.getHost() == null ? "localhost" : uri.getHost());
         defaultTcpUri = URISupport.createRemainingURI(defaultTcpUri, params);
         return defaultTcpUri;
      }
      return uri;
   } catch (URISyntaxException e) {
      throw (IllegalArgumentException) new IllegalArgumentException("Invalid broker URI: " + brokerURL).initCause(e);
   }
}
 
Example #3
Source File: TcpTransportFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public TransportServer doBind(final URI location) throws IOException {
   try {
      Map<String, String> options = new HashMap<>(URISupport.parseParameters(location));

      ServerSocketFactory serverSocketFactory = createServerSocketFactory();
      TcpTransportServer server = createTcpTransportServer(location, serverSocketFactory);
      server.setWireFormatFactory(createWireFormatFactory(options));
      IntrospectionSupport.setProperties(server, options);
      Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport.");
      server.setTransportOption(transportOptions);
      server.bind();

      return server;
   } catch (URISyntaxException e) {
      throw IOExceptionSupport.create(e);
   }
}
 
Example #4
Source File: DiscoveryTransportNoBrokerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testSetDiscoveredBrokerProperties() throws Exception {
   final String extraParameterName = "connectionTimeout";
   final String extraParameterValue = "3000";
   final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&" + DiscoveryListener.DISCOVERED_OPTION_PREFIX + extraParameterName + "=" + extraParameterValue);
   CompositeData compositeData = URISupport.parseComposite(uri);

   StubCompositeTransport compositeTransport = new StubCompositeTransport();
   DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());

   discoveryTransport.onServiceAdd(new DiscoveryEvent("tcp://localhost:61616"));
   assertEquals("expected added URI after discovery event", compositeTransport.getTransportURIs().length, 1);

   URI discoveredServiceURI = compositeTransport.getTransportURIs()[0];
   Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI);
   assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName));
   assertEquals("incorrect value for parameter added to discovered service", parameters.get(extraParameterName), extraParameterValue);
}
 
Example #5
Source File: DiscoveryTransportNoBrokerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testSetDiscoveredStaticBrokerProperties() throws Exception {
   final String extraParameterName = "connectionTimeout";
   final String extraParameterValue = "3000";
   final URI uri = new URI("discovery:(static:tcp://localhost:61616)?initialReconnectDelay=100&" + DiscoveryListener.DISCOVERED_OPTION_PREFIX + extraParameterName + "=" + extraParameterValue);
   CompositeData compositeData = URISupport.parseComposite(uri);

   StubCompositeTransport compositeTransport = new StubCompositeTransport();
   DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());

   discoveryTransport.start();
   assertEquals("expected added URI after discovery event", 1, compositeTransport.getTransportURIs().length);

   URI discoveredServiceURI = compositeTransport.getTransportURIs()[0];
   Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI);
   assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName));
   assertEquals("incorrect value for parameter added to discovered service", parameters.get(extraParameterName), extraParameterValue);
}
 
Example #6
Source File: TcpFaultyTransportFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public TransportServer doBind(final URI location) throws IOException {
   try {
      Map<String, String> options = new HashMap<>(URISupport.parseParameters(location));

      ServerSocketFactory serverSocketFactory = createServerSocketFactory();
      TcpFaultyTransportServer server = createTcpFaultyTransportServer(location, serverSocketFactory);
      server.setWireFormatFactory(createWireFormatFactory(options));
      IntrospectionSupport.setProperties(server, options);
      Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport.");
      server.setTransportOption(transportOptions);
      server.bind();

      return server;
   } catch (URISyntaxException e) {
      throw IOExceptionSupport.create(e);
   }
}
 
Example #7
Source File: JmsFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static boolean isSSL(URI uri) {
    try {
        CompositeData compositeData = URISupport.parseComposite(uri);
        if ("ssl".equals(compositeData.getScheme())) {
            return true;
        }
        for(URI component : compositeData.getComponents()){
            if ("ssl".equals(component.getScheme())) {
                return true;
            }
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Attempting to initiate JMS with invalid composite URI [" + uri + "]", e);
    }
    return false;
}
 
Example #8
Source File: ActiveMQ5Factory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private BrokerService newPatchedBrokerService() {
    return new BrokerService() {
        @Override
        public NetworkConnector addNetworkConnector(final URI discoveryAddress) throws Exception {
            final NetworkConnector connector = new DiscoveryNetworkConnector(discoveryAddress);
            try { // try to set properties to broker too
                final Map<String, String> props = URISupport.parseParameters(discoveryAddress);
                if (!props.containsKey("skipConnector")) {
                    IntrospectionSupport.setProperties(connector, props);
                }
            } catch (final URISyntaxException e) {
                // low level cause not supported by AMQ by default
                Logger.getInstance(LogCategory.OPENEJB_STARTUP, ActiveMQ5Factory.class).getChildLogger("service")
                        .debug(e.getMessage());
            }
            return addNetworkConnector(connector);
        }
    };
}
 
Example #9
Source File: KubernetesDiscoveryAgentFactory.java    From activemq-k8s-discovery with Apache License 2.0 5 votes vote down vote up
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
    try {
        Map<String, String> options = URISupport.parseParameters(uri);
        KubernetesDiscoveryAgent rc = new KubernetesDiscoveryAgent();
        IntrospectionSupport.setProperties(rc, options);
        LOG.info("Succesfully created Kubernetes discovery agent from URI: {}", uri);

        return rc;
        
    } catch (Throwable e) {
        LOG.error("Could not create Kubernetes discovery agent: " + uri, e);
        throw IOExceptionSupport.create("Could not create Kubernetes discovery agent: " + uri, e);
    }
}
 
Example #10
Source File: KubeDiscoveryAgentFactory.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
@Override
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
    try {
        LOGGER.info("Creating Kubernetes discovery agent for {}.", uri.toString());
        final Map<String, String> options = URISupport.parseParameters(uri);
        uri = URISupport.removeQuery(uri);
        final OpenShiftDiscoveryAgent agent = new OpenShiftDiscoveryAgent(new KubePeerAddressResolver(
                uri.getHost(), uri.getPort()));
        IntrospectionSupport.setProperties(agent, options);
        return agent;
    } catch (Throwable e) {
        throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e);
    }
}
 
Example #11
Source File: DNSDiscoveryAgentFactory.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
@Override
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
    try {
        LOGGER.info("Creating DNS discovery agent for {}.", uri.toString());
        final Map<String, String> options = URISupport.parseParameters(uri);
        uri = URISupport.removeQuery(uri);
        final OpenShiftDiscoveryAgent agent = new OpenShiftDiscoveryAgent(new DNSPeerResolver(uri.getHost(), uri.getPort()));
        IntrospectionSupport.setProperties(agent, options);
        return agent;
    } catch (Throwable e) {
        throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e);
    }
}
 
Example #12
Source File: ActiveMQConnectionFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public ActiveMQConnectionFactory(String brokerURL) {
   this(createURI(brokerURL));
   try {
      URI uri = new URI(brokerURL);
      String scheme = uri.getScheme();
      if ("vm".equals(scheme)) {
         Map<String, String> params = URISupport.parseParameters(uri);
         params.clear();

         this.vmBrokerUri = URISupport.createRemainingURI(uri, params);
      }
   } catch (URISyntaxException e) {
   }

}
 
Example #13
Source File: TcpTransportFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public Transport doConnect(URI location) throws Exception {
   //here check broker, if no broker, we start one
   Map<String, String> params = URISupport.parseParameters(location);
   String brokerId = params.remove("invmBrokerId");
   boolean autoCreate = true;
   String create = params.remove("create");
   if (create != null) {
      autoCreate = "true".equals(create);
   }

   URI location1 = URISupport.createRemainingURI(location, Collections.EMPTY_MAP);

   LOG.info("deciding whether starting an internal broker: " + brokerService + " flag: " + BrokerService.disableWrapper);
   if (autoCreate && brokerService == null && !BrokerService.disableWrapper && BrokerService.checkPort(location1.getPort())) {

      LOG.info("starting internal broker: " + location1);
      ArtemisBrokerHelper.startArtemisBroker(location1);
      brokerService = new InternalServiceInfo(location.toString());

      if (brokerId != null) {
         BrokerRegistry.getInstance().bind(brokerId, ArtemisBrokerHelper.getBroker());
         LOG.info("bound: " + brokerId);
      }
   }
   //remove unused invm parameters
   params.remove("broker.persistent");
   params.remove("broker.useJmx");
   params.remove("marshal");
   params.remove("create");
   params.remove("asyncQueueDepth");
   URI location2 = URISupport.createRemainingURI(location, params);
   return super.doConnect(location2);
}
 
Example #14
Source File: DiscoveryTransportNoBrokerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testAddRemoveDiscoveredBroker() throws Exception {
   final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&connectionTimeout=3000");
   CompositeData compositeData = URISupport.parseComposite(uri);

   StubCompositeTransport compositeTransport = new StubCompositeTransport();
   DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());

   final String serviceName = "tcp://localhost:61616";
   discoveryTransport.onServiceAdd(new DiscoveryEvent(serviceName));
   assertEquals("expected added URI after discovery event", 1, compositeTransport.getTransportURIs().length);

   discoveryTransport.onServiceRemove(new DiscoveryEvent(serviceName));
   assertEquals("expected URI removed after discovery event", 0, compositeTransport.getTransportURIs().length);
}
 
Example #15
Source File: ActiveMQ5Factory.java    From tomee with Apache License 2.0 5 votes vote down vote up
private BrokerService newDefaultBroker(final URI uri) throws Exception {
    final URISupport.CompositeData compositeData = URISupport.parseComposite(uri);
    final Map<String, String> params = new HashMap<>(compositeData.getParameters());

    final BrokerService brokerService = newPatchedBrokerService();

    IntrospectionSupport.setProperties(brokerService, params);
    if (!params.isEmpty()) {
        String msg = "There are " + params.size()
                + " Broker options that couldn't be set on the BrokerService."
                + " Check the options are spelled correctly."
                + " Unknown parameters=[" + params + "]."
                + " This BrokerService cannot be started.";
        throw new IllegalArgumentException(msg);
    }

    if (compositeData.getPath() != null) {
        brokerService.setBrokerName(compositeData.getPath());
    }

    for (final URI component : compositeData.getComponents()) {
        if ("network".equals(component.getScheme())) {
            brokerService.addNetworkConnector(component.getSchemeSpecificPart());
        } else if ("proxy".equals(component.getScheme())) {
            brokerService.addProxyConnector(component.getSchemeSpecificPart());
        } else {
            brokerService.addConnector(component);
        }
    }
    return brokerService;
}
 
Example #16
Source File: DurableConsumerCloseAndReconnectTcpTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   return new ActiveMQConnectionFactory(URISupport.removeQuery(connector.getConnectUri()) + "?useKeepAlive=false&wireFormat.maxInactivityDuration=2000");
}