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.activemq.web.config; 018 019import org.osgi.framework.BundleContext; 020import org.osgi.framework.Constants; 021import org.osgi.framework.FrameworkUtil; 022import org.osgi.framework.ServiceRegistration; 023import org.osgi.service.cm.ConfigurationException; 024import org.osgi.service.cm.ManagedService; 025 026import javax.jms.ConnectionFactory; 027import javax.management.remote.JMXServiceURL; 028import java.util.Collection; 029import java.util.Dictionary; 030import java.util.Hashtable; 031 032public class OsgiConfiguration extends AbstractConfiguration implements ManagedService { 033 034 private ServiceRegistration service; 035 036 private String jmxUrl = "service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root"; 037 private String jmxUser = "karaf"; 038 private String jmxPassword = "karaf"; 039 040 private String jmsUrl = "tcp://localhost:61616"; 041 private String jmsUser = "karaf"; 042 private String jmsPassword = "karaf"; 043 044 public OsgiConfiguration() { 045 046 BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); 047 Dictionary properties = new Hashtable(); 048 properties.put(Constants.SERVICE_PID, "org.apache.activemq.webconsole"); 049 service = context.registerService(ManagedService.class.getName(), 050 this, properties); 051 052 } 053 054 @Override 055 public String getJmxPassword() { 056 return jmxPassword; 057 } 058 059 @Override 060 public Collection<JMXServiceURL> getJmxUrls() { 061 return makeJmxUrls(jmxUrl); 062 } 063 064 @Override 065 public String getJmxUser() { 066 return jmxUser; 067 } 068 069 @Override 070 public ConnectionFactory getConnectionFactory() { 071 return makeConnectionFactory(jmsUrl, jmsUser, jmsPassword); 072 } 073 074 @Override 075 public void updated(Dictionary dictionary) throws ConfigurationException { 076 if (dictionary != null) { 077 jmxUrl = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_URL); 078 if (jmxUrl == null) { 079 throw new IllegalArgumentException("A JMS-url must be specified (system property " + SystemPropertiesConfiguration.PROPERTY_JMX_URL); 080 } 081 jmxUser = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_USER); 082 jmxPassword = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_PASSWORD); 083 jmsUrl = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_URL); 084 jmsUser = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_USER); 085 jmsPassword = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_PASSWORD); 086 } 087 } 088}