Search in sources :

Example 1 with Type

use of org.glassfish.hk2.external.org.objectweb.asm.Type in project Payara by payara.

the class GetHttpListener method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
    if (!optionalListener.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
        return;
    }
    NetworkListener listener = optionalListener.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", listener.getName()));
    report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
    report.appendMessage(String.format("Port: %s\n", listener.getPort()));
    report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
    report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
    if (verbose) {
        report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
        report.appendMessage(String.format("Type: %s\n", listener.getType()));
        report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
        report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
        report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", listener.getName());
    properties.put("enabled", listener.getEnabled());
    properties.put("port", listener.getPort());
    properties.put("address", listener.getAddress());
    properties.put("protocol", listener.getProtocol());
    properties.put("transport", listener.getTransport());
    properties.put("type", listener.getType());
    properties.put("threadPool", listener.getThreadPool());
    properties.put("jkEnabled", listener.getJkEnabled());
    properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with Type

use of org.glassfish.hk2.external.org.objectweb.asm.Type in project Payara by payara.

the class WeldUtils method getCDIEnablingAnnotations.

/**
 * Get the names of any annotation types that are applied to beans, which should enable CDI
 * processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 *
 * @return An array of annotation type names; The array could be empty if none are found.
 */
public static String[] getCDIEnablingAnnotations(DeploymentContext context) {
    List<String> result = new ArrayList<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at)) {
                        if (!result.contains(at.getName())) {
                            result.add(at.getName());
                        }
                    }
                }
            }
        }
    }
    return result.toArray(new String[result.size()]);
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) ArrayList(java.util.ArrayList) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType)

Example 3 with Type

use of org.glassfish.hk2.external.org.objectweb.asm.Type in project Payara by payara.

the class GlassFishInjectionProvider method getAnnotatedClassesInCurrentModule.

@Override
public Map<String, List<ScannedAnnotation>> getAnnotatedClassesInCurrentModule(ServletContext servletContext) throws InjectionProviderException {
    Map<String, List<ScannedAnnotation>> classesByAnnotation = new HashMap<String, List<ScannedAnnotation>>();
    Collection<Type> allTypes = ((DeploymentContext) servletContext.getAttribute(DEPLOYMENT_CONTEXT_ATTRIBUTE)).getTransientAppMetaData(Types.class.getName(), Types.class).getAllTypes();
    for (Type type : allTypes) {
        for (AnnotationModel annotationModel : type.getAnnotations()) {
            String annotationName = annotationModel.getType().getName();
            List<ScannedAnnotation> classesWithThisAnnotation = classesByAnnotation.get(annotationName);
            if (classesWithThisAnnotation == null) {
                classesWithThisAnnotation = new ArrayList<ScannedAnnotation>();
                classesByAnnotation.put(annotationName, classesWithThisAnnotation);
            }
            ScannedAnnotation toAdd = new ScannedAnnotation() {

                @Override
                public boolean equals(Object obj) {
                    boolean result = false;
                    if (obj instanceof ScannedAnnotation) {
                        String otherName = ((ScannedAnnotation) obj).getFullyQualifiedClassName();
                        if (otherName != null) {
                            result = type.getName().equals(otherName);
                        }
                    }
                    return result;
                }

                @Override
                public int hashCode() {
                    String str = getFullyQualifiedClassName();
                    Collection<URI> obj = getDefiningURIs();
                    int result = str != null ? str.hashCode() : 0;
                    result = 31 * result + (obj != null ? obj.hashCode() : 0);
                    return result;
                }

                @Override
                public String getFullyQualifiedClassName() {
                    return type.getName();
                }

                @Override
                public Collection<URI> getDefiningURIs() {
                    return type.getDefiningURIs();
                }
            };
            if (!classesWithThisAnnotation.contains(toAdd)) {
                classesWithThisAnnotation.add(toAdd);
            }
        }
    }
    return classesByAnnotation;
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) HashMap(java.util.HashMap) URI(java.net.URI) Type(org.glassfish.hk2.classmodel.reflect.Type) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 4 with Type

use of org.glassfish.hk2.external.org.objectweb.asm.Type in project Payara by payara.

the class EjbOptionalIntfGenerator method generateNonAccessibleMethod.

private static void generateNonAccessibleMethod(ClassVisitor cv, java.lang.reflect.Method m) throws Exception {
    String methodName = m.getName();
    Type returnType = Type.getReturnType(m);
    Type[] argTypes = Type.getArgumentTypes(m);
    Method asmMethod = new Method(methodName, returnType, argTypes);
    // Only called for non-static Protected or Package access
    int access = ACC_PUBLIC;
    GeneratorAdapter mg = new GeneratorAdapter(access, asmMethod, null, getExceptionTypes(m), cv);
    mg.throwException(Type.getType(javax.ejb.EJBException.class), "Illegal non-business method access on no-interface view");
    mg.returnValue();
    mg.endMethod();
}
Also used : GeneratorAdapter(org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter) Method(org.glassfish.hk2.external.org.objectweb.asm.commons.Method)

Example 5 with Type

use of org.glassfish.hk2.external.org.objectweb.asm.Type in project Payara by payara.

the class EarHandler method getClassLoader.

public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
    final ReadableArchive archive = context.getSource();
    final ApplicationHolder holder = getApplicationHolder(archive, context, true);
    // the ear classloader hierachy will be
    // ear lib classloader <- embedded rar classloader <-
    // ear classloader <- various module classloaders
    final DelegatingClassLoader embeddedConnCl;
    final EarClassLoader cl;
    // add the libraries packaged in the application library directory
    try {
        String compatProp = context.getAppProps().getProperty(DeploymentProperties.COMPATIBILITY);
        // let's see if it's defined in glassfish-application.xml
        if (compatProp == null) {
            GFApplicationXmlParser gfApplicationXmlParser = new GFApplicationXmlParser(context.getSource());
            compatProp = gfApplicationXmlParser.getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        // let's see if it's defined in sun-application.xml
        if (compatProp == null) {
            SunApplicationXmlParser sunApplicationXmlParser = new SunApplicationXmlParser(context.getSourceDir());
            compatProp = sunApplicationXmlParser.getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        if (System.getSecurityManager() != null) {
            // procee declared permissions
            earDeclaredPC = PermsArchiveDelegate.getDeclaredPermissions(SMGlobalPolicyUtil.CommponentType.ear, context);
            // process ee permissions
            processEEPermissions(context);
        }
        final URL[] earLibURLs = ASClassLoaderUtil.getAppLibDirLibraries(context.getSourceDir(), holder.app.getLibraryDirectory(), compatProp);
        final EarLibClassLoader earLibCl = AccessController.doPrivileged(new PrivilegedAction<EarLibClassLoader>() {

            @Override
            public EarLibClassLoader run() {
                return new EarLibClassLoader(earLibURLs, parent);
            }
        });
        String clDelegate = holder.app.getClassLoadingDelegate();
        // default to true if null
        if (Boolean.parseBoolean(clDelegate == null ? "true" : clDelegate) == false) {
            earLibCl.enableCurrentBeforeParentUnconditional();
        } else if (clDelegate != null) {
            // otherwise clDelegate == true
            earLibCl.disableCurrentBeforeParent();
        }
        if (System.getSecurityManager() != null) {
            addEEOrDeclaredPermissions(earLibCl, earDeclaredPC, false);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("added declaredPermissions to earlib: " + earDeclaredPC);
            addEEOrDeclaredPermissions(earLibCl, eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ear), true);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("added all ee permissions to earlib: " + eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ear));
        }
        embeddedConnCl = AccessController.doPrivileged(new PrivilegedAction<DelegatingClassLoader>() {

            @Override
            public DelegatingClassLoader run() {
                return new DelegatingClassLoader(earLibCl);
            }
        });
        cl = AccessController.doPrivileged(new PrivilegedAction<EarClassLoader>() {

            @Override
            public EarClassLoader run() {
                return new EarClassLoader(embeddedConnCl, holder.app);
            }
        });
        // add ear lib to module classloader list so we can
        // clean it up later
        cl.addModuleClassLoader(EAR_LIB, earLibCl);
        if (System.getSecurityManager() != null) {
            // push declared permissions to ear classloader
            addEEOrDeclaredPermissions(cl, earDeclaredPC, false);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("declaredPermissions added: " + earDeclaredPC);
            // push ejb permissions to ear classloader
            addEEOrDeclaredPermissions(cl, eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ejb), true);
            if (_logger.isLoggable(Level.FINE))
                _logger.fine("ee permissions added: " + eeGarntsMap.get(SMGlobalPolicyUtil.CommponentType.ejb));
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, strings.get("errAddLibs"), e);
        throw new RuntimeException(e);
    }
    for (ModuleDescriptor md : holder.app.getModules()) {
        ReadableArchive sub = null;
        String moduleUri = md.getArchiveUri();
        try {
            sub = archive.getSubArchive(moduleUri);
            if (sub instanceof InputJarArchive) {
                throw new IllegalArgumentException(strings.get("wrongArchType", moduleUri));
            }
        } catch (IOException e) {
            _logger.log(Level.FINE, "Sub archive " + moduleUri + " seems unreadable", e);
        }
        if (sub != null) {
            try {
                ArchiveHandler handler = context.getModuleArchiveHandlers().get(moduleUri);
                if (handler == null) {
                    handler = getArchiveHandlerFromModuleType(md.getModuleType());
                    if (handler == null) {
                        handler = deployment.getArchiveHandler(sub);
                    }
                    context.getModuleArchiveHandlers().put(moduleUri, handler);
                }
                if (handler != null) {
                    ActionReport subReport = context.getActionReport().addSubActionsReport();
                    // todo : this is a hack, once again,
                    // the handler is assuming a file:// url
                    ExtendedDeploymentContext subContext = new DeploymentContextImpl(subReport, sub, context.getCommandParameters(DeployCommandParameters.class), env) {

                        @Override
                        public File getScratchDir(String subDirName) {
                            String modulePortion = Util.getURIName(getSource().getURI());
                            return (new File(super.getScratchDir(subDirName), modulePortion));
                        }
                    };
                    // sub context will store the root archive handler also
                    // so we can figure out the enclosing archive type
                    subContext.setArchiveHandler(context.getArchiveHandler());
                    subContext.setParentContext((ExtendedDeploymentContext) context);
                    sub.setParentArchive(context.getSource());
                    ClassLoader subCl = handler.getClassLoader(cl, subContext);
                    if ((System.getSecurityManager() != null) && (subCl instanceof DDPermissionsLoader)) {
                        addEEOrDeclaredPermissions(subCl, earDeclaredPC, false);
                        if (_logger.isLoggable(Level.FINE))
                            _logger.fine("added declared permissions to sub module of " + subCl);
                    }
                    if (md.getModuleType().equals(DOLUtils.ejbType())) {
                        // for ejb module, we just add the ejb urls
                        // to EarClassLoader and use that to load
                        // ejb module
                        URL[] moduleURLs = ((URLClassLoader) subCl).getURLs();
                        for (URL moduleURL : moduleURLs) {
                            cl.addURL(moduleURL);
                        }
                        cl.addModuleClassLoader(moduleUri, cl);
                        PreDestroy.class.cast(subCl).preDestroy();
                    } else if (md.getModuleType().equals(DOLUtils.rarType())) {
                        embeddedConnCl.addDelegate((DelegatingClassLoader.ClassFinder) subCl);
                        cl.addModuleClassLoader(moduleUri, subCl);
                    } else {
                        Boolean isTempClassLoader = context.getTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.class);
                        if (subCl instanceof URLClassLoader && (isTempClassLoader != null) && isTempClassLoader) {
                            // for temp classloader, we add all the module
                            // urls to the top level EarClassLoader
                            URL[] moduleURLs = ((URLClassLoader) subCl).getURLs();
                            for (URL moduleURL : moduleURLs) {
                                cl.addURL(moduleURL);
                            }
                        }
                        cl.addModuleClassLoader(moduleUri, subCl);
                    }
                }
            } catch (IOException e) {
                _logger.log(Level.SEVERE, strings.get("noClassLoader", moduleUri), e);
            }
        }
    }
    return cl;
}
Also used : AbstractArchiveHandler(com.sun.enterprise.deploy.shared.AbstractArchiveHandler) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URL(java.net.URL) ApplicationHolder(org.glassfish.javaee.core.deployment.ApplicationHolder) PrivilegedAction(java.security.PrivilegedAction) DDPermissionsLoader(com.sun.enterprise.security.integration.DDPermissionsLoader) URLClassLoader(java.net.URLClassLoader) DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) SAXParseException(org.xml.sax.SAXParseException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) URLClassLoader(java.net.URLClassLoader) PreDestroy(org.glassfish.hk2.api.PreDestroy)

Aggregations

ServiceLocator (org.glassfish.hk2.api.ServiceLocator)18 ActionReport (org.glassfish.api.ActionReport)13 MultiException (org.glassfish.hk2.api.MultiException)13 ParameterMap (org.glassfish.api.admin.ParameterMap)12 List (java.util.List)10 Map (java.util.Map)10 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)7 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Sniffer (org.glassfish.api.container.Sniffer)6 CommandRunner (org.glassfish.embeddable.CommandRunner)6 File (java.io.File)5 Types (org.glassfish.hk2.classmodel.reflect.Types)5 PropertyVetoException (java.beans.PropertyVetoException)4 Method (java.lang.reflect.Method)4 Type (java.lang.reflect.Type)4 JsonString (javax.json.JsonString)4 PrivilegedActionException (java.security.PrivilegedActionException)3