AnsweredAssumed Answered

Unable to get 'WebApplicationContext' in custom servlet

Question asked by sam4alf on Jul 7, 2011
Latest reply on Oct 5, 2011 by lesoft
All Java JCR enthusiasts out there,

I have a custom servlet from where I'm trying to access repository and a node. I need to get this node's content and send it to an applet running in the same context. I have user login ticket and node reference. Using those, I'm trying to get the node and it's content.

Here is my code. Somehow, I always get NullPointerException while getting request. It won't move anywhere from that line. What am I missing? Any clues are really appreciated. Thanks.
             System.out.println("ticketFromApplet given to content handler is: " +    ticketFromApplet);
             System.out.println("NodeRef given to content handler is: " +  nodeRef);
             Ticket ticket = new Ticket("http://<host>:8080/alfresco",  ticketFromApplet);
             StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,  "SpacesStore");
             HttpServletRequest request = (HttpServletRequest) MessageContext.getCurrentContext()                                                                                     .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
            ServletContext sc = request.getSession().getServletContext();
            WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
            // get registry of services
            final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
            SearchService searchService = serviceRegistry.getSearchService();
            ResultSet rs = searchService.query(storeRef,SerchService.LANGUAGE_LUCENE, "ID:\"" + nodeRef + "\"");
            ResultSetRow row = rs.getRow(0);
            NodeRef docRef = row.getNodeRef();
            ContentServiceImpl contentService = new ContentServiceImpl();
            contentService.readContentIntoStream(ticket, docRef, QName.createQName("cm:content"), outputStream);