Hi Ludovico,

Yes, I can definately confirm that I have called my own servlets in the same 
application-context as magnolia.

There are 2 ways to do it:

1) Configure a bypass in magnolia's filter chain (at the root level) for the 
URL of your servlet. Configure the servlet in web.xml.
2) Configure the servlet in magnolia's filter-chain directly. Do not configure 
the servlet in web.xml.
Take a look under config -> /server/filters/servlets  You can add your servlet 
here. The configuration format should be quite obvious.

I would go with option #2 - its more "magnolia-compatible".

Adding the servlet in the module descriptor is good too, but (I think) this 
will only take effect if the module is newly installed, and will then cause 
your servlet to be added in the filter configuration. If your module was 
already installed I don't think that adding the servlet to module descriptor 
will change anything, but maybe someone at magnolia can confirm that.

Regards from Vienna,

Richard



-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] 
Im Auftrag von ludovic (via Magnolia Forums)
Gesendet: Dienstag, 08. Jänner 2013 23:14
An: Magnolia User List
Betreff: [magnolia-user] Re: Problem to use a servlet in Magnolia

I would like to know if someone has done a direct call to a servlet in admin 
part (Author) context.

Because I found the filter info.magnolia.cms.filters.AggregorFilter stop my 
request. This method return an exception and my server throws page not found.

[code]

  /**
     * Collect content from the pre configured repository and attach it to the 
HttpServletRequest.
     * @throws PathNotFoundException
     * @throws RepositoryException
     */
    protected boolean collect() throws RepositoryException {
        final AggregationState aggregationState = 
MgnlContext.getAggregationState();
        final String handle = aggregationState.getHandle();
        final String repository = aggregationState.getRepository();

        final HierarchyManager hierarchyManager = 
MgnlContext.getHierarchyManager(repository);

        Content requestedPage = null;
        NodeData requestedData = null;
        final String templateName;

        if (!isJcrPathValid(handle)) {
            // avoid calling isExist if the path can't be valid
            return false;
        }
        if (hierarchyManager.isExist(handle) && 
!hierarchyManager.isNodeData(handle)) {
            requestedPage = hierarchyManager.getContent(handle);

            // check if its a request for a versioned page
            if (MgnlContext.getAttribute(VERSION_NUMBER) != null) {
                // get versioned state
                try {
                    requestedPage = 
requestedPage.getVersionedContent((String)MgnlContext.getAttribute(VERSION_NUMBER));
                }
                catch (RepositoryException re) {
                    log.debug(re.getMessage(), re);
                    log.error("Unable to get versioned state, rendering current 
state of {}", handle);
                }
            }

            templateName = requestedPage.getMetaData().getTemplate();

            if (StringUtils.isBlank(templateName)) {
                log.error("No template configured for page [{}].", 
requestedPage.getHandle()); //$NON-NLS-1$
            }
        }
        else {
            if (hierarchyManager.isNodeData(handle)) {
                requestedData = hierarchyManager.getNodeData(handle);
            }
            else {
                // check again, resource might have different name
                int lastIndexOfSlash = handle.lastIndexOf("/"); //$NON-NLS-1$

                if (lastIndexOfSlash > 0) {

                    final String handleToUse = 
StringUtils.substringBeforeLast(handle, "/"); //$NON-NLS-1$

                    try {
                        requestedData = 
hierarchyManager.getNodeData(handleToUse);
                        aggregationState.setHandle(handleToUse);

                        // this is needed for binary nodedata, e.g. images are 
found using the path:
                        // /features/integration/headerImage instead of 
/features/integration/headerImage/header30_2

                    }
                    catch (PathNotFoundException e) {
                        // no page available
                        return false;
                    }
                    catch (RepositoryException e) {
                        log.debug(e.getMessage(), e);
                        return false;
                    }
                }
            }

            if (requestedData != null) {
                templateName = 
requestedData.getAttribute(FileProperties.PROPERTY_TEMPLATE);
            }
            else {
                return false;
            }
        }

        // Attach all collected information to the HttpServletRequest.
        if (requestedPage != null) {
            aggregationState.setMainContent(requestedPage);
            aggregationState.setCurrentContent(requestedPage);
        }
        if ((requestedData != null) && (requestedData.getType() == 
PropertyType.BINARY)) {
            File file = new File(requestedData);
            aggregationState.setFile(file);
        }

        aggregationState.setTemplateName(templateName);

        return true;
    }


[/code]

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=46792229-594e-4050-ad6c-94a43ced29d7


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to