Fuse ESB/OSGI/Blueprint reading configuration files alphabetically? - apache-camel

I experience something rather strange and I would like to know if other people have experienced the same...
I am currently working on a project using jboss fuse (previously fuse esb) and we are using blueprint for our configuration files.
We use property place holders and have the following files under src/main/resources/OSGI-INF/blueprint:
blueprint.xml
properties.xml
In blueprint.xml we have something like this:
<bean id="myBean" class="com.test.MyClass">
<property name="prop1" value="${my.prop}" />
<∕bean>
Then in properties.xml I have this:
<cm:property-placeholder persistent-id="my.properties" update-strategy="reload">
<cm:default-properties>
<cm:property name="my.prop" value="true" />
</cm:default-properties>
</cm:property-placeholder>
And I obviously have a setter for prop1 (which is a String) in MyClass.
But what I see is that when I deploy this, prop1 is set to "${my.prop}" instead of "true", i.e the variable never gets replaced with its defined value!
But now if I call the properties file aaa_properties.xml, it works!!
Is this a bug in the blueprint container?
Did any one else experience the same behaviour?
Thanks for your feedback :)
JM.

I found some information about Blueprint Configuration in Fuse ESB
It states:
If you need to place your blueprint configuration files in a non-standard location (that is, somewhere other than OSGI-INF/blueprint/*.xml), you can specify a comma-separated list of alternative locations in the Bundle-Blueprint header in the manifest
For Example:
Bundle-Blueprint: lib/account.xml, security.bp, cnf/*.xml
I suggest, can you please give this a try, and specify your xml files here, naturally in the correct ordering.

Related

Camel Processor And .cfg File

Does anybody know if there is a chance to read a .cfg file directly in a camel processor?
My .cfg looks like:
key=value
key=value
...
And I want to get a specific value after its key, but I want to do that in a processor!
Thank you!
Just use plain old Java:
Reader reader = new FileReader("myprop.cfg");
Properties prop = new Properties();
prop.load(reader);
Also have a look at Read contents of a file containing key value pairs without normal parsing. As Claus Ibsen stated, there are good chances that a File -> Properties converter will be added in future Camel versions, see https://issues.apache.org/jira/browse/CAMEL-7312.
If you just need to access some key value pairs, use Camel's properties component:
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:com/mycompany/myprop.cfg"/>
</bean>
Access the property in your routes with the {{key}} syntax:
<to uri="{{cool.end}}"/>
The Camel documentation shows all possibilities.

Camel route using spring-ws client occasionally throws javax.xml.transform.stax.StAXSource exception

I have a camel 'seda' route that contains code roughly:
JaxbDataFormat jaxb = new JaxbDataFormat(false);
jaxb.setContextPath("com.example.data.api");
from("seda:validate")
.marshal(jaxb)
.to("spring-ws:" + getDataServiceURL())
.unmarshal(jaxb)
I send an object from com.example.data.api, the JaxbDataFormat formatter sets it up as a SOAP request and passes it along wo spring-ws to actually send to my service. This works like a charm most of the time.
I say "most" because every now and then, spring-ws throws an exception like so:
org.springframework.ws.client.WebServiceTransformerException: Transformation error: Can't transform a Source of type javax.xml.transform.stax.StAXSource; nested exception is javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:608)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:479)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:470)
at org.apache.camel.component.spring.ws.SpringWebserviceProducer.process(SpringWebserviceProducer.java:81)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
The core of that is this error message: "Can't transform a Source of type javax.xml.transform.stax.StAXSource".
None of that makes sense. The Jaxb marshalling will have already made sure that the object in question is an XML string (according to any debug logging I do). Furthermore, this exact code works most of the time and only occasionally will fail. It appears random.
For instance, I ran a test just a few minutes ago where I sent a message into my route and got this error. I then restarted my service and resend the exact same message... and it worked like a charm. Same code; same environment; same test -- two different results.
It's this randomness that makes this so maddening. Any ideas what I should be looking for to making sure this never happens?
The issue is not with Camel but Spring-WS. Modifying the transformerFactoryClass in WS template config would work
<bean id="baseCamelMarshallerWSTemplate" class="org.springframework.ws.client.core.WebServiceTemplate" scope="prototype">
<constructor-arg ref="messageFactory" />
<property name="messageSender">
<ref bean="httpSender"/>
</property>
<property name="checkConnectionForError" value="true"/>
**<property name="transformerFactoryClass" value="com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>**
</bean>
If you still face the issue, please share spring WS config and a test case

iBatis - Why is sqlMapConfig.xml unable to find the sql maps defined in it?

I have a sqlMapConfig.xml that has three SQLMaps defined in it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- Statement namespaces are required for Ibator -->
<settings enhancementEnabled="true" useStatementNamespaces="true"/>
<!-- Setup the transaction manager and data source that are
appropriate for your environment
-->
<transactionManager type="JDBC">
<dataSource type="SIMPLE" >
<property name="JDBC.Driver"
value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost:3306/sug"/>
<property name="JDBC.Username"
value="root"/>
<property name="JDBC.Password"
value="admin"/>
</dataSource>
</transactionManager>
<!-- SQL Map XML files should be listed here -->
<sqlMap resource="com/tatakelabs/dbmaps/categories_SqlMap.xml" />
<sqlMap resource="com/tatakelabs/dbmaps/pro_SqlMap.xml" />
<sqlMap resource="com/tatakelabs/dbmaps/pro_category_SqlMap.xml" />
</sqlMapConfig>
I get a runtime error - Cause: java.io.IOException: Could not find resource com/tatakelabs/dbmaps/categories_SqlMap.xml
categories_SqlMap.xml is present in that location. I tried changing the location of the map xml, but that did not help. sqlMapConfig.xml validates against the DTD. categories_SqlMap.xml also validates against the right DTD. I am at my wits end trying to figure out why it can't find the resource. The sqlMap files are generated by iBator.
This was happening because the sqlmap file location was not getting copied to target. Added a copy goal and that fixed it.
I had the same problem. It appears the problem lies with the location of the config file. Thus, its in relation of the project resource structure.
I moved the config file in the same package as the mapper classes and it worked. In this case try moving all the resources to this package and update the resource attributes to:
<sqlMap resource="categories_SqlMap.xml" />
<sqlMap resource="pro_SqlMap.xml" />
<sqlMap resource="pro_category_SqlMap.xml" />
Solved it.
I moved the xml file to where the Pojo was located and provided the path as follows:
<sqlMap resource="com/heena/ibatis/model/jsr/jsr.xml" />
And it worked.
place it ...src\java\abc.xml under the Source Packages directory.
If you are using Spring, you can use a SqlMapClientFactoryBean specifying property "mappingLocations". In this property you can specify a generic path, such as "com/tatakelabs/dbmaps/*_SqlMap.xml" or with a variable such as ${mapfiles}, that will be resolved by Spring as an array of file names. This lets you omit sqlMap element in sqlMapConfig. This technique will run with iBatis 2.3.4 on. However sql-map-config-2.dtd is also contained inside iBatis.jar, so you can experience some parsing errors, as /com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd may have a bug. In this case you may want to replace it inside the jar with the one from the URL:
http://ibatis.apache.org/dtd/sql-map-config-2.dtd.

Is it possible to use environment variables within solrconfig.xml for dataDir variable?

We have a situation where we have to maybe create multiple instances of Solr/Tomcat running on different ports on either a single machine or several different machines. Towards doing this I was wondering if it's possible to specify the dataDir variable (within solrconfig.xml) using an environmentvariable for example like so: <dataDir>${envvar}/path/to/index</dataDir>.
As i'm working on a similar setup, i needed this too. I don't think it's good practise to use ENV variables for this. You are probably better off using the multicore setup or use a property file in solr.xml.
eg.
<core name="core_1" instanceDir="core_1" properties="core1.properties" />
and then in your core1.properties:
config.datadir=/datadir1
and then use that in your solrconfig.xml:
<dataDir>${config.datadir}</dataDir>
Cheers,
Patrick
Yes, you can do this, but you need to do jump through a couple hoops to set this up using system properties passed to the JVM when you start it.
Anywhere you want your environment variable to work in your configuration files, put the variable like this:
${VAR}
Then, when you start your JVM, pass it the variable by doing:
java -DVAR=$your-system-variable
So, to make this concrete, here's what we do:
java -DINSTALL_ROOT=$INSTALL_ROOT -jar -server start.jar
And our config has something like:
<filter class="solr.SynonymFilterFactory" synonyms=${INSTALL_ROOT}/Solr/conf/synonyms.txt />
Works like a charm.
Go multi-core .
You can tell Solr to deploy a particular index directory as a core. For example, to deploy a Solr index on path_to_instance_directory on http://localhost:8983/solr/coreX, you would do:
http://localhost:8983/solr/admin/cores?action=CREATE&name=coreX&instanceDir=path_to_instance_directory&config=config_file_name.xml&schema=schem_file_name.xml&dataDir=data
You can tell Solr to create, load, swap two running cores, swap a running core with an inactive core etc.
As explained on wiki.apache.org, you can use system property substitution in solrconfig.xml like below:
<dataDir>${data.dir}</dataDir>
Then you can specify values in a properties file:
#solrcore.properties
data.dir=/data/solrindex
Another way is to dictate the data directory during Solr runtime in this manner:
java -Dsolr.data.dir=/data/dir -jar start.jar
and in XML file use the following syntax:
<dataDir>${solr.data.dir:./solr/data}</dataDir>
I think the better method is to define solr.xml within your solr.home, e.g.:
<solr persistent="true" sharedLib="lib">
<cores adminPath="/admin/cores">
<core name="core0" instanceDir="core0" dataDir="/var/lib/solr/core0" />
<core name="core1" instanceDir="core1" dataDir="/var/lib/solr/core1" />
</cores>
</solr>
Note: I don't think you can use any external variables here.
Finally using JVM system property file (e.g. solr.xml) in conf/Catalina/localhost, for example:
<Context docBase="webapps/solr.war" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="/opt/solr/ads_solr" override="true" />
<Environment name="solr/data/dir" type="java.lang.String" value="/var/lib/solr" override="true" />
</Context>
where solr/home would work, however solr/data/dir won't work without patching your Solr.
See: tomcat_solr.xml.erb

wpf & validation application block > message localization > messageTemplateResource Name&Type

I'm trying to write validation rules for my data objects in a WPF application. I'm writing them in the configuration file, and so far they are working fine.
I'm stumped on how to localize the messages using messageTemplateResourceName and messageTemplateResourceType. What I know is that the strings can be writen in a resource file, given a name and referenced by that name. I get the idea, but i haven't been able to make this work.
<ruleset name="Rule Set">
<properties>
<property name="StringValue">
<validator lowerBound="0" lowerBoundType="Ignore" upperBound="25"
upperBoundType="Inclusive" negated="false" messageTemplate=""
messageTemplateResourceName="msg1" messageTemplateResourceType="Resources"
tag=""
type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation"
name="String Length Validator" />
</property>
</properties>
</ruleset>
Where is the resource file and what value do I pass to messageTemplateResourceType?
I have tried writing the messages in the shell project's resource file but no sucess trying to retrieve the value. I only get the default built-in message.
I've tried
messageTemplateResourceType="typeof(Resources)"
messageTemplateResourceType="Resources"
messageTemplateResourceType="Resources.resx"
messageTemplateResourceType="typeof(Shell)"
messageTemplateResourceType="Shell"
messageTemplateResourceType="Shell,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"
I've also tried adding a new resource file in the shell project, and adding a resource file to the data object's library. I'm all out of ideas Does anyone have any suggestions? I'm not even married to the idea of resource files, so if there are other ways to localize these messages I'd love to know!
thanks
You need to create your own resource file and then point the messageTemplateResourceType attribute to your fully qualified resource type. As long as the resource file can be loaded at runtime you should be fine.
<ruleset name="Rule Set">
...
messageTemplateResourceName="msg1"
messageTemplateResourceType="My.Fully.Qualified.ResourceType, My.AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
...
</ruleset>
An alternate way to do it would be use the messageTemplate as a key and write custom code to look up the actual localized string based on the messageTemplate key (either from a resource file or from a database or wherever else you are storing it).

Resources