Search in sources :

Example 11 with EnvironmentProperty

use of com.sun.enterprise.deployment.EnvironmentProperty in project Payara by payara.

the class WebFilterHandler method processAnnotation.

private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebBundleDescriptor webBundleDesc) throws AnnotationProcessorException {
    Class filterClass = (Class) ainfo.getAnnotatedElement();
    if (!javax.servlet.Filter.class.isAssignableFrom(filterClass)) {
        log(Level.SEVERE, ainfo, localStrings.getLocalString("web.deployment.annotation.handlers.needtoimpl", "The Class {0} having annotation {1} need to implement the interface {2}.", new Object[] { filterClass.getName(), WebFilter.class.getName(), javax.servlet.Filter.class.getName() }));
        return getDefaultFailedResult();
    }
    WebFilter webFilterAn = (WebFilter) ainfo.getAnnotation();
    String filterName = webFilterAn.filterName();
    if (filterName == null || filterName.length() == 0) {
        filterName = filterClass.getName();
    }
    ServletFilterDescriptor servletFilterDesc = null;
    for (ServletFilter sfDesc : webBundleDesc.getServletFilters()) {
        if (filterName.equals(sfDesc.getName())) {
            servletFilterDesc = (ServletFilterDescriptor) sfDesc;
            break;
        }
    }
    if (servletFilterDesc == null) {
        servletFilterDesc = new ServletFilterDescriptor();
        servletFilterDesc.setName(filterName);
        webBundleDesc.addServletFilter(servletFilterDesc);
    } else {
        String filterImpl = servletFilterDesc.getClassName();
        if (filterImpl != null && filterImpl.length() > 0 && !filterImpl.equals(filterClass.getName())) {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("web.deployment.annotation.handlers.filternamedontmatch", "The filter ''{0}'' has implementation ''{1}'' in xml. It does not match with ''{2}'' from annotation @{3}.", new Object[] { filterName, filterImpl, filterClass.getName(), WebFilter.class.getName() }));
            return getDefaultFailedResult();
        }
    }
    servletFilterDesc.setClassName(filterClass.getName());
    if (servletFilterDesc.getDescription() == null || servletFilterDesc.getDescription().length() == 0) {
        servletFilterDesc.setDescription(webFilterAn.description());
    }
    if (servletFilterDesc.hasSetDisplayName()) {
        servletFilterDesc.setDisplayName(webFilterAn.displayName());
    }
    if (servletFilterDesc.getInitializationParameters().size() == 0) {
        WebInitParam[] initParams = webFilterAn.initParams();
        if (initParams != null && initParams.length > 0) {
            for (WebInitParam initParam : initParams) {
                servletFilterDesc.addInitializationParameter(new EnvironmentProperty(initParam.name(), initParam.value(), initParam.description()));
            }
        }
    }
    if (servletFilterDesc.getSmallIconUri() == null) {
        servletFilterDesc.setSmallIconUri(webFilterAn.smallIcon());
    }
    if (servletFilterDesc.getLargeIconUri() == null) {
        servletFilterDesc.setLargeIconUri(webFilterAn.largeIcon());
    }
    if (servletFilterDesc.isAsyncSupported() == null) {
        servletFilterDesc.setAsyncSupported(webFilterAn.asyncSupported());
    }
    ServletFilterMapping servletFilterMappingDesc = null;
    boolean hasUrlPattern = false;
    boolean hasServletName = false;
    for (ServletFilterMapping sfm : webBundleDesc.getServletFilterMappings()) {
        if (filterName.equals(sfm.getName())) {
            servletFilterMappingDesc = sfm;
            hasUrlPattern = hasUrlPattern || (sfm.getUrlPatterns().size() > 0);
            hasServletName = hasServletName || (sfm.getServletNames().size() > 0);
        }
    }
    if (servletFilterMappingDesc == null) {
        servletFilterMappingDesc = new ServletFilterMappingDescriptor();
        servletFilterMappingDesc.setName(filterName);
        webBundleDesc.addServletFilterMapping(servletFilterMappingDesc);
    }
    if (!hasUrlPattern) {
        String[] urlPatterns = webFilterAn.urlPatterns();
        if (urlPatterns == null || urlPatterns.length == 0) {
            urlPatterns = webFilterAn.value();
        }
        // accept here as url patterns may be defined in top level xml
        boolean validUrlPatterns = true;
        if (urlPatterns != null && urlPatterns.length > 0) {
            for (String up : urlPatterns) {
                if (!URLPattern.isValid(up)) {
                    validUrlPatterns = false;
                    break;
                }
                servletFilterMappingDesc.addURLPattern(up);
            }
        }
        if (!validUrlPatterns) {
            String urlPatternString = (urlPatterns != null) ? Arrays.toString(urlPatterns) : "";
            throw new IllegalArgumentException(localStrings.getLocalString("web.deployment.annotation.handlers.invalidUrlPatterns", "Invalid url patterns: {0}.", urlPatternString));
        }
    }
    if (!hasServletName) {
        String[] servletNames = webFilterAn.servletNames();
        if (servletNames != null && servletNames.length > 0) {
            for (String sn : servletNames) {
                servletFilterMappingDesc.addServletName(sn);
            }
        }
    }
    if (servletFilterMappingDesc.getDispatchers().size() == 0) {
        DispatcherType[] dispatcherTypes = webFilterAn.dispatcherTypes();
        if (dispatcherTypes != null && dispatcherTypes.length > 0) {
            for (DispatcherType dType : dispatcherTypes) {
                servletFilterMappingDesc.addDispatcher(dType.name());
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : WebFilter(javax.servlet.annotation.WebFilter) ServletFilter(com.sun.enterprise.deployment.web.ServletFilter) ServletFilterDescriptor(org.glassfish.web.deployment.descriptor.ServletFilterDescriptor) ServletFilterMappingDescriptor(org.glassfish.web.deployment.descriptor.ServletFilterMappingDescriptor) ServletFilter(com.sun.enterprise.deployment.web.ServletFilter) WebFilter(javax.servlet.annotation.WebFilter) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) WebInitParam(javax.servlet.annotation.WebInitParam) ServletFilterMapping(com.sun.enterprise.deployment.web.ServletFilterMapping) DispatcherType(javax.servlet.DispatcherType)

Example 12 with EnvironmentProperty

use of com.sun.enterprise.deployment.EnvironmentProperty in project Payara by payara.

the class WebServletHandler method processAnnotation.

private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebComponentDescriptor webCompDesc) throws AnnotationProcessorException {
    Class webCompClass = (Class) ainfo.getAnnotatedElement();
    if (!HttpServlet.class.isAssignableFrom(webCompClass)) {
        log(Level.SEVERE, ainfo, localStrings.getLocalString("web.deployment.annotation.handlers.needtoextend", "The Class {0} having annotation {1} need to be a derived class of {2}.", new Object[] { webCompClass.getName(), WebServlet.class.getName(), HttpServlet.class.getName() }));
        return getDefaultFailedResult();
    }
    WebServlet webServletAn = (WebServlet) ainfo.getAnnotation();
    String servletName = getServletName(webServletAn, webCompClass);
    if (!servletName.equals(webCompDesc.getCanonicalName())) {
        // skip the processing as it is not for given webCompDesc
        return getDefaultProcessedResult();
    }
    String webCompImpl = webCompDesc.getWebComponentImplementation();
    if (webCompImpl != null && webCompImpl.length() > 0 && (!webCompImpl.equals(webCompClass.getName()) || !webCompDesc.isServlet())) {
        String messageKey = null;
        String defaultMessage = null;
        if (webCompDesc.isServlet()) {
            messageKey = "web.deployment.annotation.handlers.servletimpldontmatch";
            defaultMessage = "The servlet ''{0}'' has implementation ''{1}'' in xml. It does not match with ''{2}'' from annotation @{3}.";
        } else {
            messageKey = "web.deployment.annotation.handlers.servletimpljspdontmatch";
            defaultMessage = "The servlet ''{0}'' is a jsp ''{1}'' in xml. It does not match with ''{2}'' from annotation @{3}.";
        }
        log(Level.SEVERE, ainfo, localStrings.getLocalString(messageKey, defaultMessage, new Object[] { webCompDesc.getCanonicalName(), webCompImpl, webCompClass.getName(), WebServlet.class.getName() }));
        return getDefaultFailedResult();
    }
    webCompDesc.setServlet(true);
    webCompDesc.setWebComponentImplementation(webCompClass.getName());
    if (webCompDesc.getUrlPatternsSet().isEmpty()) {
        String[] urlPatterns = webServletAn.urlPatterns();
        if (urlPatterns == null || urlPatterns.length == 0) {
            urlPatterns = webServletAn.value();
        }
        // no url patterns is accepted as it may be defined in top level xml
        boolean validUrlPatterns = true;
        if (urlPatterns != null && urlPatterns.length > 0) {
            for (String up : urlPatterns) {
                if (!URLPattern.isValid(up)) {
                    validUrlPatterns = false;
                    break;
                }
                webCompDesc.addUrlPattern(TranslatedConfigView.expandValue(up));
            }
        }
        if (!validUrlPatterns) {
            String urlPatternString = (urlPatterns != null) ? Arrays.toString(urlPatterns) : "";
            throw new IllegalArgumentException(localStrings.getLocalString("web.deployment.annotation.handlers.invalidUrlPatterns", "Invalid url patterns for {0}: {1}.", new Object[] { webCompClass, urlPatternString }));
        }
    }
    if (webCompDesc.getLoadOnStartUp() == null) {
        webCompDesc.setLoadOnStartUp(webServletAn.loadOnStartup());
    }
    WebInitParam[] initParams = webServletAn.initParams();
    if (initParams != null && initParams.length > 0) {
        for (WebInitParam initParam : initParams) {
            webCompDesc.addInitializationParameter(new EnvironmentProperty(initParam.name(), TranslatedConfigView.expandValue(initParam.value()), initParam.description()));
        }
    }
    if (webCompDesc.getSmallIconUri() == null) {
        webCompDesc.setSmallIconUri(webServletAn.smallIcon());
    }
    if (webCompDesc.getLargeIconUri() == null) {
        webCompDesc.setLargeIconUri(webServletAn.largeIcon());
    }
    if (webCompDesc.getDescription() == null || webCompDesc.getDescription().length() == 0) {
        webCompDesc.setDescription(webServletAn.description());
    }
    if (webCompDesc.getDisplayName() == null || webCompDesc.getDisplayName().length() == 0) {
        webCompDesc.setDisplayName(webServletAn.displayName());
    }
    if (webCompDesc.isAsyncSupported() == null) {
        webCompDesc.setAsyncSupported(webServletAn.asyncSupported());
    }
    return getDefaultProcessedResult();
}
Also used : WebServlet(javax.servlet.annotation.WebServlet) HttpServlet(javax.servlet.http.HttpServlet) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) WebInitParam(javax.servlet.annotation.WebInitParam)

Example 13 with EnvironmentProperty

use of com.sun.enterprise.deployment.EnvironmentProperty in project Payara by payara.

the class SafeProperties method copy.

void copy(Set s) {
    Iterator i = s.iterator();
    defaults = new Properties();
    while (i.hasNext()) {
        EnvironmentProperty p = (EnvironmentProperty) i.next();
        if (p.getName().startsWith(ejb10Prefix)) {
            String newName = p.getName().substring(ejb10Prefix.length());
            defaults.put(newName, p.getValue());
        }
    }
}
Also used : EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty)

Example 14 with EnvironmentProperty

use of com.sun.enterprise.deployment.EnvironmentProperty in project Payara by payara.

the class EjbReferenceNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, String nodeName, EjbReference descriptor) {
    Node ejbRefNode = appendChild(parent, nodeName);
    if (descriptor instanceof Descriptor) {
        Descriptor ejbRefDesc = (Descriptor) descriptor;
        writeLocalizedDescriptions(ejbRefNode, ejbRefDesc);
    }
    appendTextChild(ejbRefNode, TagNames.EJB_REFERENCE_NAME, descriptor.getName());
    appendTextChild(ejbRefNode, TagNames.EJB_REFERENCE_TYPE, descriptor.getType());
    if (descriptor.isLocal()) {
        appendTextChild(ejbRefNode, TagNames.LOCAL_HOME, descriptor.getEjbHomeInterface());
        appendTextChild(ejbRefNode, TagNames.LOCAL, descriptor.getEjbInterface());
    } else {
        appendTextChild(ejbRefNode, TagNames.HOME, descriptor.getEjbHomeInterface());
        appendTextChild(ejbRefNode, TagNames.REMOTE, descriptor.getEjbInterface());
    }
    appendTextChild(ejbRefNode, TagNames.EJB_LINK, descriptor.getLinkName());
    if (descriptor instanceof EnvironmentProperty) {
        EnvironmentProperty envProp = (EnvironmentProperty) descriptor;
        appendTextChild(ejbRefNode, TagNames.MAPPED_NAME, envProp.getMappedName());
    }
    if (descriptor.isInjectable()) {
        InjectionTargetNode ijNode = new InjectionTargetNode();
        for (InjectionTarget target : descriptor.getInjectionTargets()) {
            ijNode.writeDescriptor(ejbRefNode, TagNames.INJECTION_TARGET, target);
        }
    }
    if (descriptor.hasLookupName()) {
        appendTextChild(ejbRefNode, TagNames.LOOKUP_NAME, descriptor.getLookupName());
    }
    return ejbRefNode;
}
Also used : Node(org.w3c.dom.Node) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Descriptor(org.glassfish.deployment.common.Descriptor) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget)

Example 15 with EnvironmentProperty

use of com.sun.enterprise.deployment.EnvironmentProperty in project Payara by payara.

the class MessageDrivenHandler method setEjbDescriptorInfo.

/**
 * Set Annotation information to Descriptor.
 * This method will also be invoked for an existing descriptor with
 * annotation as user may not specific a complete xml.
 * @param ejbDesc
 * @param ainfo
 * @return HandlerProcessingResult
 */
protected HandlerProcessingResult setEjbDescriptorInfo(EjbDescriptor ejbDesc, AnnotationInfo ainfo) throws AnnotationProcessorException {
    MessageDriven mdAn = (MessageDriven) ainfo.getAnnotation();
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    EjbMessageBeanDescriptor ejbMsgBeanDesc = (EjbMessageBeanDescriptor) ejbDesc;
    HandlerProcessingResult procResult = setMessageListenerInterface(mdAn, ejbMsgBeanDesc, ejbClass, ainfo);
    doDescriptionProcessing(mdAn.description(), ejbMsgBeanDesc);
    doMappedNameProcessing(mdAn.mappedName(), ejbMsgBeanDesc);
    for (ActivationConfigProperty acProp : mdAn.activationConfig()) {
        EnvironmentProperty envProp = new EnvironmentProperty(acProp.propertyName(), TranslatedConfigView.expandValue(acProp.propertyValue()), "");
        // xml override
        switch(acProp.propertyName()) {
            case "resourceAdapter":
                ejbMsgBeanDesc.setResourceAdapterMid(envProp.getValue());
                break;
            case DescriptorConstants.MAX_POOL_SIZE:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setMaxPoolSize(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.POOL_RESIZE_QTY:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setPoolResizeQuantity(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.STEADY_POOL_SIZE:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setSteadyPoolSize(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.MAX_WAIT_TIME:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setMaxWaitTimeInMillis(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.POOL_IDLE_TIMEOUT:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setPoolIdleTimeoutInSeconds(Integer.valueOf(envProp.getValue()));
                break;
            case "SingletonBeanPool":
                NameValuePairDescriptor singletonProperty = new NameValuePairDescriptor();
                singletonProperty.setName("singleton-bean-pool");
                singletonProperty.setValue(envProp.getValue());
                ejbMsgBeanDesc.getEjbBundleDescriptor().addEnterpriseBeansProperty(singletonProperty);
                break;
            default:
                if (ejbMsgBeanDesc.getActivationConfigValue(envProp.getName()) == null) {
                    ejbMsgBeanDesc.putActivationConfigProperty(envProp);
                }
                break;
        }
    }
    return procResult;
}
Also used : ActivationConfigProperty(javax.ejb.ActivationConfigProperty) EjbMessageBeanDescriptor(org.glassfish.ejb.deployment.descriptor.EjbMessageBeanDescriptor) NameValuePairDescriptor(com.sun.enterprise.deployment.NameValuePairDescriptor) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) MessageDriven(javax.ejb.MessageDriven)

Aggregations

EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)29 Result (com.sun.enterprise.tools.verifier.Result)10 Iterator (java.util.Iterator)6 Node (org.w3c.dom.Node)4 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)3 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)3 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)3 Set (java.util.Set)3 ServletFilterDescriptor (org.glassfish.web.deployment.descriptor.ServletFilterDescriptor)3 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)2 MessageListener (com.sun.enterprise.deployment.MessageListener)2 Method (java.lang.reflect.Method)2 URISyntaxException (java.net.URISyntaxException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)2 WebInitParam (javax.servlet.annotation.WebInitParam)2 MultiException (org.glassfish.hk2.api.MultiException)2 AdminObject (com.sun.enterprise.deployment.AdminObject)1 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)1