Search in sources :

Example 16 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebMigrateOperation method migrateWelcomeFiles.

private void migrateWelcomeFiles(Map<PathAddress, ModelNode> newAddOperations, ModelNode newAddOp) {
    ModelNode welcome = newAddOp.get("welcome-file");
    if (welcome.isDefined()) {
        for (ModelNode w : welcome.asList()) {
            PathAddress wa = pathAddress(pathAddress(UndertowExtension.SUBSYSTEM_PATH, pathElement(Constants.SERVLET_CONTAINER, "default"), pathElement(Constants.WELCOME_FILE, w.asString())));
            ModelNode add = createAddOperation(wa);
            newAddOperations.put(wa, add);
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 17 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebSubsystemParser method parseHostRewrite.

static void parseHostRewrite(XMLExtendedStreamReader reader, final PathAddress parent, List<ModelNode> list, int rewriteCount) throws XMLStreamException {
    final ModelNode rewrite = Util.createAddOperation();
    final int count = reader.getAttributeCount();
    String name = RULE_PREFIX + rewriteCount;
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case PATTERN:
                WebReWriteDefinition.PATTERN.parseAndSetParameter(value, rewrite, reader);
                break;
            case SUBSTITUTION:
                WebReWriteDefinition.SUBSTITUTION.parseAndSetParameter(value, rewrite, reader);
                break;
            case FLAGS:
                WebReWriteDefinition.FLAGS.parseAndSetParameter(value, rewrite, reader);
                break;
            case NAME:
                name = value;
                break;
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    final PathAddress address = PathAddress.pathAddress(parent, PathElement.pathElement(REWRITE, name));
    rewrite.get(OP_ADDR).set(address.toModelNode());
    list.add(rewrite);
    int conditionCount = 0;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch(Namespace.forUri(reader.getNamespaceURI())) {
            case WEB_1_0:
            case WEB_1_1:
            case WEB_1_2:
            case WEB_1_3:
            case WEB_1_4:
            case WEB_1_5:
            case WEB_2_0:
            case WEB_2_1:
            case WEB_2_2:
                {
                    final Element element = Element.forName(reader.getLocalName());
                    switch(element) {
                        case CONDITION:
                            final ModelNode condition = Util.createAddOperation();
                            String condName = CONDITION_PREFIX + conditionCount;
                            final int count2 = reader.getAttributeCount();
                            for (int i = 0; i < count2; i++) {
                                requireNoNamespaceAttribute(reader, i);
                                final String value = reader.getAttributeValue(i);
                                final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
                                switch(attribute) {
                                    case NAME:
                                        condName = value;
                                        break;
                                    case TEST:
                                        WebReWriteConditionDefinition.TEST.parseAndSetParameter(value, condition, reader);
                                        break;
                                    case PATTERN:
                                        WebReWriteConditionDefinition.PATTERN.parseAndSetParameter(value, condition, reader);
                                        break;
                                    case FLAGS:
                                        WebReWriteConditionDefinition.FLAGS.parseAndSetParameter(value, condition, reader);
                                        break;
                                    default:
                                        throw unexpectedAttribute(reader, i);
                                }
                            }
                            PathAddress condAddress = address.append(PathElement.pathElement(CONDITION, condName));
                            condition.get(OP_ADDR).set(condAddress.toModelNode());
                            requireNoContent(reader);
                            list.add(condition);
                            conditionCount++;
                            break;
                        default:
                            throw unexpectedElement(reader);
                    }
                    break;
                }
            default:
                throw unexpectedElement(reader);
        }
    }
}
Also used : ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ParseUtils.readStringAttributeElement(org.jboss.as.controller.parsing.ParseUtils.readStringAttributeElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) ModelNode(org.jboss.dmr.ModelNode)

Example 18 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebSubsystemParser method parseContainerConfig.

static void parseContainerConfig(XMLExtendedStreamReader reader, PathAddress parent, List<ModelNode> list) throws XMLStreamException {
    PathAddress address = PathAddress.pathAddress(parent, WebExtension.CONTAINER_PATH);
    final ModelNode config = new ModelNode();
    config.get(OP).set(ADD);
    config.get(OP_ADDR).set(address.toModelNode());
    // no attributes
    list.add(config);
    if (reader.getAttributeCount() > 0) {
        throw unexpectedAttribute(reader, 0);
    }
    // elements
    boolean staticResourcesConfigured = false;
    boolean jspConfigured = false;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case STATIC_RESOURCES:
                {
                    parseStaticResources(reader, parent, list);
                    staticResourcesConfigured = true;
                    break;
                }
            case JSP_CONFIGURATION:
                {
                    parseJSPConfiguration(reader, parent, list);
                    jspConfigured = true;
                    break;
                }
            case MIME_MAPPING:
                {
                    final String[] array = requireAttributes(reader, Attribute.NAME.getLocalName(), Attribute.VALUE.getLocalName());
                    WebContainerDefinition.MIME_MAPPINGS.parseAndAddParameterElement(array[0], array[1], config, reader);
                    requireNoContent(reader);
                    break;
                }
            case WELCOME_FILE:
                {
                    final String welcomeFile = reader.getElementText().trim();
                    WebContainerDefinition.WELCOME_FILES.parseAndAddParameterElement(welcomeFile, config, reader);
                    break;
                }
            default:
                throw unexpectedElement(reader);
        }
    }
    if (!staticResourcesConfigured) {
        addDefaultStaticConfiguration(parent, list);
    }
    if (!jspConfigured) {
        addDefaultJSPConfiguration(parent, list);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ParseUtils.readStringAttributeElement(org.jboss.as.controller.parsing.ParseUtils.readStringAttributeElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) ModelNode(org.jboss.dmr.ModelNode)

Example 19 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebSubsystemParser method addDefaultStaticConfiguration.

private static void addDefaultStaticConfiguration(final PathAddress parent, List<ModelNode> list) {
    PathAddress address = PathAddress.pathAddress(parent, WebExtension.STATIC_RESOURCES_PATH);
    final ModelNode resources = new ModelNode();
    resources.get(OP).set(ADD);
    resources.get(OP_ADDR).set(address.toModelNode());
    list.add(resources);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 20 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebSubsystemParser method parseHostAccessLog.

static void parseHostAccessLog(XMLExtendedStreamReader reader, final PathAddress parent, List<ModelNode> list) throws XMLStreamException {
    PathAddress address = PathAddress.pathAddress(parent, ACCESS_LOG_PATH);
    final ModelNode log = new ModelNode();
    log.get(OP).set(ADD);
    log.get(OP_ADDR).set(address.toModelNode());
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case PATTERN:
                WebAccessLogDefinition.PATTERN.parseAndSetParameter(value, log, reader);
                break;
            case RESOLVE_HOSTS:
                WebAccessLogDefinition.RESOLVE_HOSTS.parseAndSetParameter(value, log, reader);
                break;
            case EXTENDED:
                WebAccessLogDefinition.EXTENDED.parseAndSetParameter(value, log, reader);
                break;
            case PREFIX:
                WebAccessLogDefinition.PREFIX.parseAndSetParameter(value, log, reader);
                break;
            case ROTATE:
                WebAccessLogDefinition.ROTATE.parseAndSetParameter(value, log, reader);
                break;
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    list.add(log);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch(Namespace.forUri(reader.getNamespaceURI())) {
            case WEB_1_0:
            case WEB_1_1:
            case WEB_1_2:
            case WEB_1_3:
            case WEB_1_4:
            case WEB_1_5:
            case WEB_2_0:
            case WEB_2_1:
            case WEB_2_2:
                {
                    final Element element = Element.forName(reader.getLocalName());
                    switch(element) {
                        case DIRECTORY:
                            parseDirOrFile(reader, address, list, WebExtension.DIRECTORY_PATH);
                            break;
                        default:
                            throw unexpectedElement(reader);
                    }
                    break;
                }
            default:
                throw unexpectedElement(reader);
        }
    }
}
Also used : ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ParseUtils.readStringAttributeElement(org.jboss.as.controller.parsing.ParseUtils.readStringAttributeElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)1634 PathAddress (org.jboss.as.controller.PathAddress)351 Test (org.junit.Test)344 KernelServices (org.jboss.as.subsystem.test.KernelServices)102 Property (org.jboss.dmr.Property)92 OperationFailedException (org.jboss.as.controller.OperationFailedException)89 OperationContext (org.jboss.as.controller.OperationContext)68 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)68 ArrayList (java.util.ArrayList)58 Resource (org.jboss.as.controller.registry.Resource)54 PathElement (org.jboss.as.controller.PathElement)53 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)52 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)50 IOException (java.io.IOException)49 ServiceName (org.jboss.msc.service.ServiceName)49 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)47 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)44 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)42 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)42 Map (java.util.Map)38