Package org.apache.muse.core.platform.osgi.mini.internal

Source Code of org.apache.muse.core.platform.osgi.mini.internal.ResourceManagementAdminServiceImpl

/*=============================================================================*
*  Copyright 2006 The Apache Software Foundation
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*=============================================================================*/


package org.apache.muse.core.platform.osgi.mini.internal;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.apache.muse.core.platform.osgi.ResourceManagementProvider;
import org.apache.muse.osgi.soa.core.web.ServletDescriptor;
import org.apache.muse.osgi.soa.core.web.WebApp;
import org.apache.muse.osgi.soa.core.web.WebAppDescriptor;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;

/**
*
* ResourceManagementAdminServiceImpl administers the interaction between the OSGi-hosted
* Muse Axis2 environment and an OSGi service that provides the actual Axis2 runtime environment
*
* @see ResourceManagementProvider
* @see ResourceManagementAdminService
* @author Joel Hawkins (joelh)
*
*/
public class ResourceManagementAdminServiceImpl implements ResourceManagementProvider {

  public static final String DEFAULT_CONTEXT = "management";

  private BundleContext context;
  private Bundle bundle; 
  private ServiceReference provider;
 
  private Map contextToWebAppMap = new HashMap();

  public ResourceManagementAdminServiceImpl(BundleContext context, ServiceReference provider){
    this.context = context;
    this.provider = provider;
  }


  public void deployManagementService(Bundle bundle, String homeName, String wsdlPath) throws Exception {
    deployManagementService(bundle, DEFAULT_CONTEXT, homeName);
  }
 
 
  private WebAppDescriptor getWebAppDescriptor(String context, boolean requiresHttps) {
    WebAppDescriptor wad = new WebAppDescriptor();

    OSGiMinServlet servlet = new OSGiMinServlet();

    wad.servlet = new ServletDescriptor[1];
    if (context.startsWith("/"))
      wad.context = context;
    else
      wad.context = "/" + context;
    wad.servlet[0] = new ServletDescriptor("/services", servlet);
    return wad;
  }
 
 
  private WebApp getWebApp(Bundle bundle, String contextPath, boolean create){

    WebApp webApp = (WebApp) contextToWebAppMap.get(contextPath);
    if (webApp == null && create) {
      try {
        String secureString = (String)bundle.getHeaders().get("SOA-HTTPS-REQUIRED");
        boolean requiresHttps = false;
        if("true".equals(secureString)) requiresHttps = true;
        webApp = new WebApp(getWebAppDescriptor(contextPath, requiresHttps));
        webApp.start(context);
        contextToWebAppMap.put(contextPath, webApp);
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
    return webApp;
  }


  private WebApp getWebApp(String contextPath, boolean create){
    return getWebApp(context.getBundle(),contextPath,create);
  }
 


  public void deployManagementService(Bundle bundle, String contextPath, String srvName, String wsdlPath) throws Exception {
    WebApp webApp = null;
    if (contextPath != null) {
      try {
        webApp = getWebApp(bundle, contextPath, true);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
}
TOP

Related Classes of org.apache.muse.core.platform.osgi.mini.internal.ResourceManagementAdminServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.