Here is the Filter that I implemented (
http://www.nabble.com/file/5085/AIMSFilter.java AIMSFilter.java ).  It works
for me, for now...  I still don't fully understand what I have done, I think
understanding will come with some more experimentation and exploration.  

I don't even know if this is the right approach, so I will gladly take some
criticism if it will save me headaches down the road.

Chuck


Nathan Hamblen-2 wrote:
> 
> Chuck's using extended sessions, so using that filter for the Wicket
> side wouldn't be an option. But I also don't think that wrapping a
> Wicket RequestCycle around a servlet request is a good idea (if it's
> even possible).
> 
> Instead, I would use a filter for the legacy stuff only. You can still
> tie such a filter to DataStaticService if you want. The session factory
> would be in there (initted by your Wicket app), you just need to tell it
> to open and bind the session to your thread.
> 
> In fact, such a filter for legacy requests is something I'd like to have
> in Databinder, if you make it. Then we could use it for XML-RPC or other
> Web services. As it is, we open the Hibernate session inline:
> http://databinder.net/wsvn/Databinder/message/r1.0/src/main/java/example/BottleService.java?op=file
> 
> (Though that particular service also handles Cajo requests so it
> wouldn't work with an HTTP filter.)
> 
> Nathan
> 
> Martijn Dashorst wrote:
>> You could instead use a OpenSessionInViewFilter (which you can
>> blatently copy from Spring) that opens a hibernate session for you and
>> you can use that in both your wicket app and legacy app.
>> 
>> Martijn
>> 
>> On 12/22/06, ChuckDeal <[EMAIL PROTECTED]> wrote:
>>> I have a legacy app that I am replacing with Wicket.  It has to be done
>>> over
>>> time, so I can't do a wholesale rewrite of the app.  I have Wicket as
>>> the
>>> "main" framework and my legacy, homemade framework will be the
>>> secondary.
>>> The few Wicket/Databinder pages that I have work pretty well.  My legacy
>>> pages are data-oriented as well and I was planning on a partial rewrite
>>> of
>>> the legacy data tier to use Hibernate instead of pure JDBC.
>>>
>>> My problem comes in when I try and access the Hibernate Session from my
>>> legacy data-tier.  I call DataStaticService.getHibernateSession();, but
>>> I
>>> get this exception:
>>>
>>> [code]
>>> org.hibernate.HibernateException: No session currently bound to
>>> execution
>>> context
>>>         at
>>> org.hibernate.context.ManagedSessionContext.currentSession(ManagedSessionContext.java:50)
>>>         at
>>> org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
>>>         at
>>> net.databinder.DataStaticService.getHibernateSession(DataStaticService.java:45)
>>> [/code]
>>>
>>> I know on the surface this looks like a Datbinder question, but I think
>>> it
>>> may be deeper than that.  I believe I am getting this because the
>>> WicketFilter (and therefore the RequestCycle processing) isn't happening
>>> for
>>> my legacy pages.  So I thought that I could write my own filter that
>>> would
>>> attempt to do the RequestCycle stuff, but I'm afraid it is currently a
>>> little overwhelming.  Before I really dig in, does that seem to be a
>>> good
>>> approach?  I am thinking that if I can use Wicket to somehow process the
>>> requests of my legacy app I can get the benefits of Wicket without
>>> having to
>>> rewrite everything upfront.
>>>
>>> When I made my first attempt at my own filter, it literally was a
>>> capture of
>>> the WicketFilter doGet method (with some minor mods.
>>>
>>> public void doFilter(ServletRequest servletRequest, ServletResponse
>>> servletResponse,
>>>         FilterChain chain) throws IOException, ServletException {
>>>     HttpServletRequest httpServletRequest = (HttpServletRequest)
>>> servletRequest;
>>>     HttpServletResponse httpServletResponse = (HttpServletResponse)
>>> servletResponse;
>>>
>>>     String url = httpServletRequest.getRequestURI();
>>>     if (url.contains(".jsp")) {
>>>         log.info("AIMSFilter.doFilter(): " + url);
>>>
>>>         final WebApplication webApplication = (WebApplication)
>>> Application.get("aimsWicket");
>>>
>>>         // Create a new webrequest
>>>         final WebRequest request =
>>> webApplication.newWebRequest(httpServletRequest);
>>>
>>>         // First, set the webapplication for this thread
>>>         Application.set(webApplication);
>>>
>>>         // Get session for request
>>>         final WebSession session = webApplication.getSession(request);
>>>
>>>         RequestCycle cycle = RequestCycle.get();
>>>         if (cycle == null) {
>>>             // Create a response object and set the output encoding
>>> according to
>>>             // wicket's application setttings.
>>>             final WebResponse response =
>>> webApplication.newWebResponse(httpServletResponse);
>>>             response.setAjax(request.isAjax());
>>>
>>> response.setCharacterEncoding(webApplication.getRequestCycleSettings().getResponseRequestEncoding());
>>>
>>>             try {
>>>                 cycle = session.newRequestCycle(request, response);
>>>                 try {
>>>                     // Process request
>>>                     cycle.request();
>>>                 }
>>>                 catch (AbortException e) {
>>>                     // noop
>>>                 }
>>>             }
>>>             finally {
>>>                 // Close response
>>>                 response.close();
>>>
>>>                 // Clean up thread local session
>>>                 Session.unset();
>>>
>>>                 // Clean up thread local application
>>>                 Application.unset();
>>>             }
>>>         }
>>>     }
>>>
>>>     chain.doFilter(servletRequest, servletResponse);
>>> }
>>>
>>> What ended up happening was the MainPage/getHomePage() class was
>>> included in
>>> the response.  I'm not comepletely sure that that description is
>>> accurate
>>> because I don't have a lot of scenarios to test for proof, but that is
>>> what
>>> I see on the screen and that was the pageClass that I saw in
>>> DefaultResponseStrategy.respond on the requestCycle.getRequestTarget().
>>>
>>> Ultimately, I want to be able to do similar processing that takes place
>>> for
>>> Wicket Pages when I request one of my legacy pages.  Where should I even
>>> start?
>>>
>>> Thanks!
>>> Chuck
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Legacy-apps-tf2871064.html#a8024672
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Take Surveys. Earn Cash. Influence the Future of IT
>>> Join SourceForge.net's Techsay panel and you'll get the chance to share
>>> your
>>> opinions on IT & business topics through brief surveys - and earn cash
>>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>> _______________________________________________
>>> Wicket-user mailing list
>>> Wicket-user@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>>
>> 
>> 
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 
-- 
View this message in context: 
http://www.nabble.com/Legacy-apps-tf2871064.html#a8027420
Sent from the Wicket - User mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to