Hi Ulf,

I've just merged the PR, a snapshot with the change should be
available in a few minutes.

thanks for following this through! :-)


best regards,
juan pablo

On Fri, Nov 24, 2023 at 4:34 PM Ulf Dittmer
<ulf.ditt...@googlemail.com.invalid> wrote:
>
> Hi Juan-
>
> Done: https://github.com/apache/jspwiki/pull/322
>
> It's strange that the URL decoding is commented out, because that is
> actually needed.
>
> Ulf
>
> On Fri, Nov 24, 2023 at 2:49 PM Juan Pablo Santos Rodríguez <
> juanpablo.san...@gmail.com> wrote:
>
> > Hi Ulf!
> >
> > Hmmm seems to me that URLConstructor.parsePageFromUrl was thought with the
> > short URL constructors in mind. I'd rather change it so it looks like:
> >
> >     static String parsePageFromURL( final HttpServletRequest request, final
> > Charset encoding ) {
> >         final String name = request.getPathInfo();
> >         if( name == null || name.length() <= 1 ) {
> >             return request.getParameter("page"); /////////// change here,
> > might still return null for front page, so perhaps it should return
> > engine.getFrontPage in that case?
> >         } else if( name.charAt(0) == '/' ) {
> >             return name.substring(1);
> >         }
> >
> >         // This is required, because by default all URLs are handled as
> > Latin1, even if they are really UTF-8.
> >         // name = TextUtil.urlDecode( name, encoding );
> >
> >         return name;
> >     }
> >
> > }
> >
> > fixing/adding appropriate unit tests. Would you mind trying that & sending
> > a PR if it fixes the issue? If not able, I think I can commit/push the code
> > myself this weekend.
> >
> > The issue with the parsePage method is that it needs the current wiki
> > context (attach, view, edit, etc.), which isn't there in a straightforward
> > way.
> >
> >
> > Best regards,
> > juan pablo
> >
> > El jue, 23 nov 2023, 11:43, Ulf Dittmer <ulf.ditt...@googlemail.com
> > .invalid>
> > escribió:
> >
> > > I'm confused: URLConstructor.parsePageFromURL -which is used to extract
> > the
> > > page name from the HttpServletRequest when firing the PAGE_REQUESTED and
> > > PAGE_DELIVERED events- looks at the path info rather than the query
> > string
> > > (which contains the page name). How is that supposed to work? Should it
> > be
> > > using URLConstructor.parsePage instead?
> > >
> > > Something like this seems to do the trick:
> > >
> > > String name = request.getParameter("page");
> > > if (StringUtils.isBlank(name)) {
> > >     // TODO: get reference to Engine
> > >     // name = engine.getFrontPage();
> > > } else {
> > >     // This is required, because by default all URLs are handled as
> > Latin1,
> > > even if they are really UTF-8.
> > >     name = URLDecoder.decode(name, encoding);
> > > }
> > >
> > >
> > >
> > >
> > > On Wed, Nov 22, 2023 at 7:02 PM Ulf Dittmer <ulf.ditt...@googlemail.com>
> > > wrote:
> > >
> > > > Now we're getting somewhere :-)
> > > >
> > > > In WikIEventManager, I can see my listener being added
> > > > in WikiEventDelegate.addWikiEventListener, but the reference is null
> > when
> > > > the event reaches WikiEventDelegate.fireEvent. Probably courtesy of the
> > > > WeakReference.
> > > >
> > > > Ok, making the event listener a static class, and keeping a reference
> > to
> > > > it in CoreBean, causes the listener to not be null, and to receive
> > > > PAGE_DELIVERED events.
> > > > engine.addWikiEventListener(myListener) now works fine.
> > > >
> > > > BUT: for both PAGE_REQUESTED and PAGE_DELIVERED, the event's
> > > getPageName()
> > > > method returns null
> > > > The javadocs state "Returns the Wiki page name associated with this
> > > > event. This may be null if unavailable." but why would it be
> > unavailable?
> > > >
> > > > Thanks,
> > > > Ulf
> > > >
> > > > On Wed, Nov 22, 2023 at 6:01 PM Juan Pablo Santos Rodríguez <
> > > > juanpablo.san...@gmail.com> wrote:
> > > >
> > > >> Hi!,
> > > >>
> > > >> The lifecycle extension was just an easy entry point to register the
> > > >> listener, if you're doing it elsewhere it should be fine, you should
> > be
> > > >> receiving the events as soon as you've registered it.
> > > >>
> > > >> Regarding the registration,
> > > >>
> > > >>
> > WikiEventManager.addWikiEventListener(org.apache.wiki.WikiEngine.class,
> > > >> new
> > > >> WikiEventListener() {
> > > >>
> > > >> Having skimmed the code this morning, I think it should use the engine
> > > >> instance, something like
> > > >>
> > > >> WikiEventManager.addWikiEventListener(m_engine, new
> > > >> WikiEventListener() {
> > > >>
> > > >> As this is where WikiJSPFilter send the events. Would you mind trying
> > to
> > > >> debug inside WikiEventManager.fireEvent to see where the events are
> > > being
> > > >> dispatched? I'll try to look into this throughout the week, but can't
> > > >> promise anything.
> > > >>
> > > >>
> > > >> Best regards,
> > > >> juan pablo
> > > >>
> > > >> El mié, 22 nov 2023, 16:52, Ulf Dittmer <ulf.ditt...@googlemail.com
> > > >> .invalid>
> > > >> escribió:
> > > >>
> > > >> > Hm, creating an extension seems like a lot of effort for something
> > > that
> > > >> > should -from my reading of the javadocs- be relatively simple to do.
> > > >> >
> > > >> > I'm beefing up the CoreBean with page view statistics. So the code I
> > > >> posted
> > > >> > before would be run as part of the CoreBean constructor, which
> > should
> > > >> > ensure that it is run during startup time.
> > > >> >
> > > >> > Based on what you said I just tried
> > > >> >
> > > >>
> > > >>
> > WikiEventManager.addWikiEventListener(org.apache.wiki.WikiEngine.class,
> > > >> new
> > > >>
> > > >> WikiEventListener() {
> > > >> >
> > > >>
> > > >> but some (non-) result: The listener is just not called. I feel like
> > I'm
> > > >> > missing something very simple, but I have experimented a lot, and
> > > can't
> > > >> > figure out what it is.
> > > >> >
> > > >> > Thanks,
> > > >> > Ulf
> > > >> >
> > > >> > On Wed, Nov 22, 2023 at 3:33 PM Juan Pablo Santos Rodríguez <
> > > >> > juanpablo.san...@gmail.com> wrote:
> > > >> >
> > > >> > > Hi Ulf,
> > > >> > >
> > > >> > > I haven't had time to look into this in detail, but I'd try to
> > > >> register
> > > >> > the
> > > >> > > listener through an Engine lifecycle extension (#1), from there
> > you
> > > >> > should
> > > >> > > be able to register your listener as soon as the Engine is
> > > >> instantiated.
> > > >> > >
> > > >> > > WikiJSPFilter fires some Page events, but fires them to the
> > running
> > > >> > > WikiEngine, so it's there where you should listen to.
> > > >> > >
> > > >> > > WikiEventUtils disappeared long ago, IIRC due to a refactor so
> > that
> > > >> the
> > > >> > > jspwiki-event could be extracted to it's own module. Don't
> > remember
> > > >> very
> > > >> > > well, but its methods ended up mostly in WiliEventManager
> > > >> > >
> > > >> > >
> > > >> > > HTH,
> > > >> > > juan pablo
> > > >> > >
> > > >> > > #1:
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> > https://jspwiki-wiki.apache.org/Wiki.jsp?page=HowToWriteAnEngineLifecycleExtension
> > > >> > >
> > > >> > >
> > > >> > > El mié, 22 nov 2023, 10:49, Ulf Dittmer <
> > ulf.ditt...@googlemail.com
> > > >> > > .invalid>
> > > >> > > escribió:
> > > >> > >
> > > >> > > > I also tried
> > > >> > > >
> > > >> > > >
> > > >> > > >
> > > >> > >
> > > >> >
> > > >>
> > >
> > WikiEventManager.addWikiEventListener(org.apache.wiki.ui.WikiServletFilter.class,
> > > >> > > > new WikiEventListener() {
> > > >> > > > ...
> > > >> > > >
> > > >> > > > but that doesn't get called, either. Does anyone know how that
> > is
> > > >> > > supposed
> > > >> > > > to work?
> > > >> > > >
> > > >> > > > If I understand
> > > >> > https://jspwiki-wiki.apache.org/Wiki.jsp?page=WikiEvent
> > > >> > > > correctly, that might need to be done BEFORE WikiServletFilter
> > in
> > > >> > > > instantiated, but I don't see how that is possible. But then,
> > I'm
> > > >> not
> > > >> > > sure
> > > >> > > > how accurate that page is - some of the other pages describing
> > > event
> > > >> > > > handling some out of date.
> > > >> > > >
> > > >> > > > Thanks,
> > > >> > > > Ulf
> > > >> > > >
> > > >> > > > On Tue, Nov 21, 2023 at 11:10 AM Ulf Dittmer <
> > > >> > ulf.ditt...@googlemail.com
> > > >> > > >
> > > >> > > > wrote:
> > > >> > > >
> > > >> > > > > Hi-
> > > >> > > > >
> > > >> > > > > I'm trying to get notified whenever a page is delivered by
> > > >> listening
> > > >> > to
> > > >> > > > > WikiPageEvent.PAGE_DELIVERED events. To that end I
> > implemented a
> > > >> > > > > WikiEventListener like this
> > > >> > > > >
> > > >> > > > > engine.addWikiEventListener(new WikiEventListener() {
> > > >> > > > >     @Override
> > > >> > > > >         public void actionPerformed (WikiEvent event) {
> > > >> > > > >             log.info(event.toString());
> > > >> > > > >             if (event instanceof WikiPageEvent) {
> > > >> > > > > ...
> > > >> > > > >             }
> > > >> > > > >         }
> > > >> > > > >     });
> > > >> > > > > }
> > > >> > > > >
> > > >> > > > > But the listener is never called with WikiPageEvents.
> > According
> > > to
> > > >> > > > > https://jspwiki-wiki.apache.org/Wiki.jsp?page=WikiEventUtils
> > (a
> > > >> > class
> > > >> > > > > which apparently no longer exists) I may have to register the
> > > >> > listener
> > > >> > > > with
> > > >> > > > > WikiServletFilter rather than WikiEngine. How would I go about
> > > >> that?
> > > >> > > > >
> > > >> > > > > Thanks,
> > > >> > > > > Ulf
> > > >> > > > >
> > > >> > > >
> > > >> > >
> > > >> >
> > > >>
> > > >
> > >
> >

Reply via email to