Search in sources :

Example 11 with Context

use of org.glassfish.hk2.api.Context in project Payara by payara.

the class AbstractJMSContextManager method cleanup.

// Close and remove the JMSContext instances
@PreDestroy
public synchronized void cleanup() {
    ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
    InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
    ComponentInvocation currentInv = invMgr.getCurrentInvocation();
    for (Entry<String, JMSContextEntry> entry : contexts.entrySet()) {
        JMSContextEntry contextEntry = entry.getValue();
        String ipId = contextEntry.getInjectionPointId();
        JMSContext context = contextEntry.getCtx();
        if (context != null) {
            ComponentInvocation inv = contextEntry.getComponentInvocation();
            if (inv != null && currentInv != inv)
                invMgr.preInvoke(inv);
            try {
                context.close();
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, localStrings.getLocalString("JMSContext.impl.close", "Closed JMSContext instance associated with id {0}: {1}.", ipId, context.toString()));
                }
            } catch (Exception e) {
                logger.log(Level.SEVERE, localStrings.getLocalString("JMSContext.impl.close.failure", "Failed to close JMSContext instance associated with id {0}: {1}.", ipId, context.toString()), e);
            } finally {
                if (inv != null && currentInv != inv)
                    invMgr.postInvoke(inv);
            }
        }
    }
    contexts.clear();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JMSContext(javax.jms.JMSContext) PreDestroy(javax.annotation.PreDestroy)

Example 12 with Context

use of org.glassfish.hk2.api.Context in project Payara by payara.

the class AbstractJMSContextManager method getContext.

public synchronized JMSContext getContext(String ipId, String id, JMSContextMetadata metadata, ConnectionFactory connectionFactory) {
    JMSContextEntry contextEntry = contexts.get(id);
    JMSContext context = null;
    if (contextEntry == null) {
        context = createContext(ipId, metadata, connectionFactory);
        ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
        InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
        contexts.put(id, new JMSContextEntry(ipId, context, invMgr.getCurrentInvocation()));
    } else {
        context = contextEntry.getCtx();
    }
    return context;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) InvocationManager(org.glassfish.api.invocation.InvocationManager) JMSContext(javax.jms.JMSContext)

Example 13 with Context

use of org.glassfish.hk2.api.Context in project Payara by payara.

the class GetMonitoringConfiguration method execute.

/**
 * Method that is invoked when the asadmin command is performed.
 *  Pretty prints the Monitoring Service Configuration values.
 * @param context
 */
@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config name: " + targetUtil);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport actionReport = context.getActionReport();
    ActionReport notifiersReport = actionReport.addSubActionsReport();
    ActionReport attributeReport = actionReport.addSubActionsReport();
    ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
    MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
    actionReport.appendMessage(StringUtils.EOL);
    Map<String, Object> map = new HashMap<>();
    Properties extraProps = new Properties();
    map.put("enabled", monitoringConfig.getEnabled());
    map.put("amx", monitoringConfig.getAmx());
    map.put("logfrequency", monitoringConfig.getLogFrequency());
    map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
    extraProps.put("jmxmonitoringConfiguration", map);
    List<Map<String, String>> monitoredAttributes = new ArrayList<>();
    for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
        Object[] values = new Object[3];
        values[0] = monitoredBean.getObjectName();
        values[1] = monitoredBean.getAttributeName();
        values[2] = monitoredBean.getDescription();
        Map<String, String> monitoredAttribute = new HashMap<>();
        monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
        monitoredAttributes.add(monitoredAttribute);
        attributeColumnFormatter.addRow(values);
    }
    // Cannot change key in line below - required for admingui propertyDescTable.inc
    extraProps.put("monitored-beans", monitoredAttributes);
    actionReport.setExtraProperties(extraProps);
    if (!monitoringConfig.getNotifierList().isEmpty()) {
        List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {

            @Override
            public Class<Notifier> apply(Notifier input) {
                return resolveNotifierClass(input);
            }
        });
        Properties notifierProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
            Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
            if (notifier != null) {
                ConfigView view = ConfigSupport.getImpl(notifier);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierClassList.contains(view.<Notifier>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = annotation.type();
                    values[1] = notifier.getEnabled();
                    notifiersColumnFormatter.addRow(values);
                    Map<String, Object> mapNotifiers = new HashMap<>(2);
                    mapNotifiers.put("notifierName", values[0]);
                    mapNotifiers.put("notifierEnabled", values[1]);
                    notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
                }
            }
            actionReport.getExtraProperties().putAll(notifierProps);
        }
    }
    notifiersReport.setMessage(notifiersColumnFormatter.toString());
    notifiersReport.appendMessage(StringUtils.EOL);
    attributeReport.setMessage(attributeColumnFormatter.toString());
    attributeReport.appendMessage(StringUtils.EOL);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) Notifier(fish.payara.nucleus.notification.configuration.Notifier) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Context

use of org.glassfish.hk2.api.Context in project Payara by payara.

the class ConnectionManager method getSecureConnection.

/**
 * creates a connection to the loadbalancer
 * @param contextRoot context root that will be used in constructing the URL
 * @throws java.io.IOException
 * @return HTTPS connection to the load balancer.
 */
private HttpsURLConnection getSecureConnection(String contextRoot) throws IOException {
    if (_lbHost == null || _lbPort == null) {
        String msg = LbLogUtil.getStringManager().getString("LbDeviceNotConfigured", _lbName);
        throw new IOException(msg);
    }
    HttpsURLConnection conn = null;
    URL url = null;
    try {
        // ---------------------------------
        // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }

            @Override
            public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }
        } };
        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance(TLS);
        ServiceLocator habitat = Globals.getDefaultHabitat();
        SSLUtils sslUtils = habitat.getService(SSLUtils.class);
        sc.init(sslUtils.getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
        // ---------------------------------
        url = new URL(HTTPS_PROTOCOL, _lbHost, Integer.parseInt(_lbPort), contextRoot);
        if (_lbProxyHost != null && _lbProxyPort != null) {
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(_lbProxyHost, Integer.parseInt(_lbProxyPort)));
            conn = (HttpsURLConnection) url.openConnection(proxy);
        } else {
            conn = (HttpsURLConnection) url.openConnection();
        }
        conn.setSSLSocketFactory(sc.getSocketFactory());
        HostnameVerifier hnv = new SSLHostNameVerifier();
        conn.setDefaultHostnameVerifier(hnv);
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
    return conn;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) SSLContext(javax.net.ssl.SSLContext) URL(java.net.URL) IOException(java.io.IOException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Proxy(java.net.Proxy) X509TrustManager(javax.net.ssl.X509TrustManager) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SSLUtils(com.sun.enterprise.security.ssl.SSLUtils)

Example 15 with Context

use of org.glassfish.hk2.api.Context in project Payara by payara.

the class ACCModulesManager method initialize.

public static synchronized void initialize(final ClassLoader loader) throws URISyntaxException {
    /*
         * The habitat might have been initialized earlier.  Currently
         * we use a single habitat for the JVM.  
         */
    if (habitat == null) {
        habitat = prepareHabitat(loader);
        /*
             * Set up the default habitat in Globals as soon as we know
             * which habitat we'll use.
             */
        Globals.setDefaultHabitat(habitat);
        ServiceLocator locator = habitat;
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
        /*
             * Remove any already-loaded startup context so we can replace it
             * with the ACC one.
             */
        config.addUnbindFilter(BuilderHelper.createContractFilter(StartupContext.class.getName()));
        /*
             * Following the example from AppServerStartup, remove any
             * pre-loaded lazy inhabitant for ProcessEnvironment that exists
             * from HK2's scan for services.  Then add in
             * an ACC ProcessEnvironment.
             */
        config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));
        config.commit();
        config = dcs.createDynamicConfiguration();
        StartupContext startupContext = new ACCStartupContext();
        AbstractActiveDescriptor<?> startupContextDescriptor = BuilderHelper.createConstantDescriptor(startupContext);
        startupContextDescriptor.addContractType(StartupContext.class);
        config.addActiveDescriptor(startupContextDescriptor);
        ModulesRegistry modulesRegistry = new StaticModulesRegistry(ACCModulesManager.class.getClassLoader());
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(modulesRegistry));
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));
        /*
             * Create the ClientNamingConfigurator used by naming.
             */
        ClientNamingConfigurator cnc = new ClientNamingConfiguratorImpl();
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(cnc));
        Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
        AbstractActiveDescriptor<Logger> di = BuilderHelper.createConstantDescriptor(logger);
        di.addContractType(Logger.class);
        config.addActiveDescriptor(di);
        config.commit();
    }
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) Logger(java.util.logging.Logger) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment) ClientNamingConfigurator(org.glassfish.api.naming.ClientNamingConfigurator) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ClientNamingConfiguratorImpl(com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry)

Aggregations

ActionReport (org.glassfish.api.ActionReport)12 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 IOException (java.io.IOException)11 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)7 MultiException (org.glassfish.hk2.api.MultiException)7 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)7 Config (com.sun.enterprise.config.serverbeans.Config)6 PropertyVetoException (java.beans.PropertyVetoException)6 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)6 Types (org.glassfish.hk2.classmodel.reflect.Types)6 RetryableException (org.jvnet.hk2.config.RetryableException)6 Logger (java.util.logging.Logger)5 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)5 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)4 ServletContext (javax.servlet.ServletContext)4 TargetType (org.glassfish.config.support.TargetType)4 Notifier (fish.payara.nucleus.notification.configuration.Notifier)3 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)3 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)3