include::../shared-doc/attributes.adoc[]

= helloworld-mbean: Helloworld Using MBean and CDI component
:author: Lagarde Jeremie
:level: Intermediate
:technologies: CDI, JMX, MBean
:imagesdir: images/

[abstract]
The `helloworld-mbean` quickstart demonstrates the use of CDI and MBean in {productName} and includes JConsole instructions and Arquillian tests.

:standalone-server-type: default
:archiveType: war
:archiveName: {artifactId}-service

== What is it?

The `helloworld-mbean` quickstart demonstrates the use of _CDI_ and _MBean_ in {productNameFull}. The project also includes a set of Arquillian tests for MBeans.

The example is composed of the following MBeans.

[cols="30%,70%",options="headers"]
|===
|MBean |Description

| `AnnotatedComponentHelloWorld`
| This MBean is a managed bean with `@MXBean` annotation.

| `MXComponentHelloWorld`
| This MBean is a managed bean with `MXBean` interface.

| `MXPojoHelloWorld`
| This MBean is a POJO using `MXBean` interface and declared in the `jboss-service.xml` file.

| `SarMXPojoHelloWorld`
| This MBean is a pojo using `MXBean` interface and declared in the `jboss-service.xml` file using SAR packaging.
|===

// System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]
// Use of {jbossHomeName}
include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1]
// Start the {productName} Standalone Server
include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+1]
// Build and Deploy the Quickstart
include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+1]

// Additional deployment information
This also deploys the `{artifactId}-service/target/{artifactId}-service.sar` to the running instance of the server.

== Access and Test the MBeans

This quickstart differs from the other quickstarts in that it uses _JConsole_ to access and test the quickstart rather than access an URL in the browser. If you do access http://localhost:8080/{artifactId}-webapp/, you will see a screen shot image of the _JConsole_ application,

The following sections describe how to use _JConsole_ to inspect and test the MBeans.

[[start_jconsole]]
== Start JConsole

. To connect to the {productName} server using _JConsole_, open a terminal and type the following command, replacing __JDK_HOME__ with the path to your JDK installation :
+
[source,subs="+quotes,attributes+",options="nowrap"]
----
__JDK_HOME__/bin/jconsole
----
NOTE: For Windows, type `JDK_HOME\bin\jconsole.exe`.

. Select the local *org.jboss.modules.Main* process and click *Connect*.
+
image:jconsole_connection.png[MBeans in JConsole Connection]

. A dialog displays with the warning: `Secure connection failed. Retry insecurely?`

. Click *Insecure* to continue.

[[test_the_mbeans_in_jconsole]]
== Test the MBeans in JConsole

You can use _JConsole_ to inspect and use the MBeans :
image:jconsole.png[MBeans in JConsole]

. Click on the MBeans tab.
. Expand *quickstarts* in the left column of the console.
. Under *quickstarts*, you see the 4 MBeans: *AnnotatedComponentHelloWorld*, *MXComponentHelloWorld*, *MXPojoHelloWorld*, and *SarMXPojoHelloWorld*
. Expand each MBean and choose: *Operations* -> *sayHello*.
. Type your name in the *(p0 String )* input text box and click the *sayHello* button.
* For the *AnnotatedComponentHelloWorld* and *MXComponentHelloWorld* examples, you will see a popup Window displaying *Hello <your name>!*.
* For the *MXPojoHelloWorld* and *SarMXPojoHelloWorld* examples, you will see a popup Window displaying *Welcome <your name>!*.

// Undeploy the Quickstart
include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1]
// Run the Arquillian Tests
include::../shared-doc/run-arquillian-tests.adoc[leveloffset=+1]
// Run the Quickstart in Red Hat Developer Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]

// Additional Red Hat Developer Studio instructions
This quickstart consists of multiple projects and requires installation of the `JBoss Tools Maven Packaging Configurator`, so it deploys and runs differently in {JBDSProductName} than the other quickstarts.

. Install the JBoss Tools Maven Packaging Configurator
** If the *Red Hat Central* page is not showing, open it by choosing *Help* -> *Red Hat Central*.
** Click the *Software/Update* tab at the bottom of the *Red Hat Central*.
** Scroll down to the *Maven* section, select the *JBoss Tools Maven Packaging Configurator* and click *Install/Update*.
. Right click on the parent *{artifactId}* parent project and choose *Maven* -> *Update Project...*. Select all projects and click *OK*.
. Right-click on the *{artifactId}-service* project and choose *Run As* -> *Run on Server*.
. Right-click on the *{artifactId}-webapp* project and choose *Run As* -> *Run on Server*.
. xref:start_jconsole[Start JConsole] and xref:test_the_mbeans_in_jconsole[Test the MBeans in JConsole] as described above.
. To undeploy the web application, right-click on the *{artifactId}-wepapp* project and choose *Run As* -> *Maven build*. Enter `wildfly:undeploy` for the *Goals* and click *Run*.
. To undeploy the web service, right-click on the *{artifactId}-service* project and choose *Run As* -> *Maven build*. Enter `wildfly:undeploy` for the *Goals* and click *Run*.

// Debug the Application
include::../shared-doc/debug-the-application.adoc[leveloffset=+1]
