I am new to Camel and I am using uri:validator in order to validate an XML against a .XSD file. However, I am not sure I am actually pointing to the .xsd file correctly as I my gradle build fails with the following error:
Caused by: java.io.FileNotFoundException: mydirectory\anotherDirectory\myxsdFile-v1.0.xsd (The system cannot find the path specified)
In my common-routes.xml file, I have the following:
<route>
<from uri="direct:util-xmltojson"/>
<log loggingLevel="INFO" message="XML Validation"/>
<doTry>
<to uri="validator:file:mydirectory\anotherDirectory\myxsdFile-v1.0.xsd"/>
<doCatch>
<exception>org.apache.camel.ValidationException</exception>
</doCatch>
</doTry>
</route>
Is this the correct way to use the validator component?
Thank you for your help,
I.
The validator component take in the uri the location of the xsd file used for the validation.
This can be:
A file, with validator:file:_path_. This path is relative to the folder of the execution of your application
A classpath resources (it's, in my opinion, the preferred way): com/test/package/resource.xsd : the schema will be looked in the jar, under com/test/package
A remote resource, with validator:http://remotehost/path : camel will download the resource in order to validate the xml
In your example, camel is looking for the file mydirectory\anotherDirectory\myxsdFile-v1.0.xsd which it doesn't found. Check if this file exist, relatively to the execution folder of your application. If this resource is static, you should place it in your jar, and use the classpath lookup.
Related
I have the following servlet mapping present -
<mvc:resources mapping="/js/**" location="/resources/js/" />
Observation:
If any web request starts with the /js request path, then it will be mapped to the resources directory, and the /** symbol indicates the recursive look for any resource files underneath the base resource directory. Here I can access js/test.js, js/test2.js
Requirement :
I want to access only one specific file(js/test.js). How can I access specific one file(js/test.js) not all files which present into /resources/js location.
Can I use below servlet mapping :::
<mvc:resources mapping="/js/test.js" location="/resources/js/" />
When you add this line
<mvc:resources mapping="/js/**" location="/resources/js/" />
Spring will add a filter rule which says
Whenever any URL with /js/** is fired, spring look for it recursively in /resources/js/ folder.
When you add following configuration
<mvc:resources mapping="/js/test.js" location="/resources/js/" />
Only URL with /js/test.js will be looked in /resources/js/ folder.
Please be mindful that any other request eg /js/jquery or js/abc will not be filtered.
My project is implemented in Spring3 and configuration is almost xml.
Configuration of static resource mapping is like below:
<mvc:resources mapping="/a/**" location="file:/data/a/"/>
There is no problem when accessing /a/xxx.jpg but 404 Error is occurred when accessing subdirectory like /a/b/yyy.jpg. There is no problem about access authority of filesystem. How can I solve this problem? Additional configuration is needed?
(Add) Project directory is fine, but filesystem directory does not work
Use something like below :
<mvc:resources location="/" mapping="/resources/**"/>
You can specify classpath also to location any particular folder like below.
<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>
I am trying to validate the xml file against the xsd using the validator component of camel using blueprint DSL.
<to id="validateXML" uri="validator:file:D:/data/schema/flow.xsd" /> --> working
<to id="validateXML" uri="validator:file:${property.flowXsdPath}" /> --> Not working
flowXsdPath is an exchange property which is set to the xsd location defined by the variable xsdPathVar as given below:
exchange.setProperty("flowXsdPath", exchange.getContext().resolvePropertyPlaceholders(xsdPathVar));
I get exception "Failed to create Producer for endpoint: Endpoint[validator://file:$%7Bproperty.flowXsdPath%7D]. Reason: java.io.FileNotFoundException: ${property.flowXsdPath} (The system cannot find the file specified)"
Though I can access the property value in a log message just before validating the xml file, like this
<log message="File ${file:name} XSD Location = ${property.flowXsdPath}" />
2017-10-16 11:48:44,037 | INFO | processXMLFiles] | file-jms-hums-route | ID-ITEM-XXXXX-49898-1508134722113-0-3 | File 20150603-161237-A412-MFSC.xml XSD Location = D:/data/schema/FSC.xsd
Could you please help how can I access this property inside validator file component?
You should use Dynamic To <toD> instead of <to> to send a message to a dynamic computed Endpoint.
See the related section in http://camel.apache.org/message-endpoint.html
I am trying to enable logging for cxf framework in weblogic application server along with log4j.
I have placed cxf.xml in domain home and have modified setdomainenv to add cxf.xml entry -Dcxf.config.file.url=cxf.xml.
I am setting System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger") before making a webservice call and i have tried configuring all 3 types of configuration specified in http://cxf.apache.org/docs/configuration.html. But nothing seems to work.
I even tried creating org.apache.cxf.Logger file containing value org.apache.cxf.common.logging.Log4jLogger.
my log4j.properties
log4j.rootLogger = DEBUG, FILE
log4j.logger.org.apache.cxf=DEBUG
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=<>/logFile.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
CXF version: 2.7.5
Please suggest if there is change required for me to log both request and response xml?
Make sure your org.apache.cxf.Logger file is under META-INF/cxf. Inspect your war to make sure.
Also, assuming you are defining your services using jaxws, make sure you're defining loggers under the jaxws:inInterceptor and jaxws:outInterceptor
<jaxws:client id="..." serviceClass="..." address="..." >
<jaxws:outInterceptors>
<ref bean="logOut" />
</jaxws:outInterceptors>
<jaxws:inInterceptors>
<ref bean="logIn"/>
</jaxws:inInterceptors>
</jaxws:client>
<bean class='org.apache.cxf.interceptor.LoggingInInterceptor' id='logIn'/>
<bean class='org.apache.cxf.interceptor.LoggingOutInterceptor' id='logOut'/>
I am using spring web mvc project, and I put all the spring related files under WEB-INF\spring, including a ormlite.xml and a jdbc.properties.
Now I want to locate the jdbc.properties file in the ormlite.xml,Like this:
<context:property-placeholder location="/WEB-INF/spring/jdbc.properties"/>
But when I run the application ,it will told me that :
Could not load properties
It can not find the properties file.
What is the problem?
From Spring forum:
The problem is that /WEB-INF isn't accessible as it isn't in the root
of the path, you must use the same path as you use in your test case
(include the src/main/webapp part but that will break your application
from running).
I suggest you move the jdbc.properties to the src/main/resources
directory and simply use classpath: prefix to load the properties.
Code:
<context:property-placeholder location="classpath:jdbc.properties"/>
The code above assumes they are on the root of the classpath (which is
where they are when they are in src/main/resources).
I hope this can help someone else.
I had the same problem - property files outside the classpath.
My solution:
First define a properties bean:
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/your.properties</value>
</property>
</bean>
Then reference it in the property-placeholder:
<context:property-placeholder properties-ref="configProperties" />
Works perfectly well for me!
Instead of:
<context:property-placeholder location="/WEB-INF/spring/jdbc.properties"/>
Use:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/spring/jdbc.properties"/>
And your properties will be available in Spring file, and don't forget to add a namespace: xmlns:p="http://www.springframework.org/schema/p"
I think you're missing the prefix to instruct Spring how to attempt to load the properties. I think your definition needs to be:
<context:property-placeholder location="file:/WEB-INF/spring/jdbc.properties"/>
Note the addition of the file: prefix.