Git Product home page Git Product logo

Comments (4)

novtor avatar novtor commented on April 18, 2024

I think, the issue is in this file:

should be replaced by
if (!(resolvedValue.**contains**("#{") && value.**contains**("}"))) {

from spring-amqp.

artembilan avatar artembilan commented on April 18, 2024

I think you have a point here!

Indeed the TemplateAwareExpressionParser used from the StandardBeanExpressionResolver parses the first aaa.bbb. part as LiteralExpression and the next part with the #{...} as a SpelExpression to evaluation.

I've just tested and confirmed that we are good to go with your suggestion!

@RabbitListener(queues = "test.#{'simple'}", group = "testGroup")

But that's only the part of the solution for your. Since your expression is very complex there, you should be careful with all the required symbols to honor SpEL syntax.

For now I'd suggest you as workaround as:

amqp:
  queue:
    suffix: 001
    name: #{'aaa.bbb.' + '${amqp.queue.suffix}' == '001' ? 'default': '${amqp.queue.suffix}'}

Pay attention to single quotes everywhere. Since after resolving the property placeholder, the result becomes something valuable for the SpEL and tries to be resolved against application context. As far as they all are literals they have to be quoted. Not sure though if a single quote ' will be enough: https://docs.spring.io/spring-cloud-dataflow/docs/1.3.0.M2/reference/htmlsingle/#shell-white-space. But it worth to try!

Feel free to come back to us with the contribution on the matter!

from spring-amqp.

garyrussell avatar garyrussell commented on April 18, 2024

I don't think changing it contains(() is the right solution.

I think we should simply document that the SpEL evaluation is done after the property placeholder resolution and must match the regex pattern ^#{...}$.

My 2c.

from spring-amqp.

artembilan avatar artembilan commented on April 18, 2024

Gary, one more time.

The TemplateAwareExpressionParser is able to parse an expression like foo.#{myBean.x}.bar to the CompositeStringExpression: LiteralExpression, SpelExpression, LiteralExpression. Just because it has a logic like:

	while (startIdx < expressionString.length()) {
			int prefixIndex = expressionString.indexOf(prefix, startIdx);
			if (prefixIndex >= startIdx) {
				// an inner expression was found - this is a composite
				if (prefixIndex > startIdx) {
					expressions.add(new LiteralExpression(expressionString.substring(startIdx, prefixIndex)));
				}

That CompositeStringExpression does exactly string concatenation under hood:

for (Expression expression : this.expressions) {
	String value = expression.getValue(String.class);
	if (value != null) {
		sb.append(value);
	}
}

I would even say that we don't need that condition to check if that contains expression tokens or not.
We always can rely on the TemplateAwareExpressionParser and get a simple LiteralExpression for non-templated string. Well, that is actually what is done by Spring per se. See AbstractBeanFactory.doResolveBeanClass() for example:

String className = mbd.getBeanClassName();
		if (className != null) {
			Object evaluated = evaluateBeanDefinitionString(className, mbd);
			if (!className.equals(evaluated)) {

So, I would even say that with the current logic we even restrict the user in possible expression variants.

Well, I may see your concern to make such a change in the current GA release, but we definitely should reconsider it in the next 2.1.0 or even in the point 2.0.1 version.

FYI. I have just commented out the code:

if (!(resolvedValue.startsWith("#{") && value.endsWith("}"))) {
	return resolvedValue;
}

And all our tests are passing.

from spring-amqp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.