Question

I'm having big trouble with Magnolia Servlet, so far I've tried everything I can think of.

Regarding to the magnolia documentation we can set servlet definition in module definition instead of web.xml (which sounds more neat idea especially for expanding)

So I placed this code in my xml module

 <servlets>
    <servlet>
        <name>jcaptcha</name>
        <class>com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet</class>
        <mappings>
        <mapping>/jcaptcha.jpg</mapping>
        </mappings>
    </servlet>
 </servlets>

And then I created the bypass node (config.server.filters.bypasses.jcaptcha.xml) for the filter

 <?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="jcaptcha" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sv:property sv:name="jcr:primaryType" sv:type="Name">
        <sv:value>mgnl:contentNode</sv:value>
    </sv:property>
    <sv:property sv:name="jcr:uuid" sv:type="String">
        <sv:value>f845ae89-a537-4e9f-b074-57d812fd92a6</sv:value>
    </sv:property>
    <sv:property sv:name="class" sv:type="String">
        <sv:value>info.magnolia.voting.voters.URIStartsWithVoter</sv:value>
    </sv:property>
    <sv:property sv:name="pattern" sv:type="String">
        <sv:value>/jcaptcha.jpg</sv:value>
    </sv:property>
    <sv:node sv:name="MetaData">
        <sv:property sv:name="jcr:primaryType" sv:type="Name">
            <sv:value>mgnl:metaData</sv:value>
        </sv:property>
        <sv:property sv:name="mgnl:activated" sv:type="Boolean">
            <sv:value>false</sv:value>
        </sv:property>
        <sv:property sv:name="mgnl:activatorid" sv:type="String">
            <sv:value>superuser</sv:value>
        </sv:property>
        <sv:property sv:name="mgnl:authorid" sv:type="String">
            <sv:value>superuser</sv:value>
        </sv:property>
        <sv:property sv:name="mgnl:creationdate" sv:type="Date">
            <sv:value>2007-04-25T18:23:31.784+02:00</sv:value>
        </sv:property>
        <sv:property sv:name="mgnl:lastaction" sv:type="Date">
            <sv:value>2007-05-02T17:00:15.025+02:00</sv:value>
        </sv:property>
        <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
            <sv:value>2012-06-07T05:41:25.275-05:00</sv:value>
        </sv:property>
    </sv:node>
</sv:node>

Still when I request localhost/magnolia/jcaptcha.jpg it gives me 404 error. "But" When I put the servlet definition in web.xml , it gives the right result.

Can anyone tell me what am I missing?

Was it helpful?

Solution

Here is the answer I got from magnolia forum

 <servlets>
 <servlet>
 <name>jcaptcha</name>
 <class>com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet</class>
 <mappings>
 <mapping>/jcaptcha.jpg</mapping>
 </mappings>
 </servlet>
 </servlets>

Doing so tells Magnolia to run the servlet for you. You can verify that the servlet is installed when you install module in config:/server/filters/servlets/jcaptcha.

And then I created the bypass node (config.server.filters.bypasses.jcaptcha.xml) for the filter

Doing so you tell Magnolia to NOT treat said bypass url, but instead let Servlet container handler that request. Since only Magnolia knows about the servlet, but not the container you get 404. Once you make container aware of the servlet (by adding it to web.xml) you get the result.

You have 2 options - either you keep bypass and definition in web.xml or you keep the servlet definition in your module. You can't have both. Also please remember that Magnolia will read servlet definition from your module descriptor during installation of the module, so if that module was already installed, you need to invoke info.magnolia.module.delta.RegisterModuleServletsTask as part of your update.

HTH, Jan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top