changcheng / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

WroManager cannot be created using ServletContextAttributeHelper outside the request cycle #431

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I'm trying to use the new WroServletContextListener in my taglib (I used to 
parse wro.xml with a custom implementation).

Basically, I'm trying to have the following informations from the WroModel :
- to know all group names and the ResourceTypes
- to know which files are in a specific group

I want to do this in a ServletContextListener as well to pre-calculate these 
and other informations and when I do this :

        ServletContextAttributeHelper helper = new ServletContextAttributeHelper(servletContext);
        WroModel model = helper.getManagerFactory().create().getModelFactory().create();

I get the following exception:

- Error while scanning @Inject annotation
ro.isdc.wro.WroRuntimeException: Exception while trying to process @Inject 
annotation
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:77)
    at ro.isdc.wro.model.group.processor.Injector.inject(Injector.java:48)
    at ro.isdc.wro.model.group.processor.InjectorBuilder$8.create(InjectorBuilder.java:135)
    at ro.isdc.wro.model.group.processor.InjectorBuilder$8.create(InjectorBuilder.java:132)
    at ro.isdc.wro.model.group.processor.Injector.acceptAnnotatedField(Injector.java:117)
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:64)
    at ro.isdc.wro.model.group.processor.Injector.inject(Injector.java:48)
    at ro.isdc.wro.manager.factory.BaseWroManagerFactory$1.initialize(BaseWroManagerFactory.java:109)
    at ro.isdc.wro.manager.factory.BaseWroManagerFactory$1.initialize(BaseWroManagerFactory.java:68)
    at ro.isdc.wro.util.LazyInitializer.get(LazyInitializer.java:33)
    at ro.isdc.wro.manager.factory.BaseWroManagerFactory.create(BaseWroManagerFactory.java:123)
    at ro.isdc.wro.manager.factory.BaseWroManagerFactory.create(BaseWroManagerFactory.java:49)
    at ro.isdc.wro.manager.factory.DefaultWroManagerFactory.create(DefaultWroManagerFactory.java:59)
    at ro.isdc.wro.manager.factory.DefaultWroManagerFactory.create(DefaultWroManagerFactory.java:18)
    at org.everlong.wro4j.taglib.WroConfig.loadConfig(WroConfig.java:60)
    at org.everlong.wro4j.taglib.WroConfig.getInstance(WroConfig.java:50)
    at org.everlong.wro4j.taglib.IncludeTag.doTag(IncludeTag.java:35)
    at org.apache.jsp.index_min_jsp._jspx_meth_wro_005fstyle_005f0(index_min_jsp.java:159)
    at org.apache.jsp.index_min_jsp._jspService(index_min_jsp.java:58)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:679)
Caused by: ro.isdc.wro.WroRuntimeException: Exception while trying to process 
@Inject annotation
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:77)
    at ro.isdc.wro.model.group.processor.Injector.inject(Injector.java:48)
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:73)
    ... 36 more
Caused by: ro.isdc.wro.WroRuntimeException: Exception while trying to process 
@Inject annotation
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:77)
    at ro.isdc.wro.model.group.processor.Injector.inject(Injector.java:48)
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:73)
    ... 38 more
Caused by: ro.isdc.wro.WroRuntimeException: Exception while trying to process 
@Inject annotation
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:77)
    at ro.isdc.wro.model.group.processor.Injector.inject(Injector.java:48)
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:73)
    ... 40 more
Caused by: ro.isdc.wro.WroRuntimeException: Exception while trying to process 
@Inject annotation
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:77)
    at ro.isdc.wro.model.group.processor.Injector.inject(Injector.java:48)
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:73)
    ... 42 more
Caused by: ro.isdc.wro.WroRuntimeException: No context associated with CURRENT 
request cycle!
    at ro.isdc.wro.config.Context.validateContext(Context.java:125)
    at ro.isdc.wro.config.Context.get(Context.java:106)
    at ro.isdc.wro.model.group.processor.InjectorBuilder$10.create(InjectorBuilder.java:147)
    at ro.isdc.wro.model.group.processor.InjectorBuilder$10.create(InjectorBuilder.java:145)
    at ro.isdc.wro.model.group.processor.Injector.acceptAnnotatedField(Injector.java:117)
    at ro.isdc.wro.model.group.processor.Injector.processInjectAnnotation(Injector.java:64)
    ... 44 more

I tried to use these lines in a ContextServletListener's contextInitialized or 
in a doTag (so during a request).

What is the correct way to get the WroModel ?

Thanks !

Original issue reported on code.google.com by alex.obj...@gmail.com on 13 May 2012 at 2:05

GoogleCodeExporter commented 9 years ago
Wiki page updated: http://code.google.com/p/wro4j/wiki/WroServletContextListener
WroContextFilter added in latest development branch: 
https://github.com/alexo/wro4j/blob/1.4.x/wro4j-core/src/main/java/ro/isdc/wro/h
ttp/WroContextFilter.java

Original comment by alex.obj...@gmail.com on 14 May 2012 at 5:49