exclude pattern with spring interceptor - spring

I am using a spring interceptor and I want to exclude only the first page in my application.
The first page serves to authenticate then redirects towards other pages.
so I wrote in my config file
<mvc:interceptors>
<mvc:interceptor>
<mvc:exclude-mapping path="/" />
<bean class="com.app.interceptor.AuthentificationInterceptor">
</bean>
</mvc:interceptor>
</mvc:interceptors>
But I got an error in the deployement.
Where did I go wrong ?

I am sorry, I made a mistake.
I made a confusion between the path that I saw in the URL (the first page in the URL was located at the root of the app, hence the "/"), and the path of my restangular call in the first page, which was "/contexte".
So I wrote
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/contexte/**" />
<bean class="fr.smabtp.ig.saisines.metier.interceptor.AuthentificationInterceptor">
</bean>
</mvc:interceptor>
</mvc:interceptors>
and it works fine.

Related

Moving mvc interceptor from module-context to web-application context

Can we move mvc interceptors from individual context file to web-application context.xml
Thus removing interceptor from individual module context?
You can put them in the web-context as follow:
<mvc:interceptors>
<bean class="com.package.TheInterceptor" />
<bean class="com.package.AnotherInterceptor" />
</mvc:interceptors>

How to set Last-Modified response header in Spring JSPs

I am using the following configuration for setting cache related response headers in Spring.
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/*.*"/>
<bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="31536000"/>
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
</bean>
</mvc:interceptor>
<!-- Map other interceptors here -->
</mvc:interceptors>
Question: How do I set Last-Modified here ?
[Another Q : Is it just me or its really difficult to find such documentation, especially on property names from Spring docs ?]
According to me there is a better way to achieve this in Spring Framework.
There is a filter called ShallowEtagHeaderFilter. You just need to specify this as a filter in your web.xml.
Please read its javadoc here for more details.
Hope this helps you. Cheers.

about spring social xml configuration

i wonder "#{request.userPrincipal.name}" in configuration blow. when I run my spring social project it always has error at "#{request.userPrincipal.name}", if I set a value such as "123" my project runs well. what's wrong and is there any other configuration instead of "#{request.userPrincipal.name}" ?
<bean id="connectionRepository" factory-method="createConnectionRepository" factory-bean="usersConnectionRepository" scope="request">
<constructor-arg value="#{request.userPrincipal.name}" />
<aop:scoped-proxy proxy-target-class="false" />
</bean>
This is a Spring EL expression, which means getting the user identity from the Http request. Once you apply your own User Management component, you can replace #{request.userPrincipal.name} with your own way.

Spring 3 mvc:resources causing mvc:interceptors to run multiple times

in Spring 3 MVC dispather-servlet.xml with the configuration below, it seems like everytime a .js file is called the interceptor is kicked off.
<mvc:interceptors>
<bean class="com.something.SomeInterceptor" />
</mvc:interceptors>
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/jsp/**" location="/jsp/" />
My view/jsp calls four .js and the interceptor runs four times...
What is the proper way to set up the xml file so that this does not happen?
thanks
It's actually the browser that is requesting the JS files, so 4 HTTP requests are being made to your application. You'll need to use the "mapping" element of mvc:interceptor to select a subset of paths that the interceptor will be applied to. For example:
<mvc:interceptors>
<mvc:interceptor>
<mapping path="/secure/*"/>
<bean class="org.example.SecurityInterceptor" />
</mvc:interceptor>
</mvc:interceptors

setting no cache for different parts of spring mvc 3 using WebContentInterceptor?

Hi there I have developed a dynamic web application that uses Ajax to fetch data from databases and keep the GUI up to date but while testing it with IE8 I am experiencing caching issues.
I used the following code in my webmvc-config.xml file to stop the browser from caching:
<mvc:annotation-driven />
<mvc:interceptors>
<bean id="webContentInterceptor"
class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0"/>
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
<property name="useCacheControlNoStore" value="true"/>
</bean>
</mvc:interceptors>
and it works exactly as it should, but the problem is that now the browser obviously doesn't cache anything. what I want to know is how to modify that xml code so that it applies to the Ajax parts of the web app (which are controlled using 5 Controller files); so that the icons..etc are still cached? The path to these controller files would be something like "/admin/**"
I know that the Spring WebContentInterceptor has properties such as "setCacheMappings" and "setPathMatcher" but there is nowhere online that I can find examples of these being using in the xml config file.
ANY help would be much appreciated, it's really doing my head in.. Thanks. Jake
In your <mvc:interceptors> you can restrict the URL path each interceptor should apply to, as follows:
<mvc:interceptors>
<mvc:interceptor>
<mapping path="/admin/*"/>
<bean id="webContentInterceptor" ..... />
</mvc:interceptor>
<mvc:interceptors>
It's all explained here.

Resources