You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Charlee Chitsuk <ch...@gmail.com> on 2013/05/30 11:05:50 UTC

Could you please help to advise about the Container & Control?

Hi All,

I'm using DS version 0.3-incunating together with deltaspike-cdictrl-weld
and Weld-SE version 1.1.12.Final. I've started the DS by using the

contextControl.startContexts();

with purpose to start all Contexts. When I try to stop the RequestScoped by
using the

ctxCtrl.stopContext(RequestScoped.class);

There is an exception  as the following: -

java.lang.NullPointerException
at
org.jboss.weld.context.bound.BoundRequestContextImpl.dissociate(BoundRequestContextImpl.java:40)
at
org.jboss.weld.context.bound.BoundRequestContextImpl.dissociate(BoundRequestContextImpl.java:13)
at
org.apache.deltaspike.cdise.weld.ContextController.stopRequestScope(ContextController.java:156)
at
org.apache.deltaspike.cdise.weld.WeldContextControl.stopRequestScope(WeldContextControl.java:213)
at
org.apache.deltaspike.cdise.weld.WeldContextControl.stopContext(WeldContextControl.java:106)

    Please note, If I catch that NullPointerException and try to start/stop
again, it works without any exception as the following example: -

        try {
            ctxCtrl.stopContext(RequestScoped.class);
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

        ctxCtrl.startContext(RequestScoped.class);

        ctxCtrl.stopContext(RequestScoped.class);
        ctxCtrl.startContext(RequestScoped.class);

I'm not sure If I'm doing something wrong or miss understanding. Could you
please help to advise further?

-- 
   Best Regards,

   Charlee Chitsuk

Re: Could you please help to advise about the Container & Control?

Posted by Charlee Chitsuk <ch...@gmail.com>.
Hi All,

I've found some steps to fix it as the following: -

The exception occurs when I'm using

ContextControl ctxCtrl =
BeanProvider.getContextualReference(ContextControl.class);
ctxCtrl.stopContext(RequestScoped.class);

If I'm switching to use the

CdiContainer CdiContainer = CdiContainerLoader.getCdiContainer();
ContextControl contextControl = cdiContainer.getContextControl();
ctxCtrl.stopContext(RequestScoped.class);

There is no any exception. Everything seems fine.

I thought the root cause may be my customized JUnit runner as the
following: -

public class CdiJUnit4Runner extends BlockJUnit4ClassRunner {

static {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
cdiContainer.boot();
ContextControl contextControl = cdiContainer.getContextControl();
contextControl.startContexts();
}
 private final Class<?> klass;

public CdiJUnit4Runner(final Class<?> myKlass) throws InitializationError {
super(myKlass); this.klass = myKlass; }

    @Override
    protected Object createTest() throws Exception {
        Object test = null;
        try {
            test = BeanProvider.getContextualReference(this.klass, true);
            return test;
        } finally {
            test = null;
        }

    }
}

@RunWith(CdiJUnit4Runner.class)
public class MyTest { ... }

Could you please help to advise further about the ContextControl  between
getting it by using the BeanProvider and getting it from CdiContainer?
Thank you very much for your help in advance. I'm looking forward to
hearing from you soon.

-- 
   Best Regards,

   Charlee Chitsuk


2013/5/30 Charlee Chitsuk <ch...@gmail.com>

> Hi All,
>
> I'm using DS version 0.3-incunating together with deltaspike-cdictrl-weld
> and Weld-SE version 1.1.12.Final. I've started the DS by using the
>
> contextControl.startContexts();
>
> with purpose to start all Contexts. When I try to stop the RequestScoped
> by using the
>
> ctxCtrl.stopContext(RequestScoped.class);
>
> There is an exception  as the following: -
>
> java.lang.NullPointerException
> at
> org.jboss.weld.context.bound.BoundRequestContextImpl.dissociate(BoundRequestContextImpl.java:40)
>  at
> org.jboss.weld.context.bound.BoundRequestContextImpl.dissociate(BoundRequestContextImpl.java:13)
> at
> org.apache.deltaspike.cdise.weld.ContextController.stopRequestScope(ContextController.java:156)
>  at
> org.apache.deltaspike.cdise.weld.WeldContextControl.stopRequestScope(WeldContextControl.java:213)
> at
> org.apache.deltaspike.cdise.weld.WeldContextControl.stopContext(WeldContextControl.java:106)
>
>     Please note, If I catch that NullPointerException and try to
> start/stop again, it works without any exception as the following example: -
>
>         try {
>             ctxCtrl.stopContext(RequestScoped.class);
>         } catch (NullPointerException e) {
>             e.printStackTrace();
>         }
>
>         ctxCtrl.startContext(RequestScoped.class);
>
>         ctxCtrl.stopContext(RequestScoped.class);
>         ctxCtrl.startContext(RequestScoped.class);
>
> I'm not sure If I'm doing something wrong or miss understanding. Could you
> please help to advise further?
>
> --
>    Best Regards,
>
>    Charlee Chitsuk
>