Hi Introducing a collection wrapper is a not a bad idea - WADL will generate an element for it, but it is not strictly needed. I was just suggesting to introduce *our own* ObjectName wrapper, a bean which will only have a String property initialized from JMX ObjectName.
Introducing a custom JAX-RS MessageBodyWriter which will handle JMX ObjectName/etc can also work, but no schema will be generated in that case... Cheers, Sergey On Mon, Apr 18, 2011 at 2:35 PM, Travis Roy <[email protected]> wrote: > Yes, Sergey. > > I am trying to do this, but so far, can't get rid of the replying on must > have @XmlRootElement annotation for ObjectName. Probably, I need to create > some testing purpose mbeans, register to InstrumentationManagerImpl, and see > how they work. > > > @XmlRootElement > public class ObjectNameCollection { > private Set<ObjectName> endPointNames; > > @XmlElement(name="endpoint") > @XmlElementWrapper(name="endpoints") > public Set<ObjectName> getEndPointNames() { > return endPointNames; > } > > public void setEndPointNames(Set<ObjectName> endPointNames) { > this.endPointNames = endPointNames; > } > } > > @GET > @Path("/list") > public ObjectNameCollection 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)); > ObjectNameCollection objNameCollection = newObjectNameCollection(); > objNameCollection.setEndPointNames(endpointNames); > Iterator<ObjectName> it = endpointNames.iterator(); > while(it.hasNext()){ > ObjectName objectName = it.next(); > System.out.println("CanonicalName = " > +objectName.getCanonicalName()); > System.out.println("Domain = "+objectName.getDomain()); > } > return objNameCollection; > } > > Another question is, are these all the cxf registered mbeans, (In *All > known Implementing Classes*) ? > org.apache.cxf.management > Interface ManagedComponent *All Known Subinterfaces:* > Counter<http://cxf.apache.org/apidocs/org/apache/cxf/management/counters/Counter.html> > *All Known Implementing Classes:* > ManagedBus<http://cxf.apache.org/apidocs/org/apache/cxf/bus/ManagedBus.html> > , > ManagedEndpoint<http://cxf.apache.org/apidocs/org/apache/cxf/endpoint/ManagedEndpoint.html> > , > PerformanceCounter<http://cxf.apache.org/apidocs/org/apache/cxf/management/counters/PerformanceCounter.html> > , > ResponseTimeCounter<http://cxf.apache.org/apidocs/org/apache/cxf/management/counters/ResponseTimeCounter.html> > , > WorkQueueImplMBeanWrapper<http://cxf.apache.org/apidocs/org/apache/cxf/workqueue/WorkQueueImplMBeanWrapper.html> > , > WorkQueueManagerImplMBeanWrapper<http://cxf.apache.org/apidocs/org/apache/cxf/workqueue/WorkQueueManagerImplMBeanWrapper.html> > > > Regards > Shenglin Qiu > > > > > > > > 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 <[email protected]> > 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 > > > > > > > > -- Sergey Beryozkin Application Integration Division of Talend <http://www.talend.com/> http://sberyozkin.blogspot.com
