liam_davison
I'm new here

Writing, debugging and testing a custom UrlGenerator

Jump to solution

Hello,

I am writing a custom URL Generator for a forthcoming project. I implemented UrlFactory and deployed the new module to FirstSpirit. I then selected the new generator in the "PathGeneration" menu item in the "Execute generation" schedule item. But when I run the generate schedule, I'm not seeing any of the file names I expect to see.

I then attached the IntelliJ debugger to the FirstSpirit server, and set some breakpoints in my UrlFactory implementation.

The breakpoint does fire for the public void init(Map<String, String> settings, PathLookup pathLookup) method. But no breakpoints fire in public String getUrl(ContentProducer contentProducer, TemplateSet templateSet, Language language, PageParams pageParams), so I don't think my code is being called correctly.

How can I add some debugging/logging statements to getUrl()? Is their a Context object available?

Many thanks,

Liam

0 Kudos
1 Solution

Accepted Solutions
mbergmann
Crownpeak employee

Hi Liam,

did you reset the stored urls? If you used another UrlFactory before that uses storedUrls (e.g. the AdvancedUrlFactory) and your implementation uses them too, it won't be used to create urls for nodes that already have a stored url.

The default configuration for this behavior is done in the module.xml but can be overridden in the schedule entry using the "useregistry" parameter, see also here.

Michael

View solution in original post

0 Kudos
5 Replies
mbergmann
Crownpeak employee

Hi Liam,

did you reset the stored urls? If you used another UrlFactory before that uses storedUrls (e.g. the AdvancedUrlFactory) and your implementation uses them too, it won't be used to create urls for nodes that already have a stored url.

The default configuration for this behavior is done in the module.xml but can be overridden in the schedule entry using the "useregistry" parameter, see also here.

Michael

0 Kudos
mikula
Crownpeak employee

Hello Liam, 

do you need further help or did Michaels reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily. If you have already found a solution by yourself, it would be very kind of you, if you could share it here.

Best regards 

Martin

0 Kudos

The stored urls was helpful.

I would still like to be able to add logging statements in my UrlFactory but I don't have a Context object available for logging.

0 Kudos

Hi Liam,

you should always be able to use the method Logging.logInfo (warning/error/debug). Even when there is a context object you should use that approach.

BTW: When you do not want to reset (and lose...) the stored URLs until your implementation is done, you can also just disable the use of stored URLs in your UrlFactory. The setting is used both to configure if already stored URLs should be used and (if this is activated) if the URLs calculated by your UrlFactory shoould be stored. You can achieve this by using the "useregistry" parameter in the configuration part in the module.xml and/or by "overriding" it by a script in the generation schedule.

Michael

0 Kudos

Hi Michael,

Thank you for the logging information.

When I add <useRegistry>false</useRegistry> I get thousands of NullPointerExceptions, though the URLs and files are generated correctly. 11 NullPointerExceptions per page generated!

ERROR 22.09.2017 08:46:50.342{g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.344{g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.345{g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.347{g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.349{g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.386{g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.484{g-sec=661828,g-node=661826,g-entity=News and Events(5451)} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.715{g-sec=716312,g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.727{g-sec=716011,g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.729{g-sec=688182,g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

ERROR 22.09.2017 08:46:50.731{g-sec=716459,g-node=661826} (de.espirit.firstspirit.generate.SiteProduction): Error resolving reference - java.lang.NullPointerException

INFO  22.09.2017 08:46:50.734 (de.espirit.firstspirit.generate.SiteProduction): creating output stream for /news-events/rural-priorities-scheme-contracts---management-diaries-2017.html

Unfortunately there's no more information in the logs to help me find the source of the error.

Liam

0 Kudos