This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from tsegismont/bug/1311140
Bug 1311140 - EAP7 - missing rt filter modules for eap7
- Loading branch information
Showing
16 changed files
with
883 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ RHQ Management Platform | ||
~ Copyright 2016, Red Hat Middleware LLC, and individual contributors | ||
~ as indicated by the @author tags. See the copyright.txt file in the | ||
~ distribution for a full listing of individual contributors. | ||
~ | ||
~ This program is free software; you can redistribute it and/or modify | ||
~ it under the terms of the GNU General Public License as published by | ||
~ the Free Software Foundation version 2 of the License. | ||
~ | ||
~ This program is distributed in the hope that it will be useful, | ||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
~ GNU General Public License for more details. | ||
~ | ||
~ You should have received a copy of the GNU General Public License along | ||
~ with this program; if not, write to the Free Software Foundation, Inc., | ||
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.rhq.helpers</groupId> | ||
<artifactId>rhq-helpers</artifactId> | ||
<version>4.14.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rhq-rtfilter-wfly-10-subsystem</artifactId> | ||
|
||
<name>RHQ Response-Time Filter - Wildfly 10 Subsystem</name> | ||
|
||
<properties> | ||
<version.wildfly>10.0.0.Final</version.wildfly> | ||
<version.wildfly.core>2.0.10.Final</version.wildfly.core> | ||
<moduleName>${project.groupId}.${project.artifactId}</moduleName> | ||
</properties> | ||
|
||
|
||
<build> | ||
|
||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
|
||
<plugins> | ||
|
||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<descriptors> | ||
<descriptor>src/main/scripts/module-assembly.xml</descriptor> | ||
</descriptors> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>module-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.wildfly.core</groupId> | ||
<artifactId>wildfly-controller</artifactId> | ||
<version>${version.wildfly.core}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wildfly</groupId> | ||
<artifactId>wildfly-undertow</artifactId> | ||
<version>${version.wildfly}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rhq.helpers</groupId> | ||
<artifactId>rhq-rtfilter</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
211 changes: 211 additions & 0 deletions
211
...-subsystem/src/main/java/org/rhq/helpers/rtfilter/subsystem/wfly10/RtFilterExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* | ||
* RHQ Management Platform | ||
* Copyright 2016, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
package org.rhq.helpers.rtfilter.subsystem.wfly10; | ||
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*; | ||
|
||
import java.util.*; | ||
|
||
import javax.xml.stream.XMLStreamConstants; | ||
import javax.xml.stream.XMLStreamException; | ||
|
||
import org.jboss.as.controller.*; | ||
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; | ||
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; | ||
import org.jboss.as.controller.parsing.ExtensionParsingContext; | ||
import org.jboss.as.controller.parsing.ParseUtils; | ||
import org.jboss.as.controller.persistence.SubsystemMarshallingContext; | ||
import org.jboss.as.controller.registry.ManagementResourceRegistration; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.staxmapper.XMLElementReader; | ||
import org.jboss.staxmapper.XMLElementWriter; | ||
import org.jboss.staxmapper.XMLExtendedStreamReader; | ||
import org.jboss.staxmapper.XMLExtendedStreamWriter; | ||
|
||
/** | ||
* @author Thomas Segismont | ||
*/ | ||
public class RtFilterExtension implements Extension { | ||
|
||
/** | ||
* The name space used for the {@code subsystem} element | ||
*/ | ||
public static final String NAMESPACE = "urn:rhq:rtfilter:1.0"; | ||
|
||
/** | ||
* The name of our subsystem within the model. | ||
*/ | ||
public static final String SUBSYSTEM_NAME = "rhq-rtfilter"; | ||
|
||
private final SubsystemReader reader = new SubsystemReader(); | ||
private final SubsystemWriter writer = new SubsystemWriter(); | ||
|
||
protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); | ||
private static final String RESOURCE_NAME = RtFilterExtension.class.getPackage().getName() + ".LocalDescriptions"; | ||
|
||
public static final Map<String, String> INIT_PARAMS = new LinkedHashMap<String, String>(); | ||
|
||
public static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) { | ||
String prefix = SUBSYSTEM_NAME + (keyPrefix == null ? "" : "." + keyPrefix); | ||
return new StandardResourceDescriptionResolver(prefix, RESOURCE_NAME, RtFilterExtension.class.getClassLoader(), | ||
true, false); | ||
} | ||
|
||
@Override | ||
public void initializeParsers(ExtensionParsingContext context) { | ||
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, NAMESPACE, reader); | ||
} | ||
|
||
@Override | ||
public void initialize(ExtensionContext context) { | ||
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, ModelVersion.create(1)); | ||
final ManagementResourceRegistration registration = subsystem | ||
.registerSubsystemModel(RtFilterSubsystemDefinition.INSTANCE); | ||
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, | ||
GenericSubsystemDescribeHandler.INSTANCE); | ||
subsystem.registerXMLElementWriter(writer); | ||
} | ||
|
||
/** | ||
* The subsystem reader, which uses STAX to read the subsystem XML. | ||
*/ | ||
private static class SubsystemReader implements XMLStreamConstants, XMLElementReader<List<ModelNode>> { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { | ||
INIT_PARAMS.clear(); | ||
|
||
// Parse the 'subsystem' element... | ||
ParseUtils.requireNoAttributes(reader); | ||
|
||
list.add(createAddSubsystemOperation()); | ||
|
||
// Read the child elements | ||
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { | ||
if (reader.getLocalName().equals("init-param")) { | ||
readInitParam(reader); | ||
} else { | ||
throw ParseUtils.unexpectedElement(reader); | ||
} | ||
// TODO: Add support for configuring filter mappings. | ||
} | ||
} | ||
|
||
private void readInitParam(XMLExtendedStreamReader reader) throws XMLStreamException { | ||
String id = null; | ||
for (int i = 0; i < reader.getAttributeCount(); i++) { | ||
if (reader.getAttributeLocalName(i).equals("id")) { | ||
if (id != null) { | ||
throw ParseUtils.unexpectedAttribute(reader, i); | ||
} | ||
id = reader.getAttributeValue(i); | ||
} else { | ||
throw ParseUtils.unexpectedAttribute(reader, i); | ||
} | ||
} | ||
|
||
String description = null; | ||
String paramName = null; | ||
String paramValue = null; | ||
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { | ||
if (reader.isStartElement()) { | ||
if (reader.getLocalName().equals("description")) { | ||
if (description != null) { | ||
throw ParseUtils.unexpectedElement(reader); | ||
} | ||
description = reader.getElementText(); | ||
} else if (reader.getLocalName().equals("param-name")) { | ||
if (paramName != null) { | ||
throw ParseUtils.unexpectedElement(reader); | ||
} | ||
paramName = reader.getElementText(); | ||
} else if (reader.getLocalName().equals("param-value")) { | ||
if (paramValue != null) { | ||
throw ParseUtils.unexpectedElement(reader); | ||
} | ||
paramValue = reader.getElementText(); | ||
} else { | ||
throw ParseUtils.unexpectedElement(reader); | ||
} | ||
} | ||
} | ||
|
||
Set<String> missingRequiredElements = new HashSet<String>(); | ||
if (paramName == null) { | ||
missingRequiredElements.add("param-name"); | ||
} | ||
if (paramValue == null) { | ||
missingRequiredElements.add("param-value"); | ||
} | ||
if (!missingRequiredElements.isEmpty()) { | ||
throw ParseUtils.missingRequiredElement(reader, missingRequiredElements); | ||
} | ||
|
||
// There's no need for us to expose the init params via the AS7 management model. Just store them in a | ||
// static Map that RtFilterDeploymentUnitProcessor will be able to access. | ||
INIT_PARAMS.put(paramName, paramValue); | ||
} | ||
|
||
private static ModelNode createAddSubsystemOperation() { | ||
final ModelNode subsystem = new ModelNode(); | ||
subsystem.get(OP).set(ADD); | ||
subsystem.get(OP_ADDR).add(SUBSYSTEM, SUBSYSTEM_NAME); | ||
return subsystem; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* The subsystem writer, which uses STAX to write the subsystem XML. | ||
*/ | ||
private static class SubsystemWriter implements XMLStreamConstants, XMLElementWriter<SubsystemMarshallingContext> { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) | ||
throws XMLStreamException { | ||
context.startSubsystemElement(RtFilterExtension.NAMESPACE, false); | ||
|
||
for (String paramName : INIT_PARAMS.keySet()) { | ||
writer.writeStartElement("init-param"); | ||
|
||
writer.writeStartElement("param-name"); | ||
writer.writeCharacters(paramName); | ||
writer.writeEndElement(); // param-name | ||
|
||
writer.writeStartElement("param-value"); | ||
String paramValue = INIT_PARAMS.get(paramName); | ||
writer.writeCharacters(paramValue); | ||
writer.writeEndElement(); // param-value | ||
|
||
writer.writeEndElement(); // init-param | ||
} | ||
|
||
writer.writeEndElement(); // subsystem | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.