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.
Related
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 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.
How can I create a file and serve it as a resource, my /src/main/webapp/WEB-INF/spring/web/dispatcherServlet-context.xml file snippet:
<mvc:resources mapping="/resources/**" location="/resources/" />
Any nice approaches?
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'/>
When I use in my application:
<resources location="/resources/favicon.ico" mapping="/favicon.ico" />
to map out single resource.
How can I map single resource to be accessible through multiple mappings without need to duplicate the file locally ?
For example like this:
<resources location="/resources/favicon.ico" mapping="/favicon.ico" />
<resources location="/resources/favicon.ico" mapping="/favicon.png" />
You can include wildcards. mapping="/favicon.*"