Hi,
I am trying to write a simple example to see how a service defined with @ManagedObject
annotation in the JBossAS and then access it using the ProfileService. I wrote below
sample code
Service in JBoss AS
| @ManagementObject(name="MyService")
| @ManagementComponent(type="foo", subtype="service")
| public class MyService {
|
| private String value = "property value";
|
| public void start() {
| System.out.println("Myservice has been started");
| }
|
| public void stop() {
| System.out.println("Myservice has been shut down");
| }
|
| @ManagementProperty(name="Myservice.value")
| public String getValue() {
| return this.value;
| }
|
| @ManagementOperation(description="Call me", impact=Impact.ReadOnly,
params={@ManagementParameter(name="message", description="message to
invoke")})
| public String callMe(String msg) {
| System.out.println("Somebody called me = "+msg);
| return msg + "called";
| }
| }
|
I bundled the above in to jar file and deployed into JBossAS. Then to access it, I wrote a
simple JSP page like this
| <%@ page import="org.jboss.deployers.spi.management.*,
org.jboss.managed.api.*, javax.naming.*, java.util.*,
org.jboss.metatype.api.values.*" %>
| <HTML>
| <BODY>
| <%
| InitialContext ic = new InitialContext();
| ManagementView mgtView =
(ManagementView)ic.lookup("java:ManagementView");
| ManagedComponent mc = mgtView.getComponent("MyService", new
ComponentType("foo", "service"));
|
| SimpleValueSupport result = null;
| Set<ManagedOperation> operations = mc.getOperations();
| for (ManagedOperation op:operations) {
| if (op.getName().equals("callMe")) {
| result = (SimpleValueSupport)op.invoke(SimpleValueSupport.wrap("*"));
| }
| }
| %>
| Response from call is = <%= result.getValue() %>
| </TABLE>
| </BODY>
| </HTML>
|
When I execute this, I always end up in NPE on the response. I see the metadata on the
object like its operations and properties etc, but not seemed to access the property
values or invoke operations. I think I may be missing some step, can somebody please help
or point toward a example?
I looked in "admin-console" code, but I did not see any difference from above.
Thank you.
Ramesh..
Teiid Team.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4265092#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...