Skip to content

Commit a654920

Browse files
author
Gregor Tudan
committed
added documentation and only add ozark if a controller is present
1 parent fdcb880 commit a654920

File tree

9 files changed

+95
-76
lines changed

9 files changed

+95
-76
lines changed

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
1-
# Activation
1+
[![Build Status](https://travis-ci.org/gtudan/wildfly-ozark.svg?branch=master)](https://travis-ci.org/gtudan/wildfly-ozark)
22

3-
Activate using the cli:
3+
# About this project
4+
5+
This module adds support for the MVC 1.0 spec to wildfly 10.x by installing the
6+
reference implementation "Ozark".
7+
8+
# Installation
9+
10+
## Installing the Module
11+
12+
Unpack the distribution to the root of your wildfly installation. This will create
13+
a new folder `ozark` in `modules/system/addons/`.
14+
15+
## Activating the subsystem
16+
17+
You can use the jboss-cli to activate the subsystem using these commands:
418

519
```
620
/extension=org.mvc-spec.ozark.wildfly:add(module=org.mvc-spec.ozark.wildfly)
721
/subsystem=mvc:add()
8-
```
22+
```
23+
24+
Or you can directly edit the config file (standalone.xml or domain.xml).
25+
26+
Add this inside the `extensions` tag at the top of the file:
27+
```xml
28+
<extension module="org.mvc-spec.ozark.wildfly"/>
29+
```
30+
31+
Then add the subsystem the profile your using:
32+
33+
```xml
34+
<subsystem xmlns="urn:org.mvc-spec.ozark:mvc:1.0"/>
35+
```
36+
37+
Finally you need to restart the server.
38+
39+
# Using MVC 1.0 in your deployment
40+
41+
The subsystem will automatically add the necessary dependencies to your deployment
42+
if it defects a `@Controller`-annotated class.
43+
44+
All you need is the MVC-API. If you are using Maven, you can add it like this:
45+
46+
```xml
47+
<dependencies>
48+
<!-- ... -->
49+
<dependency>
50+
<groupId>javax.mvc</groupId>
51+
<artifactId>javax.mvc-api</artifactId>
52+
<version>1.0-edr2</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
</dependencies>
56+
```
57+
58+
The API-Package does not depend on the JAX-RS-API, so you will need to add this as well
59+
if you are not using the full Java-EE 7 API package.

src/etc/add-ons/ozark/org/mvc-spec/ozark/wildfly/main/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<module name="org.jboss.msc"/>
1313
<module name="org.jboss.logging"/>
1414
<module name="org.jboss.vfs"/>
15+
<module name="org.jboss.jandex"/>
1516
</dependencies>
1617
</module>

src/main/java/org/mvcspec/ozwark/wildfly/deployment/SubsystemDeploymentProcessor.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
11
package org.mvcspec.ozwark.wildfly.deployment;
22

3-
import org.jboss.as.server.AbstractDeploymentChainStep;
43
import org.jboss.as.server.deployment.*;
4+
import org.jboss.as.server.deployment.annotation.CompositeIndex;
55
import org.jboss.as.server.deployment.module.ModuleDependency;
66
import org.jboss.as.server.deployment.module.ModuleSpecification;
7+
import org.jboss.jandex.AnnotationInstance;
8+
import org.jboss.jandex.DotName;
79
import org.jboss.logging.Logger;
810
import org.jboss.modules.Module;
911
import org.jboss.modules.ModuleIdentifier;
1012
import org.jboss.modules.ModuleLoader;
1113

14+
import java.util.List;
15+
16+
1217
public class SubsystemDeploymentProcessor implements DeploymentUnitProcessor {
1318

1419
private static final ModuleIdentifier MVC_API = ModuleIdentifier.create("javax.mvc.api");
1520
private static final ModuleIdentifier OZARK = ModuleIdentifier.create("org.mvc-spec.ozark.core");
1621
private static final ModuleIdentifier OZARK_RESTEASY = ModuleIdentifier.create("org.mvc-spec.ozark.resteasy");
22+
private static final DotName CONTROLLER = DotName.createSimple("javax.mvc.annotation.Controller");
1723

1824
private final Logger log = Logger.getLogger(SubsystemDeploymentProcessor.class);
1925

20-
/**
21-
* See {@link Phase} for a description of the different phases
22-
*/
2326
public static final Phase PHASE = Phase.DEPENDENCIES;
24-
2527
public static final int PRIORITY = Phase.DEPENDENCIES_JAXRS;
2628

2729
@Override
2830
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
2931
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
30-
log.debugf("Initializing Ozark for deployment {0}", deploymentUnit.getName());
31-
3232
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
3333
final ModuleLoader moduleLoader = Module.getBootModuleLoader();
3434

35-
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, MVC_API, false, false, false, false));
36-
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, OZARK, false, true, true, false));
37-
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, OZARK_RESTEASY, false, true, true, false));
35+
// all modules get the API dependency
36+
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, MVC_API, false, false, false, false));
37+
38+
if (!isMVCDeployment(deploymentUnit)) {
39+
return;
40+
}
41+
42+
log.debugf("Initializing Ozark for deployment %s", deploymentUnit.getName());
43+
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, OZARK, false, false, true, false));
44+
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, OZARK_RESTEASY, false, false, true, false));
45+
}
46+
47+
private boolean isMVCDeployment(DeploymentUnit deploymentUnit) {
48+
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
49+
50+
final List<AnnotationInstance> annotations = index.getAnnotations(CONTROLLER);
51+
return !annotations.isEmpty();
3852
}
3953

4054
@Override

src/main/java/org/mvcspec/ozwark/wildfly/extension/SubsystemAdd.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@ class SubsystemAdd extends AbstractBoottimeAddStepHandler {
1818
private SubsystemAdd() {
1919
}
2020

21-
2221
/**
2322
* {@inheritDoc}
2423
*/
2524
@Override
2625
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
27-
28-
//Add deployment processors here
29-
//Remove this if you don't need to hook into the deployers, or you can add as many as you like
30-
//see SubDeploymentProcessor for explanation of the phases
3126
context.addStep(new AbstractDeploymentChainStep() {
3227
public void execute(DeploymentProcessorTarget processorTarget) {
3328
processorTarget.addDeploymentProcessor(SubsystemExtension.SUBSYSTEM_NAME,
@@ -39,6 +34,4 @@ public void execute(DeploymentProcessorTarget processorTarget) {
3934
}, OperationContext.Stage.RUNTIME);
4035

4136
}
42-
43-
4437
}

src/main/java/org/mvcspec/ozwark/wildfly/extension/SubsystemDefinition.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@
33
import org.jboss.as.controller.SimpleResourceDefinition;
44
import org.jboss.as.controller.registry.ManagementResourceRegistration;
55

6-
/**
7-
* @author <a href="mailto:tcerar@redhat.com">Tomaz Cerar</a>
8-
*/
96
public class SubsystemDefinition extends SimpleResourceDefinition {
10-
public static final SubsystemDefinition INSTANCE = new SubsystemDefinition();
7+
static final SubsystemDefinition INSTANCE = new SubsystemDefinition();
118

129
private SubsystemDefinition() {
1310
super(SubsystemExtension.SUBSYSTEM_PATH,
1411
SubsystemExtension.getResourceDescriptionResolver(null),
15-
//We always need to add an 'add' operation
1612
SubsystemAdd.INSTANCE,
17-
//Every resource that is added, normally needs a remove operation
1813
SubsystemRemove.INSTANCE);
1914
}
2015

2116
@Override
2217
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
2318
super.registerOperations(resourceRegistration);
24-
//you can register additional operations here
2519
}
2620

2721
@Override
2822
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
29-
//you can register attributes here
3023
}
3124
}

src/main/java/org/mvcspec/ozwark/wildfly/extension/SubsystemExtension.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@
2727
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
2828
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
2929

30-
31-
/**
32-
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
33-
*/
3430
public class SubsystemExtension implements Extension {
3531

3632
/**
3733
* The name space used for the {@code subsystem} element
3834
*/
39-
public static final String NAMESPACE = "urn:org.mvc-spec.ozark:mvc:1.0";
35+
static final String NAMESPACE = "urn:org.mvc-spec.ozark:mvc:1.0";
4036

4137
/**
4238
* The name of our subsystem within the model.
4339
*/
44-
public static final String SUBSYSTEM_NAME = "mvc";
40+
static final String SUBSYSTEM_NAME = "mvc";
4541

4642
/**
4743
* The parser used for parsing our subsystem
@@ -88,8 +84,7 @@ private static class SubsystemParser implements XMLStreamConstants, XMLElementRe
8884
*/
8985
@Override
9086
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
91-
context.startSubsystemElement(SubsystemExtension.NAMESPACE, false);
92-
writer.writeEndElement();
87+
context.startSubsystemElement(SubsystemExtension.NAMESPACE, true);
9388
}
9489

9590
/**

src/main/java/org/mvcspec/ozwark/wildfly/extension/SubsystemRemove.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@
55
import org.jboss.as.controller.OperationFailedException;
66
import org.jboss.dmr.ModelNode;
77

8-
/**
9-
* Handler responsible for removing the subsystem resource from the model
10-
*
11-
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
12-
*/
138
class SubsystemRemove extends AbstractRemoveStepHandler {
149

1510
static final SubsystemRemove INSTANCE = new SubsystemRemove();
1611

17-
1812
private SubsystemRemove() {
1913
}
2014

2115
@Override
2216
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
23-
//Remove any services installed by the corresponding add handler here
24-
//context.removeService(ServiceName.of("some", "name"));
17+
// nothing to do here
2518
}
2619

2720

src/test/java/org/mvcspec/ozwark/wildfly/extension/SubsystemBaseParsingTestCase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ public SubsystemBaseParsingTestCase() {
1616
super(SubsystemExtension.SUBSYSTEM_NAME, new SubsystemExtension());
1717
}
1818

19-
2019
@Override
2120
protected String getSubsystemXml() throws IOException {
22-
return "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
23-
"</subsystem>";
21+
return "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\"/>";
2422
}
2523

2624
}

src/test/java/org/mvcspec/ozwark/wildfly/extension/SubsystemParsingTestCase.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
import org.junit.Assert;
1717
import org.junit.Test;
1818

19-
20-
/**
21-
* Tests all management expects for subsystem, parsing, marshaling, model definition and other
22-
* Here is an example that allows you a fine grained controler over what is tested and how. So it can give you ideas what can be done and tested.
23-
* If you have no need for advanced testing of subsystem you look at {@link SubsystemBaseParsingTestCase} that testes same stuff but most of the code
24-
* is hidden inside of test harness
25-
*
26-
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
27-
*/
2819
public class SubsystemParsingTestCase extends AbstractSubsystemTest {
2920

3021
public SubsystemParsingTestCase() {
@@ -37,9 +28,7 @@ public SubsystemParsingTestCase() {
3728
@Test
3829
public void testParseSubsystem() throws Exception {
3930
//Parse the subsystem xml into operations
40-
String subsystemXml =
41-
"<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
42-
"</subsystem>";
31+
String subsystemXml = "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\"/>";
4332
List<ModelNode> operations = super.parse(subsystemXml);
4433

4534
///Check that we have the expected number of operations
@@ -48,9 +37,9 @@ public void testParseSubsystem() throws Exception {
4837
//Check that each operation has the correct content
4938
ModelNode addSubsystem = operations.get(0);
5039
Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
51-
PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
52-
Assert.assertEquals(1, addr.size());
53-
PathElement element = addr.getElement(0);
40+
PathAddress address = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
41+
Assert.assertEquals(1, address.size());
42+
PathElement element = address.getElement(0);
5443
Assert.assertEquals(SUBSYSTEM, element.getKey());
5544
Assert.assertEquals(SubsystemExtension.SUBSYSTEM_NAME, element.getValue());
5645
}
@@ -61,9 +50,7 @@ public void testParseSubsystem() throws Exception {
6150
@Test
6251
public void testInstallIntoController() throws Exception {
6352
//Parse the subsystem xml and install into the controller
64-
String subsystemXml =
65-
"<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
66-
"</subsystem>";
53+
String subsystemXml = "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\"/>";
6754
KernelServices services = super.createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
6855

6956
//Read the whole model and make sure it looks as expected
@@ -73,21 +60,19 @@ public void testInstallIntoController() throws Exception {
7360

7461
/**
7562
* Starts a controller with a given subsystem xml and then checks that a second
76-
* controller started with the xml marshalled from the first one results in the same model
63+
* controller started with the xml marshaled from the first one results in the same model
7764
*/
7865
@Test
7966
public void testParseAndMarshalModel() throws Exception {
8067
//Parse the subsystem xml and install into the first controller
81-
String subsystemXml =
82-
"<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
83-
"</subsystem>";
68+
String subsystemXml = "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\"/>";
8469
KernelServices servicesA = super.createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
8570
//Get the model and the persisted xml from the first controller
8671
ModelNode modelA = servicesA.readWholeModel();
87-
String marshalled = servicesA.getPersistedSubsystemXml();
72+
String marshaled = servicesA.getPersistedSubsystemXml();
8873

8974
//Install the persisted xml from the first controller into a second controller
90-
KernelServices servicesB = super.createKernelServicesBuilder(null).setSubsystemXml(marshalled).build();
75+
KernelServices servicesB = super.createKernelServicesBuilder(null).setSubsystemXml(marshaled).build();
9176
ModelNode modelB = servicesB.readWholeModel();
9277

9378
//Make sure the models from the two controllers are identical
@@ -100,13 +85,9 @@ public void testParseAndMarshalModel() throws Exception {
10085
@Test
10186
public void testSubsystemRemoval() throws Exception {
10287
//Parse the subsystem xml and install into the first controller
103-
String subsystemXml =
104-
"<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
105-
"</subsystem>";
88+
String subsystemXml = "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\"/>";
10689
KernelServices services = super.createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
10790
//Checks that the subsystem was removed from the model
10891
super.assertRemoveSubsystemResources(services);
109-
110-
//TODO Chek that any services that were installed were removed here
11192
}
11293
}

0 commit comments

Comments
 (0)