Search in sources :

Example 1 with DescriptionGroupMetaData

use of org.jboss.metadata.javaee.spec.DescriptionGroupMetaData in project wildfly by wildfly.

the class UndertowDeploymentInfoService method createTldInfo.

private static TagLibraryInfo createTldInfo(final String location, final TldMetaData tldMetaData, final HashMap<String, TagLibraryInfo> ret) throws ClassNotFoundException {
    String relativeLocation = location;
    String jarPath = null;
    if (relativeLocation != null && relativeLocation.startsWith("/WEB-INF/lib/")) {
        int pos = relativeLocation.indexOf('/', "/WEB-INF/lib/".length());
        if (pos > 0) {
            jarPath = relativeLocation.substring(pos);
            if (jarPath.startsWith("/")) {
                jarPath = jarPath.substring(1);
            }
            relativeLocation = relativeLocation.substring(0, pos);
        }
    }
    TagLibraryInfo tagLibraryInfo = new TagLibraryInfo();
    tagLibraryInfo.setTlibversion(tldMetaData.getTlibVersion());
    if (tldMetaData.getJspVersion() == null) {
        tagLibraryInfo.setJspversion(tldMetaData.getVersion());
    } else {
        tagLibraryInfo.setJspversion(tldMetaData.getJspVersion());
    }
    tagLibraryInfo.setShortname(tldMetaData.getShortName());
    tagLibraryInfo.setUri(tldMetaData.getUri());
    if (tldMetaData.getDescriptionGroup() != null) {
        tagLibraryInfo.setInfo(tldMetaData.getDescriptionGroup().getDescription());
    }
    // Validator
    if (tldMetaData.getValidator() != null) {
        TagLibraryValidatorInfo tagLibraryValidatorInfo = new TagLibraryValidatorInfo();
        tagLibraryValidatorInfo.setValidatorClass(tldMetaData.getValidator().getValidatorClass());
        if (tldMetaData.getValidator().getInitParams() != null) {
            for (ParamValueMetaData paramValueMetaData : tldMetaData.getValidator().getInitParams()) {
                tagLibraryValidatorInfo.addInitParam(paramValueMetaData.getParamName(), paramValueMetaData.getParamValue());
            }
        }
        tagLibraryInfo.setValidator(tagLibraryValidatorInfo);
    }
    // Tag
    if (tldMetaData.getTags() != null) {
        for (TagMetaData tagMetaData : tldMetaData.getTags()) {
            TagInfo tagInfo = new TagInfo();
            tagInfo.setTagName(tagMetaData.getName());
            tagInfo.setTagClassName(tagMetaData.getTagClass());
            tagInfo.setTagExtraInfo(tagMetaData.getTeiClass());
            if (tagMetaData.getBodyContent() != null) {
                tagInfo.setBodyContent(tagMetaData.getBodyContent().toString());
            }
            tagInfo.setDynamicAttributes(tagMetaData.getDynamicAttributes());
            // Description group
            if (tagMetaData.getDescriptionGroup() != null) {
                DescriptionGroupMetaData descriptionGroup = tagMetaData.getDescriptionGroup();
                if (descriptionGroup.getIcons() != null && descriptionGroup.getIcons().value() != null && (descriptionGroup.getIcons().value().length > 0)) {
                    Icon icon = descriptionGroup.getIcons().value()[0];
                    tagInfo.setLargeIcon(icon.largeIcon());
                    tagInfo.setSmallIcon(icon.smallIcon());
                }
                tagInfo.setInfoString(descriptionGroup.getDescription());
                tagInfo.setDisplayName(descriptionGroup.getDisplayName());
            }
            // Variable
            if (tagMetaData.getVariables() != null) {
                for (VariableMetaData variableMetaData : tagMetaData.getVariables()) {
                    TagVariableInfo tagVariableInfo = new TagVariableInfo();
                    tagVariableInfo.setNameGiven(variableMetaData.getNameGiven());
                    tagVariableInfo.setNameFromAttribute(variableMetaData.getNameFromAttribute());
                    tagVariableInfo.setClassName(variableMetaData.getVariableClass());
                    tagVariableInfo.setDeclare(variableMetaData.getDeclare());
                    if (variableMetaData.getScope() != null) {
                        tagVariableInfo.setScope(variableMetaData.getScope().toString());
                    }
                    tagInfo.addTagVariableInfo(tagVariableInfo);
                }
            }
            // Attribute
            if (tagMetaData.getAttributes() != null) {
                for (AttributeMetaData attributeMetaData : tagMetaData.getAttributes()) {
                    TagAttributeInfo tagAttributeInfo = new TagAttributeInfo();
                    tagAttributeInfo.setName(attributeMetaData.getName());
                    tagAttributeInfo.setType(attributeMetaData.getType());
                    tagAttributeInfo.setReqTime(attributeMetaData.getRtexprvalue());
                    tagAttributeInfo.setRequired(attributeMetaData.getRequired());
                    tagAttributeInfo.setFragment(attributeMetaData.getFragment());
                    if (attributeMetaData.getDeferredValue() != null) {
                        tagAttributeInfo.setDeferredValue("true");
                        tagAttributeInfo.setExpectedTypeName(attributeMetaData.getDeferredValue().getType());
                    } else {
                        tagAttributeInfo.setDeferredValue("false");
                    }
                    if (attributeMetaData.getDeferredMethod() != null) {
                        tagAttributeInfo.setDeferredMethod("true");
                        tagAttributeInfo.setMethodSignature(attributeMetaData.getDeferredMethod().getMethodSignature());
                    } else {
                        tagAttributeInfo.setDeferredMethod("false");
                    }
                    tagInfo.addTagAttributeInfo(tagAttributeInfo);
                }
            }
            tagLibraryInfo.addTagInfo(tagInfo);
        }
    }
    // Tag files
    if (tldMetaData.getTagFiles() != null) {
        for (TagFileMetaData tagFileMetaData : tldMetaData.getTagFiles()) {
            TagFileInfo tagFileInfo = new TagFileInfo();
            tagFileInfo.setName(tagFileMetaData.getName());
            tagFileInfo.setPath(tagFileMetaData.getPath());
            tagLibraryInfo.addTagFileInfo(tagFileInfo);
        }
    }
    // Function
    if (tldMetaData.getFunctions() != null) {
        for (FunctionMetaData functionMetaData : tldMetaData.getFunctions()) {
            FunctionInfo functionInfo = new FunctionInfo();
            functionInfo.setName(functionMetaData.getName());
            functionInfo.setFunctionClass(functionMetaData.getFunctionClass());
            functionInfo.setFunctionSignature(functionMetaData.getFunctionSignature());
            tagLibraryInfo.addFunctionInfo(functionInfo);
        }
    }
    if (jarPath == null && relativeLocation == null) {
        if (!ret.containsKey(tagLibraryInfo.getUri())) {
            ret.put(tagLibraryInfo.getUri(), tagLibraryInfo);
        }
    } else if (jarPath == null) {
        tagLibraryInfo.setLocation("");
        tagLibraryInfo.setPath(relativeLocation);
        if (!ret.containsKey(tagLibraryInfo.getUri())) {
            ret.put(tagLibraryInfo.getUri(), tagLibraryInfo);
        }
        ret.put(relativeLocation, tagLibraryInfo);
    } else {
        tagLibraryInfo.setLocation(relativeLocation);
        tagLibraryInfo.setPath(jarPath);
        if (!ret.containsKey(tagLibraryInfo.getUri())) {
            ret.put(tagLibraryInfo.getUri(), tagLibraryInfo);
        }
        if (jarPath.equals("META-INF/taglib.tld")) {
            ret.put(relativeLocation, tagLibraryInfo);
        }
    }
    return tagLibraryInfo;
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) FunctionMetaData(org.jboss.metadata.web.spec.FunctionMetaData) TagFileInfo(org.apache.jasper.deploy.TagFileInfo) AttributeMetaData(org.jboss.metadata.web.spec.AttributeMetaData) TagLibraryValidatorInfo(org.apache.jasper.deploy.TagLibraryValidatorInfo) TagAttributeInfo(org.apache.jasper.deploy.TagAttributeInfo) TagMetaData(org.jboss.metadata.web.spec.TagMetaData) TagVariableInfo(org.apache.jasper.deploy.TagVariableInfo) FunctionInfo(org.apache.jasper.deploy.FunctionInfo) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) TagFileMetaData(org.jboss.metadata.web.spec.TagFileMetaData) TagInfo(org.apache.jasper.deploy.TagInfo) Icon(org.jboss.annotation.javaee.Icon) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData) TagLibraryInfo(org.apache.jasper.deploy.TagLibraryInfo) VariableMetaData(org.jboss.metadata.web.spec.VariableMetaData)

Example 2 with DescriptionGroupMetaData

use of org.jboss.metadata.javaee.spec.DescriptionGroupMetaData in project wildfly by wildfly.

the class OpenAPIModelServiceConfigurator method get.

@Override
public OpenAPI get() {
    OpenApiConfig config = new OpenApiConfigImpl(this.config);
    IndexView indexView = new FilteredIndexView(this.index, config);
    OpenAPIDocumentBuilder builder = new OpenAPIDocumentBuilder();
    builder.config(config);
    Map.Entry<VirtualFile, Format> entry = findStaticFile(this.root);
    if (entry != null) {
        VirtualFile file = entry.getKey();
        Format format = entry.getValue();
        try (OpenApiStaticFile staticFile = new OpenApiStaticFile(file.openStream(), format)) {
            builder.staticFileModel(OpenApiProcessor.modelFromStaticFile(staticFile));
        } catch (IOException e) {
            throw MicroProfileOpenAPILogger.LOGGER.failedToLoadStaticFile(e, file.getPathNameRelativeTo(this.root), this.deploymentName);
        }
    }
    builder.annotationsModel(OpenApiProcessor.modelFromAnnotations(config, AnnotationScanner.class.getClassLoader(), indexView));
    builder.readerModel(OpenApiProcessor.modelFromReader(config, this.module.getClassLoader()));
    builder.filter(OpenApiProcessor.getFilter(config, this.module.getClassLoader()));
    OpenAPI model = builder.build();
    // Generate default title and description based on web metadata
    DescriptionGroupMetaData descriptionMetaData = this.metaData.getDescriptionGroup();
    String displayName = (descriptionMetaData != null) ? descriptionMetaData.getDisplayName() : null;
    String title = (displayName != null) ? displayName : this.deploymentName;
    String description = (descriptionMetaData != null) ? descriptionMetaData.getDescription() : null;
    Info info = model.getInfo();
    // Override SmallRye's default title
    if (info.getTitle().equals(DEFAULT_TITLE)) {
        info.setTitle(title);
    }
    if (info.getDescription() == null) {
        info.setDescription(description);
    }
    Host host = this.host.get();
    List<UndertowListener> listeners = host.getServer().getListeners();
    if (model.getServers() == null) {
        // Generate Server entries if none exist
        String contextPath = this.info.get().getContextPath();
        if (this.config.getOptionalValue(RELATIVE_SERVER_URLS, Boolean.class).orElse(Boolean.TRUE).booleanValue()) {
            model.setServers(Collections.singletonList(OASFactory.createServer().url(contextPath)));
        } else {
            int aliases = host.getAllAliases().size();
            int size = 0;
            for (UndertowListener listener : listeners) {
                size += aliases + listener.getSocketBinding().getClientMappings().size();
            }
            List<Server> servers = new ArrayList<>(size);
            for (UndertowListener listener : listeners) {
                SocketBinding binding = listener.getSocketBinding();
                Set<String> virtualHosts = new TreeSet<>(host.getAllAliases());
                // The name of the host is not a real virtual host (e.g. default-host)
                virtualHosts.remove(host.getName());
                InetAddress address = binding.getAddress();
                // Omit wildcard addresses
                if (!address.isAnyLocalAddress()) {
                    virtualHosts.add(address.getCanonicalHostName());
                }
                for (String virtualHost : virtualHosts) {
                    Server server = createServer(listener.getProtocol(), virtualHost, binding.getPort(), contextPath);
                    if (server != null) {
                        servers.add(server);
                    }
                }
                for (ClientMapping mapping : binding.getClientMappings()) {
                    Server server = createServer(listener.getProtocol(), mapping.getDestinationAddress(), mapping.getDestinationPort(), contextPath);
                    if (server != null) {
                        servers.add(server);
                    }
                }
            }
            model.setServers(servers);
        }
    }
    if (listeners.stream().map(UndertowListener::getProtocol).noneMatch(REQUISITE_LISTENERS::contains)) {
        LOGGER.requiredListenersNotFound(host.getServer().getName(), REQUISITE_LISTENERS);
    }
    return model;
}
Also used : FilteredIndexView(io.smallrye.openapi.runtime.scanner.FilteredIndexView) VirtualFile(org.jboss.vfs.VirtualFile) SocketBinding(org.jboss.as.network.SocketBinding) Server(org.eclipse.microprofile.openapi.models.servers.Server) ArrayList(java.util.ArrayList) Format(io.smallrye.openapi.runtime.io.Format) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) TreeSet(java.util.TreeSet) FilteredIndexView(io.smallrye.openapi.runtime.scanner.FilteredIndexView) IndexView(org.jboss.jandex.IndexView) OpenApiStaticFile(io.smallrye.openapi.runtime.OpenApiStaticFile) Host(org.wildfly.extension.undertow.Host) IOException(java.io.IOException) Info(org.eclipse.microprofile.openapi.models.info.Info) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) OpenApiConfigImpl(io.smallrye.openapi.api.OpenApiConfigImpl) ClientMapping(org.jboss.as.network.ClientMapping) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData) Map(java.util.Map) EnumMap(java.util.EnumMap) AbstractMap(java.util.AbstractMap) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) InetAddress(java.net.InetAddress) UndertowListener(org.wildfly.extension.undertow.UndertowListener)

Example 3 with DescriptionGroupMetaData

use of org.jboss.metadata.javaee.spec.DescriptionGroupMetaData in project wildfly by wildfly.

the class WarAnnotationDeploymentProcessor method getDescriptionGroup.

protected DescriptionGroupMetaData getDescriptionGroup(String description) {
    DescriptionGroupMetaData dg = null;
    if (description.length() > 0) {
        dg = new DescriptionGroupMetaData();
        Descriptions descriptions = getDescription(description);
        dg.setDescriptions(descriptions);
    }
    return dg;
}
Also used : Descriptions(org.jboss.annotation.javaee.Descriptions) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData)

Example 4 with DescriptionGroupMetaData

use of org.jboss.metadata.javaee.spec.DescriptionGroupMetaData in project wildfly by wildfly.

the class WarAnnotationDeploymentProcessor method processAnnotations.

/**
 * Process a single index.
 *
 * @param index the annotation index
 *
 * @throws DeploymentUnitProcessingException
 */
protected WebMetaData processAnnotations(Index index) throws DeploymentUnitProcessingException {
    WebMetaData metaData = new WebMetaData();
    // @WebServlet
    final List<AnnotationInstance> webServletAnnotations = index.getAnnotations(webServlet);
    if (webServletAnnotations != null && !webServletAnnotations.isEmpty()) {
        ServletsMetaData servlets = new ServletsMetaData();
        List<ServletMappingMetaData> servletMappings = new ArrayList<ServletMappingMetaData>();
        for (final AnnotationInstance annotation : webServletAnnotations) {
            ServletMetaData servlet = new ServletMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebServletAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            servlet.setServletClass(classInfo.toString());
            AnnotationValue nameValue = annotation.value("name");
            if (nameValue == null || nameValue.asString().isEmpty()) {
                servlet.setName(classInfo.toString());
            } else {
                servlet.setName(nameValue.asString());
            }
            AnnotationValue loadOnStartup = annotation.value("loadOnStartup");
            if (loadOnStartup != null && loadOnStartup.asInt() >= 0) {
                servlet.setLoadOnStartupInt(loadOnStartup.asInt());
            }
            AnnotationValue asyncSupported = annotation.value("asyncSupported");
            if (asyncSupported != null) {
                servlet.setAsyncSupported(asyncSupported.asBoolean());
            }
            AnnotationValue initParamsValue = annotation.value("initParams");
            if (initParamsValue != null) {
                AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
                if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
                    List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
                    for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
                        ParamValueMetaData initParam = new ParamValueMetaData();
                        AnnotationValue initParamName = initParamsAnnotation.value("name");
                        AnnotationValue initParamValue = initParamsAnnotation.value();
                        if (initParamName == null || initParamValue == null) {
                            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
                        }
                        AnnotationValue initParamDescription = initParamsAnnotation.value("description");
                        initParam.setParamName(initParamName.asString());
                        initParam.setParamValue(initParamValue.asString());
                        if (initParamDescription != null) {
                            Descriptions descriptions = getDescription(initParamDescription.asString());
                            if (descriptions != null) {
                                initParam.setDescriptions(descriptions);
                            }
                        }
                        initParams.add(initParam);
                    }
                    servlet.setInitParam(initParams);
                }
            }
            AnnotationValue descriptionValue = annotation.value("description");
            AnnotationValue displayNameValue = annotation.value("displayName");
            AnnotationValue smallIconValue = annotation.value("smallIcon");
            AnnotationValue largeIconValue = annotation.value("largeIcon");
            DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
            if (descriptionGroup != null) {
                servlet.setDescriptionGroup(descriptionGroup);
            }
            ServletMappingMetaData servletMapping = new ServletMappingMetaData();
            servletMapping.setServletName(servlet.getName());
            List<String> urlPatterns = new ArrayList<String>();
            AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            urlPatternsValue = annotation.value();
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            if (!urlPatterns.isEmpty()) {
                servletMapping.setUrlPatterns(urlPatterns);
                servletMappings.add(servletMapping);
            }
            servlets.add(servlet);
        }
        metaData.setServlets(servlets);
        metaData.setServletMappings(servletMappings);
    }
    // @WebFilter
    final List<AnnotationInstance> webFilterAnnotations = index.getAnnotations(webFilter);
    if (webFilterAnnotations != null && !webFilterAnnotations.isEmpty()) {
        FiltersMetaData filters = new FiltersMetaData();
        List<FilterMappingMetaData> filterMappings = new ArrayList<FilterMappingMetaData>();
        for (final AnnotationInstance annotation : webFilterAnnotations) {
            FilterMetaData filter = new FilterMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFilterAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            filter.setFilterClass(classInfo.toString());
            AnnotationValue nameValue = annotation.value("filterName");
            if (nameValue == null || nameValue.asString().isEmpty()) {
                filter.setName(classInfo.toString());
            } else {
                filter.setName(nameValue.asString());
            }
            AnnotationValue asyncSupported = annotation.value("asyncSupported");
            if (asyncSupported != null) {
                filter.setAsyncSupported(asyncSupported.asBoolean());
            }
            AnnotationValue initParamsValue = annotation.value("initParams");
            if (initParamsValue != null) {
                AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
                if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
                    List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
                    for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
                        ParamValueMetaData initParam = new ParamValueMetaData();
                        AnnotationValue initParamName = initParamsAnnotation.value("name");
                        AnnotationValue initParamValue = initParamsAnnotation.value();
                        if (initParamName == null || initParamValue == null) {
                            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
                        }
                        AnnotationValue initParamDescription = initParamsAnnotation.value("description");
                        initParam.setParamName(initParamName.asString());
                        initParam.setParamValue(initParamValue.asString());
                        if (initParamDescription != null) {
                            Descriptions descriptions = getDescription(initParamDescription.asString());
                            if (descriptions != null) {
                                initParam.setDescriptions(descriptions);
                            }
                        }
                        initParams.add(initParam);
                    }
                    filter.setInitParam(initParams);
                }
            }
            AnnotationValue descriptionValue = annotation.value("description");
            AnnotationValue displayNameValue = annotation.value("displayName");
            AnnotationValue smallIconValue = annotation.value("smallIcon");
            AnnotationValue largeIconValue = annotation.value("largeIcon");
            DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
            if (descriptionGroup != null) {
                filter.setDescriptionGroup(descriptionGroup);
            }
            filters.add(filter);
            FilterMappingMetaData filterMapping = new FilterMappingMetaData();
            filterMapping.setFilterName(filter.getName());
            List<String> urlPatterns = new ArrayList<String>();
            List<String> servletNames = new ArrayList<String>();
            List<DispatcherType> dispatchers = new ArrayList<DispatcherType>();
            AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            urlPatternsValue = annotation.value();
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            if (!urlPatterns.isEmpty()) {
                filterMapping.setUrlPatterns(urlPatterns);
            }
            AnnotationValue servletNamesValue = annotation.value("servletNames");
            if (servletNamesValue != null) {
                for (String servletName : servletNamesValue.asStringArray()) {
                    servletNames.add(servletName);
                }
            }
            if (!servletNames.isEmpty()) {
                filterMapping.setServletNames(servletNames);
            }
            AnnotationValue dispatcherTypesValue = annotation.value("dispatcherTypes");
            if (dispatcherTypesValue != null) {
                for (String dispatcherValue : dispatcherTypesValue.asEnumArray()) {
                    dispatchers.add(DispatcherType.valueOf(dispatcherValue));
                }
            }
            if (!dispatchers.isEmpty()) {
                filterMapping.setDispatchers(dispatchers);
            }
            if (!urlPatterns.isEmpty() || !servletNames.isEmpty()) {
                filterMappings.add(filterMapping);
            }
        }
        metaData.setFilters(filters);
        metaData.setFilterMappings(filterMappings);
    }
    // @WebListener
    final List<AnnotationInstance> webListenerAnnotations = index.getAnnotations(webListener);
    if (webListenerAnnotations != null && !webListenerAnnotations.isEmpty()) {
        List<ListenerMetaData> listeners = new ArrayList<ListenerMetaData>();
        for (final AnnotationInstance annotation : webListenerAnnotations) {
            ListenerMetaData listener = new ListenerMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebListenerAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            listener.setListenerClass(classInfo.toString());
            AnnotationValue descriptionValue = annotation.value();
            if (descriptionValue != null) {
                DescriptionGroupMetaData descriptionGroup = getDescriptionGroup(descriptionValue.asString());
                if (descriptionGroup != null) {
                    listener.setDescriptionGroup(descriptionGroup);
                }
            }
            listeners.add(listener);
        }
        metaData.setListeners(listeners);
    }
    // @RunAs
    final List<AnnotationInstance> runAsAnnotations = index.getAnnotations(runAs);
    if (runAsAnnotations != null && !runAsAnnotations.isEmpty()) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : runAsAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                continue;
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            if (annotation.value() == null) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidRunAsAnnotation(target));
            }
            RunAsMetaData runAs = new RunAsMetaData();
            runAs.setRoleName(annotation.value().asString());
            annotationMD.setRunAs(runAs);
        }
    }
    // @DeclareRoles
    final List<AnnotationInstance> declareRolesAnnotations = index.getAnnotations(declareRoles);
    if (declareRolesAnnotations != null && !declareRolesAnnotations.isEmpty()) {
        SecurityRolesMetaData securityRoles = metaData.getSecurityRoles();
        if (securityRoles == null) {
            securityRoles = new SecurityRolesMetaData();
            metaData.setSecurityRoles(securityRoles);
        }
        for (final AnnotationInstance annotation : declareRolesAnnotations) {
            if (annotation.value() == null) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidDeclareRolesAnnotation(annotation.target()));
            }
            for (String role : annotation.value().asStringArray()) {
                SecurityRoleMetaData sr = new SecurityRoleMetaData();
                sr.setRoleName(role);
                securityRoles.add(sr);
            }
        }
    }
    // @MultipartConfig
    final List<AnnotationInstance> multipartConfigAnnotations = index.getAnnotations(multipartConfig);
    if (multipartConfigAnnotations != null && !multipartConfigAnnotations.isEmpty()) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : multipartConfigAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidMultipartConfigAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            MultipartConfigMetaData multipartConfig = new MultipartConfigMetaData();
            AnnotationValue locationValue = annotation.value("location");
            if (locationValue != null && locationValue.asString().length() > 0) {
                multipartConfig.setLocation(locationValue.asString());
            }
            AnnotationValue maxFileSizeValue = annotation.value("maxFileSize");
            if (maxFileSizeValue != null && maxFileSizeValue.asLong() != -1L) {
                multipartConfig.setMaxFileSize(maxFileSizeValue.asLong());
            }
            AnnotationValue maxRequestSizeValue = annotation.value("maxRequestSize");
            if (maxRequestSizeValue != null && maxRequestSizeValue.asLong() != -1L) {
                multipartConfig.setMaxRequestSize(maxRequestSizeValue.asLong());
            }
            AnnotationValue fileSizeThresholdValue = annotation.value("fileSizeThreshold");
            if (fileSizeThresholdValue != null && fileSizeThresholdValue.asInt() != 0) {
                multipartConfig.setFileSizeThreshold(fileSizeThresholdValue.asInt());
            }
            annotationMD.setMultipartConfig(multipartConfig);
        }
    }
    // @ServletSecurity
    final List<AnnotationInstance> servletSecurityAnnotations = index.getAnnotations(servletSecurity);
    if (servletSecurityAnnotations != null && !servletSecurityAnnotations.isEmpty()) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : servletSecurityAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidServletSecurityAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            ServletSecurityMetaData servletSecurity = new ServletSecurityMetaData();
            AnnotationValue httpConstraintValue = annotation.value();
            List<String> rolesAllowed = new ArrayList<String>();
            if (httpConstraintValue != null) {
                AnnotationInstance httpConstraint = httpConstraintValue.asNested();
                AnnotationValue httpConstraintERSValue = httpConstraint.value();
                if (httpConstraintERSValue != null) {
                    servletSecurity.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpConstraintERSValue.asEnum()));
                }
                AnnotationValue httpConstraintTGValue = httpConstraint.value("transportGuarantee");
                if (httpConstraintTGValue != null) {
                    servletSecurity.setTransportGuarantee(TransportGuaranteeType.valueOf(httpConstraintTGValue.asEnum()));
                }
                AnnotationValue rolesAllowedValue = httpConstraint.value("rolesAllowed");
                if (rolesAllowedValue != null) {
                    for (String role : rolesAllowedValue.asStringArray()) {
                        rolesAllowed.add(role);
                    }
                }
            }
            servletSecurity.setRolesAllowed(rolesAllowed);
            AnnotationValue httpMethodConstraintsValue = annotation.value("httpMethodConstraints");
            if (httpMethodConstraintsValue != null) {
                AnnotationInstance[] httpMethodConstraints = httpMethodConstraintsValue.asNestedArray();
                if (httpMethodConstraints.length > 0) {
                    List<HttpMethodConstraintMetaData> methodConstraints = new ArrayList<HttpMethodConstraintMetaData>();
                    for (AnnotationInstance httpMethodConstraint : httpMethodConstraints) {
                        HttpMethodConstraintMetaData methodConstraint = new HttpMethodConstraintMetaData();
                        AnnotationValue httpMethodConstraintValue = httpMethodConstraint.value();
                        if (httpMethodConstraintValue != null) {
                            methodConstraint.setMethod(httpMethodConstraintValue.asString());
                        }
                        AnnotationValue httpMethodConstraintERSValue = httpMethodConstraint.value("emptyRoleSemantic");
                        if (httpMethodConstraintERSValue != null) {
                            methodConstraint.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpMethodConstraintERSValue.asEnum()));
                        }
                        AnnotationValue httpMethodConstraintTGValue = httpMethodConstraint.value("transportGuarantee");
                        if (httpMethodConstraintTGValue != null) {
                            methodConstraint.setTransportGuarantee(TransportGuaranteeType.valueOf(httpMethodConstraintTGValue.asEnum()));
                        }
                        AnnotationValue rolesAllowedValue = httpMethodConstraint.value("rolesAllowed");
                        rolesAllowed = new ArrayList<String>();
                        if (rolesAllowedValue != null) {
                            for (String role : rolesAllowedValue.asStringArray()) {
                                rolesAllowed.add(role);
                            }
                        }
                        methodConstraint.setRolesAllowed(rolesAllowed);
                        methodConstraints.add(methodConstraint);
                    }
                    servletSecurity.setHttpMethodConstraints(methodConstraints);
                }
            }
            annotationMD.setServletSecurity(servletSecurity);
        }
    }
    return metaData;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) SecurityRoleMetaData(org.jboss.metadata.javaee.spec.SecurityRoleMetaData) ArrayList(java.util.ArrayList) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) ServletSecurityMetaData(org.jboss.metadata.web.spec.ServletSecurityMetaData) Descriptions(org.jboss.annotation.javaee.Descriptions) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) MultipartConfigMetaData(org.jboss.metadata.web.spec.MultipartConfigMetaData) ServletMetaData(org.jboss.metadata.web.spec.ServletMetaData) DispatcherType(org.jboss.metadata.web.spec.DispatcherType) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData) AnnotationTarget(org.jboss.jandex.AnnotationTarget) ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) RunAsMetaData(org.jboss.metadata.javaee.spec.RunAsMetaData) HttpMethodConstraintMetaData(org.jboss.metadata.web.spec.HttpMethodConstraintMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) ServletMappingMetaData(org.jboss.metadata.web.spec.ServletMappingMetaData) ServletsMetaData(org.jboss.metadata.web.spec.ServletsMetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData) AnnotationsMetaData(org.jboss.metadata.web.spec.AnnotationsMetaData) AnnotationMetaData(org.jboss.metadata.web.spec.AnnotationMetaData) WebMetaData(org.jboss.metadata.web.spec.WebMetaData) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 5 with DescriptionGroupMetaData

use of org.jboss.metadata.javaee.spec.DescriptionGroupMetaData in project wildfly by wildfly.

the class UndertowDeploymentProcessor method createTldInfo.

private static TagLibraryInfo createTldInfo(final String location, final TldMetaData tldMetaData, final HashMap<String, TagLibraryInfo> ret) {
    String relativeLocation = location;
    String jarPath = null;
    if (relativeLocation != null && relativeLocation.startsWith("/WEB-INF/lib/")) {
        int pos = relativeLocation.indexOf('/', "/WEB-INF/lib/".length());
        if (pos > 0) {
            jarPath = relativeLocation.substring(pos);
            if (jarPath.startsWith("/")) {
                jarPath = jarPath.substring(1);
            }
            relativeLocation = relativeLocation.substring(0, pos);
        }
    }
    TagLibraryInfo tagLibraryInfo = new TagLibraryInfo();
    if (tldMetaData.getListeners() != null) {
        for (ListenerMetaData l : tldMetaData.getListeners()) {
            tagLibraryInfo.addListener(l.getListenerClass());
        }
    }
    tagLibraryInfo.setTlibversion(tldMetaData.getTlibVersion());
    if (tldMetaData.getJspVersion() == null) {
        tagLibraryInfo.setJspversion(tldMetaData.getVersion());
    } else {
        tagLibraryInfo.setJspversion(tldMetaData.getJspVersion());
    }
    tagLibraryInfo.setShortname(tldMetaData.getShortName());
    tagLibraryInfo.setUri(tldMetaData.getUri());
    if (tldMetaData.getDescriptionGroup() != null) {
        tagLibraryInfo.setInfo(tldMetaData.getDescriptionGroup().getDescription());
    }
    // Validator
    if (tldMetaData.getValidator() != null) {
        TagLibraryValidatorInfo tagLibraryValidatorInfo = new TagLibraryValidatorInfo();
        tagLibraryValidatorInfo.setValidatorClass(tldMetaData.getValidator().getValidatorClass());
        if (tldMetaData.getValidator().getInitParams() != null) {
            for (ParamValueMetaData paramValueMetaData : tldMetaData.getValidator().getInitParams()) {
                tagLibraryValidatorInfo.addInitParam(paramValueMetaData.getParamName(), paramValueMetaData.getParamValue());
            }
        }
        tagLibraryInfo.setValidator(tagLibraryValidatorInfo);
    }
    // Tag
    if (tldMetaData.getTags() != null) {
        for (TagMetaData tagMetaData : tldMetaData.getTags()) {
            TagInfo tagInfo = new TagInfo();
            tagInfo.setTagName(tagMetaData.getName());
            tagInfo.setTagClassName(tagMetaData.getTagClass());
            tagInfo.setTagExtraInfo(tagMetaData.getTeiClass());
            if (tagMetaData.getBodyContent() != null) {
                tagInfo.setBodyContent(tagMetaData.getBodyContent().toString());
            }
            tagInfo.setDynamicAttributes(tagMetaData.getDynamicAttributes());
            // Description group
            if (tagMetaData.getDescriptionGroup() != null) {
                DescriptionGroupMetaData descriptionGroup = tagMetaData.getDescriptionGroup();
                if (descriptionGroup.getIcons() != null && descriptionGroup.getIcons().value() != null && (descriptionGroup.getIcons().value().length > 0)) {
                    Icon icon = descriptionGroup.getIcons().value()[0];
                    tagInfo.setLargeIcon(icon.largeIcon());
                    tagInfo.setSmallIcon(icon.smallIcon());
                }
                tagInfo.setInfoString(descriptionGroup.getDescription());
                tagInfo.setDisplayName(descriptionGroup.getDisplayName());
            }
            // Variable
            if (tagMetaData.getVariables() != null) {
                for (VariableMetaData variableMetaData : tagMetaData.getVariables()) {
                    TagVariableInfo tagVariableInfo = new TagVariableInfo();
                    tagVariableInfo.setNameGiven(variableMetaData.getNameGiven());
                    tagVariableInfo.setNameFromAttribute(variableMetaData.getNameFromAttribute());
                    tagVariableInfo.setClassName(variableMetaData.getVariableClass());
                    tagVariableInfo.setDeclare(variableMetaData.getDeclare());
                    if (variableMetaData.getScope() != null) {
                        tagVariableInfo.setScope(variableMetaData.getScope().toString());
                    }
                    tagInfo.addTagVariableInfo(tagVariableInfo);
                }
            }
            // Attribute
            if (tagMetaData.getAttributes() != null) {
                for (AttributeMetaData attributeMetaData : tagMetaData.getAttributes()) {
                    TagAttributeInfo tagAttributeInfo = new TagAttributeInfo();
                    tagAttributeInfo.setName(attributeMetaData.getName());
                    tagAttributeInfo.setType(attributeMetaData.getType());
                    tagAttributeInfo.setReqTime(attributeMetaData.getRtexprvalue());
                    tagAttributeInfo.setRequired(attributeMetaData.getRequired());
                    tagAttributeInfo.setFragment(attributeMetaData.getFragment());
                    if (attributeMetaData.getDeferredValue() != null) {
                        tagAttributeInfo.setDeferredValue("true");
                        tagAttributeInfo.setExpectedTypeName(attributeMetaData.getDeferredValue().getType());
                    } else {
                        tagAttributeInfo.setDeferredValue("false");
                    }
                    if (attributeMetaData.getDeferredMethod() != null) {
                        tagAttributeInfo.setDeferredMethod("true");
                        tagAttributeInfo.setMethodSignature(attributeMetaData.getDeferredMethod().getMethodSignature());
                    } else {
                        tagAttributeInfo.setDeferredMethod("false");
                    }
                    tagInfo.addTagAttributeInfo(tagAttributeInfo);
                }
            }
            tagLibraryInfo.addTagInfo(tagInfo);
        }
    }
    // Tag files
    if (tldMetaData.getTagFiles() != null) {
        for (TagFileMetaData tagFileMetaData : tldMetaData.getTagFiles()) {
            TagFileInfo tagFileInfo = new TagFileInfo();
            tagFileInfo.setName(tagFileMetaData.getName());
            tagFileInfo.setPath(tagFileMetaData.getPath());
            tagLibraryInfo.addTagFileInfo(tagFileInfo);
        }
    }
    // Function
    if (tldMetaData.getFunctions() != null) {
        for (FunctionMetaData functionMetaData : tldMetaData.getFunctions()) {
            FunctionInfo functionInfo = new FunctionInfo();
            functionInfo.setName(functionMetaData.getName());
            functionInfo.setFunctionClass(functionMetaData.getFunctionClass());
            functionInfo.setFunctionSignature(functionMetaData.getFunctionSignature());
            tagLibraryInfo.addFunctionInfo(functionInfo);
        }
    }
    if (jarPath == null && relativeLocation == null) {
        if (!ret.containsKey(tagLibraryInfo.getUri())) {
            ret.put(tagLibraryInfo.getUri(), tagLibraryInfo);
        }
    } else if (jarPath == null) {
        tagLibraryInfo.setLocation("");
        tagLibraryInfo.setPath(relativeLocation);
        if (!ret.containsKey(tagLibraryInfo.getUri())) {
            ret.put(tagLibraryInfo.getUri(), tagLibraryInfo);
        }
        ret.put(relativeLocation, tagLibraryInfo);
    } else {
        tagLibraryInfo.setLocation(relativeLocation);
        tagLibraryInfo.setPath(jarPath);
        if (!ret.containsKey(tagLibraryInfo.getUri())) {
            ret.put(tagLibraryInfo.getUri(), tagLibraryInfo);
        }
        if (jarPath.equals("META-INF/taglib.tld")) {
            ret.put(relativeLocation, tagLibraryInfo);
        }
    }
    return tagLibraryInfo;
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) FunctionMetaData(org.jboss.metadata.web.spec.FunctionMetaData) TagFileInfo(org.apache.jasper.deploy.TagFileInfo) AttributeMetaData(org.jboss.metadata.web.spec.AttributeMetaData) TagLibraryValidatorInfo(org.apache.jasper.deploy.TagLibraryValidatorInfo) TagAttributeInfo(org.apache.jasper.deploy.TagAttributeInfo) TagMetaData(org.jboss.metadata.web.spec.TagMetaData) TagVariableInfo(org.apache.jasper.deploy.TagVariableInfo) FunctionInfo(org.apache.jasper.deploy.FunctionInfo) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) TagFileMetaData(org.jboss.metadata.web.spec.TagFileMetaData) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) TagInfo(org.apache.jasper.deploy.TagInfo) Icon(org.jboss.annotation.javaee.Icon) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData) TagLibraryInfo(org.apache.jasper.deploy.TagLibraryInfo) VariableMetaData(org.jboss.metadata.web.spec.VariableMetaData)

Aggregations

DescriptionGroupMetaData (org.jboss.metadata.javaee.spec.DescriptionGroupMetaData)5 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)3 ArrayList (java.util.ArrayList)2 FunctionInfo (org.apache.jasper.deploy.FunctionInfo)2 TagAttributeInfo (org.apache.jasper.deploy.TagAttributeInfo)2 TagFileInfo (org.apache.jasper.deploy.TagFileInfo)2 TagInfo (org.apache.jasper.deploy.TagInfo)2 TagLibraryInfo (org.apache.jasper.deploy.TagLibraryInfo)2 TagLibraryValidatorInfo (org.apache.jasper.deploy.TagLibraryValidatorInfo)2 TagVariableInfo (org.apache.jasper.deploy.TagVariableInfo)2 Descriptions (org.jboss.annotation.javaee.Descriptions)2 Icon (org.jboss.annotation.javaee.Icon)2 AttributeMetaData (org.jboss.metadata.web.spec.AttributeMetaData)2 FunctionMetaData (org.jboss.metadata.web.spec.FunctionMetaData)2 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)2 TagFileMetaData (org.jboss.metadata.web.spec.TagFileMetaData)2 TagMetaData (org.jboss.metadata.web.spec.TagMetaData)2 VariableMetaData (org.jboss.metadata.web.spec.VariableMetaData)2 ControlPoint (org.wildfly.extension.requestcontroller.ControlPoint)2 OpenApiConfig (io.smallrye.openapi.api.OpenApiConfig)1