001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.management.mbean; 018 019import java.util.List; 020import javax.management.openmbean.CompositeData; 021import javax.management.openmbean.CompositeDataSupport; 022import javax.management.openmbean.CompositeType; 023import javax.management.openmbean.TabularData; 024import javax.management.openmbean.TabularDataSupport; 025 026import org.apache.camel.CamelContext; 027import org.apache.camel.api.management.ManagedResource; 028import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes; 029import org.apache.camel.api.management.mbean.ManagedRestRegistryMBean; 030import org.apache.camel.spi.RestRegistry; 031import org.apache.camel.util.ObjectHelper; 032 033/** 034 * 035 */ 036@ManagedResource(description = "Managed RestRegistry") 037public class ManagedRestRegistry extends ManagedService implements ManagedRestRegistryMBean { 038 039 private final RestRegistry registry; 040 041 public ManagedRestRegistry(CamelContext context, RestRegistry registry) { 042 super(context, registry); 043 this.registry = registry; 044 } 045 046 public RestRegistry getRegistry() { 047 return registry; 048 } 049 050 @Override 051 public int getNumberOfRestServices() { 052 return registry.size(); 053 } 054 055 @Override 056 public TabularData listRestServices() { 057 try { 058 TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listRestServicesTabularType()); 059 List<RestRegistry.RestService> services = registry.listAllRestServices(); 060 for (RestRegistry.RestService entry : services) { 061 CompositeType ct = CamelOpenMBeanTypes.listRestServicesCompositeType(); 062 String url = entry.getUrl(); 063 String baseUrl = entry.getBaseUrl(); 064 String basePath = entry.getBasePath(); 065 String uriTemplate = entry.getUriTemplate(); 066 String method = entry.getMethod(); 067 String consumes = entry.getConsumes(); 068 String produces = entry.getProduces(); 069 String state = entry.getState(); 070 String inType = entry.getInType(); 071 String outType = entry.getOutType(); 072 String routeId = entry.getRouteId(); 073 String description = entry.getDescription(); 074 075 CompositeData data = new CompositeDataSupport(ct, new String[] 076 {"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state", "routeId", "description"}, 077 new Object[]{url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, state, routeId, description}); 078 answer.put(data); 079 } 080 return answer; 081 } catch (Exception e) { 082 throw ObjectHelper.wrapRuntimeCamelException(e); 083 } 084 } 085}