All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.veithen.visualwas.env.EnvUtil Maven / Gradle / Ivy

/*
 * #%L
 * VisualWAS
 * %%
 * Copyright (C) 2013 - 2018 Andreas Veithen
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */
package com.github.veithen.visualwas.env;

import java.net.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.management.remote.JMXConnectorFactory;

import com.github.veithen.visualwas.client.config.ConfigClientFeature;
import com.github.veithen.visualwas.client.jsr77.JSR77ClientFeature;
import com.github.veithen.visualwas.client.pmi.PmiClientFeature;
import com.github.veithen.visualwas.client.repository.RepositoryClientFeature;
import com.github.veithen.visualwas.connector.feature.Feature;
import com.github.veithen.visualwas.connector.federation.DisableFederationFeature;
import com.github.veithen.visualwas.jmx.soap.SOAPJMXConnector;
import com.github.veithen.visualwas.trust.TrustStore;

public final class EnvUtil {
    private EnvUtil() {}
    
    public static Map createEnvironment(boolean securityEnabled, boolean federationDisabled) {
        Map env = new HashMap();
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, SOAPJMXConnector.class.getClassLoader());
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "com.github.veithen.visualwas.jmx");
        // In VisualVM, one typically configures the HTTP proxy to download new plugins and updates,
        // i.e. to connect to the Internet. SOAP connections to WebSphere should not pass through that proxy.
        env.put(SOAPJMXConnector.PROXY, Proxy.NO_PROXY);
        if (securityEnabled) {
            env.put(SOAPJMXConnector.TRUST_MANAGER, TrustStore.getInstance().createTrustManager());
        }
        WebSphereClassLoaderProvider classLoaderProvider = WebSphereClassLoaderProvider.getInstance();
        env.put(SOAPJMXConnector.CLASS_LOADER_PROVIDER, classLoaderProvider);
        List features = new ArrayList<>();
        if (federationDisabled) {
            features.add(DisableFederationFeature.INSTANCE);
        }
        features.addAll(Arrays.asList(
                ConfigClientFeature.INSTANCE,
                JSR77ClientFeature.INSTANCE,
                PmiClientFeature.INSTANCE,
                RepositoryClientFeature.INSTANCE));
        env.put(SOAPJMXConnector.FEATURES, features.toArray(new Feature[features.size()]));
        return env;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy