Announcement Announcement Module
Collapse
No announcement yet.
EndPointInterceptor and Transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EndPointInterceptor and Transaction

    Hello everybody.

    I'm currently working on a spring WS and my main mission was to add some security before the call of the webservice.
    To do that, i used an EndPointInterceptor.

    Everything is working right.
    User sends a request, interceptor checks some data before the endpoint is called and accepts or rejects it.

    BUT
    In my interceptor, i use some data services that should be transactionnal : all those services are called from the webservice endpoint and from a separate web application. When beeing called from the webapplication or from the EndPoint, the transaction is correctly called.
    But not when called from my interceptor : the systems opens a brand new JDBC connection...

    With a little debugging, I realized that the SpringTransactionAnnotationParser was not called for the services inside the interceptor, but was called when the endpoint was called. (yes, i'm using the @Transactional annotation on service methods that needs it)


    Does this description rings a bell to anyone, or a I doing it wrong (maybe the point)

    Here is my endpoint mapping

    Code:
    <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
            <description>
                Detects @PayloadRoot annotations on @Endpoint bean methods. It uses two interceptors: one that logs the message payload, and the other validates
                it accoring to the 'yyy.xsd' schema file.
            </description>
            <property name="interceptors">
                <list>
                                   <bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
                        <property name="schema" value="classpath:/com/xxx/yyy/ws/xxx.xsd"/>
                        <property name="validateRequest" value="true"/>
                        <property name="validateResponse" value="true"/>
                    </bean>
                    <bean id="endPointSecurity" class="com.xxx.yyy.ws.security.EndPointSecurity"/>
                </list>
            </property>
            <property name="order" value="1"/>
        </bean>
    The implementation of my EndPointSecurity bean is simple and only implements EndpointInterceptor.

    Here is the aspect mapping for transaction
    Code:
    <tx:annotation-driven transaction-manager="txManager" order="-1" />
    <context:annotation-config />
     <context:component-scan base-package="all my packages"/>
    
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="myDataSource"/>
            <property name="configLocation" value="classpath:/hibernate.cfg.xml"/>
        </bean>
    
    <!-- # Informer Advice # -->
        <!-- ################### -->
        <bean id="informer" class="com.xxx.yyy.tech.security.InformerAdvice">
            <!-- execute after the transactional advice (hence the upper order number) -->
            <!-- Lower values have higher priority -->
            <property name="order" value="0"/>
            <property name="dataSource" ref="myDataSource" />
            <property name="procName"
                value="system.connectionpool.set_user_login" />
            <property name="securityContext" ref="securityContext"/>
        </bean>
    
        <!-- security context -->
        <bean name="securityContext" class="com.xxx.yyy.ws.security.InformerSecurityContext" />
    
    <aop:config>
            <aop:aspect id="informerAdvice" ref="informer">
                <!-- on service transactional methods -->
                <aop:pointcut id="transationalServiceMethod"
                    expression="execution(* com.xxx.yyy.service.*.*Service.*(..)) &amp;&amp;
                    @annotation(org.springframework.transaction.annotation.Transactional)"/>
                <aop:before method="callInformer" pointcut-ref="transationalServiceMethod"/>
            </aop:aspect>
        </aop:config>
    Thanks a lot if you got a clue somewhere !
Working...
X