Placeholder of Camel from tag is not getting updated with new values - spring

I have my publicAddress property defined in Spring XML and using it in Java DSL(Route builders). Value of 'publicAddress' comes from Web GUI.
<util:properties id="service-properties">
<prop key="publicAddress"></prop></util:properties>
I was previously using Camel 2.10 and have switched to 2.15.
Following code is used to create Route builders which has different public addresses. With this code in place, if I create second Route builder, value of 'publicAddress' does not gets updated. RouteBuilder gets created with old value of 'publicAddress'
from(abcd+ ":"+ serviceName+ "://{{publicAddress}}?loggingEnabled= {{loggingEnabled}}").routeId(xyz + serviceName + "Route");
I tried using service-properties:{{publicAddress}} but that gave me null value.
Any idea which placeholder I need to use to resolve this issue ?

Related

How to load VM_global_library.vm for Velocity in Spring Boot?

We're using a VelocityLayoutServlet as the view resolver in Spring Boot.
#Bean(name = "velocityViewResolver")
public VelocityLayoutViewResolver velocityViewResolver() {
VelocityLayoutViewResolver resolver = new VelocityLayoutViewResolver();
this.properties.applyToViewResolver(resolver);
resolver.setLayoutUrl("layout/default.vm");
return resolver;}
We want to load global macros from a VM_global_library.vm file, as described in the Velocity User Guide. Expected Velocity to load that default file from /templates directory, but not happening.
Adding theexplicit setting mentioned in the Velocity User Guide did not work either:
spring.velocity.velocimacro.library=VM_global_library.vm
velocimacro.library - A comma-separated list of all Velocimacro template libraries. By default, Velocity looks for a single library: VM_global_library.vm. The configured template path is used to find the Velocimacro libraries.
Are we missing some magic, or is this missing from the integration?
Velocity properties can be set with "spring.velocity.properties.*" attribute.
This configuration works for me:
spring.velocity.properties.velocimacro.library=templates/VM_global_library.vm

How To invoke a model's template from another model in xpand for AUTOSAR

I've been trying to develop an AUTOSAR 4.2.1 module to generate code using Xpand/Xtend. I'm using artext demonstrator 1.6.0. But my query is that the concept of defining a variation point is not found in the PDF(ECUConfigurationParameters.arxml) when I create a new Ecu platform project in the demonstrator (or maybe I'm not familiar with finding out how).
By default I'm able to fetch parameter values from an arxml. But when there is more than one value for a parameter which is defined in a different post build variant condition, I'm getting only the first value.
For example, if the arxml contains this
<ECUC-NUMERICAL-PARAM-VALUE>
<DEFINITION-REF DEST="ECUC-BOOLEAN-PARAM-DEF"> /AUTOSAR/EcucDefs/Com/ComConfig/ComIPdu/ComIPduCancellationSuppo rt</DEFINITION-REF>
<VARIATION-POINT>
<POST-BUILD-VARIANT-CONDITIONS>
<POST-BUILD-VARIANT-CONDITION>
<MATCHING-CRITERION-REF DEST="POST-BUILD-VARIANT-CRITERION">/EcucDemo/PostBuildConfigSet</MATCHING-CRITERION-REF>
<VALUE>1</VALUE>
</POST-BUILD-VARIANT-CONDITION>
</POST-BUILD-VARIANT-CONDITIONS>
</VARIATION-POINT>
<VALUE>1</VALUE>
</ECUC-NUMERICAL-PARAM-VALUE>
<ECUC-NUMERICAL-PARAM-VALUE>
<DEFINITION-REF DEST="ECUC-BOOLEAN-PARAM-DEF"> /AUTOSAR/EcucDefs/Com/ComConfig/ComIPdu/ComIPduCancellationSuppo rt</DEFINITION-REF>
<VARIATION-POINT>
<POST-BUILD-VARIANT-CONDITIONS>
<POST-BUILD-VARIANT-CONDITION>
<MATCHING-CRITERION-REF DEST="POST-BUILD-VARIANT-CRITERION">/EcucDemo/PostBuildConfigSet</MATCHING-CRITERION-REF>
<VALUE>2</VALUE>
</POST-BUILD-VARIANT-CONDITION>
</POST-BUILD-VARIANT-CONDITIONS>
</VARIATION-POINT>
<VALUE>0</VALUE>
</ECUC-NUMERICAL-PARAM-VALUE>
it gives me value as 'true' in Xpand if I do Com.ComConfig.ComIpdus.ComIPduCancellationSupport. I’m unable to access the second value ‘false’.
How may I proceed to fetch the parameter values based on the post-build variant conditions?
I'm trying to do the following:
«DEFINE Gen1 FOR varianthandling::VariationPoint»
«EXPAND Gen1::GetThings»
«ENDDEFINE»
«DEFINE GenMain FOR AUTOSAR::EcucDefs::Com»
«EXPAND Gen1 FOR varianthandling::VariationPoint»
«ENDDEFINE»
This gives me an error as 'Couldn't find definition ComOtherVarGen for type xpand2::Type'. How do I achieve the above?
Please note that I am not trying to add/modify any functionality to the template of 'MainObj' so 'AROUND' is not what I'm looking for.
Any help is greatly appreciated.
The tool which you are using to create the model (which is created from the PDF file + EcuC Values file) must be able to build a model which is post-build compatible.
If you are sure, this being done- Then try the below method
Com.ComConfig.ComIpdus.ComIPduCancellationSupport changes to
<FOREACH Com.ComConfig.ComIpdus.ComIPduCancellationSupport AS ele>
<ele>
<ENDFOREACH>
or
Com.ComConfig.ComIpdus.ComIPduCancellationSupport.get(0)
Com.ComConfig.ComIpdus.ComIPduCancellationSupport.get(1)

Spring matrix parameters

I have upgraded my spring version to 4.1.4 and now want to use Matrix parameters.
I have added below to enable support for matrix parameters in configuration file:
<mvc:annotation-driven conversion-service="applicationConversionService" enable-matrix-variables="true"/>
and in code I am accessing it as below in my method:
public ResponseEntity<String> transactions(#PathVariable("accountNumber") String accountNumber,
#MatrixVariable(required = true,value="sinceDate") String sinceDate){....}
and my url is : http://localhost:8080/spring_test/accounts/8293/transactions;sinceDate=2014-01-20;untilDate=2014-01-01;
But I am getting sinceDate value as null, which is declared with #MatrixVariable.
Please suggest if I am missing any steps?
Thanks,
Manasi
If you have your own AbstractHandlerMapping definition you should specify its <beans:property name="removeSemicolonContent" value="false"/>.
Otherwise I suggest you to debug the Spring code and figure out why removeSemicolonContent isn't reseted for the default RequestMappingHandlerMapping.
The break point should be in the UrlPathHelper#removeSemicolonContent
To make this worked you should place matrix variables in the URL just after the approriate pathVariable:
http://localhost:8080/spring_test/accounts/8293;sinceDate=2014-01-20;untilDate=‌​2014-01-01;/transactions

BIRT Reporting: how to access LinkedHashMap in script

While creating BIRT Report, I'm trying to access a LinkedHashMap in report beforeFactory event thro' rhino scripting..Able to print the map. But, when i use any method like size(), the following error is thrown
size not found
var test1 = reportVO.getTest(); // "test" is a LinkedHashMap
log(test1) // --> In the logs, im able to see the LinkedHashMap contents printed
(log test1.size()) // --> this fails.
I have imported the util package.
I read about org.eclipse.birt.core.script.NativeJavaLinkedHashMap. I tried accessing the LinkedHashMap thro' methods of this class also, like
test1.getIds() // Method from NativeJavaLinkedHashMap --> this fails too
getIds not found
Is there a specific way to access LinkedhashMap in script.
Thanks,
Vishnupriya
Did you used test1.length ? you are now accessing javascript variable instead of java variable
For More Click Here

Spring, property file, empty values

I have configured spring security with a ldap server (but continue reading, it's not a problem if you have no knowledge about it, this is really a spring problem). All runs like a charm. Here is the line I use for that:
<ldap-server ldif="" root="" manager-dn="" manager-password="" url="" id="ldapServer" />
If I fill ldif and root attributes, it will run an embeded server:
<ldap-server ldif="classpath://ldap.ldif" root="dc=springframework,dc=org" manager-dn="" manager-password="" url="" id="ldapServer" />
If I fill other fields, it will run a distant server:
<ldap-server ldif="" root="" manager-dn="dc=admin,dc=springframeworg,dc=org" manager-password="password" url="ldap://myldapserver.com/dc=springframeworg,dc=org" id="ldapServer" />
All this stuff run correctly. Now I want to use Spring mechanism to load such parameters from a property file:
So I replace attribute values like this:
<ldap-server ldif="${ldap.ldif.path}" root="${ldap.ldif.root}" manager-dn="${ldap.server.manager.dn}" manager-password="${ldap.server.manager.password}" url="${ldap.server.url}" id="ldapServer" />
and create a property file with:
ldap.server.url=
ldap.server.manager.dn=
ldap.server.manager.password=
ldap.ldif.path=
ldap.ldif.root=
Now, the funny part of the problem. If I fill the following properties in the file:
ldap.server.url=ldap://myldapserver.com/dc=springframeworg,dc=org
ldap.server.manager.dn=dc=admin,dc=springframeworg,dc=org
ldap.server.manager.password=password
ldap.ldif.path=
ldap.ldif.root=
It runs a distant server as expected.
If I fill the property file like this:
ldap.server.url=
ldap.server.manager.dn=
ldap.server.manager.password=
ldap.ldif.path= classpath:ldap.ldif
ldap.ldif.root= dc=springframeworg,dc=org
It does not run, complaining that the ldap url is missing. But the problem is that if I change the spring configuration from:
<ldap-server ldif="${ldap.ldif.path}" root="${ldap.ldif.root}" manager-dn="${ldap.server.manager.dn}" manager-password="${ldap.server.manager.password}" url="${ldap.server.url}" id="ldapServer" />
to (by just removing the reference to the variable ${ldap.server.url})
<ldap-server ldif="${ldap.ldif.path}" root="${ldap.ldif.root}" manager-dn="${ldap.server.manager.dn}" manager-password="${ldap.server.manager.password}" url="" id="ldapServer" />
It runs !
My thoughs are that spring does not replace the attribute value with the property config one if this one is empty. But I find it strange.
Can you give me some clue to understand that ? And what's the best to do to configure my ldap server via a property file ?
EDIT: this is due to a poor design choice (look at accepted answer), an issue has been opened on jira :
https://jira.springsource.org/browse/SEC-1966
Ok, I think this is a spring security bug.
If I debug and look at the class LdapServerBeanDefinition, there is a method called "parse". Here is an extract:
public BeanDefinition parse(Element elt, ParserContext parserContext) {
String url = elt.getAttribute(ATT_URL);
RootBeanDefinition contextSource;
if (!StringUtils.hasText(url)) {
contextSource = createEmbeddedServer(elt, parserContext);
} else {
contextSource = new RootBeanDefinition();
contextSource.setBeanClassName(CONTEXT_SOURCE_CLASS);
contextSource.getConstructorArgumentValues().addIndexedArgumentValue(0, url);
}
contextSource.setSource(parserContext.extractSource(elt));
String managerDn = elt.getAttribute(ATT_PRINCIPAL);
String managerPassword = elt.getAttribute(ATT_PASSWORD);
if (StringUtils.hasText(managerDn)) {
if(!StringUtils.hasText(managerPassword)) {
parserContext.getReaderContext().error("You must specify the " + ATT_PASSWORD +
" if you supply a " + managerDn, elt);
}
contextSource.getPropertyValues().addPropertyValue("userDn", managerDn);
contextSource.getPropertyValues().addPropertyValue("password", managerPassword);
}
...
}
If I debug here, all variables (url, managerDn, managerPassword...) are not replaced by the value specified in the property file. And so, url has the value ${ldap.server.url}, managerDn has the value ${ldap.server.manager.dn} and so on.
The method parse creates a bean, a context source that will be used further. And when this bean will be used, place holders will be replaced.
Here, we got the bug. The parse method check if url is empty or not. The problem is that url is not empty here because it has the value ${ldap.server.url}. So, the parse method creates a context source as a distant server.
When the created source will be used, it will replace the ${ldap.server.url} by empty value (like specified in the property file). And....... Bug !
I don't know really how to solve this for the moment, but I now understand why it bugs ;)
I cannot explain it, but I think you can fix your problem using defaulting syntax, available since Spring 3.0.0.RC1 (see).
In the chageg log you can read: PropertyPlaceholderConfigurer supports "${myKey:myDefaultValue}" defaulting syntax
Anyway, I think that the problem is because "" is valid value, but no value in the property file don't.
I think that url="" works because url attribute is of type xs:token in spring-security XSD and empty string is converted to null (xs:token is removing any leading or trailing spaces, so "" can be recognized as no value). Maybe the value of ${ldap.server.url} is resolved as empty string and that is why you've got an error.
You can try use Spring profiles to define different configurations of ldap server (see Spring Team Blog for details about profiles)
I believe there is an issue here while using place holders. The following will most probably solve the problem:
Create a class which extends PropertyPlaceHolderConfigurer and override its method convertPropertyValue()
in the method you can return the property as empty string if you find anything other than a string which is of type LDAP url i.e. ldap://myldapserver.com/dc=springframeworg,dc=org
Also you need to configure your new specialization of class PropertyPlaceHolderConfigurer in the context file.
Hope this helps.
You can define empty String in the application.properties file as following:
com.core.estimation.stopwords=\ \

Resources