PageableHandlerMethodArgumentResolver in spring-projects/spring-data-commons - java

I use spring and in my context I created bean:
<bean id="pageableResolver" class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
<constructor-arg ref="sortResolver" />
<property name="oneIndexedParameters" value="true"/>
</bean>
Also I use backbone framework as frontend.
When I generate request with page=1&size=10 when oneIndexedParameters is true then I expect to receive first page with 10 records. In current configuration I receive first page with nine records. It is right? How I can configure PageableHandlerMethodArgumentResolver to decrement only pageNumber, but not pageSize?

I filed and fixed DATACMNS-761 for you.

Related

How to inject an attribute using spring in a type handler?

I'm setting up an application which uses mybatis to map objects to/from the database.
In my mybatis file, I use a typehandler to map one of the objects being sent to the database.
In the typeHandler, I am injecting an attribute using spring #resource.
However, when the typehandler is called, the injected property is always null.
From my research, I have discovered that mybatis sets its configuration before spring loads. That means the bean is cannot be injected into the handler as it is created after.
Does anyone know a solution to this?
Should let spring manage customized type handler, like this:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="typeHandlers">
<array>
<bean class="com.example.YourCustomTypeHandler">
<!-- inject -->
<property name="property" ref="bean"/>
</bean>
</array>
</property>
</bean>

Configure pagination with PageableHandlerMethodArgumentResolver for a RESTful server [duplicate]

I use spring and in my context I created bean:
<bean id="pageableResolver" class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
<constructor-arg ref="sortResolver" />
<property name="oneIndexedParameters" value="true"/>
</bean>
Also I use backbone framework as frontend.
When I generate request with page=1&size=10 when oneIndexedParameters is true then I expect to receive first page with 10 records. In current configuration I receive first page with nine records. It is right? How I can configure PageableHandlerMethodArgumentResolver to decrement only pageNumber, but not pageSize?
I filed and fixed DATACMNS-761 for you.

Spring-security creates malformed ldap-query

I am trying to get a Single-signon solution working, which has previously worked with Novell eDirectory as an LDAP-provider. Now, I am trying to get it to work with OpenLDAP. In the signon-process, one of the steps is retrieving the actual user from the LDAP. This is done by Spring-security, but it seems to have a bug.
For getting the user, LdapUserDetailsService#loadUserByUsername is called. This uses a predefined LdapUserSearch to find a user with the given username. In my case, the configuration looks something like this:
base:ou=something,ou=somethingElse,dc=oh,dc=my,dc=god
filter:cn={0}
where {0} is replaced with the actual username. So far this works, and the user is retrieved, in the form of userdata returned by FilterBasedLdapUserSearch#searchForUser. But, the userdata does not separate between dn and base, so it has:
base: (empty)
dn:cn=someUsername,ou=something,ou=somethingElse,dc=oh,dc=my,dc=god
This userdata-object is in turn used to retrieve the authorities for the user, so it the tries to do another search with the base above, and the dn as filter. But, this query fails, since OpenLDAP does not allow any queries with an empty string as base.
I have tried with 3.1.3.RELEASE, 3.1.7.RELEASE and 3.2.7.RELEASE, all have the same issue.
Is this a bug in spring-security? Or am I doing something wrong here?
Managed to fix it, by moving away from the "template" way of defining the ldap user service:
Before:
<sec:ldap-user-service id="ldapUserDetailsService"
server-ref="contextSource"
user-search-filter="${my.ldap.filter}"
user-search-base="${my.ldap.base}"
user-context-mapper-ref="myUserDetailsContextMapper"/>
After:
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0" value="${my.ldap.base}"/>
<constructor-arg index="1" value="${my.ldap.filter}"/>
<constructor-arg index="2" ref="contextSource"/>
</bean>
<bean id="ldapAuthoritiesPopulator" class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource"/>
<constructor-arg value="${my.ldap.usersearch.base}"/>
<property name="groupSearchFilter" value="${my.group.filter}" />
<property name="groupRoleAttribute" value="${my.group.attribute}" />
<property name="searchSubtree" value="true" />
</bean>
<bean id="ldapUserDetailsService" class="org.springframework.security.ldap.userdetails.LdapUserDetailsService">
<constructor-arg ref="userSearch"/>
<constructor-arg ref="ldapAuthoritiesPopulator"/>
</bean>
Don't ask me how or why this works..

Spring RabbitMQ SimpleRabbitListenerContainerFactory usage

From the docs, I want to use consume from queues by dynamically changing the consumers without restarting the application.
I do see that Spring RabbitMQ latest version supports the same, but no clue/example/explanation to change the same. I couldn't see proper source code for the same or how to pass params like maxConcurrentConsumers
I am using XML based configuration of Spring RabbitMQ along with Spring integration
<bean id="rabbitListenerContainerFactory"
class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
<property name="concurrentConsumers" value="3"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="acknowledgeMode" value="AUTO" />
</bean>
<int-amqp:inbound-channel-adapter channel="lowInboundChannel" queue-names="lowLoadQueue" advice-chain="retryInterceptor" acknowledge-mode="AUTO" listener-container="rabbitListenerContainerFactory" />
<int-amqp:inbound-channel-adapter channel="highInboundChannel" queue-names="highLoadQueue" advice-chain="retryInterceptor" acknowledge-mode="AUTO" listener-container="rabbitListenerContainerFactory" />
Can anyone guide me how to dynamically configure the consumers?
First of all you shouldn't share the same rabbitListenerContainerFactory for different <int-amqp:inbound-channel-adapter>s, because they do this:
protected void onInit() {
this.messageListenerContainer.setMessageListener(new ChannelAwareMessageListener() {
So, only last adapter wins.
From other side there is even no reason to have several adapters. You can specify queue-names="highLoadQueue,lowLoadQueue" for a single adapter.
Although in case of listener-container you must specify queues on the SimpleRabbitListenerContainerFactory.
If you want to change some rabbitListenerContainerFactory options at runtime, you can just inject it to some service and invoke its setters.
Let me know if I have missed anything.

Spring MVC - How can I use different timeouts for my resttemplates?

I am using Spring MVC with Spring 3.1. I have a web application that uses many REST services. One of these REST services takes up to an hour to respond - which I can not change. I have my timeout for the RestTemplate set up like this with the timeout set to 60 minutes:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate ">
<constructor-arg>
<bean class="org.springframework.http.client.CommonsClientHttpRequestFactory">
<property name="readTimeout" value="3600000" />
<property name="connectTimeout" value="3600000" />
</bean>
</constructor-arg>
</bean>
I would like to be able to set all of my other REST calls to a different set of timeouts. Any ideas on how to do this?
Thanks,
Tim
You can't do this on a method call basis. In other words, all calls on the restTemplate bean will use the same underlying ClientHttpRequestFactory. If you want different requests to use different timeout values, declare multiple RestTemplate beans and inject the appropriate ones in your beans.

Categories

Resources