boolean create = true; int waitForStart = -1; CompositeData data = URISupport.parseComposite(location); if (data.getComponents().length == 1 && "broker".equals(data.getComponents()[0].getScheme())) { brokerURI = data.getComponents()[0]; CompositeData brokerData = URISupport.parseComposite(brokerURI); host = brokerData.getParameters().get("brokerName"); if (host == null) { location = new URI("vm://" + host); } else { options = URISupport.parseParameters(location); String config = options.remove("brokerConfig"); if (config != null) { brokerURI = new URI(config); } else { Map<String, Object> brokerOptions = IntrospectionSupport.extractProperties(options, "broker."); brokerURI = new URI("broker://()/" + host + "?" + URISupport.createQueryString(brokerOptions)); throw IOExceptionSupport.create(e1); broker = BrokerFactory.createBroker(brokerURI);
String params; if (!checkParenthesis(ssp)) { throw new URISyntaxException(uri.toString(), "Not a matching number of '(' and ')' parenthesis"); p = indexOfParenthesisMatch(ssp, initialParen); componentString = ssp.substring(initialParen + 1, p); params = ssp.substring(p + 1).trim(); String components[] = splitComponents(componentString); rc.components = new URI[components.length]; for (int i = 0; i < components.length; i++) { rc.components[i] = new URI(components[i].trim()); if (p >= 0) { if (p > 0) { rc.path = stripPrefix(params.substring(0, p), "/"); rc.parameters = parseQuery(params.substring(p + 1)); } else { if (params.length() > 0) { rc.path = stripPrefix(params, "/"); rc.parameters = emptyMap();
@Override public void onServiceAdd(DiscoveryEvent event) { String url = event.getServiceName(); if (url != null) { try { URI uri = new URI(url); LOG.info("Adding new broker connection URL: " + uri); uri = URISupport.applyParameters(uri, parameters, DISCOVERED_OPTION_PREFIX); serviceURIs.put(event.getServiceName(), uri); next.add(false,new URI[] {uri}); } catch (URISyntaxException e) { LOG.warn("Could not connect to remote URI: " + url + " due to bad URI syntax: " + e, e); } } }
/** * Creates a URI from the original URI and the remaining parameters. * * When the query options of a URI are applied to certain objects the used portion of the query options needs * to be removed and replaced with those that remain so that other parts of the code can attempt to apply the * remainder or give an error is unknown values were given. This method is used to update a URI with those * remainder values. * * @param originalURI * The URI whose current parameters are remove and replaced with the given remainder value. * @param params * The URI params that should be used to replace the current ones in the target. * * @return a new URI that matches the original one but has its query options replaced with the given ones. * @throws URISyntaxException */ public static URI createRemainingURI(URI originalURI, Map<String, String> params) throws URISyntaxException { String s = createQueryString(params); if (s.length() == 0) { s = null; } return createURIWithQuery(originalURI, s); }
private static Transport createLocalTransport(URI uri, boolean async) throws Exception { HashMap<String, String> map = new HashMap<String, String>(URISupport.parseParameters(uri)); map.put("async", String.valueOf(async)); map.put("create", "false"); // we don't want a vm connect during shutdown to trigger a broker create uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map)); return TransportFactory.connect(uri); }
/** * Examine a URI and determine if it is a Composite type or not. * * @param uri * The URI that is to be examined. * * @return true if the given URI is a Compsote type. */ public static boolean isCompositeURI(URI uri) { String ssp = stripPrefix(uri.getRawSchemeSpecificPart().trim(), "//").trim(); if (ssp.indexOf('(') == 0 && checkParenthesis(ssp)) { return true; } return false; }
String group = location.getHost(); String broker = URISupport.stripPrefix(location.getPath(), "/"); final Map<String, String> brokerOptions = new HashMap<String, String>(URISupport.parseParameters(location)); if (!brokerOptions.containsKey("persistent")) { brokerOptions.put("persistent", "false"); final URI finalLocation = new URI("vm://" + broker); final String finalBroker = broker; final String finalGroup = group; throw IOExceptionSupport.create(e);
sb.append(','); sb.append(components[i].toString()); sb.append(createQueryString(parameters)); sb.append(fragment); return new URI(sb.toString());
/** * Strip a URI of its scheme element. * * @param uri * The URI whose scheme value should be stripped. * * @return The stripped URI value. * @throws URISyntaxException */ public static URI stripScheme(URI uri) throws URISyntaxException { return new URI(stripPrefix(uri.getSchemeSpecificPart().trim(), "//")); }
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException { try { if (LOG.isTraceEnabled()) { LOG.trace("doCreateDiscoveryAgent: uri = " + uri.toString()); } MulticastDiscoveryAgent mda = new MulticastDiscoveryAgent(); mda.setDiscoveryURI(uri); // allow MDA's params to be set via query arguments // (e.g., multicast://default?group=foo Map options = URISupport.parseParameters(uri); IntrospectionSupport.setProperties(mda, options); return mda; } catch (Throwable e) { throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e); } } }
public BrokerService createBroker(URI brokerURI) throws Exception { CompositeData compositeData = URISupport.parseComposite(brokerURI); Map<String, String> params = new HashMap<String, String>(compositeData.getParameters()); BrokerService brokerService = new BrokerService(); 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()); } URI[] components = compositeData.getComponents(); for (int i = 0; i < components.length; i++) { if ("network".equals(components[i].getScheme())) { brokerService.addNetworkConnector(components[i].getSchemeSpecificPart()); } else if ("proxy".equals(components[i].getScheme())) { brokerService.addProxyConnector(components[i].getSchemeSpecificPart()); } else { brokerService.addConnector(components[i]); } } return brokerService; }
private void validateUriContainSpecificScheme(StartupForm target, List<String> errors, URI uri) { String scheme = uri.getScheme(); if (scheme != null && ("static".equals(scheme) || "broker".equals(scheme))) { if (isCompositeURI(uri)) { try { URISupport.CompositeData data = parseComposite(uri); validateCompositeDataUri(target, errors, data); } catch (URISyntaxException e) { errors.add(String.format(ERROR_INVALID, QUEUE_URL)); } } else { isValidUri(target, errors, uri.toString()); } } else { isValidUri(target, errors, uri.toString()); } } }
URI uri; try { uri = new URI(url); } catch (URISyntaxException e) { LOG.warn("Could not connect to remote URI: {} due to bad URI syntax: ", url, e); if (localURI.equals(uri)) { LOG.debug("not connecting loopback: {}", uri); return; connectUri = URISupport.applyParameters(connectUri, parameters, DISCOVERED_OPTION_PREFIX); } catch (URISyntaxException e) { LOG.warn("could not apply query parameters: {} to: {}", new Object[]{ parameters, connectUri }, e); SslContext.setCurrentSslContext(getSslContext()); } else { SslContext.setCurrentSslContext(getBrokerService().getSslContext());
@Override public void validate(StartupForm target, List<String> errors, ConfigSource configSource) { if (isNullOrEmpty(target.getQueueUrl())) { if (!configSource.isFile()) { errors.add(String.format(ERROR_REQUIRED, QUEUE_URL)); } return; } try { String value = target.getQueueUrl().replace("localhost", "127.0.0.1"); URI brokerURL = new URI(value); if (isCompositeURI(brokerURL)) { URISupport.CompositeData data = parseComposite(brokerURL); String scheme = data.getScheme(); if (scheme != null && ("failover".equals(scheme) || "fanout".equals(scheme) || "vm".equals(scheme))) { for (URI uri : data.getComponents()) { validateUriContainSpecificScheme(target, errors, uri); } } else { errors.add(String.format(ERROR_INVALID, QUEUE_URL)); } } else { isValidUri(target, errors, value); } } catch (URISyntaxException e) { errors.add(String.format(ERROR_INVALID, QUEUE_URL)); } }
/** * Given a composite URI, parse the individual URI elements contained within that URI and return * a CompsoteData instance that contains the parsed URI values. * * @param uri * The target URI that should be parsed. * * @return a new CompsiteData instance representing the parsed composite URI. * @throws URISyntaxException */ public static CompositeData parseComposite(URI uri) throws URISyntaxException { CompositeData rc = new CompositeData(); rc.scheme = uri.getScheme(); String ssp = stripPrefix(uri.getRawSchemeSpecificPart().trim(), "//").trim(); parseComposite(uri, rc, ssp); rc.fragment = uri.getFragment(); return rc; }
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException { try { Map options = URISupport.parseParameters(uri); ZeroconfDiscoveryAgent rc = new ZeroconfDiscoveryAgent(); rc.setGroup(uri.getHost()); IntrospectionSupport.setProperties(rc, options); return rc; } catch (Throwable e) { throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e); } } }
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; }
public Transport doConnect(URI location) throws Exception { try { Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location)); if( !options.containsKey("wireFormat.host") ) { options.put("wireFormat.host", location.getHost()); } WireFormat wf = createWireFormat(options); Transport transport = createTransport(location, wf); Transport rc = configure(transport, wf, options); //remove auto IntrospectionSupport.extractProperties(options, "auto."); if (!options.isEmpty()) { throw new IllegalArgumentException("Invalid connect parameters: " + options); } return rc; } catch (URISyntaxException e) { throw IOExceptionSupport.create(e); } }
/** * Given a URI parse and extract any URI query options and return them as a Key / Value mapping. * * This method differs from the {@link parseQuery} method in that it handles composite URI types and * will extract the URI options from the outermost composite URI. * * @param uri * The URI whose query should be extracted and processed. * * @return A Mapping of the URI options. * @throws URISyntaxException */ public static Map<String, String> parseParameters(URI uri) throws URISyntaxException { if (!isCompositeURI(uri)) { return uri.getQuery() == null ? emptyMap() : parseQuery(stripPrefix(uri.getQuery(), "?")); } else { CompositeData data = URISupport.parseComposite(uri); Map<String, String> parameters = new HashMap<String, String>(); parameters.putAll(data.getParameters()); if (parameters.isEmpty()) { parameters = emptyMap(); } return parameters; } }
if (this.brokerURL.getQuery() != null) { Map<String,String> map = URISupport.parseQuery(this.brokerURL.getQuery()); Map<String,Object> jmsOptionsMap = IntrospectionSupport.extractProperties(map, "jms."); if (buildFromMap(jmsOptionsMap)) { if (!jmsOptionsMap.isEmpty()) { this.brokerURL = URISupport.createRemainingURI(this.brokerURL, map); CompositeData data = URISupport.parseComposite(this.brokerURL); Map<String,Object> jmsOptionsMap = IntrospectionSupport.extractProperties(data.getParameters(), "jms."); if (buildFromMap(jmsOptionsMap)) { if (!jmsOptionsMap.isEmpty()) {