Juergen Lorenz Simon wrote:
Hi,
On 18.12.2008, at 15:08, Thomas Mortagne wrote:
> On Thu, Dec 18, 2008 at 3:03 PM, Juergen Lorenz Simon <simon(a)webtecc.com
>> wrote:
>> Hi,
>>
>> On 18.12.2008, at 14:37, Thomas Mortagne wrote:
>>
>>> On Thu, Dec 18, 2008 at 1:54 PM, Juergen Lorenz Simon <simon(a)webtecc.com
>>>> wrote:
>>>> Hi Thomas,
>>>>
>>>> no, I do not create a context myself. I'm running this in Eclipse
>>> But where do you get the XWikiContext you give to
>>> createExternalURL() ?
>>
>> When the indexing plugin is instantiated I grab the context:
>>
>> public IndexUpdater(XWiki wiki, XWikiContext context) {
>> this.xwiki = wiki;
>> this.context = context;
>> }
>>
>> Which is obtained from XWiki at plugin initialization time:
>>
>> public void init(XWikiContext context) {
>> ...
>> // initialize the actual plugin
>> indexUpdater = new IndexUpdater(context.getWiki(), context);
>> indexUpdater.start();
>>
>> // Hook into the document change notifications
>> DocChangeRule docChangeRule = new DocChangeRule(indexUpdater);
>>
>> context
>> .getWiki().getNotificationManager().addGeneralRule(docChangeRule);
>> }
>>
>> Do you think I should use the context that comes in the notify()
>> method instead?
> No need, even if it's cleaner but it should be exactly the same java
> object I think, so I don't understand why your context's request
> object is wrong.
No, that is not true. The context received from the notification
mechanism is always the current context, while the one from the
initialization is the context created for the first request that
triggered the initialization.
The stale context has references to the initial ServletRequest and
ServletResponse objects, but the container (usually) closes those
objects. This is container-specific, and I was also bugged by this
problem in Tomcat. So, what happens in Tomcat (if I remember correctly
what I found a long time ago debugging), is that its HttpServletRequest
object is a wrapper over another class holding the actual request data.
After the request finishes, the internal object is cleaned, but the
request wrapper remains in the XWikiContext, although all the calls will
fail (the internal object is missing, thus the NPE).
any more ideas? We need the external URL so we can
point to Wiki pages
from the index. I could maybe wing it together by constructing the url
in some other way, using the host name from confifuration and some
elaborated guessing on the URL, but that would be brittle and
unpleasant to maintain.
Yes, try using the context passed in the notify method.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/