Search in sources :

Example 31 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class CompositeUtil method analyzeInterface.

private void analyzeInterface(Class<?> iface, Map<String, Map<String, Object>> properties) throws SecurityException {
    // find class level bean reference
    String defaultBean = null;
    if (iface.isAnnotationPresent(DefaultBeanReference.class)) {
        DefaultBeanReference beanRef = iface.getAnnotation(DefaultBeanReference.class);
        defaultBean = beanRef.bean();
    }
    for (Method method : iface.getMethods()) {
        String name = method.getName();
        final boolean isGetter = name.startsWith("get");
        if (isGetter || name.startsWith("set")) {
            name = name.substring(3);
            Map<String, Object> property = properties.get(name);
            if (property == null) {
                property = new HashMap<String, Object>();
                properties.put(name, property);
            }
            String bean = null;
            String attribute = null;
            AttributeReference ar = method.getAnnotation(AttributeReference.class);
            if (ar != null) {
                bean = ar.bean();
                attribute = ar.attribute();
            }
            if (!StringUtil.notEmpty(bean)) {
                bean = defaultBean;
            }
            if (!StringUtil.notEmpty(attribute)) {
                attribute = name;
            }
            if (StringUtil.notEmpty(bean) && StringUtil.notEmpty(attribute)) {
                property.put("annotations", gatherReferencedAttributes(bean, attribute));
            }
            Attribute attr = method.getAnnotation(Attribute.class);
            if (attr != null) {
                property.put("defaultValue", attr.defaultValue());
            }
            Class<?> type = isGetter ? method.getReturnType() : method.getParameterTypes()[0];
            property.put("type", type);
        }
    }
}
Also used : DefaultBeanReference(org.glassfish.admin.rest.composite.metadata.DefaultBeanReference) Attribute(org.jvnet.hk2.config.Attribute) AttributeReference(org.glassfish.admin.rest.composite.metadata.AttributeReference) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Method(java.lang.reflect.Method)

Example 32 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class EJBTimerServiceUpgrade method doUpgrade.

private void doUpgrade(EjbTimerService ts) {
    String value = ts.getMinimumDeliveryIntervalInMillis();
    if (value == null || "7000".equals(value)) {
        value = "" + EjbContainerUtil.MINIMUM_TIMER_DELIVERY_INTERVAL;
    }
    List<Property> properties = ts.getProperty();
    if (properties != null) {
        for (Property p : properties) {
            if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
                // Already set
                return;
            }
        }
    }
    try {
        final String minDelivery = value;
        ConfigSupport.apply(new SingleConfigCode<EjbTimerService>() {

            public Object run(EjbTimerService ts) throws PropertyVetoException, TransactionFailure {
                Property prop = ts.createChild(Property.class);
                ts.getProperty().add(prop);
                prop.setName(EjbContainerUtil.TIMER_SERVICE_UPGRADED);
                prop.setValue("false");
                ts.setMinimumDeliveryIntervalInMillis(minDelivery);
                return null;
            }
        }, ts);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Property(org.jvnet.hk2.config.types.Property) EjbTimerService(org.glassfish.ejb.config.EjbTimerService) PropertyVetoException(java.beans.PropertyVetoException)

Example 33 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class PersistentEJBTimerService method isUpgrade.

private static boolean isUpgrade(String resource, EjbTimerService _ejbt, File root) {
    boolean upgrade = false;
    Property prop = null;
    if (_ejbt != null) {
        List<Property> properties = _ejbt.getProperty();
        if (properties != null) {
            for (Property p : properties) {
                if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
                    String value = p.getValue();
                    if (value != null && "false".equals(value)) {
                        upgrade = true;
                        prop = p;
                        break;
                    }
                }
            }
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("===> Upgrade? <==");
    }
    if (upgrade) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("===> Upgrade! <==");
        }
        boolean success = false;
        try {
            File dir = new File(root, "lib/install/databases/upgrade");
            if (!dir.exists()) {
                logger.log(Level.WARNING, "Cannot upgrade EJBTimerService: " + "required directory is not available");
            } else {
                Java2DBProcessorHelper h = new Java2DBProcessorHelper(TIMER_SERVICE_APP_NAME);
                success = h.executeDDLStatement(dir.getCanonicalPath() + "/ejbtimer_upgrade_", resource);
                ConfigSupport.apply(new SingleConfigCode<Property>() {

                    public Object run(Property p) throws PropertyVetoException, TransactionFailure {
                        p.setValue("true");
                        return null;
                    }
                }, prop);
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "", e);
        }
        if (!success) {
            logger.log(Level.SEVERE, "Failed to upgrade EJBTimerService: see log for details");
        }
    }
    return upgrade;
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Property(org.jvnet.hk2.config.types.Property) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 34 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class WebContainerImpl method addVirtualServer.

/**
 * Adds the given <tt>VirtualServer</tt> to this
 * <tt>WebContainer</tt>.
 *
 * <p>If this <tt>WebContainer</tt> has already been started,
 * the given <tt>virtualServer</tt> will be started as well.
 *
 * @param virtualServer the <tt>VirtualServer</tt> to add
 *
 * @throws ConfigException if a <tt>VirtualServer</tt> with the
 * same id has already been registered with this
 * <tt>WebContainer</tt>
 * @throws GlassFishException if the given <tt>virtualServer</tt> fails
 * to be started
 */
public void addVirtualServer(VirtualServer virtualServer) throws ConfigException, GlassFishException {
    if (!initialized) {
        init();
    }
    if (log.isLoggable(Level.INFO)) {
        log.info("Adding virtual server " + virtualServer.getID());
    }
    com.sun.enterprise.web.VirtualServer vs = (com.sun.enterprise.web.VirtualServer) engine.findChild(virtualServer.getID());
    if (vs != null) {
        throw new ConfigException("VirtualServer with id " + virtualServer.getID() + " is already registered");
    }
    Collection<WebListener> webListeners = virtualServer.getWebListeners();
    List<String> names = new ArrayList<String>();
    if ((webListeners != null) && (!webListeners.isEmpty())) {
        for (WebListener listener : webListeners) {
            names.add(listener.getId());
        }
    } else {
        for (NetworkListener networkListener : networkConfig.getNetworkListeners().getNetworkListener()) {
            names.add(networkListener.getName());
        }
        webListeners = listeners;
    }
    StringBuffer networkListeners = new StringBuffer("");
    if (names.size() > 0) {
        networkListeners.append(names.get(0));
    }
    for (int i = 1; i < names.size(); i++) {
        networkListeners.append(",");
        networkListeners.append(names.get(i));
    }
    String docRoot = null;
    if (virtualServer.getDocRoot() != null) {
        docRoot = virtualServer.getDocRoot().getAbsolutePath();
    }
    String hostName = null;
    if (virtualServer.getConfig() != null) {
        hostName = virtualServer.getConfig().getHostNames();
    }
    final String root = docRoot;
    final String nl = networkListeners.toString();
    final String id = virtualServer.getID();
    final String hosts = hostName;
    try {
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                com.sun.enterprise.config.serverbeans.VirtualServer newVirtualServer = param.createChild(com.sun.enterprise.config.serverbeans.VirtualServer.class);
                newVirtualServer.setId(id);
                newVirtualServer.setNetworkListeners(nl);
                if (hosts != null) {
                    newVirtualServer.setHosts(hosts);
                }
                Property property = newVirtualServer.createChild(Property.class);
                property.setName("docroot");
                property.setValue(root);
                newVirtualServer.getProperty().add(property);
                param.getVirtualServer().add(newVirtualServer);
                return newVirtualServer;
            }
        }, httpService);
    } catch (Exception ex) {
        throw new GlassFishException(ex);
    }
    if ((webListeners != null) && (!webListeners.isEmpty())) {
        for (WebListener listener : webListeners) {
            if (getWebListener(listener.getId()) == null) {
                addWebListener(listener, virtualServer.getID());
            }
        }
    }
    vs = (com.sun.enterprise.web.VirtualServer) engine.findChild(id);
    if (vs != null) {
        if (log.isLoggable(Level.INFO)) {
            log.info("Added virtual server " + id + " docroot " + docRoot + " networklisteners " + nl);
        }
        if (virtualServer instanceof VirtualServerFacade) {
            ((VirtualServerFacade) virtualServer).setVirtualServer(vs);
        }
        vs.setNetworkListenerNames(names.toArray(new String[names.size()]));
    } else {
        log.severe("Could not add virtual server " + id);
        throw new GlassFishException(new Exception("Cannot add virtual server " + id));
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ConfigException(org.glassfish.embeddable.web.ConfigException) VirtualServerFacade(com.sun.enterprise.web.VirtualServerFacade) Property(org.jvnet.hk2.config.types.Property) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException) PropertyVetoException(java.beans.PropertyVetoException) WebListener(org.glassfish.embeddable.web.WebListener) HttpService(com.sun.enterprise.config.serverbeans.HttpService) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 35 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class WebContainerImpl method setConfiguration.

// --------------------------------------------------------- Public Methods
public void setConfiguration(WebContainerConfig config) {
    if (!initialized) {
        init();
    }
    this.config = config;
    final WebContainerConfig webConfig = config;
    try {
        VirtualServer vs = getVirtualServer(config.getVirtualServerId());
        if (vs != null) {
            ((StandardHost) vs).setDefaultWebXmlLocation(config.getDefaultWebXml().getPath());
        }
        com.sun.enterprise.config.serverbeans.VirtualServer vsBean = httpService.getVirtualServerByName(config.getVirtualServerId());
        if (vsBean != null) {
            ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {

                public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException, TransactionFailure {
                    avs.setId(webConfig.getVirtualServerId());
                    if (webConfig.getDocRootDir() != null) {
                        avs.setDocroot(webConfig.getDocRootDir().getAbsolutePath());
                    }
                    avs.setHosts(webConfig.getHostNames());
                    avs.setNetworkListeners(webConfig.getListenerName());
                    Property property = avs.createChild(Property.class);
                    property.setName("default-web-xml");
                    property.setValue(webConfig.getDefaultWebXml().getPath());
                    avs.getProperty().add(property);
                    return avs;
                }
            }, vsBean);
        } else {
            vs = createVirtualServer(config.getVirtualServerId(), config.getDocRootDir());
            addVirtualServer(vs);
        }
        EmbeddedWebArchivist archivist = habitat.<EmbeddedWebArchivist>getService(EmbeddedWebArchivist.class);
        archivist.setDefaultWebXml(config.getDefaultWebXml());
        embedded.setDirectoryListing(config.getListings());
        WebListener listener = getWebListener(config.getListenerName());
        if (listener == null) {
            listener = getWebListener(config.getPort());
            if (listener == null) {
                boolean found = false;
                for (Map.Entry entry : webContainer.getConnectorMap().entrySet()) {
                    if (((WebConnector) entry.getValue()).getPort() == config.getPort()) {
                        found = true;
                        log.info("Port " + config.getPort() + " is already configured");
                    }
                }
                if (!found) {
                    listener = createWebListener(config.getListenerName(), HttpListener.class);
                    listener.setPort(config.getPort());
                    addWebListener(listener, config.getVirtualServerId());
                }
            }
        } else {
            if (listener.getPort() != config.getPort()) {
                listener.setPort(config.getPort());
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : WebContainerConfig(org.glassfish.embeddable.web.config.WebContainerConfig) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException) PropertyVetoException(java.beans.PropertyVetoException) WebListener(org.glassfish.embeddable.web.WebListener) StandardHost(org.apache.catalina.core.StandardHost) HttpListener(org.glassfish.embeddable.web.HttpListener) org.jvnet.hk2.config(org.jvnet.hk2.config) Property(org.jvnet.hk2.config.types.Property)

Aggregations

Property (org.jvnet.hk2.config.types.Property)149 PropertyVetoException (java.beans.PropertyVetoException)30 HashMap (java.util.HashMap)27 Properties (java.util.Properties)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 ArrayList (java.util.ArrayList)18 ActionReport (org.glassfish.api.ActionReport)17 Map (java.util.Map)15 File (java.io.File)13 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)12 Config (com.sun.enterprise.config.serverbeans.Config)11 List (java.util.List)11 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)10 HttpService (com.sun.enterprise.config.serverbeans.HttpService)9 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)9 Server (com.sun.enterprise.config.serverbeans.Server)8 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 Application (com.sun.enterprise.config.serverbeans.Application)7 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)7