Uploaded image for project: 'Magnolia DX Core'
  1. Magnolia DX Core
  2. MGNLEE-103

Not able to instantiate MgnlContext

    XMLWordPrintable

Details

    • Bug
    • Resolution: Outdated
    • Major
    • None
    • None
    • None
    • None

    Description

      Hi

      I want to integrate the Magnolia with other web application
      i am writing my own filter to get the instantiation of MgnlContext in my application
      the code is as follows

      public void init(FilterConfig filterConfig) throws ServletException

      { this.servletContext = filterConfig.getServletContext(); }

      //
      public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
      throws IOException, ServletException {

      // if the filter chain was reset, this filter could be called several time. Using this flag so that only the
      // first call will unset the context (which should be the last post-filters operation)
      boolean contextSet = false;
      if (!MgnlContext.hasInstance() || MgnlContext.isSystemInstance())

      { MgnlContext.initAsWebContext(request, response, servletContext); contextSet = true; }

      try

      { System.out.println("Test"); chain.doFilter(request, response); }

      finally {
      if (contextSet)

      { MgnlContext.release(); MgnlContext.setInstance(null); }

      }
      }
      //
      public void destroy()

      { // TODO Auto-generated method stub }

      //
      public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException

      { doFilter((HttpServletRequest) request, (HttpServletResponse) response, chain); }

      }

      when i want to write a jsp using this Filter
      A.jsp

      <% Content content=MgnlContext.getActivePage();%>

      i am getting the following error

      ERROR info.magnolia.context.MgnlContext MgnlContext.java(getInstance:365) 10.07.2008 16:18:57 MgnlContext is not initialized, This could happen if the request does not go through magnolia default filters.
      java.lang.IllegalStateException: MgnlContext is not set for this thread
      at info.magnolia.context.MgnlContext.getInstance(MgnlContext.java:364)
      at info.magnolia.context.MgnlContext.getAggregationState(MgnlContext.java:271)
      at magnolia.utilities.RequestFilter.doFilter(RequestFilter.java:45)
      at magnolia.utilities.RequestFilter.doFilter(RequestFilter.java:69)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
      at java.lang.Thread.run(Thread.java:595)
      ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Ex].[jsp] StandardWrapperValve.java(invoke:260) 10.07.2008 16:18:57 Servlet.service() for servlet jsp threw exception
      java.lang.IllegalStateException: MgnlContext is not set for this thread
      at info.magnolia.context.MgnlContext.getInstance(MgnlContext.java:364)
      at info.magnolia.context.MgnlContext.getAggregationState(MgnlContext.java:271)
      at magnolia.utilities.RequestFilter.doFilter(RequestFilter.java:45)
      at magnolia.utilities.RequestFilter.doFilter(RequestFilter.java:69)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
      at java.lang.Thread.run(Thread.java:595)

      Can you please provide the solution for this

      i am thinking it is a bug

      thanks
      regards
      Krishna

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              gjoseph Magnolia International
              krishna Krishna LVR
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Bug DoR
                  Task DoD