Search in sources :

Example 6 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class AttributeRemovalTest method removeAttributeTest.

@Test
public void removeAttributeTest() throws TransactionFailure {
    HttpService httpService = Utils.instance.getHabitat(this).getService(HttpService.class);
    VirtualServer vs = httpService.getVirtualServerByName("server");
    ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            param.setDefaultWebModule("/context/bar");
            return null;
        }
    }, vs);
    // ensure it's here
    org.junit.Assert.assertNotNull(vs.getDefaultWebModule());
    ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            param.setDefaultWebModule(null);
            return null;
        }
    }, vs);
    // ensure it's removed
    org.junit.Assert.assertNull(vs.getDefaultWebModule());
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) HttpService(com.sun.enterprise.config.serverbeans.HttpService) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 7 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class DuplicateKeyedElementTest method identicalKeyTest.

@Test(expected = TransactionFailure.class)
public void identicalKeyTest() throws TransactionFailure {
    HttpService httpService = getHabitat().getService(HttpService.class);
    assertNotNull(httpService);
    // let's find a acceptable target.
    VirtualServer target = null;
    for (VirtualServer vs : httpService.getVirtualServer()) {
        if (!vs.getProperty().isEmpty()) {
            target = vs;
            break;
        }
    }
    assertNotNull(target);
    Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            Property firstProp = param.createChild(Property.class);
            firstProp.setName("foo");
            firstProp.setValue("bar");
            param.getProperty().add(firstProp);
            // this should fail...
            Property secondProp = param.createChild(Property.class);
            secondProp.setName("foo");
            secondProp.setValue("bar");
            param.getProperty().add(secondProp);
            return secondProp;
        }
    }, target);
    // if we arrive here, this is an error, we succeeded adding a property with
    // the same key name.
    assertTrue(false);
}
Also used : SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 8 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class GetHostAndPortCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    HttpService httpService = null;
    HostAndPort hostAndPort = null;
    try {
        if (config == null) {
            throw new Exception("No such target:" + target);
        }
        httpService = config.getHttpService();
        if (httpService != null) {
            hostAndPort = getHostAndPortForRequest(httpService);
        }
    } catch (Exception e) {
        report.setMessage(e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (hostAndPort != null) {
        part.setMessage(hostAndPort.getHost() + ":" + hostAndPort.getPort());
        // property for REST Access
        part.addProperty("host", hostAndPort.getHost());
        // property for REST Access
        part.addProperty("port", "" + hostAndPort.getPort());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ActionReport(org.glassfish.api.ActionReport)

Example 9 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class WarHandler method configureContextXmlAttribute.

protected void configureContextXmlAttribute(WebappClassLoader cloader, File base, DeploymentContext dc) throws XMLStreamException, IOException {
    boolean consistent = true;
    Boolean value = null;
    File warContextXml = new File(base.getAbsolutePath(), WAR_CONTEXT_XML);
    if (warContextXml.exists()) {
        ContextXmlParser parser = new ContextXmlParser(warContextXml);
        value = parser.getClearReferencesStatic();
    }
    if (value == null) {
        Boolean domainCRS = null;
        File defaultContextXml = new File(serverEnvironment.getInstanceRoot(), DEFAULT_CONTEXT_XML);
        if (defaultContextXml.exists()) {
            ContextXmlParser parser = new ContextXmlParser(defaultContextXml);
            domainCRS = parser.getClearReferencesStatic();
        }
        List<Boolean> csrs = new ArrayList<Boolean>();
        HttpService httpService = serverConfig.getHttpService();
        DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
        String vsIDs = params.virtualservers;
        List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
        if (httpService != null && vsList != null && !vsList.isEmpty()) {
            for (VirtualServer vsBean : httpService.getVirtualServer()) {
                if (vsList.contains(vsBean.getId())) {
                    Boolean csr = null;
                    Property prop = vsBean.getProperty("contextXmlDefault");
                    if (prop != null) {
                        File contextXml = new File(serverEnvironment.getInstanceRoot(), prop.getValue());
                        if (contextXml.exists()) {
                            // vs context.xml
                            ContextXmlParser parser = new ContextXmlParser(contextXml);
                            csr = parser.getClearReferencesStatic();
                        }
                    }
                    if (csr == null) {
                        csr = domainCRS;
                    }
                    csrs.add(csr);
                }
            }
            // check that it is consistent
            for (Boolean b : csrs) {
                if (b != null) {
                    if (value != null && !b.equals(value)) {
                        consistent = false;
                        break;
                    }
                    value = b;
                }
            }
        }
    }
    if (consistent) {
        if (value != null) {
            cloader.setClearReferencesStatic(value);
        }
    } else if (logger.isLoggable(Level.WARNING)) {
        logger.log(Level.WARNING, LogFacade.INCONSISTENT_CLEAR_REFERENCE_STATIC);
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 10 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class CreateHttpListener 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) {
    final ActionReport report = context.getActionReport();
    if (!validateInputs(report)) {
        return;
    }
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    networkConfig = config.getNetworkConfig();
    HttpService httpService = config.getHttpService();
    if (!(verifyUniqueName(report, networkConfig) && verifyUniquePort(report, networkConfig) && verifyDefaultVirtualServer(report))) {
        return;
    }
    VirtualServer vs = httpService.getVirtualServerByName(defaultVirtualServer);
    boolean listener = false;
    boolean protocol = false;
    boolean transport = false;
    try {
        transport = createOrGetTransport(null);
        protocol = createProtocol(context);
        createHttp(context);
        final ThreadPool threadPool = getThreadPool(networkConfig);
        listener = createNetworkListener(networkConfig, transport, threadPool);
        updateVirtualServer(vs);
    } catch (TransactionFailure e) {
        try {
            if (listener) {
                deleteListener(context);
            }
            if (protocol) {
                deleteProtocol(context);
            }
            if (transport) {
                deleteTransport(context);
            }
        } catch (Exception e1) {
            if (logger.isLoggable(Level.INFO)) {
                logger.log(Level.INFO, e.getMessage(), e);
            }
            throw new RuntimeException(e.getMessage());
        }
        if (logger.isLoggable(Level.INFO)) {
            logger.log(Level.INFO, e.getMessage(), e);
        }
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_FAIL), listenerId, e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : 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) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

HttpService (com.sun.enterprise.config.serverbeans.HttpService)16 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)10 Property (org.jvnet.hk2.config.types.Property)8 PropertyVetoException (java.beans.PropertyVetoException)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 Test (org.junit.Test)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 Config (com.sun.enterprise.config.serverbeans.Config)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 LifecycleException (org.apache.catalina.LifecycleException)3 ActionReport (org.glassfish.api.ActionReport)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 MalformedURLException (java.net.MalformedURLException)2 CommandTarget (org.glassfish.config.support.CommandTarget)2 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)2 Target (org.glassfish.internal.api.Target)2 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)2