[MGNLEE-103] Not able to instantiate MgnlContext Created: 10/Jul/08  Updated: 19/Mar/10  Resolved: 19/Mar/10

Status: Closed
Project: Magnolia DX Core
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Krishna LVR Assignee: Magnolia International
Resolution: Outdated Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 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



 Comments   
Comment by Magnolia International [ 19/Mar/10 ]

Your jsp call is probably not going through your filter. Closing as outdated; please reopen if this is still a (support?) issue.

Generated at Mon Feb 12 05:26:44 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.