Skip to content

Commit

Permalink
Properly use defaults, improve tests & add xsd validation for all sub…
Browse files Browse the repository at this point in the history
…system versions
  • Loading branch information
ctomc committed Jun 15, 2015
1 parent 491d6f4 commit 55e2d6f
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 19 deletions.
16 changes: 6 additions & 10 deletions undertow/src/main/java/org/wildfly/extension/undertow/HostAdd.java
Expand Up @@ -22,8 +22,6 @@

package org.wildfly.extension.undertow;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;

import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -56,26 +54,24 @@ private HostAdd() {

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
final PathAddress serverAddress = address.subAddress(0, address.size() - 1);
final PathAddress subsystemAddress = serverAddress.subAddress(0, address.size() - 2);
final PathAddress address = context.getCurrentAddress();
final PathAddress serverAddress = address.getParent();
final PathAddress subsystemAddress = serverAddress.getParent();
final ModelNode subsystemModel = Resource.Tools.readModel(context.readResourceFromRoot(subsystemAddress, false), 1);
final ModelNode serverModel = Resource.Tools.readModel(context.readResourceFromRoot(serverAddress, false), 1);

final String name = address.getLastElement().getValue();
final List<String> aliases = HostDefinition.ALIAS.unwrap(context, model);
final String defaultWebModule = HostDefinition.DEFAULT_WEB_MODULE.resolveModelAttribute(context, model).asString();
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
final String defaultServerName = UndertowRootDefinition.DEFAULT_SERVER.resolveModelAttribute(context, subsystemModel).asString();
final String defaultHostName = ServerDefinition.DEFAULT_HOST.resolveModelAttribute(context, serverModel).asString();
final String serverName = serverAddress.getLastElement().getValue();
final boolean isDefaultHost = defaultServerName.equals(serverName) && name.equals(defaultHostName);
final ModelNode defaultResponseCode = HostDefinition.DEFAULT_RESPONSE_CODE.resolveModelAttribute(context, model);
final int defaultResponseCode = HostDefinition.DEFAULT_RESPONSE_CODE.resolveModelAttribute(context, model).asInt();

final ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, name);
final Host service = defaultResponseCode.isDefined() ? new Host(name, aliases == null ? new LinkedList<String>()
: aliases, defaultWebModule, defaultResponseCode.asInt()) : new Host(name,
aliases == null ? new LinkedList<String>() : aliases, defaultWebModule);

final Host service = new Host(name, aliases == null ? new LinkedList<>(): aliases, defaultWebModule, defaultResponseCode);
final ServiceBuilder<Host> builder = context.getServiceTarget().addService(virtualHostServiceName, service)
.addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerInjection())
.addDependency(UndertowService.UNDERTOW, UndertowService.class, service.getUndertowService());
Expand Down
Expand Up @@ -55,9 +55,9 @@
</xs:complexType>
<xs:complexType name="serverType">
<xs:sequence>
<xs:element name="ajp-listener" type="ajp-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="http-listener" type="http-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="https-listener" type="https-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ajp-listener" type="ajp-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="host" type="hostType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string"/>
Expand Down
Expand Up @@ -55,9 +55,9 @@
</xs:complexType>
<xs:complexType name="serverType">
<xs:sequence>
<xs:element name="ajp-listener" type="ajp-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="http-listener" type="http-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="https-listener" type="https-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ajp-listener" type="ajp-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="host" type="hostType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string"/>
Expand Down
Expand Up @@ -54,9 +54,9 @@
</xs:complexType>
<xs:complexType name="serverType">
<xs:sequence>
<xs:element name="ajp-listener" type="ajp-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="http-listener" type="http-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="https-listener" type="https-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ajp-listener" type="ajp-listener-type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="host" type="hostType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string"/>
Expand Down
Expand Up @@ -210,7 +210,7 @@
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute name="alias" use="optional" type="xs:string"/>
<xs:attribute name="default-web-module" use="optional" type="xs:string" default="ROOT.war"/>
<xs:attribute name="default-response-code" use="optional" type="xs:int">
<xs:attribute name="default-response-code" use="optional" type="xs:int" default="404">
<xs:annotation>
<xs:documentation>Default response code should be set in case server should respond with nonstandard code( other than 404 ) for unavailable resource.
For instance, server behind load balancer might want to respond with 5xx code to avoid being dropped by it. </xs:documentation>
Expand Down
Expand Up @@ -33,6 +33,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Properties;

import io.undertow.predicate.Predicates;
import io.undertow.server.HttpHandler;
Expand All @@ -56,7 +57,6 @@
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.wildfly.extension.io.BufferPoolService;
import org.wildfly.extension.io.IOServices;
Expand All @@ -71,7 +71,6 @@
*
* @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a>
*/
@Ignore("needs ElementParser impl in core")
public class UndertowSubsystem10TestCase extends AbstractSubsystemBaseTest {

public UndertowSubsystem10TestCase() {
Expand All @@ -83,6 +82,20 @@ protected String getSubsystemXml() throws IOException {
return readResource("undertow-1.0.xml");
}

@Override
protected String getSubsystemXsdPath() throws Exception {
return "schema/wildfly-undertow_1_0.xsd";
}

@Override
protected Properties getResolvedProperties() {
Properties properties = new Properties();
properties.put("jboss.home.dir", System.getProperty("java.io.tmpdir"));
properties.put("jboss.server.server.dir", System.getProperty("java.io.tmpdir"));
properties.put("server.data.dir", System.getProperty("java.io.tmpdir"));
return properties;
}

@Override
protected KernelServices standardSubsystemTest(String configId, boolean compareXml) throws Exception {
return super.standardSubsystemTest(configId, false);
Expand Down
Expand Up @@ -33,6 +33,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Properties;

import io.undertow.predicate.Predicates;
import io.undertow.server.HttpHandler;
Expand All @@ -56,7 +57,6 @@
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.wildfly.extension.io.BufferPoolService;
import org.wildfly.extension.io.IOServices;
Expand All @@ -71,7 +71,6 @@
*
* @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a>
*/
@Ignore("needs ElementParser impl in core")
public class UndertowSubsystem11TestCase extends AbstractSubsystemBaseTest {

public UndertowSubsystem11TestCase() {
Expand All @@ -83,6 +82,21 @@ protected String getSubsystemXml() throws IOException {
return readResource("undertow-1.1.xml");
}

@Override
protected String getSubsystemXsdPath() throws Exception {
return "schema/wildfly-undertow_1_1.xsd";
}

@Override
protected Properties getResolvedProperties() {
Properties properties = new Properties();
properties.put("jboss.home.dir", System.getProperty("java.io.tmpdir"));
properties.put("jboss.server.server.dir", System.getProperty("java.io.tmpdir"));
properties.put("server.data.dir", System.getProperty("java.io.tmpdir"));
return properties;
}


@Override
protected KernelServices standardSubsystemTest(String configId, boolean compareXml) throws Exception {
return super.standardSubsystemTest(configId, false);
Expand Down
Expand Up @@ -33,6 +33,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Properties;

import io.undertow.predicate.Predicates;
import io.undertow.server.HttpHandler;
Expand Down Expand Up @@ -80,6 +81,20 @@ protected String getSubsystemXml() throws IOException {
return readResource("undertow-1.2.xml");
}

@Override
protected String getSubsystemXsdPath() throws Exception {
return "schema/wildfly-undertow_1_2.xsd";
}

@Override
protected Properties getResolvedProperties() {
Properties properties = new Properties();
properties.put("jboss.home.dir", System.getProperty("java.io.tmpdir"));
properties.put("jboss.server.server.dir", System.getProperty("java.io.tmpdir"));
properties.put("server.data.dir", System.getProperty("java.io.tmpdir"));
return properties;
}

@Override
public void testSubsystem() throws Exception {
this.standardSubsystemTest(null, false);
Expand Down
Expand Up @@ -25,6 +25,7 @@

<buffer-caches>
<buffer-cache name="default" buffer-size="1025" buffers-per-region="1054" max-regions="15"/>
<buffer-cache name="extra" buffer-size="1025" buffers-per-region="1054" max-regions="15"/>
</buffer-caches>

<server name="default-server" default-host="other-host" servlet-container="myContainer">
Expand Down
Expand Up @@ -47,7 +47,7 @@
<access-log pattern="REQ %{i,test-header}" directory="${jboss.server.server.dir}" prefix="access"/>
<single-sign-on domain="${prop.domain:myDomain}" http-only="true" secure="true" path="/" cookie-name="SSOID"/>
</host>
<host name="other-host" alias="www.mysite.com" default-web-module="something.war">
<host name="other-host" alias="www.mysite.com" default-web-module="something.war" default-response-code="503">
<location name="/" handler="welcome-content">
<filter-ref name="limit-connections"/>
<filter-ref name="headers"/>
Expand Down

0 comments on commit 55e2d6f

Please sign in to comment.