Hi Shenglin Thanks for this update. I'd like to clarify why I suggested adding ServerLifeCycleManager listener. The only reason is for JMXServer to be able to keep an internal uptodate list of existing CXF endpoints which are currently being managed.
Please check the comments I made in the other (main) thread about it. Lets focus right now on only GETing the representations of: 1. All CXF MBeans representing all the CXF endpoints 2. CXF service-specific MBeans I believe you've nearly implemented 1. In order to implement 2, we need to know the list of existing CXF services (not MBeans) and JMXServer needs to return this list (getListOfManagedServices or similar). Next, JMXServer has to be able to return service-scoped MBeans (see 2.), it should have a resource method accepting the service expanded qname ({http://bar}service or similar) and return a collection of MBeans relevant to this particular service only (Service, its Endpoints as well as the bus - the bus is not necessarily endpoint specific - but is relevant). So whenever your ServerLifeCycleManager listener gets an event it updates the (concurrent/thread-safe) list accordingly. The question is how to get this list (task 2.) initialized with the list of service qnames which have already been created, by the time JMXServer is being created itself. Looks like you need to get a ServerRegistry extension from the bus and get a list of existing Servers (and Services) from it. Please see more comments inline On Thu, May 5, 2011 at 4:04 AM, Shenglin Qiu <dabaip...@hotmail.com> wrote: > Hi Sergey: > > As you mentioned last time, I am trying to have this > ServerLifeCycleManager.class into > > private ServerLifeCycleManager lifeCycleManager; > > public void setInstrumentationManager(InstrumentationManagerImpl > instrumentationManager) { > this.instrumentationManager = instrumentationManager; > lifeCycleManager = > instrumentationManager.getBus().getExtension(ServerLifeCycleManager.class); > lifeCycleManager.registerListener(new ServerLifeCycleListener() { > public void startServer(Server server) { > String address = > server.getEndpoint().getEndpointInfo().getAddress(); > } > public void stopServer(Server server) { > String address = > server.getEndpoint().getEndpointInfo().getAddress(); > } > }); > } > > @GET > @POST > @Path("start") > public CxfMBeanCollection start(){ > lifeCycleManager.startServer(server); > > return ?; > } > > @GET > @POST > @Path("stop") > public CxfMBeanCollection stop(){ > lifeCycleManager.startServer(server); > > return ?; > } > > > I am stuck at getting a server instance in start() and stop(); Here is my > applicationContext.xml, I think if applicationContext is loaded, then all > Jax-Ws and Jax-Rs are started by default, then up in start() function will > have duplicated starting issue. I am thinking, should I use non-spring > approach, and create JAXRSServerFactoryBean -> create endpoint -> start > server in plain java code at first? JMXServer should not deal with starting/stopping CXF endpoints - at least not at the initial stage, at the moment its main 'responsibility' is to show all relevant MBeans and also access properties of individual MBeans, and may be modify some of the properties, when possible. > Either way, I will spend some time more reading jax-rs-frontend-* module. > > <!-- JAX-WS Service Endpoint --> > <jaxws:endpoint id="personService" implementor="#personServ" > address="/PersonService"> > <jaxws:inInterceptors> > <bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" > /> > <bean > class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> > <constructor-arg> > <map> > <entry key="action" value="UsernameToken" /> > <entry key="passwordType" value="PasswordText" /> > <entry key="passwordCallbackClass" > value="org.apache.cxf.gsoc.ws.auth.ServerPasswordCallback" /> > </map> > </constructor-arg> > </bean> > </jaxws:inInterceptors> > </jaxws:endpoint> > > <!-- JAX-RS Server 1 --> > <jaxrs:server id="userServiceRs" address="/jaxrs1"> > <jaxrs:serviceBeans> > <ref bean="userService" /> > </jaxrs:serviceBeans> > </jaxrs:server> > > <!-- JAX-RS Server 2 --> > <jaxrs:server id="customerServiceRs" address="/jaxrs2"> > <jaxrs:serviceBeans> > <ref bean="customerService" /> > </jaxrs:serviceBeans> > </jaxrs:server> > OK, we have 3 application endpoints, one JAX-WS, and JAX-RS endpoints > <!-- CXF3388: Expose JMXServer --> > <jaxrs:server id="jmxServerRs" address="/jaxserver"> > <jaxrs:serviceBeans> > <ref bean="jmxServer" /> > </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> > OK > <!-- This jmxServer should be exposed to jax-rs which should be > separated from other service endpoints --> > <bean id="jmxServer" > class="org.apache.cxf.gsoc.management.web.JMXServer"> > <property name="managedJaxRsEndpoints"> > <list> > <ref bean="userServiceRs"/> > <ref bean="customerServiceRs"/> > </list> > </property> > <property name="managedJaxWsEndpoints"> > <list> > <ref bean="personService"/> > </list> > </property> > <property name="instrumentationManager" > ref="instrumentationManager"/> > </bean> > Right now, we probably do not need "managedJaxRsEndpoints" and "managedJaxWsEndpoints" properties - only if we decide at the later stage to return the list of MBeans specific to JAX-RS or JAX-WS endpoints only then we will use them. That may be a good idea, but at the moment please focus on using bus extensions only for building up the list of endpoints. > <bean id="userService" > class="org.apache.cxf.gsoc.ws.service.impl.UserServiceImpl" /> > <bean id="customerService" > class="org.apache.cxf.gsoc.ws.service.impl.CustomerServiceImpl" /> > > > PS. I saw I a lot check-in at late night, you guys are really working on cxf > so hard, my previous web service projects are all 2.3.0, I think I should > all migrate the dependencies to 2.4. > Sure. Please finish the work to do with retrieving the list of all and endpoint specific MBeans and then migrate To summarize: - Have only InstrumentationManager injected in JMXServer - Use the bus to get ServiceRegistry in order to initialize a list of existing managed endpoints - Register ServerLifeCycleManager Listener for the list to be kept uptodate - Have your server returning the list of all CXFMbeans, the list of QNames representing managed services/endpoints and service specific CXF MBeans One you finish this task then we will move on to other ones... Ping me on #cxf please if you have any questions Thanks, Sergey > > Regards: > Shenglin Qiu > -- Sergey Beryozkin Application Integration Division of Talend http://sberyozkin.blogspot.com