Java Code Examples for org.apache.activemq.util.URISupport#parseParameters()

The following examples show how to use org.apache.activemq.util.URISupport#parseParameters() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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);
}