Search in sources :

Example 1 with Property

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

the class CreateVirtualServer method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    if (networkListeners != null && httpListeners != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_BOTH_HTTP_NETWORK), virtualServerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // use the listener parameter provided by the user.
    if (networkListeners == null) {
        networkListeners = httpListeners;
    }
    HttpService httpService = config.getHttpService();
    // ensure we don't already have one of this name
    for (VirtualServer virtualServer : httpService.getVirtualServer()) {
        if (virtualServer.getId().equals(virtualServerId)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_DUPLICATE), virtualServerId));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                // default
                String docroot = "${com.sun.aas.instanceRoot}/docroot";
                // default
                String accessLog = "${com.sun.aas.instanceRoot}/logs/access";
                VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
                newVirtualServer.setId(virtualServerId);
                newVirtualServer.setHosts(hosts);
                newVirtualServer.setNetworkListeners(networkListeners);
                newVirtualServer.setDefaultWebModule(defaultWebModule);
                newVirtualServer.setState(state);
                newVirtualServer.setLogFile(logFile);
                // values if the properties have not been specified.
                if (properties != null) {
                    for (Map.Entry entry : properties.entrySet()) {
                        String pn = (String) entry.getKey();
                        String pv = (String) entry.getValue();
                        if ("docroot".equals(pn)) {
                            docroot = pv;
                        } else if ("accesslog".equals(pn)) {
                            accessLog = pv;
                        } else {
                            Property property = newVirtualServer.createChild(Property.class);
                            property.setName(pn);
                            property.setValue(pv);
                            newVirtualServer.getProperty().add(property);
                        }
                    }
                }
                newVirtualServer.setDocroot(docroot);
                newVirtualServer.setAccessLog(accessLog);
                param.getVirtualServer().add(newVirtualServer);
                return newVirtualServer;
            }
        }, httpService);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_FAIL), virtualServerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ActionReport(org.glassfish.api.ActionReport) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 2 with Property

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

the class ServerConfigLookup method getWebContainerAvailabilityPropertyString.

/**
 * Get the String value of the property under web-container-availability
 * element from domain.xml whose name matches propName
 * return defaultValue if not found
 * @param propName
 */
protected String getWebContainerAvailabilityPropertyString(String propName, String defaultValue) {
    WebContainerAvailability wcAvailabilityBean = getWebContainerAvailability();
    if (wcAvailabilityBean == null) {
        return defaultValue;
    }
    List<Property> props = wcAvailabilityBean.getProperty();
    if (props == null) {
        return defaultValue;
    }
    for (Property prop : props) {
        String name = prop.getName();
        String value = prop.getValue();
        if (name.equalsIgnoreCase(propName)) {
            return value;
        }
    }
    return defaultValue;
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 3 with Property

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

the class VirtualServer method configure.

/**
 * Configures this virtual server.
 * @param vsID
 * @param vsBean
 * @param vsDocroot
 * @param vsLogFile
 * @param logServiceFile
 * @param logLevel
 */
public void configure(String vsID, com.sun.enterprise.config.serverbeans.VirtualServer vsBean, String vsDocroot, String vsLogFile, MimeMap vsMimeMap, String logServiceFile, String logLevel) {
    setDebug(debug);
    setAppBase(vsDocroot);
    setName(vsID);
    setID(vsID);
    setBean(vsBean);
    setMimeMap(vsMimeMap);
    String defaultContextXmlLocation = Constants.DEFAULT_CONTEXT_XML;
    String defaultWebXmlLocation = Constants.DEFAULT_WEB_XML;
    // Begin EE: 4920692 Make the default-web.xml be relocatable
    Property prop = vsBean.getProperty("default-web-xml");
    if (prop != null) {
        defaultWebXmlLocation = prop.getValue();
    }
    // End EE: 4920692 Make the default-web.xml be relocatable
    // allowLinking
    boolean allowLinking = false;
    prop = vsBean.getProperty("allowLinking");
    if (prop != null) {
        allowLinking = Boolean.parseBoolean(prop.getValue());
    }
    setAllowLinking(allowLinking);
    prop = vsBean.getProperty("contextXmlDefault");
    if (prop != null) {
        defaultContextXmlLocation = prop.getValue();
    }
    setDefaultWebXmlLocation(defaultWebXmlLocation);
    setDefaultContextXmlLocation(defaultContextXmlLocation);
    // Set vs state
    String state = vsBean.getState();
    if (state == null) {
        state = ON;
    }
    if (DISABLED.equalsIgnoreCase(state)) {
        setIsActive(false);
    } else {
        setIsActive(Boolean.parseBoolean(state));
    }
    setLogFile(vsLogFile, logLevel, logServiceFile);
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 4 with Property

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

the class VirtualServer method configureAuthRealm.

/**
 * Configures this virtual server with its authentication realm.
 *
 * Checks if this virtual server specifies any authRealm property, and
 * if so, ensures that its value identifies a valid realm.
 *
 * @param securityService The security-service element from domain.xml
 */
void configureAuthRealm(SecurityService securityService) {
    List<Property> properties = vsBean.getProperty();
    if (properties != null && properties.size() > 0) {
        for (Property p : properties) {
            if (p != null && "authRealm".equals(p.getName())) {
                authRealmName = p.getValue();
                if (authRealmName != null) {
                    AuthRealm realm = null;
                    List<AuthRealm> rs = securityService.getAuthRealm();
                    if (rs != null && rs.size() > 0) {
                        for (AuthRealm r : rs) {
                            if (r != null && r.getName().equals(authRealmName)) {
                                realm = r;
                                break;
                            }
                        }
                    }
                    if (realm == null) {
                        _logger.log(Level.SEVERE, LogFacade.INVALID_AUTH_REALM, new Object[] { getID(), authRealmName });
                    }
                }
                break;
            }
        }
    }
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Property(org.jvnet.hk2.config.types.Property)

Example 5 with Property

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

the class VirtualServer method configureCatalinaProperties.

/**
 * Configures the valve_ and listener_ properties of this VirtualServer.
 */
protected void configureCatalinaProperties() {
    List<Property> props = vsBean.getProperty();
    if (props == null) {
        return;
    }
    for (Property prop : props) {
        String propName = prop.getName();
        String propValue = prop.getValue();
        if (propName == null || propValue == null) {
            _logger.log(Level.WARNING, LogFacade.NULL_VIRTUAL_SERVER_PROPERTY, getName());
        }
        if (propName != null) {
            if (propName.startsWith("valve_")) {
                addValve(propValue);
            } else if (propName.startsWith("listener_")) {
                addListener(propValue);
            } else if (propName.equals("securePagesWithPragma")) {
                setSecurePagesWithPragma(Boolean.valueOf(propValue));
            }
        }
    }
}
Also used : 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