Hi Sergey: I am able to use sub-resource locator and @UriInfo and implement: class JMXServer:
@Path("/mbean/") public CxfMBean locateMBean() throws MalformedObjectNameException, NullPointerException{ UriBuilder uriBuilder = uriInfo.getBaseUriBuilder().path(this.getClass(), "list"); System.out.println("uriInfo.getPath() = "+uriInfo.getPath()); String key = uriInfo.getPath().substring("mbean/".length()); System.out.println(key); CxfMBeanCollection cxfMBeans = list(); CxfMBean cxfMBean = cxfMBeans.getCxfMBean(key); return cxfMBean; } class CxfMBeanCollection: public CxfMBean getCxfMBean(String key){ for(CxfMBean cxfMBean : cxfMBeans){ if(cxfMBean.getId() != null && cxfMBean.getId().equals(key)){ return cxfMBean; } } return null; } class CxfMBean: @GET @Path("{key}") public CxfMBean getCxfMBean(@PathParam("key") String key){ if(id != null && id.equals(key)){ return this; }else{ return null; } } Request: http://localhost:8080/services/jmx/mbean/5 Response: <MBean href="http://localhost:8080/services/jmx/mbean/5"> <attribute> <busId>cxf32436715</busId> <port>"UserServiceImpl"</port> <service>"{http://server.gsoc.apache.org/}UserServiceImpl"</service> <type>Bus.Service.Endpoint</type> </attribute> <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="UserServiceImpl",service="{http://server.gsoc.apache.org/}UserServiceImpl",type=Bus.Service.Endpoint</canonicalName> <domain>org.apache.cxf</domain> <id>5</id> </MBean> And so on for other mbean with id 1, 3, 4, 5, 6 and response with the same format <MBean href="http://localhost:8080/services/jmx/mbean/3"> <attribute> <busId>cxf32436715</busId> <type>Bus</type> </attribute> <canonicalName>org.apache.cxf:bus.id=cxf32436715,type=Bus</canonicalName> <domain>org.apache.cxf</domain> <id>3</id> </MBean> Request: http://localhost:8080/services/jmx/list Response: <MBeans> <MBean href="http://localhost:8080/services/jmx/mbean/5"> <attribute> <busId>cxf32436715</busId> <port>"UserServiceImpl"</port> <service>"{http://server.gsoc.apache.org/}UserServiceImpl"</service> <type>Bus.Service.Endpoint</type> </attribute> <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="UserServiceImpl",service="{http://server.gsoc.apache.org/}UserServiceImpl",type=Bus.Service.Endpoint</canonicalName> <domain>org.apache.cxf</domain> <id>5</id> </MBean> <MBean href="http://localhost:8080/services/jmx/mbean/4"> <attribute> <busId>cxf32436715</busId> <port>"SoapPort"</port> <service>"{http://org.apache.gsoc.server/Greeter_Soap}SOAPService"</service> <type>Bus.Service.Endpoint</type> </attribute> <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="SoapPort",service="{http://org.apache.gsoc.server/Greeter_Soap}SOAPService",type=Bus.Service.Endpoint</canonicalName> <domain>org.apache.cxf</domain> <id>4</id> </MBean> <MBean href="http://localhost:8080/services/jmx/mbean/3"> <attribute> <busId>cxf32436715</busId> <type>Bus</type> </attribute> <canonicalName>org.apache.cxf:bus.id=cxf32436715,type=Bus</canonicalName> <domain>org.apache.cxf</domain> <id>3</id> </MBean> <MBean href="http://localhost:8080/services/jmx/mbean/1"> <attribute> <busId>cxf32436715</busId> <port>"CustomerServiceImpl"</port> <service>"{http://server.gsoc.apache.org/}CustomerServiceImpl"</service> <type>Bus.Service.Endpoint</type> </attribute> <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="CustomerServiceImpl",service="{http://server.gsoc.apache.org/}CustomerServiceImpl",type=Bus.Service.Endpoint</canonicalName> <domain>org.apache.cxf</domain> <id>1</id> </MBean> <MBean href="http://localhost:8080/services/jmx/mbean/6"> <attribute> <type>MBeanServerDelegate</type> </attribute> <canonicalName>JMImplementation:type=MBeanServerDelegate</canonicalName> <domain>JMImplementation</domain> <id>6</id> </MBean> </MBeans> I will clean up my code a little for the next step. Thank you. Regards: Shenglin Qiu > Date: Sat, 21 May 2011 16:37:29 +0100 > Subject: Re: Expose MBeans in CXF > From: sberyoz...@gmail.com > To: dev@cxf.apache.org > > >> Are you saying that you have to use UriInfo and UriBuilder for > >> creating hrefs whenever you need to > >> build an MBean representation ? > >> > > > > After everytime server bounces, I need to at first use this url request: > > http://localhost:8080/services/jmx/, the good thing is, this request only > > need once, > > > > What do you mean it is needed only once ? > > > Then my JMXServer will save the UriInfo and also all the href values in > > MBean are fixed, no further change until another server's bounce. > > > > I don't understand - as I said on IRC JMXServer should expect > endpoints created dynamically > > Cheers, Sergey > > >> Please have UriInfo injected in one of the JMXServer's fields, remove > >> NPE declaration > >> > > Done. > > > > > > I will do a fewer more rounds of testing, and put up the source code again. > > > > > > > > Thank you. > > > > > > Regards: > > Shenglin Qiu > > > > > > > >> Date: Fri, 20 May 2011 11:39:55 +0100 > >> Subject: Re: Expose MBeans in CXF > >> From: sberyoz...@gmail.com > >> To: dabaip...@hotmail.com > >> CC: dev@cxf.apache.org > >> > >> Hi Shenglin > >> > >> I've removed some XML fragments to make it simpler to read... > >> > >> > Here is what I have right now: > >> > > >> > <MBeans> > >> > <MBean href="http://localhost:8080/services/jmx/mbean/0"> > >> > </MBean> > >> > </MBeans> > >> > > >> > >> OK > >> > >> > > >> > And > >> > Request: > >> > http://localhost:8080/services/jmx/mbean/0 > >> > Response: > >> > <MBean href="http://localhost:8080/services/jmx/mbean/0"> > >> > </MBean> > >> > > >> > And so on with others. > >> > >> Very good. > >> > >> > > >> > However, I have to make http://localhost:8080/services/jmx/ at every > >> > time I > >> > am trying to do anything further, because I need to use this following > >> > function to load up all mbeans along with their /mbean/** unique > >> > identifiers, and I think this may not be what you want. Please correct > >> > me on > >> > this. > >> > > >> Are you saying that you have to use UriInfo and UriBuilder for > >> creating hrefs whenever you need to > >> build an MBean representation ? > >> > > > > > > > >> Perhaps, you may want to keep "http://localhost:8080/services/jmx/" > >> parts of hrefs in the map as well, as you suggested on #cxf. This will > >> let you avoid recalculating the base values for those MBeans which > >> have already been retrieved before. These values may not 'survive' the > >> restarts for ex, say a port may've been changed, etc, but I agree it > >> may be worth optimizing. I'm not sure if injecting UriInfo via > >> constructor can provide a way to get to the base address at the > >> JMXServer initialization time - may be worth trying later on... > >> > >> Please don't spend much time on it right now, because it's more > >> important at the moment to try to build a more or less complete > >> solution around exposing JMX mbeans over HTTP. > >> > >> Have a look at it a bit further, and then start focusing on making sure > >> > >> "http://localhost:8080/services/jmx/mbean/0", etc, are handled by > >> MBeanResource subresource, we can keep adding methods for dealing with > >> individual MBeans to JMXServer itself, but having a subresource > >> dealing with such requests may be a bit cleaner... > >> > >> > >> > @GET > >> > public CxfMBeanCollection traversMBeans(@Context UriInfo uriInfo) > >> > throws > >> > MalformedObjectNameException, NullPointerException{ > >> > .... > >> > } > >> > > >> > > >> > >> Please have UriInfo injected in one of the JMXServer's fields, remove > >> NPE declaration > >> > >> Cheers, Sergey > >> > > >> > Thank you. > >> > > >> > Regards: > >> > Shenglin Qiu > >> > > >> > > >> >> Date: Thu, 19 May 2011 17:02:36 +0100 > >> >> Subject: Re: Expose MBeans in CXF > >> >> From: sberyoz...@gmail.com > >> >> To: dev@cxf.apache.org > >> >> > >> >> Every MBean should have a unique id so that we can work with it later > >> >> on individually. > >> >> 0, 1, 2, 3, n, represents the unique part in the otherwise same URI. > >> >> When working with MBeans (when populating MBeans collections, etc) you > >> >> need to associate some unique number with every MBean. Have some local > >> >> AtomicInteger var, have some map there which will keep pairs like > >> >> id: Mbean ref > >> >> > >> >> and generate 'id' dynamically if none already exists in the map for a > >> >> given MBean > >> >> > >> >> may be it should be > >> >> > >> >> Map<String, Integer> > >> >> where String is a canonical name. > >> >> > >> >> So when later on you process something like > >> >> /mbean/234 > >> >> > >> >> you can get 234, use it to find the canonical name (or actual JMX > >> >> MBean reference), and use the latter to init an instance of > >> >> MBeanResource which will deal with the request > >> >> > >> >> Ping me on IRC please if you have any questions > >> >> Cheers, Sergey > >> >> > >> >> On Thu, May 19, 2011 at 4:43 PM, Shenglin Qiu <dabaip...@hotmail.com> > >> >> wrote: > >> >> > > >> >> > Yes, Sergey, > >> >> > > >> >> > Should I manually give/define every mbean an indexer which is > >> >> > accumulated as you mentioned? > >> >> >> > http://localhost:8080/services/jmx/mbean/0 > >> >> >> > http://localhost:8080/services/jmx/mbean/1 > >> >> >> > http://localhost:8080/services/jmx/mbean/2 > >> >> > ... > >> >> >> > http://localhost:8080/services/jmx/mbean/*** > >> >> > Thank you. > >> >> > > >> >> > Regards: > >> >> > Shenglin Qiu > >> >> > > >> >> >> Date: Thu, 19 May 2011 15:03:03 +0100 > >> >> >> Subject: Re: Expose MBeans in CXF > >> >> >> From: sberyoz...@gmail.com > >> >> >> To: dev@cxf.apache.org > >> >> >> > >> >> >> HI Shenglin > >> >> >> > >> >> >> On Thu, May 19, 2011 at 2:54 PM, Shenglin Qiu <dabaip...@hotmail.com> > >> >> >> wrote: > >> >> >> > > >> >> >> > Yes Sergey, will have these following pattern: > >> >> >> > > >> >> >> > http://localhost:8080/services/jmx/mbean/0 -> CXF Bus > >> >> >> > > >> >> >> > http://localhost:8080/services/jmx/mbean/01 -> UserService > >> >> >> > > >> >> >> > http://localhost:8080/services/jmx/mbean/0123 -> CustomerService > >> >> >> > > >> >> >> > http://localhost:8080/services/jmx/mbean/01234 -> GreeterService > >> >> >> > (Soap) > >> >> >> > > >> >> >> > http://localhost:8080/services/jmx/mbean/012 -> JMXServer will be > >> >> >> > hidden to user. > >> >> >> > > >> >> >> > >> >> >> That looks better, but do you think it would make sense to avoid the > >> >> >> concatenation ? > >> >> >> We can get hundreds of CXF MBeans in the production environment, so > >> >> >> IMHO it would be simpler > >> >> >> to have /mbean/199 identifying a particular MBean, > >> >> >> > >> >> >> Cheers, Sergey > >> >> >> > >> >> >> > > >> >> >> > Regards: > >> >> >> > > >> >> >> > Shenglin Qiu > >> >> >> > > >> >> >> > > >> >> >> > > >> >> > > >> >> > >> >> > >> >> > >> >> -- > >> >> Sergey Beryozkin > >> >> > >> >> Application Integration Division of Talend > >> >> http://sberyozkin.blogspot.com > >> > > >> > >> > >> > >> -- > >> Sergey Beryozkin > >> > >> Application Integration Division of Talend > >> http://sberyozkin.blogspot.com > > > > > > -- > Sergey Beryozkin > > Application Integration Division of Talend > http://sberyozkin.blogspot.com