You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Pablo Pita <pa...@gmail.com> on 2014/09/26 11:46:09 UTC

problem trying to use DeltaSpike JMX annotations in a standalone main application

Hello all,

I am having a problem trying to use DeltaSpike JMX annotations in a
standalone main application.

For my tests, I have taken MyMBean from DS sources. When looking into the
JMX console JConsole, I see that MyMBean is registered but when trying to
access the counter attribute, this exception comes:

26.09.2014 11:18:20 org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
getAttribute
SCHWERWIEGEND: can't get counter value
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
    at
org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
    at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
    at
com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
    at
javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
    at
javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
    at
javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
    at
javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
    at
javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
    at sun.rmi.transport.Transport$1.run(Transport.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No
active contexts for scope type javax.enterprise.context.RequestScoped
    at
org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
    at
org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
    at
org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
    at
org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
    at
org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
    at
org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
    at
org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
    at
com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
    ... 27 more

I wonder if there is something I am missing to properly setup this case. I
am on Windows running JDK 6 and Weld 1.1.18.


The main program I am using is as follows:

    public static void main(String[] args) throws Exception {

        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
        cdiContainer.boot();

        // Starting the application-context and request-context allows to
use
        // @ApplicationScoped and @RequestScoped beans
        ContextControl contextControl = cdiContainer.getContextControl();
        contextControl.startContext(ApplicationScoped.class);
        contextControl.startContext(RequestScoped.class);

        // we can use CDI here
         while (running) {
            int i = 0;
            i = i + 1;
            Thread.sleep(50);
        }
        cdiContainer.shutdown();
    }

Thanks for any feedback,
-- 
Pablo Pita Leira

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Jason Porter <li...@gmail.com>.
The problem is probably (as I understand your explanation) is that your
beans are registered as @RequestScope and they're also JMX beans. Accessing
a JMX bean through Jconsole will not activate an http request (which in a
container starts the scope) in a container. Now doing this within a main
method and manually starting the scopes will probably work, however, once
the request is finished, CDI should be destroying all beans in that scope,
which would destroy your JMX bean.

Is your JMX bean annotated @RequestScoped or @ApplicationScoped and you're
just injecting something that's request scoped?

On Fri, Sep 26, 2014 at 11:10 AM, Pablo Pita <pa...@gmail.com> wrote:

> My original idea was to emulate a normal Java application with a main
> method using Weld version for Java SE as CDI container. There, I would
> bootstrap the CDI container, and voila, the CDI JMX beans should be
> registered by DeltaSpike infrastructure.
>
> Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> deployment to JBoss, or Arquillian, just Weld SE in the test class path).
> As well, the JMX registration works OK when deploying the application to
> JBoss. I can work with the JMX Console with the JMX beans.
>
> So the code for a normal main method bootstraping the CDI Container is not
> that simple, is it?
>
> Pablo
>
>
>
> On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <li...@gmail.com>
> wrote:
>
> > Pablo,
> >
> > Does your code, looks like it's a test, start and register the MBean? Are
> > you accessing the MBeam from a running JBoss AS7 instance or something? I
> > feel like I'm missing some information.
> >
> > The cause is that the Request scope isn't active when you're accessing
> the
> > MBean.
> >
> > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com>
> wrote:
> >
> > > Hello all,
> > >
> > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > standalone main application.
> > >
> > > For my tests, I have taken MyMBean from DS sources. When looking into
> the
> > > JMX console JConsole, I see that MyMBean is registered but when trying
> to
> > > access the counter attribute, this exception comes:
> > >
> > > 26.09.2014 11:18:20
> > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > getAttribute
> > > SCHWERWIEGEND: can't get counter value
> > > java.lang.reflect.InvocationTargetException
> > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >     at
> > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >     at
> > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > >     at
> > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > >     at
> > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >     at
> > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >     at
> > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > >     at
> > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > >     at java.security.AccessController.doPrivileged(Native Method)
> > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > >     at
> > >
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > >     at
> > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > >     at
> > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > >     at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > >     at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > >     at java.lang.Thread.run(Thread.java:662)
> > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> WELD-001303
> > No
> > > active contexts for scope type javax.enterprise.context.RequestScoped
> > >     at
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > >     at
> > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > >     at
> > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > >     at
> > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > >     ... 27 more
> > >
> > > I wonder if there is something I am missing to properly setup this
> case.
> > I
> > > am on Windows running JDK 6 and Weld 1.1.18.
> > >
> > >
> > > The main program I am using is as follows:
> > >
> > >     public static void main(String[] args) throws Exception {
> > >
> > >         CdiContainer cdiContainer =
> CdiContainerLoader.getCdiContainer();
> > >         cdiContainer.boot();
> > >
> > >         // Starting the application-context and request-context allows
> to
> > > use
> > >         // @ApplicationScoped and @RequestScoped beans
> > >         ContextControl contextControl =
> cdiContainer.getContextControl();
> > >         contextControl.startContext(ApplicationScoped.class);
> > >         contextControl.startContext(RequestScoped.class);
> > >
> > >         // we can use CDI here
> > >          while (running) {
> > >             int i = 0;
> > >             i = i + 1;
> > >             Thread.sleep(50);
> > >         }
> > >         cdiContainer.shutdown();
> > >     }
> > >
> > > Thanks for any feedback,
> > > --
> > > Pablo Pita Leira
> > >
> >
> >
> >
> > --
> > Jason Porter
> > http://en.gravatar.com/lightguardjp
> >
>
>
>
> --
> Pablo Pita Leira
>



-- 
Jason Porter
http://en.gravatar.com/lightguardjp

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Jason Porter <li...@gmail.com>.
Please make sure that ds-test-control is not on the classpath of the main
app.

On Fri, Sep 26, 2014 at 1:33 PM, Pablo Pita <pa...@gmail.com> wrote:

> The JMX beans are @ApplicationScoped.
>
> In the main method, I placed the statement to start of the @RequestScope
> context because the exception I got was referring to the @RequestScope.
> Just in case it would have fix something (it did not).
>
> So, the question is if with a CDI container SE edition + DeltaSpike, is it
> easy to have the JMX Beans registered? Any example? I might have wrong the
> dependencies in Eclipse, and I was trying to run the main method by using
> the menu option Run as Java Application within eclipse.
>
> Pablo
>
> On Fri, Sep 26, 2014 at 7:20 PM, Gerhard Petracek <
> gerhard.petracek@gmail.com> wrote:
>
> > the test-control module should be only on the classpath once you run
> tests
> > and not in production mode (see e.g. [1]).
> >
> > regards,
> > gerhard
> >
> > [1] https://github.com/os890/javase-cdi-ds-project-template
> >
> > http://www.irian.at
> >
> > Your JSF/JavaEE powerhouse -
> > JavaEE Consulting, Development and
> > Courses in English and German
> >
> > Professional Support for Apache MyFaces
> >
> > 2014-09-26 19:10 GMT+02:00 Pablo Pita <pa...@gmail.com>:
> >
> > > My original idea was to emulate a normal Java application with a main
> > > method using Weld version for Java SE as CDI container. There, I would
> > > bootstrap the CDI container, and voila, the CDI JMX beans should be
> > > registered by DeltaSpike infrastructure.
> > >
> > > Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> > > deployment to JBoss, or Arquillian, just Weld SE in the test class
> path).
> > > As well, the JMX registration works OK when deploying the application
> to
> > > JBoss. I can work with the JMX Console with the JMX beans.
> > >
> > > So the code for a normal main method bootstraping the CDI Container is
> > not
> > > that simple, is it?
> > >
> > > Pablo
> > >
> > >
> > >
> > > On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <lightguard.jp@gmail.com
> >
> > > wrote:
> > >
> > > > Pablo,
> > > >
> > > > Does your code, looks like it's a test, start and register the MBean?
> > Are
> > > > you accessing the MBeam from a running JBoss AS7 instance or
> > something? I
> > > > feel like I'm missing some information.
> > > >
> > > > The cause is that the Request scope isn't active when you're
> accessing
> > > the
> > > > MBean.
> > > >
> > > > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com>
> > > wrote:
> > > >
> > > > > Hello all,
> > > > >
> > > > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > > > standalone main application.
> > > > >
> > > > > For my tests, I have taken MyMBean from DS sources. When looking
> into
> > > the
> > > > > JMX console JConsole, I see that MyMBean is registered but when
> > trying
> > > to
> > > > > access the counter attribute, this exception comes:
> > > > >
> > > > > 26.09.2014 11:18:20
> > > > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > > > getAttribute
> > > > > SCHWERWIEGEND: can't get counter value
> > > > > java.lang.reflect.InvocationTargetException
> > > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > > >     at
> > > > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > > > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > > > >     at java.security.AccessController.doPrivileged(Native Method)
> > > > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > > > >     at
> > > > >
> > >
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > > > >     at java.lang.Thread.run(Thread.java:662)
> > > > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> > > WELD-001303
> > > > No
> > > > > active contexts for scope type
> javax.enterprise.context.RequestScoped
> > > > >     at
> > > > >
> > > >
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > > > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > > > >     at
> > > > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > > > >     ... 27 more
> > > > >
> > > > > I wonder if there is something I am missing to properly setup this
> > > case.
> > > > I
> > > > > am on Windows running JDK 6 and Weld 1.1.18.
> > > > >
> > > > >
> > > > > The main program I am using is as follows:
> > > > >
> > > > >     public static void main(String[] args) throws Exception {
> > > > >
> > > > >         CdiContainer cdiContainer =
> > > CdiContainerLoader.getCdiContainer();
> > > > >         cdiContainer.boot();
> > > > >
> > > > >         // Starting the application-context and request-context
> > allows
> > > to
> > > > > use
> > > > >         // @ApplicationScoped and @RequestScoped beans
> > > > >         ContextControl contextControl =
> > > cdiContainer.getContextControl();
> > > > >         contextControl.startContext(ApplicationScoped.class);
> > > > >         contextControl.startContext(RequestScoped.class);
> > > > >
> > > > >         // we can use CDI here
> > > > >          while (running) {
> > > > >             int i = 0;
> > > > >             i = i + 1;
> > > > >             Thread.sleep(50);
> > > > >         }
> > > > >         cdiContainer.shutdown();
> > > > >     }
> > > > >
> > > > > Thanks for any feedback,
> > > > > --
> > > > > Pablo Pita Leira
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Jason Porter
> > > > http://en.gravatar.com/lightguardjp
> > > >
> > >
> > >
> > >
> > > --
> > > Pablo Pita Leira
> > >
> >
>
>
>
> --
> Pablo Pita Leira
>



-- 
Jason Porter
http://en.gravatar.com/lightguardjp

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Pablo Pita <pa...@gmail.com>.
The JMX beans are @ApplicationScoped.

In the main method, I placed the statement to start of the @RequestScope
context because the exception I got was referring to the @RequestScope.
Just in case it would have fix something (it did not).

So, the question is if with a CDI container SE edition + DeltaSpike, is it
easy to have the JMX Beans registered? Any example? I might have wrong the
dependencies in Eclipse, and I was trying to run the main method by using
the menu option Run as Java Application within eclipse.

Pablo

On Fri, Sep 26, 2014 at 7:20 PM, Gerhard Petracek <
gerhard.petracek@gmail.com> wrote:

> the test-control module should be only on the classpath once you run tests
> and not in production mode (see e.g. [1]).
>
> regards,
> gerhard
>
> [1] https://github.com/os890/javase-cdi-ds-project-template
>
> http://www.irian.at
>
> Your JSF/JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
> 2014-09-26 19:10 GMT+02:00 Pablo Pita <pa...@gmail.com>:
>
> > My original idea was to emulate a normal Java application with a main
> > method using Weld version for Java SE as CDI container. There, I would
> > bootstrap the CDI container, and voila, the CDI JMX beans should be
> > registered by DeltaSpike infrastructure.
> >
> > Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> > deployment to JBoss, or Arquillian, just Weld SE in the test class path).
> > As well, the JMX registration works OK when deploying the application to
> > JBoss. I can work with the JMX Console with the JMX beans.
> >
> > So the code for a normal main method bootstraping the CDI Container is
> not
> > that simple, is it?
> >
> > Pablo
> >
> >
> >
> > On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <li...@gmail.com>
> > wrote:
> >
> > > Pablo,
> > >
> > > Does your code, looks like it's a test, start and register the MBean?
> Are
> > > you accessing the MBeam from a running JBoss AS7 instance or
> something? I
> > > feel like I'm missing some information.
> > >
> > > The cause is that the Request scope isn't active when you're accessing
> > the
> > > MBean.
> > >
> > > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com>
> > wrote:
> > >
> > > > Hello all,
> > > >
> > > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > > standalone main application.
> > > >
> > > > For my tests, I have taken MyMBean from DS sources. When looking into
> > the
> > > > JMX console JConsole, I see that MyMBean is registered but when
> trying
> > to
> > > > access the counter attribute, this exception comes:
> > > >
> > > > 26.09.2014 11:18:20
> > > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > > getAttribute
> > > > SCHWERWIEGEND: can't get counter value
> > > > java.lang.reflect.InvocationTargetException
> > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > > >     at
> > > >
> > > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > > >     at
> > > >
> > > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > >     at
> > > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > > >     at java.security.AccessController.doPrivileged(Native Method)
> > > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > > >     at
> > > >
> > sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > > >     at
> > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > > >     at
> > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > > >     at java.lang.Thread.run(Thread.java:662)
> > > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> > WELD-001303
> > > No
> > > > active contexts for scope type javax.enterprise.context.RequestScoped
> > > >     at
> > > >
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > > >     at
> > > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > > >     at
> > > >
> > > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > > >     ... 27 more
> > > >
> > > > I wonder if there is something I am missing to properly setup this
> > case.
> > > I
> > > > am on Windows running JDK 6 and Weld 1.1.18.
> > > >
> > > >
> > > > The main program I am using is as follows:
> > > >
> > > >     public static void main(String[] args) throws Exception {
> > > >
> > > >         CdiContainer cdiContainer =
> > CdiContainerLoader.getCdiContainer();
> > > >         cdiContainer.boot();
> > > >
> > > >         // Starting the application-context and request-context
> allows
> > to
> > > > use
> > > >         // @ApplicationScoped and @RequestScoped beans
> > > >         ContextControl contextControl =
> > cdiContainer.getContextControl();
> > > >         contextControl.startContext(ApplicationScoped.class);
> > > >         contextControl.startContext(RequestScoped.class);
> > > >
> > > >         // we can use CDI here
> > > >          while (running) {
> > > >             int i = 0;
> > > >             i = i + 1;
> > > >             Thread.sleep(50);
> > > >         }
> > > >         cdiContainer.shutdown();
> > > >     }
> > > >
> > > > Thanks for any feedback,
> > > > --
> > > > Pablo Pita Leira
> > > >
> > >
> > >
> > >
> > > --
> > > Jason Porter
> > > http://en.gravatar.com/lightguardjp
> > >
> >
> >
> >
> > --
> > Pablo Pita Leira
> >
>



-- 
Pablo Pita Leira

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Gerhard Petracek <ge...@gmail.com>.
@karl:
all project-templates there are mainly about the setup (dependencies,...).
however, i can add it for sure.

regards,
gerhard

http://www.irian.at

Your JSF/JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces



2014-09-26 19:25 GMT+02:00 Karl Kildén <ka...@gmail.com>:

> I can't find the jmx support docs? I am very interested in the feature.
>
> +1 for the sample but Gerhard, I have used that sample sucessfully but imo
> it misses an actual main method. ie:
>
> https://github.com/karlkilden/smokestack/blob/master/core/src/main/java/se/smokestack/boot/Smokestack.java
>
>
>
> On 26 September 2014 19:20, Gerhard Petracek <ge...@gmail.com>
> wrote:
>
> > the test-control module should be only on the classpath once you run
> tests
> > and not in production mode (see e.g. [1]).
> >
> > regards,
> > gerhard
> >
> > [1] https://github.com/os890/javase-cdi-ds-project-template
> >
> > http://www.irian.at
> >
> > Your JSF/JavaEE powerhouse -
> > JavaEE Consulting, Development and
> > Courses in English and German
> >
> > Professional Support for Apache MyFaces
> >
> > 2014-09-26 19:10 GMT+02:00 Pablo Pita <pa...@gmail.com>:
> >
> > > My original idea was to emulate a normal Java application with a main
> > > method using Weld version for Java SE as CDI container. There, I would
> > > bootstrap the CDI container, and voila, the CDI JMX beans should be
> > > registered by DeltaSpike infrastructure.
> > >
> > > Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> > > deployment to JBoss, or Arquillian, just Weld SE in the test class
> path).
> > > As well, the JMX registration works OK when deploying the application
> to
> > > JBoss. I can work with the JMX Console with the JMX beans.
> > >
> > > So the code for a normal main method bootstraping the CDI Container is
> > not
> > > that simple, is it?
> > >
> > > Pablo
> > >
> > >
> > >
> > > On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <lightguard.jp@gmail.com
> >
> > > wrote:
> > >
> > > > Pablo,
> > > >
> > > > Does your code, looks like it's a test, start and register the MBean?
> > Are
> > > > you accessing the MBeam from a running JBoss AS7 instance or
> > something? I
> > > > feel like I'm missing some information.
> > > >
> > > > The cause is that the Request scope isn't active when you're
> accessing
> > > the
> > > > MBean.
> > > >
> > > > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com>
> > > wrote:
> > > >
> > > > > Hello all,
> > > > >
> > > > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > > > standalone main application.
> > > > >
> > > > > For my tests, I have taken MyMBean from DS sources. When looking
> into
> > > the
> > > > > JMX console JConsole, I see that MyMBean is registered but when
> > trying
> > > to
> > > > > access the counter attribute, this exception comes:
> > > > >
> > > > > 26.09.2014 11:18:20
> > > > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > > > getAttribute
> > > > > SCHWERWIEGEND: can't get counter value
> > > > > java.lang.reflect.InvocationTargetException
> > > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > > >     at
> > > > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > > > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > > > >     at java.security.AccessController.doPrivileged(Native Method)
> > > > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > > > >     at
> > > > >
> > >
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > > > >     at java.lang.Thread.run(Thread.java:662)
> > > > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> > > WELD-001303
> > > > No
> > > > > active contexts for scope type
> javax.enterprise.context.RequestScoped
> > > > >     at
> > > > >
> > > >
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > > > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > > > >     at
> > > > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > > > >     at
> > > > >
> > > > >
> > > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > > > >     ... 27 more
> > > > >
> > > > > I wonder if there is something I am missing to properly setup this
> > > case.
> > > > I
> > > > > am on Windows running JDK 6 and Weld 1.1.18.
> > > > >
> > > > >
> > > > > The main program I am using is as follows:
> > > > >
> > > > >     public static void main(String[] args) throws Exception {
> > > > >
> > > > >         CdiContainer cdiContainer =
> > > CdiContainerLoader.getCdiContainer();
> > > > >         cdiContainer.boot();
> > > > >
> > > > >         // Starting the application-context and request-context
> > allows
> > > to
> > > > > use
> > > > >         // @ApplicationScoped and @RequestScoped beans
> > > > >         ContextControl contextControl =
> > > cdiContainer.getContextControl();
> > > > >         contextControl.startContext(ApplicationScoped.class);
> > > > >         contextControl.startContext(RequestScoped.class);
> > > > >
> > > > >         // we can use CDI here
> > > > >          while (running) {
> > > > >             int i = 0;
> > > > >             i = i + 1;
> > > > >             Thread.sleep(50);
> > > > >         }
> > > > >         cdiContainer.shutdown();
> > > > >     }
> > > > >
> > > > > Thanks for any feedback,
> > > > > --
> > > > > Pablo Pita Leira
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Jason Porter
> > > > http://en.gravatar.com/lightguardjp
> > > >
> > >
> > >
> > >
> > > --
> > > Pablo Pita Leira
> > >
> >
>

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Karl Kildén <ka...@gmail.com>.
I can't find the jmx support docs? I am very interested in the feature.

+1 for the sample but Gerhard, I have used that sample sucessfully but imo
it misses an actual main method. ie:
https://github.com/karlkilden/smokestack/blob/master/core/src/main/java/se/smokestack/boot/Smokestack.java



On 26 September 2014 19:20, Gerhard Petracek <ge...@gmail.com>
wrote:

> the test-control module should be only on the classpath once you run tests
> and not in production mode (see e.g. [1]).
>
> regards,
> gerhard
>
> [1] https://github.com/os890/javase-cdi-ds-project-template
>
> http://www.irian.at
>
> Your JSF/JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
> 2014-09-26 19:10 GMT+02:00 Pablo Pita <pa...@gmail.com>:
>
> > My original idea was to emulate a normal Java application with a main
> > method using Weld version for Java SE as CDI container. There, I would
> > bootstrap the CDI container, and voila, the CDI JMX beans should be
> > registered by DeltaSpike infrastructure.
> >
> > Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> > deployment to JBoss, or Arquillian, just Weld SE in the test class path).
> > As well, the JMX registration works OK when deploying the application to
> > JBoss. I can work with the JMX Console with the JMX beans.
> >
> > So the code for a normal main method bootstraping the CDI Container is
> not
> > that simple, is it?
> >
> > Pablo
> >
> >
> >
> > On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <li...@gmail.com>
> > wrote:
> >
> > > Pablo,
> > >
> > > Does your code, looks like it's a test, start and register the MBean?
> Are
> > > you accessing the MBeam from a running JBoss AS7 instance or
> something? I
> > > feel like I'm missing some information.
> > >
> > > The cause is that the Request scope isn't active when you're accessing
> > the
> > > MBean.
> > >
> > > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com>
> > wrote:
> > >
> > > > Hello all,
> > > >
> > > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > > standalone main application.
> > > >
> > > > For my tests, I have taken MyMBean from DS sources. When looking into
> > the
> > > > JMX console JConsole, I see that MyMBean is registered but when
> trying
> > to
> > > > access the counter attribute, this exception comes:
> > > >
> > > > 26.09.2014 11:18:20
> > > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > > getAttribute
> > > > SCHWERWIEGEND: can't get counter value
> > > > java.lang.reflect.InvocationTargetException
> > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > > >     at
> > > >
> > > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > > >     at
> > > >
> > > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > > >     at
> > > >
> > > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > > >     at
> > > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > > >     at java.security.AccessController.doPrivileged(Native Method)
> > > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > > >     at
> > > >
> > sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > > >     at
> > > >
> > > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > > >     at
> > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > > >     at
> > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > > >     at java.lang.Thread.run(Thread.java:662)
> > > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> > WELD-001303
> > > No
> > > > active contexts for scope type javax.enterprise.context.RequestScoped
> > > >     at
> > > >
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > > >     at
> > > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > > >     at
> > > >
> > > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > > >     at
> > > >
> > > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > > >     ... 27 more
> > > >
> > > > I wonder if there is something I am missing to properly setup this
> > case.
> > > I
> > > > am on Windows running JDK 6 and Weld 1.1.18.
> > > >
> > > >
> > > > The main program I am using is as follows:
> > > >
> > > >     public static void main(String[] args) throws Exception {
> > > >
> > > >         CdiContainer cdiContainer =
> > CdiContainerLoader.getCdiContainer();
> > > >         cdiContainer.boot();
> > > >
> > > >         // Starting the application-context and request-context
> allows
> > to
> > > > use
> > > >         // @ApplicationScoped and @RequestScoped beans
> > > >         ContextControl contextControl =
> > cdiContainer.getContextControl();
> > > >         contextControl.startContext(ApplicationScoped.class);
> > > >         contextControl.startContext(RequestScoped.class);
> > > >
> > > >         // we can use CDI here
> > > >          while (running) {
> > > >             int i = 0;
> > > >             i = i + 1;
> > > >             Thread.sleep(50);
> > > >         }
> > > >         cdiContainer.shutdown();
> > > >     }
> > > >
> > > > Thanks for any feedback,
> > > > --
> > > > Pablo Pita Leira
> > > >
> > >
> > >
> > >
> > > --
> > > Jason Porter
> > > http://en.gravatar.com/lightguardjp
> > >
> >
> >
> >
> > --
> > Pablo Pita Leira
> >
>

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Gerhard Petracek <ge...@gmail.com>.
the test-control module should be only on the classpath once you run tests
and not in production mode (see e.g. [1]).

regards,
gerhard

[1] https://github.com/os890/javase-cdi-ds-project-template

http://www.irian.at

Your JSF/JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

2014-09-26 19:10 GMT+02:00 Pablo Pita <pa...@gmail.com>:

> My original idea was to emulate a normal Java application with a main
> method using Weld version for Java SE as CDI container. There, I would
> bootstrap the CDI container, and voila, the CDI JMX beans should be
> registered by DeltaSpike infrastructure.
>
> Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> deployment to JBoss, or Arquillian, just Weld SE in the test class path).
> As well, the JMX registration works OK when deploying the application to
> JBoss. I can work with the JMX Console with the JMX beans.
>
> So the code for a normal main method bootstraping the CDI Container is not
> that simple, is it?
>
> Pablo
>
>
>
> On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <li...@gmail.com>
> wrote:
>
> > Pablo,
> >
> > Does your code, looks like it's a test, start and register the MBean? Are
> > you accessing the MBeam from a running JBoss AS7 instance or something? I
> > feel like I'm missing some information.
> >
> > The cause is that the Request scope isn't active when you're accessing
> the
> > MBean.
> >
> > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com>
> wrote:
> >
> > > Hello all,
> > >
> > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > standalone main application.
> > >
> > > For my tests, I have taken MyMBean from DS sources. When looking into
> the
> > > JMX console JConsole, I see that MyMBean is registered but when trying
> to
> > > access the counter attribute, this exception comes:
> > >
> > > 26.09.2014 11:18:20
> > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > getAttribute
> > > SCHWERWIEGEND: can't get counter value
> > > java.lang.reflect.InvocationTargetException
> > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >     at
> > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >     at
> > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > >     at
> > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > >     at
> > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >     at
> > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >     at
> > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > >     at
> > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > >     at java.security.AccessController.doPrivileged(Native Method)
> > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > >     at
> > >
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > >     at
> > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > >     at
> > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > >     at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > >     at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > >     at java.lang.Thread.run(Thread.java:662)
> > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> WELD-001303
> > No
> > > active contexts for scope type javax.enterprise.context.RequestScoped
> > >     at
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > >     at
> > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > >     at
> > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > >     at
> > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > >     ... 27 more
> > >
> > > I wonder if there is something I am missing to properly setup this
> case.
> > I
> > > am on Windows running JDK 6 and Weld 1.1.18.
> > >
> > >
> > > The main program I am using is as follows:
> > >
> > >     public static void main(String[] args) throws Exception {
> > >
> > >         CdiContainer cdiContainer =
> CdiContainerLoader.getCdiContainer();
> > >         cdiContainer.boot();
> > >
> > >         // Starting the application-context and request-context allows
> to
> > > use
> > >         // @ApplicationScoped and @RequestScoped beans
> > >         ContextControl contextControl =
> cdiContainer.getContextControl();
> > >         contextControl.startContext(ApplicationScoped.class);
> > >         contextControl.startContext(RequestScoped.class);
> > >
> > >         // we can use CDI here
> > >          while (running) {
> > >             int i = 0;
> > >             i = i + 1;
> > >             Thread.sleep(50);
> > >         }
> > >         cdiContainer.shutdown();
> > >     }
> > >
> > > Thanks for any feedback,
> > > --
> > > Pablo Pita Leira
> > >
> >
> >
> >
> > --
> > Jason Porter
> > http://en.gravatar.com/lightguardjp
> >
>
>
>
> --
> Pablo Pita Leira
>

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Pablo Pita <pa...@gmail.com>.
My original idea was to emulate a normal Java application with a main
method using Weld version for Java SE as CDI container. There, I would
bootstrap the CDI container, and voila, the CDI JMX beans should be
registered by DeltaSpike infrastructure.

Running unit tests with the @RunWith(CdiTestRunner.class) works (no
deployment to JBoss, or Arquillian, just Weld SE in the test class path).
As well, the JMX registration works OK when deploying the application to
JBoss. I can work with the JMX Console with the JMX beans.

So the code for a normal main method bootstraping the CDI Container is not
that simple, is it?

Pablo



On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <li...@gmail.com>
wrote:

> Pablo,
>
> Does your code, looks like it's a test, start and register the MBean? Are
> you accessing the MBeam from a running JBoss AS7 instance or something? I
> feel like I'm missing some information.
>
> The cause is that the Request scope isn't active when you're accessing the
> MBean.
>
> On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com> wrote:
>
> > Hello all,
> >
> > I am having a problem trying to use DeltaSpike JMX annotations in a
> > standalone main application.
> >
> > For my tests, I have taken MyMBean from DS sources. When looking into the
> > JMX console JConsole, I see that MyMBean is registered but when trying to
> > access the counter attribute, this exception comes:
> >
> > 26.09.2014 11:18:20
> > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > getAttribute
> > SCHWERWIEGEND: can't get counter value
> > java.lang.reflect.InvocationTargetException
> >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >     at
> >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >     at
> >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >     at java.lang.reflect.Method.invoke(Method.java:597)
> >     at
> >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> >     at
> >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> >     at
> >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> >     at
> >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> >     at
> >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> >     at
> >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> >     at
> >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> >     at
> >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> >     at
> >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >     at
> >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >     at
> >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >     at java.lang.reflect.Method.invoke(Method.java:597)
> >     at
> sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> >     at java.security.AccessController.doPrivileged(Native Method)
> >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> >     at
> > sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> >     at
> >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> >     at
> >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> >     at
> >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> >     at
> >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> >     at java.lang.Thread.run(Thread.java:662)
> > Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303
> No
> > active contexts for scope type javax.enterprise.context.RequestScoped
> >     at
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> >     at
> >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> >     at
> >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> >     at
> >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> >     at
> >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> >     at
> org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> >     at
> >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> >     at
> >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> >     at
> >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> >     ... 27 more
> >
> > I wonder if there is something I am missing to properly setup this case.
> I
> > am on Windows running JDK 6 and Weld 1.1.18.
> >
> >
> > The main program I am using is as follows:
> >
> >     public static void main(String[] args) throws Exception {
> >
> >         CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
> >         cdiContainer.boot();
> >
> >         // Starting the application-context and request-context allows to
> > use
> >         // @ApplicationScoped and @RequestScoped beans
> >         ContextControl contextControl = cdiContainer.getContextControl();
> >         contextControl.startContext(ApplicationScoped.class);
> >         contextControl.startContext(RequestScoped.class);
> >
> >         // we can use CDI here
> >          while (running) {
> >             int i = 0;
> >             i = i + 1;
> >             Thread.sleep(50);
> >         }
> >         cdiContainer.shutdown();
> >     }
> >
> > Thanks for any feedback,
> > --
> > Pablo Pita Leira
> >
>
>
>
> --
> Jason Porter
> http://en.gravatar.com/lightguardjp
>



-- 
Pablo Pita Leira

Re: problem trying to use DeltaSpike JMX annotations in a standalone main application

Posted by Jason Porter <li...@gmail.com>.
Pablo,

Does your code, looks like it's a test, start and register the MBean? Are
you accessing the MBeam from a running JBoss AS7 instance or something? I
feel like I'm missing some information.

The cause is that the Request scope isn't active when you're accessing the
MBean.

On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pa...@gmail.com> wrote:

> Hello all,
>
> I am having a problem trying to use DeltaSpike JMX annotations in a
> standalone main application.
>
> For my tests, I have taken MyMBean from DS sources. When looking into the
> JMX console JConsole, I see that MyMBean is registered but when trying to
> access the counter attribute, this exception comes:
>
> 26.09.2014 11:18:20
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> getAttribute
> SCHWERWIEGEND: can't get counter value
> java.lang.reflect.InvocationTargetException
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
>
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
>     at
>
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
>     at
>
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
>     at
>
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
>     at
>
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
>     at
>
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
>     at
>
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
>     at
>
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
>     at
>
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
>     at sun.rmi.transport.Transport$1.run(Transport.java:159)
>     at java.security.AccessController.doPrivileged(Native Method)
>     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
>     at
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
>     at
>
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
>     at
>
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
>     at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
>     at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
>     at java.lang.Thread.run(Thread.java:662)
> Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No
> active contexts for scope type javax.enterprise.context.RequestScoped
>     at
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
>     at
>
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
>     at
>
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
>     at
>
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
>     at
>
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
>     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
>     at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
>     at
>
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
>     at
>
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
>     at
>
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
>     ... 27 more
>
> I wonder if there is something I am missing to properly setup this case. I
> am on Windows running JDK 6 and Weld 1.1.18.
>
>
> The main program I am using is as follows:
>
>     public static void main(String[] args) throws Exception {
>
>         CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
>         cdiContainer.boot();
>
>         // Starting the application-context and request-context allows to
> use
>         // @ApplicationScoped and @RequestScoped beans
>         ContextControl contextControl = cdiContainer.getContextControl();
>         contextControl.startContext(ApplicationScoped.class);
>         contextControl.startContext(RequestScoped.class);
>
>         // we can use CDI here
>          while (running) {
>             int i = 0;
>             i = i + 1;
>             Thread.sleep(50);
>         }
>         cdiContainer.shutdown();
>     }
>
> Thanks for any feedback,
> --
> Pablo Pita Leira
>



-- 
Jason Porter
http://en.gravatar.com/lightguardjp