Search in sources :

Example 31 with Context

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

the class TransactionLifecycleService method postConstruct.

@Override
public void postConstruct() {
    EventListener glassfishEventListener = new EventListener() {

        @Override
        public void event(Event event) {
            if (event.is(EventTypes.SERVER_READY)) {
                _logger.fine("TM LIFECYCLE SERVICE - ON READY");
                onReady();
            } else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
                _logger.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
                onShutdown();
            }
        }
    };
    events.register(glassfishEventListener);
    if (nm != null) {
        try {
            nm.publishObject(USER_TX_NO_JAVA_COMP, new NamingObjectProxy.InitializationNamingObjectProxy() {

                @Override
                public Object create(Context ic) throws NamingException {
                    ActiveDescriptor<?> descriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("javax.transaction.UserTransaction"));
                    if (descriptor == null)
                        return null;
                    return habitat.getServiceHandle(descriptor).getService();
                }
            }, false);
        } catch (NamingException e) {
            _logger.warning("Can't bind \"UserTransaction\" in JNDI");
        }
    }
}
Also used : Context(javax.naming.Context) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) NamingException(javax.naming.NamingException) EventListener(org.glassfish.api.event.EventListener)

Example 32 with Context

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

the class WeldFacesConfigProvider method getResources.

@Override
public Collection<URI> getResources(ServletContext context) {
    ServiceLocator defaultServices = (ServiceLocator) context.getAttribute(HABITAT_ATTRIBUTE);
    invokeMgr = defaultServices.getService(InvocationManager.class);
    ComponentInvocation inv = invokeMgr.getCurrentInvocation();
    WebModule webModule = (WebModule) inv.getContainer();
    WebBundleDescriptor wdesc = webModule.getWebBundleDescriptor();
    List<URI> list = new ArrayList<URI>(1);
    if (!wdesc.hasExtensionProperty(WeldDeployer.WELD_EXTENSION)) {
        return list;
    }
    // Don't use Util.getCurrentLoader().  This config resource should
    // be available from the same classloader that loaded this instance.
    // Doing so allows us to be more OSGi friendly.
    ClassLoader loader = this.getClass().getClassLoader();
    URL resource = loader.getResource(SERVICES_FACES_CONFIG);
    if (resource != null) {
        try {
            list.add(resource.toURI());
        } catch (URISyntaxException ex) {
            if (logger.isLoggable(Level.SEVERE)) {
                logger.log(Level.SEVERE, CDILoggerInfo.SEVERE_ERROR_CREATING_URI_FOR_FACES_CONFIG_XML, new Object[] { resource.toExternalForm(), ex });
            }
        }
    }
    return list;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ArrayList(java.util.ArrayList) WebModule(com.sun.enterprise.web.WebModule) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

Example 33 with Context

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

the class DolProvider method processDeploymentMetaData.

/**
 * This method populates the Application object from a ReadableArchive
 * @param archive the archive for the application
 */
public Application processDeploymentMetaData(ReadableArchive archive) throws Exception {
    FileArchive expandedArchive = null;
    File tmpFile = null;
    ExtendedDeploymentContext context = null;
    Logger logger = Logger.getAnonymousLogger();
    ClassLoader cl = null;
    try {
        String archiveName = Util.getURIName(archive.getURI());
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        if (archiveHandler == null) {
            throw new IllegalArgumentException(localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", archiveName));
        }
        DeployCommandParameters parameters = new DeployCommandParameters(new File(archive.getURI()));
        ActionReport report = new HTMLActionReporter();
        context = new DeploymentContextImpl(report, archive, parameters, env);
        context.setArchiveHandler(archiveHandler);
        String appName = archiveHandler.getDefaultApplicationName(archive, context);
        parameters.name = appName;
        if (archive instanceof InputJarArchive) {
            // we need to expand the archive first in this case
            tmpFile = File.createTempFile(archiveName, "");
            String path = tmpFile.getAbsolutePath();
            if (!tmpFile.delete()) {
                logger.log(Level.WARNING, "cannot.delete.temp.file", new Object[] { path });
            }
            File tmpDir = new File(path);
            tmpDir.deleteOnExit();
            if (!tmpDir.exists() && !tmpDir.mkdirs()) {
                throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());
            }
            expandedArchive = (FileArchive) archiveFactory.createArchive(tmpDir);
            archiveHandler.expand(archive, expandedArchive, context);
            context.setSource(expandedArchive);
        }
        context.setPhase(DeploymentContextImpl.Phase.PREPARE);
        ClassLoaderHierarchy clh = clhProvider.get();
        context.createDeploymentClassLoader(clh, archiveHandler);
        cl = context.getClassLoader();
        deployment.getDeployableTypes(context);
        deployment.getSniffers(archiveHandler, null, context);
        return processDOL(context);
    } finally {
        if (cl != null && cl instanceof PreDestroy) {
            try {
                PreDestroy.class.cast(cl).preDestroy();
            } catch (Exception e) {
            // ignore
            }
        }
        if (context != null) {
            context.postDeployClean(true);
        }
        if (expandedArchive != null) {
            try {
                expandedArchive.close();
            } catch (Exception e) {
            // ignore
            }
        }
        if (tmpFile != null && tmpFile.exists()) {
            try {
                FileUtils.whack(tmpFile);
            } catch (Exception e) {
            // ignore
            }
        }
    }
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) IOException(java.io.IOException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Logger(java.util.logging.Logger) ActionReport(org.glassfish.api.ActionReport) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) PreDestroy(org.glassfish.hk2.api.PreDestroy) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) File(java.io.File)

Example 34 with Context

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

the class GetNotificationConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport mainActionReport = context.getActionReport();
    final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
    NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    String[] headers = { "Enabled", "Notifier Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    if (configuration.getNotifierConfigurationList().isEmpty()) {
        mainActionReport.setMessage("No notifier defined");
    } else {
        List<Class<NotifierConfiguration>> notifierConfigurationClassList = Lists.transform(configuration.getNotifierConfigurationList(), new Function<NotifierConfiguration, Class<NotifierConfiguration>>() {

            @Override
            public Class<NotifierConfiguration> apply(NotifierConfiguration input) {
                return resolveNotifierConfigurationClass(input);
            }
        });
        Properties extraProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allServiceHandles) {
            NotifierConfiguration notifierConfiguration = configuration.getNotifierConfigurationByType(serviceHandle.getService().getNotifierConfigType());
            if (notifierConfiguration != null) {
                ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierConfigurationClassList.contains(view.<NotifierConfiguration>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = notificationServiceConfiguration.getEnabled();
                    values[1] = notifierConfiguration.getEnabled();
                    columnFormatter.addRow(values);
                    Map<String, Object> map;
                    if (NotifierType.LOG.equals(annotation.type())) {
                        map = new HashMap<>(3);
                        map.put("enabled", values[0]);
                        map.put("notifierEnabled", values[1]);
                        LogNotifierConfiguration logNotifierConfiguration = (LogNotifierConfiguration) notifierConfiguration;
                        map.put("useSeparateLogFile", logNotifierConfiguration.getUseSeparateLogFile());
                    } else {
                        map = new HashMap<>(2);
                        map.put("enabled", values[0]);
                        map.put("notifierEnabled", values[1]);
                    }
                    extraProps.put("getNotificationConfiguration" + annotation.type(), map);
                }
            }
        }
        mainActionReport.setExtraProperties(extraProps);
        mainActionReport.setMessage(columnFormatter.toString());
    }
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) NotifierConfiguration(fish.payara.nucleus.notification.configuration.NotifierConfiguration) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) NotificationServiceConfiguration(fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 35 with Context

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

the class NotifierServiceLister method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    if (allServiceHandles.isEmpty()) {
        report.appendMessage(strings.getLocalString("notifier.list.services.warning", "No registered notifier service found."));
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
    } else {
        StringBuffer sb = new StringBuffer();
        sb.append(strings.getLocalString("notifier.list.services.availability.info", "Available Notifier Services") + ":\n");
        Properties extrasProps = new Properties();
        ArrayList<String> names = new ArrayList<String>();
        for (ServiceHandle serviceHandle : allServiceHandles) {
            sb.append("\t" + serviceHandle.getActiveDescriptor().getName() + "\n");
            names.add(serviceHandle.getActiveDescriptor().getName());
        }
        extrasProps.put("avaliableServices", names);
        report.setMessage(sb.toString());
        report.setExtraProperties(extrasProps);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    }
}
Also used : ServiceHandle(org.glassfish.hk2.api.ServiceHandle) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

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