You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Prajapati Manish Narandas <pr...@sigmainfo.net> on 2008/04/02 18:12:10 UTC

Regarding Service layer getting called twice

Hi all,
i am using spring object factory action itself,service layer and Dao layer.
Here, service layer method is getting called twice and due to that dao layer
method is also called twice.
Can any body tell me what can be the reason of it?
This not happening service layer of all action.
Like i have another action class which shares the same service layer but for
that action service layer is not
getting called twice.
Following are the all configuration files:

*1. test1-applicationContext.xml* *(My application context file for that
test1 action)*

 <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <import resource="datasource.xml" />
<import resource="test2-applicationcontext.xml" />
 <bean id="testPreview" class="net.test1">
 ..........
  *<property name="itemListingService"> *
*<ref bean="itemListingService" /> *
*</property>*
 .............
 </bean>
</beans>

 *2. test2-applicationcontext.xml* *(application context file which is
imported in above test1 for sharing service layer)*

  <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="itemListingService"
 class="net.service.impl.ItemListingServiceImpl">
.................
*<property name="itemListingDao">*
*<ref bean="ItemListingDao" />*
*</property>*
.................
<property name="listingPeripheralDao">
<ref bean="listingPeripheralDao" />
</property>
 .............
 </bean>
</beans>

*3. struts-test1.xml (struts configuration file for test1'action)*
**
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
 <package name="AuctionPreview" extends="struts-test1Stack"
namespace="/test">
   <interceptors>
    <interceptor-stack name="auctionPreviewStack">
     <interceptor-ref name="sigmaStack">
      <param name="SSLInterceptor.excludeMethods">
        showListing
      </param>
      <param name="ActionContextInterceptor.excludeMethods">
       showListing,nextAllItemList,viewStatetaxMap
      </param>
     </interceptor-ref>
    </interceptor-stack>
   </interceptors>
  <default-interceptor-ref name="auctionPreviewStack" />

  <action name="test!*" method="{1}" class="net.test1">
   <result>/jsp/auctionpreview/success.jsp</result>

   <result
name="success">/jsp/auctionpreview/Main.jsp?page=auctionPreview</result>
........
<result name="input">/jsp/auctionpreview/success.jsp</result>
.........
   <result
name="paymentSuccess">/jsp/listing/PaymentSuccess.jsp?page=listing</result>
   <result
name="paymentFail">/jsp/listing/PaymentFailure.jsp?page=listing</result>

   <result name="error">/jsp/listing/error.jsp?page=listing</result>
  </action>
</package>
</struts>


*4.struts-test1Stack.xml (interceptor stack config file)*

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
 <package name="struts-test1Stack" extends="struts-default">
  <interceptors>
   <interceptor name="SSLInterceptor"
    class="net.sigmainfo.blackwells.action.SSLInterceptor" />
   <interceptor name="ActionContextInterceptor"
    class="net.sigmainfo.blackwells.action.ActionContextInterceptor" />
   <interceptor name="UrlActionInterceptor"
    class="net.sigmainfo.blackwells.action.UrlActionInterceptor" />
   ........................
   <interceptor-stack name="test1Stack">
    <interceptor-ref name="UrlActionInterceptor" />
    <interceptor-ref name="SSLInterceptor" />
    <interceptor-ref name="GarbageCollectionInterceptor" />
    <interceptor-ref name="defaultStack" />
    <interceptor-ref name="ActionContextInterceptor" />

   </interceptor-stack>
  </interceptors>
Summary: Here *itemListingService(Service Layer)  's method is called twice
and because of it itemListingDao (Dao layer)'s*
*method is also called twice any it gives error like Invalid attempt to
associate collection with two open session.*
**
**
*Can anybody tell me why in test1 service layer is getting called twice.*
**
**
*Please share your ideas,*
**
*Thanx in advance.*
**
*From *
*Manish*

Re: Regarding Service layer getting called twice

Posted by Prajapati Manish Narandas <pr...@sigmainfo.net>.
Thanx Laurie,

Actually issue was  in button 's hyperlink .we were calling same function on

both href and onclick event.Actually yesterday we tried to find out weather
action
is getting called twice or not but might be we some were failed to notice it
but today morning
after your mail i again tried  and i found it.

Regards,
Manish

On Thu, Apr 3, 2008 at 2:04 AM, Laurie Harper <la...@holoweb.net> wrote:

> Struts invokes your actions, not your service layer, so the first step is
> to determine where the calls to the service layer are coming from. Either
> your action is doing that or your action is being called more than once
> during one 'logical request' -- which would probably mean the browser was
> issuing more than one request to the action while building the page, unless
> you're using s:action or something. Figure out what's happening at the
> action level first, then work backwards from there.
>
> L.
>
> Prajapati Manish Narandas wrote:
>
> >  Hi all,
> > i am using spring object factory action itself,service layer and Dao
> > layer.
> > Here, service layer method is getting called twice and due to that dao
> > layer
> > method is also called twice.
> > Can any body tell me what can be the reason of it?
> > This not happening service layer of all action.
> > Like i have another action class which shares the same service layer but
> > for
> > that action service layer is not
> > getting called twice.
> > Following are the all configuration files:
> >
> > *1. test1-applicationContext.xml* *(My application context file for that
> > test1 action)*
> >
> >  <?xml version="1.0" encoding="utf-8"?>
> > <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
> > http://www.springframework.org/dtd/spring-beans.dtd">
> > <beans>
> >  <import resource="datasource.xml" />
> > <import resource="test2-applicationcontext.xml" />
> >  <bean id="testPreview" class="net.test1">
> >  ..........
> >  *<property name="itemListingService"> *
> > *<ref bean="itemListingService" /> *
> > *</property>*
> >  .............
> >  </bean>
> > </beans>
> >
> >  *2. test2-applicationcontext.xml* *(application context file which is
> > imported in above test1 for sharing service layer)*
> >
> >  <?xml version="1.0" encoding="utf-8"?>
> > <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
> > http://www.springframework.org/dtd/spring-beans.dtd">
> > <beans>
> > <bean id="itemListingService"
> >  class="net.service.impl.ItemListingServiceImpl">
> > ..................
> > *<property name="itemListingDao">*
> > *<ref bean="ItemListingDao" />*
> > *</property>*
> > ..................
> > <property name="listingPeripheralDao">
> > <ref bean="listingPeripheralDao" />
> > </property>
> >  .............
> >  </bean>
> > </beans>
> >
> > *3. struts-test1.xml (struts configuration file for test1'action)*
> > **
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
> > Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd ">
> > <struts>
> >  <package name="AuctionPreview" extends="struts-test1Stack"
> > namespace="/test">
> >   <interceptors>
> >    <interceptor-stack name="auctionPreviewStack">
> >     <interceptor-ref name="sigmaStack">
> >      <param name="SSLInterceptor.excludeMethods">
> >        showListing
> >      </param>
> >      <param name="ActionContextInterceptor.excludeMethods">
> >       showListing,nextAllItemList,viewStatetaxMap
> >      </param>
> >     </interceptor-ref>
> >    </interceptor-stack>
> >   </interceptors>
> >  <default-interceptor-ref name="auctionPreviewStack" />
> >
> >  <action name="test!*" method="{1}" class="net.test1">
> >   <result>/jsp/auctionpreview/success.jsp</result>
> >
> >   <result
> > name="success">/jsp/auctionpreview/Main.jsp?page=auctionPreview</result>
> > .........
> > <result name="input">/jsp/auctionpreview/success.jsp</result>
> > ..........
> >   <result
> >
> > name="paymentSuccess">/jsp/listing/PaymentSuccess.jsp?page=listing</result>
> >   <result
> > name="paymentFail">/jsp/listing/PaymentFailure.jsp?page=listing</result>
> >
> >   <result name="error">/jsp/listing/error.jsp?page=listing</result>
> >  </action>
> > </package>
> > </struts>
> >
> >
> > *4.struts-test1Stack.xml (interceptor stack config file)*
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
> > Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd ">
> > <struts>
> >  <package name="struts-test1Stack" extends="struts-default">
> >  <interceptors>
> >   <interceptor name="SSLInterceptor"
> >    class="net.sigmainfo.blackwells.action.SSLInterceptor" />
> >   <interceptor name="ActionContextInterceptor"
> >    class="net.sigmainfo.blackwells.action.ActionContextInterceptor" />
> >   <interceptor name="UrlActionInterceptor"
> >    class="net.sigmainfo.blackwells.action.UrlActionInterceptor" />
> >   ........................
> >   <interceptor-stack name="test1Stack">
> >    <interceptor-ref name="UrlActionInterceptor" />
> >    <interceptor-ref name="SSLInterceptor" />
> >    <interceptor-ref name="GarbageCollectionInterceptor" />
> >    <interceptor-ref name="defaultStack" />
> >    <interceptor-ref name="ActionContextInterceptor" />
> >
> >   </interceptor-stack>
> >  </interceptors>
> > Summary: Here *itemListingService(Service Layer)  's method is called
> > twice
> > and because of it itemListingDao (Dao layer)'s*
> > *method is also called twice any it gives error like Invalid attempt to
> > associate collection with two open session.*
> > **
> > **
> > *Can anybody tell me why in test1 service layer is getting called
> > twice.*
> > **
> > **
> > *Please share your ideas,*
> > **
> > *Thanx in advance.*
> > **
> > *From *
> > *Manish*
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Regarding Service layer getting called twice

Posted by Laurie Harper <la...@holoweb.net>.
Struts invokes your actions, not your service layer, so the first step 
is to determine where the calls to the service layer are coming from. 
Either your action is doing that or your action is being called more 
than once during one 'logical request' -- which would probably mean the 
browser was issuing more than one request to the action while building 
the page, unless you're using s:action or something. Figure out what's 
happening at the action level first, then work backwards from there.

L.

Prajapati Manish Narandas wrote:
> Hi all,
> i am using spring object factory action itself,service layer and Dao layer.
> Here, service layer method is getting called twice and due to that dao layer
> method is also called twice.
> Can any body tell me what can be the reason of it?
> This not happening service layer of all action.
> Like i have another action class which shares the same service layer but for
> that action service layer is not
> getting called twice.
> Following are the all configuration files:
> 
> *1. test1-applicationContext.xml* *(My application context file for that
> test1 action)*
> 
>  <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
> http://www.springframework.org/dtd/spring-beans.dtd">
> <beans>
>  <import resource="datasource.xml" />
> <import resource="test2-applicationcontext.xml" />
>  <bean id="testPreview" class="net.test1">
>  ..........
>   *<property name="itemListingService"> *
> *<ref bean="itemListingService" /> *
> *</property>*
>  .............
>  </bean>
> </beans>
> 
>  *2. test2-applicationcontext.xml* *(application context file which is
> imported in above test1 for sharing service layer)*
> 
>   <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
> http://www.springframework.org/dtd/spring-beans.dtd">
> <beans>
> <bean id="itemListingService"
>  class="net.service.impl.ItemListingServiceImpl">
> ..................
> *<property name="itemListingDao">*
> *<ref bean="ItemListingDao" />*
> *</property>*
> ..................
> <property name="listingPeripheralDao">
> <ref bean="listingPeripheralDao" />
> </property>
>  .............
>  </bean>
> </beans>
> 
> *3. struts-test1.xml (struts configuration file for test1'action)*
> **
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
> Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd ">
> <struts>
>  <package name="AuctionPreview" extends="struts-test1Stack"
> namespace="/test">
>    <interceptors>
>     <interceptor-stack name="auctionPreviewStack">
>      <interceptor-ref name="sigmaStack">
>       <param name="SSLInterceptor.excludeMethods">
>         showListing
>       </param>
>       <param name="ActionContextInterceptor.excludeMethods">
>        showListing,nextAllItemList,viewStatetaxMap
>       </param>
>      </interceptor-ref>
>     </interceptor-stack>
>    </interceptors>
>   <default-interceptor-ref name="auctionPreviewStack" />
> 
>   <action name="test!*" method="{1}" class="net.test1">
>    <result>/jsp/auctionpreview/success.jsp</result>
> 
>    <result
> name="success">/jsp/auctionpreview/Main.jsp?page=auctionPreview</result>
> .........
> <result name="input">/jsp/auctionpreview/success.jsp</result>
> ..........
>    <result
> name="paymentSuccess">/jsp/listing/PaymentSuccess.jsp?page=listing</result>
>    <result
> name="paymentFail">/jsp/listing/PaymentFailure.jsp?page=listing</result>
> 
>    <result name="error">/jsp/listing/error.jsp?page=listing</result>
>   </action>
> </package>
> </struts>
> 
> 
> *4.struts-test1Stack.xml (interceptor stack config file)*
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
> Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd ">
> <struts>
>  <package name="struts-test1Stack" extends="struts-default">
>   <interceptors>
>    <interceptor name="SSLInterceptor"
>     class="net.sigmainfo.blackwells.action.SSLInterceptor" />
>    <interceptor name="ActionContextInterceptor"
>     class="net.sigmainfo.blackwells.action.ActionContextInterceptor" />
>    <interceptor name="UrlActionInterceptor"
>     class="net.sigmainfo.blackwells.action.UrlActionInterceptor" />
>    ........................
>    <interceptor-stack name="test1Stack">
>     <interceptor-ref name="UrlActionInterceptor" />
>     <interceptor-ref name="SSLInterceptor" />
>     <interceptor-ref name="GarbageCollectionInterceptor" />
>     <interceptor-ref name="defaultStack" />
>     <interceptor-ref name="ActionContextInterceptor" />
> 
>    </interceptor-stack>
>   </interceptors>
> Summary: Here *itemListingService(Service Layer)  's method is called twice
> and because of it itemListingDao (Dao layer)'s*
> *method is also called twice any it gives error like Invalid attempt to
> associate collection with two open session.*
> **
> **
> *Can anybody tell me why in test1 service layer is getting called twice.*
> **
> **
> *Please share your ideas,*
> **
> *Thanx in advance.*
> **
> *From *
> *Manish*
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org