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

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.

Related

How to get file uploaded time in wso2 esb sequence

I am using WSO2 inbound endpoint to fetch a file from an FTP server. And I know how to get the file name back. Now my question is how to get the file uploaded time back (or the last modified time)?
This is the code to get the file name.
<property expression="get-property('transport', 'FILE_NAME')" name="ftp.var.filename"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ns2="http://org.apache.synapse/xsd"/>
I think there should be a similar code to get the timestamp of the file.
With the following property, you will be able to get the last modified time of the file polled from the inbound endpoint.
`<property expression="get-property('transport', 'LAST_MODIFIED')" name="ftp.var.last.modified.time" xmlns:ns="http://org.apache.synapse/xsd"/>`
Add this to the relevant sequence to further process and following is a sample sequence in which the file name and the last modified time is logged.
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="fileSequence" onError="fault" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property expression="get-property('transport', 'FILE_NAME')"
name="ftp.var.filename" xmlns:ns="http://org.apache.synapse/xsd"/>
<property
expression="get-property('transport', 'LAST_MODIFIED')"
name="ftp.var.last.modified.time" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
</sequence>
Please check whether this meets your requirement and please refer [1] to further clarify this.
[1]-https://github.com/wso2/wso2-synapse/blob/master/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java#L767

Is it possible to get file name while reading a file using WSO2 ESB File Connector 2

I am doing a simple file read using WSO2 ESB File connection 2. I try to read a .OUT file from the given directory. It reads the first file (alphabetical order?) well but I have no idea which file is read. Is there a (transport?) property that gets populated when a file is read?
Here is my code in a proxy service
<fileconnector.read>
<source>file:///D:/temp</source>
<filePattern>.*\.OUT</filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
<log level="full"/>
I get the following response
INFO - LogMediator To: /services/SampleProxy.SampleProxyHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:f5737693-6a51-4044-9134-95cd61eaeaa4, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">abc,123
qwe,456
</text></soapenv:Body></soapenv:Envelope>
Give it a try like this. (Just a suggestion. I didn't try.)
<log level="custom">
<property name="FileName" expression="$trp:FILE_NAME" />
</log>
If you want to read a particular file, you can pass the full path as a value in source and you can skip the file pattern value.
<fileconnector.read>
<source>file:///D:/temp/abc.OUT</source>
<filePattern></filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
This is a valid requirement. We will consider this in our future release. Please use [1] to track the progress.
[1] https://wso2.org/jira/browse/ESBCONNECT-192

Fuse ESB/OSGI/Blueprint reading configuration files alphabetically?

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.

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