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.
Related
Hi I am learning spring security and i want to implement Digest autherntication in my web app. So I have to declare a bean in my security cofig xml. With the filter bean defination i have add a entrypoint in the xml also. My question is what is the significance of this DigestAuthenticationEntryPoinnt.
-----------------------------------------code below----------------------------------------
<bean id="digestEntryPoint" class=
"org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint">
<property name="realmName" value="Contacts Realm via Digest Authentication"/>
<property name="key" value="acegi"/>
<property name="nonceValiditySeconds" value="10"/>
</bean>
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.
Searched through some other posts but could not find exactly what I needed, but I would guess this is an easy question..
So I have a property file called myprops.properties
myprops.localProp1=localProp1
myprops.localProp2=localProp2
myprops.systemProp=${systemPropertyName}
Basically, in this property file I want to use the values as is for localProp1 and locapProp2 but for systemProp, I would like to load the system property. Let's assume that the system property is always set.
My spring config xml looks like this...
<bean id="myprops" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<qualifer value="myprops" />
<property name="singleton" value="true"/>
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list><value>classpath:myprops.properties</value></list>
</property>
</bean>
I use the qualifier have this bean autowired and use the qualifier string "myprops" to access it in another class. All the expected values are there except the myprops.systemProp, it still = ${systemPropertyName}.
How would I get this property to be resolved with the actual system property?
I tried the following in my spring config:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="myprops" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
This didn't seem to help..
Any ideas? I'm hoping this is an easy one and I am just misunderstanding a common concept in property configuration.
Note: I had to manually type all the code couldn't copy/paste so please excuse typos.
Thanks.
My current project requires a customized "System date", which means a system date and it's format defined in the i18n properties file. But the class dealing with it is a general utility class but not within the web layer. However the locale(to work out the date format) has to be retrieved from a HttpServletRequest object. I am thinking autowire a HttpServletRequest instance to that utility class. It seems break the design pattern but I guess it is piratical. However it doesn't work. So what is wrong with that and is there any better way to solve the Locale in any other layers in Spring?
Thanks in advance.
Wouldn't it be a lot more elegant to simply overload the utility-class to accept a Locale as parameter on the affected methods. Then you can retrieve the locale in your controller and pass it down to the utility.
I prefer you to use the Spring Framework's SessionLocaleResolver. It will change and store the locale in the session and hence you can get that at any point of code in the application.
Please refer the below mentioned configuration for the same. And also read the Spring Documentation for the same for the better understanding.
<mvc:interceptors>
<ref bean="localeChangeInterceptor"/>
</mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en"/>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>/WEB-INF/i18n/labels</value>
<value>/WEB-INF/i18n/messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
Hope this helps you. Cheers.
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.