Hi Sergey: I have made some progress according to your last email, due to the size of each file, I have to paste some of them below. As you can see, in my spring application context, I deployed 2 testing Jax Rs services, UserServiceImpl and CustomerServiceImpl, and then I attached my JmxService in each of those 2 services, plus, I manually make these 2 services share the same root path.
Besides listing all mbeans in http://localhost:8080/cxfservice/jaxrs/jmx/list, I now can add these in the URL: http://localhost:8080/cxfservice/jaxrs/jmx/component/org.apache.cxf:type=Bus.Service.Endpoint,* http://localhost:8080/cxfservice/jaxrs/jmx/component/org.apache.cxf:type=*,* http://localhost:8080/cxfservice/jaxrs/jmx/component/*:bus.id=*,* I think I need to get on IRC with you some time, and of course, at anytime when you are free. Sadly sometimes, after coding for some while, I lost the ideas of what I am doing and what I need to do. Such as, if I use Jconsole to monitor local java instance with mbeans exposed, for example, my local jetty, it can also show up a lot of interesting stuff, like memory usage and cpu usage in real time. But right now, except showing up the definitions of each mbean, I can't see anything more, and I am not also sure about whether I have shown the right mbeans and the right url path you wanted. Thank you very much. Regards: Shenglin Qiu <bean id="instrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl"> <property name="bus" ref="cxf" /> <property name="enabled" value="true" /> <property name="JMXServiceURL" value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" /> </bean> <!-- Wiring the counter repository --> <bean id="counterRepository" class="org.apache.cxf.management.counters.CounterRepository"> <property name="bus" ref="cxf" /> </bean> <!-- JAX-RS Server 1 --> <jaxrs:server id="userServiceRs" address="/jaxrs"> <jaxrs:serviceBeans> <ref bean="userService" /> <ref bean="jmxService" /> </jaxrs:serviceBeans> <jaxrs:extensionMappings> <entry key="feed" value="application/atom+xml"/> <entry key="json" value="application/json"/> <entry key="xml" value="application/xml"/> <entry key="html" value="text/html"/> </jaxrs:extensionMappings> </jaxrs:server> <!-- JAX-RS Server 2 --> <jaxrs:server id="customerServiceRs" address="/jaxrs"> <jaxrs:serviceBeans> <ref bean="customerService" /> <ref bean="jmxService" /> </jaxrs:serviceBeans> <jaxrs:extensionMappings> <entry key="feed" value="application/atom+xml"/> <entry key="json" value="application/json"/> <entry key="xml" value="application/xml"/> <entry key="html" value="text/html"/> </jaxrs:extensionMappings> </jaxrs:server> <bean id="userService" class="com.plumchoice.ws.service.impl.UserServiceImpl" /> <bean id="customerService" class="com.plumchoice.ws.service.impl.CustomerServiceImpl" /> <bean id="jmxService" class="com.plumchoice.ws.service.impl.JaxRsJMXServiceImpl" /> Here is my Jmx exposer service class: @Path("/jmx") @Produces("application/xml") public class JaxRsJMXServiceImpl implements JaxRsJMXService { private static String jmxServerURL = "service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi"; private static MBeanServerConnection mbsc; public JaxRsJMXServiceImpl() throws IOException{ JMXServiceURL url = new JMXServiceURL(jmxServerURL); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); mbsc = jmxc.getMBeanServerConnection(); } @GET @POST @Path("/list") @Override public CxfMBeanCollection list() throws IOException, MalformedObjectNameException, NullPointerException{ Set<ObjectName> endpointNames = listBusEndpoint(); CxfMBeanCollection mBeanCollection = new CxfMBeanCollection(); Set<CxfMBean> mbeans = new HashSet<CxfMBean>(); Iterator<ObjectName> it = endpointNames.iterator(); while(it.hasNext()){ ObjectName objectName = it.next(); System.out.println("CanonicalName = "+objectName.getCanonicalName()); System.out.println("Domain = "+objectName.getDomain()); CxfMBean mbean = new CxfMBean(); mbean.setCanonicalName(objectName.getCanonicalName()); mbean.setDomain(objectName.getDomain()); mbeans.add(mbean); String canonicalKeyList = objectName.getCanonicalKeyPropertyListString(); Hashtable<String, String> keyProperties = objectName.getKeyPropertyList(); System.out.println("Canoical Key PropertyList = "+canonicalKeyList); Set<Entry<String, String>> keyPropertySet = keyProperties.entrySet(); Iterator<Entry<String, String>> keyPropertyIt = keyPropertySet.iterator(); while(keyPropertyIt.hasNext()){ Entry<String, String> keyPropertyEntry = keyPropertyIt.next(); System.out.println("Key Property key = "+keyPropertyEntry.getKey()); System.out.println("Key Property value = "+keyPropertyEntry.getValue()); } } mBeanCollection.setCxfMBeans(mbeans); return mBeanCollection; } @GET @POST @Path("/component/{objectname}") @Override public CxfMBeanCollection getComponent(@PathParam("objectname") String objectname) throws IOException, MalformedObjectNameException, NullPointerException { System.out.println("input = "+objectname); Set<ObjectName> endpointNames = listGivenBusEndpoint(objectname); CxfMBeanCollection mBeanCollection = new CxfMBeanCollection(); Set<CxfMBean> mbeans = new HashSet<CxfMBean>(); Iterator<ObjectName> it = endpointNames.iterator(); while(it.hasNext()){ ObjectName objectName = it.next(); System.out.println("CanonicalName = "+objectName.getCanonicalName()); System.out.println("Domain = "+objectName.getDomain()); CxfMBean mbean = new CxfMBean(); mbean.setCanonicalName(objectName.getCanonicalName()); mbean.setDomain(objectName.getDomain()); mbeans.add(mbean); String canonicalKeyList = objectName.getCanonicalKeyPropertyListString(); Hashtable<String, String> keyProperties = objectName.getKeyPropertyList(); System.out.println("Canoical Key PropertyList = "+canonicalKeyList); Set<Entry<String, String>> keyPropertySet = keyProperties.entrySet(); Iterator<Entry<String, String>> keyPropertyIt = keyPropertySet.iterator(); while(keyPropertyIt.hasNext()){ Entry<String, String> keyPropertyEntry = keyPropertyIt.next(); System.out.println("Key Property key = "+keyPropertyEntry.getKey()); System.out.println("Key Property value = "+keyPropertyEntry.getValue()); } } mBeanCollection.setCxfMBeans(mbeans); return mBeanCollection; } private Set<ObjectName> listBusEndpoint() throws MalformedObjectNameException, NullPointerException, IOException { ObjectName queryEndpointName = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=Bus.Service.Endpoint,*"); Set<ObjectName> endpointNames = CastUtils.cast(mbsc.queryNames(queryEndpointName, null)); return endpointNames; } private Set<ObjectName> listAllEndpoints() throws MalformedObjectNameException, NullPointerException, IOException{ ObjectName queryEndpointName = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=*,*"); Set<ObjectName> endpointNames = CastUtils.cast(mbsc.queryNames(queryEndpointName, null)); return endpointNames; } private Set<ObjectName> listAll() throws MalformedObjectNameException, NullPointerException, IOException{ ObjectName queryEndpointName = new ObjectName("*:type=*,*"); Set<ObjectName> endpointNames = CastUtils.cast(mbsc.queryNames(queryEndpointName, null)); return endpointNames; } private Set<ObjectName> listGivenBusEndpoint(String objectname) throws MalformedObjectNameException, NullPointerException, IOException { ObjectName queryEndpointName = new ObjectName(objectname); Set<ObjectName> endpointNames = CastUtils.cast(mbsc.queryNames(queryEndpointName, null)); return endpointNames; } On Apr 18, 2011, at 5:54 AM, Sergey Beryozkin wrote: > Hi > > It is a good progress, I think you are on the right path. > Just to see that things are really working, introduce ObjectName and > ManagedComponent JAXB beans which will be initialized from JMX ObjectName > and ManagedComponent JMX objects. > > That should be enough for GETs to start working. We will think on which HTTP > verbs to use to start/stop ManageComponents/etc next. > > At this stage just try to get the list of (JAXB) ObjectNames returned and > add another method which will return a specific (JAXB) ManagedComponent > given the query like this: > > GET /jaxrsjms/component/{objectname} > or > GET /jaxrsjms/component?name={objectname} > > where {objectname} is one of the returned ObjectNames. > > Cheers, Sergey > > > On Sun, Apr 17, 2011 at 12:54 AM, Travis Roy <dabaip...@hotmail.com> wrote: > >> Hi Sergey: >> >> I think i get stuck at the server's returning. Usually, I define my own >> domain object bound with JAXB annotation, but right now, if I am having this >> class: >> >> @Path("/jaxrsjmx") >> @Produces("application/xml") >> public class JaxRsJMXServiceImpl implements JaxRsJMXService { >> private static String jmxServerURL = >> "service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi"; >> private static MBeanServerConnection mbsc; >> @GET >> @Path("/list") >> public Set<ObjectName> list() throws IOException, >> MalformedObjectNameException, NullPointerException{ >> JMXServiceURL url = new JMXServiceURL(jmxServerURL); >> JMXConnector jmxc = JMXConnectorFactory.connect(url, null); >> mbsc = jmxc.getMBeanServerConnection(); >> ObjectName queryEndpointName = new ObjectName(ManagementConstants. >> DEFAULT_DOMAIN_NAME + ":type=Bus.Service.Endpoint,*"); >> Set<ObjectName> endpointNames = >> CastUtils.cast(mbsc.queryNames(queryEndpointName, >> null)); >> return endpointNames; >> } >> >> >> @GET >> @Path("/start") >> public ManagedComponent start(){ >> System.out.println("/start"); >> return null; >> } >> >> >> >> @GET >> @Path("/stop") >> public ManagedComponent stop(){ >> System.out.println("/stop"); >> return null; >> } >> >> >> @GET >> @Path("/restart") >> public ManagedComponent restart(){ >> System.out.println("/restart"); >> return null; >> } >> } >> >> As you can see, this list() function's return is obviously wrong. So far, I >> can't figure out a way to properly return a cxf mbean or a list of mbeans, >> though client can reach the above methods. >> Usually, I have domain object like this >> >> @XmlRootElement(name = "user") >> public class User { >> private Integer id; >> private String userName; >> private String firstName; >> private String lastName; >> public User(){} >> public User(Integer id, String userName){ >> this.id = id; >> this.userName = userName; >> } >> public Integer getId() { >> return id; >> } >> public void setId(Integer id) { >> this.id = id; >> } >> public String getUserName() { >> return userName; >> } >> public void setUserName(String userName) { >> this.userName = userName; >> } >> public String getFirstName() { >> return firstName; >> } >> public void setFirstName(String firstName) { >> this.firstName = firstName; >> } >> public String getLastName() { >> return lastName; >> } >> public void setLastName(String lastName) { >> this.lastName = lastName; >> } >> } >> And I can easily return this 'User' back to client in REST, however, I am >> just guessing how I am able to wrap/apply this pattern on mbeans. >> >> I need your help. >> Thank you very much. >> >> Here is part of my spring context: >> <import resource="classpath:META-INF/cxf/cxf.xml" /> >> <!-- <import >> resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/> >> --> >> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> >> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> >> <import resource= >> "classpath:META-INF/cxf/cxf-extension-ws-security.xml" /> >> <import resource="classpath*:META-INF/cxf/cxf-extension-*.xml" /> >> <!-- Enable message logging using the CXF logging feature --> >> <cxf:bus> >> <cxf:features> >> <cxf:logging/> >> </cxf:features> >> </cxf:bus> >> <bean id="instrumentationManager" class= >> "org.apache.cxf.management.jmx.InstrumentationManagerImpl"> >> <property name="bus" ref="cxf" /> >> <property name="enabled" value="true" /> >> <property name="JMXServiceURL" value= >> "service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" /> >> </bean> >> >> >> <!-- Wiring the counter repository --> >> <bean id="counterRepository" class= >> "org.apache.cxf.management.counters.CounterRepository"> >> <property name="bus" ref="cxf" /> >> </bean> >> >> >> >> >> <!-- JAX-RS Server --> >> <jaxrs:server id="userServiceRs" address="/rest"> >> <jaxrs:serviceBeans> >> <ref bean="userService" /> >> <ref bean="jmxService" /> >> </jaxrs:serviceBeans> >> <jaxrs:extensionMappings> >> <entry key="xml" value="application/xml" /> >> </jaxrs:extensionMappings> >> </jaxrs:server> >> >> <bean id="userService" class= >> "com.mycompany.ws.service.impl.UserServiceImpl" /> >> <bean id="jmxService" class= >> "com.mycompany.ws.service.impl.JaxRsJMXServiceImpl" /> >> >> PS: UserServiceImpl is working totally ok. >> >> >> >> Regards: >> Shenglin Qiu >> >> >> >> >>