ActiveMQ URI: parsing errors for failover URI (composite URI)
-------------------------------------------------------------

                 Key: AMQ-2823
                 URL: https://issues.apache.org/activemq/browse/AMQ-2823
             Project: ActiveMQ
          Issue Type: Bug
          Components: Broker
    Affects Versions: 5.2.0
            Reporter: Javier Michelson


Symptoms

the following URI "patterns" cause unexpected behaviour:

1) failover://(tcp://host:port)?connectionParameter=value

2) failover://(tcp://host:port?tcpParameter=value1)?failoverParameter=value3

3) 
failover://(tcp://host:port?tcpParameter=value1)?connectionParamater=value2&failoverParameter=value3

1) A failover URL is not parsed correctly in ActiveMQ version 5.2.0. When there 
are parameters for the connection (e.g.: prefetch policy parameters 
-"jms.prefetchSize.all", etc-) This issue has to do with the invalid parsing of 
the URI.
The issue was found when trying to append connection parameters to a failover 
URI. The problem with this is basically that the failover URI is not a "generic 
URI" (see RFC 2396 for more details), that is, it is not of the form:

<scheme>://<authority><path>?<query>

Although the URI is composed of

<scheme>:<scheme-specific-part>

and is thus a valid URI according to the RFC.

The method 

URISupport.createURIWithQuery(URI, String)

return and incorrect URI for a failover URI, because of the scheme of this URI. 
This is the content of the method:

<<< CODE

URISupport.createURIWithQuery(URI, String){
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), 
uri.getPort(), uri.getPath(), query, uri.getFragment());
}

<<< /CODE

When parsing the URI in ActiveMQConnectionFactory.createURI(String) with:

new java.util.URI(String)

The resulting URI has some missing or "invalid" values. For instance, with the 
following URL:

"failover://(tcp://host:port)?jms.prefetchSize.all=30"

the resulting URI has the following values set:

host=null
port=-1
authority="(tcp:"
path="//host:port)"
query="connectionParameter=value"

the path gets its value because of the "/" after "(tcp:".

The result is that when 

ActiveMQConnectionFacotry.setBrokerURL(String) Line 343:

<<< CODE

this.brokerURL = URISupport.createRemainingURI(this.brokerURL, map);

<<< /CODE

is excecuted, an exeption is thrown (message="Illegal character in port 
number"), because of the invalid por number.
This is silently ignored in the ActiveMQConnectionFactory.setBroker(Strin) 
method and the values of the brokerURL are not updated without the connection 
parameters.
Consecuently, when the connection is created, the following exception is thrown:

java.lang.IllegalArgumentException "Invalid connect parameters: ..."

Because of the connectionParameter that was not removed from the brokerURL.

2) The second URI pattern causes failover paramters to be ignored but the tcp 
transport gets the correct parameters.

The resulting URI in ActiveMQConnectionFactory contains the following invalid 
values:

host=null
port=-1
authority="(tcp:"
path="//host:port"
query="tcpParameter=value)?failoverParamater=value"

this is because of the extra ? in the "nested" URI.
This URI works correctly, but if a connection parameter is the first parameter 
in the composite URI as in (3):

        
failover://(tcp://host:port?tcpParameter=value1)?connectionParamater=value2&failoverParameter=value3

that parameter would be omited, and the failover transport would fail when 
connecting because of an invalid connection parameter being set for the 
failover transport.


Conclusion:

A modification of the parsing in 

ActiveMQConnectionFactory.setBrokerURL(String)

should solve the query parameter problems.
The parameter parsing should consider the nested URIs, and the call to 

URISupport.createRemainingURI(URI, Map);

should create a "nested" URI (composite) if required.
Some other modification could also be required.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to