This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-extensions-slf4j-mdc.git
commit 33dd2f7db81c1b4d1251b08c49cfb2e0d832b0f2 Author: Bertrand Delacretaz <[email protected]> AuthorDate: Tue Oct 15 13:28:59 2013 +0000 SLING-3048 - tests, contributed by Chetan Mehrotra, thanks! git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1532328 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 379 +++++++++++++++++---- .../extensions/mdc/integration/ITMDCFilter.java | 133 ++++++++ .../mdc/integration/ServerConfiguration.java | 129 +++++++ .../mdc/integration/servlet/MDCStateServlet.java | 79 +++++ 4 files changed, 660 insertions(+), 60 deletions(-) diff --git a/pom.xml b/pom.xml index 082a767..e254998 100644 --- a/pom.xml +++ b/pom.xml @@ -38,68 +38,327 @@ from requests and adds them to the MDC </description> - <build> + <properties> + <pax-exam.version>3.0.0</pax-exam.version> + <bundle.build.name> + ${basedir}/target + </bundle.build.name> + <bundle.file.name> + ${bundle.build.name}/${project.build.finalName}.jar + </bundle.file.name> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Embed-Dependency> + org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class + </Embed-Dependency> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + + <!-- Required for pax exam--> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.8</version> + <executions> + <execution> + <id>reserve-network-port</id> + <goals> + <goal>reserve-network-port</goal> + </goals> + <phase>pre-integration-test</phase> + <configuration> + <portNames> + <portName>http.port</portName> + </portNames> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>properties-maven-plugin</artifactId> + <version>1.0-alpha-2</version> + <executions> + <execution> + <goals> + <goal>set-system-properties</goal> + </goals> + <phase>pre-integration-test</phase> + <configuration> + <properties> + <property> + <name>project.bundle.file</name> + <value>${bundle.file.name}</value> + </property> + <property> + <name>http.port</name> + <value>${http.port}</value> + </property> + </properties> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.servicemix.tooling</groupId> + <artifactId>depends-maven-plugin</artifactId> + <version>1.2</version> + <executions> + <execution> + <id>generate-depends-file</id> + <goals> + <goal>generate-depends-file</goal> + </goals> + </execution> + </executions> + </plugin> + <!-- integration tests run with pax-exam --> + <plugin> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.12</version> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + <configuration> + <systemPropertyVariables> + <coverage.command>${coverage.command}</coverage.command> + <http.port>${http.port}</http.port> + <project.bundle.file>${bundle.file.name}</project.bundle.file> + </systemPropertyVariables> + <forkMode>always</forkMode> + <parallel>none</parallel> + <threadCount>1</threadCount> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <version>4.2.0</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <version>4.2.0</version> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.osgi</artifactId> + <version>2.2.0</version> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.1.0</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + + <!-- testing --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + <version>4.10</version> + </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20070829</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + </dependency> + <!-- Pax Exam Dependencies --> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-forked</artifactId> + <version>${pax-exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> + <version>${pax-exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-link-mvn</artifactId> + <version>${pax-exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.url</groupId> + <artifactId>pax-url-wrap</artifactId> + <version>1.5.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.configadmin</artifactId> + <version>1.6.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.http.jetty</artifactId> + <version>2.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.http.whiteboard</artifactId> + <version>2.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr</artifactId> + <version>1.6.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.tools</artifactId> + <version>1.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <version>4.0.2</version> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <!-- + copy the package such that IDEs may easily use it without + setting the system property + --> + <profile> + <id>ide</id> + <build> <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>scr-file-create</id> + <phase>package</phase> + <goals> + <goal>run</goal> + </goals> <configuration> - <instructions> - <Embed-Dependency> - org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class - </Embed-Dependency> - </instructions> + <target> + <copy file="${project.build.directory}/${project.build.finalName}.jar" tofile="${project.build.directory}/mdcfilter.jar" /> + </target> </configuration> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> + </execution> + </executions> + </plugin> </plugins> - </build> - - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <version>4.2.0</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <version>4.2.0</version> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.osgi</artifactId> - <version>2.2.0</version> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.api</artifactId> - <version>2.1.0</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - <version>2.0</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - </dependencies> + </build> + </profile> + <profile> + <id>coverage</id> + <build> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.6.2.201302030002</version> + <executions> + <execution> + <id>prepare-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + <configuration> + <propertyName>coverage.command</propertyName> + <includes> + <include>org.apache.sling.extensions.mdc.internal.*</include> + </includes> + </configuration> + </execution> + <execution> + <id>report</id> + <phase>post-integration-test</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + <execution> + <id>check</id> + <goals> + <goal>check</goal> + </goals> + <configuration> + <skip>true</skip> + <check> + <classRatio>100</classRatio> + <instructionRatio>90</instructionRatio> + <methodRatio>95</methodRatio> + <branchRatio>85</branchRatio> + <complexityRatio>85</complexityRatio> + <lineRatio>90</lineRatio> + </check> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> diff --git a/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java b/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java new file mode 100644 index 0000000..adda35b --- /dev/null +++ b/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.extensions.mdc.integration; + +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.cookie.BasicClientCookie; +import org.apache.sling.testing.tools.http.Request; +import org.apache.sling.testing.tools.http.RequestBuilder; +import org.apache.sling.testing.tools.http.RequestCustomizer; +import org.apache.sling.testing.tools.http.RequestExecutor; +import org.apache.sling.testing.tools.retry.RetryLoop; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.ops4j.pax.exam.ExamSystem; +import org.ops4j.pax.exam.TestContainer; +import org.ops4j.pax.exam.spi.DefaultExamSystem; +import org.ops4j.pax.exam.spi.PaxExamRuntime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static junit.framework.Assert.assertNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +public class ITMDCFilter { + private static Logger log = LoggerFactory.getLogger(ITMDCFilter.class); + private static TestContainer testContainer; + + private DefaultHttpClient httpClient = new DefaultHttpClient(); + private RequestExecutor executor = new RequestExecutor(httpClient); + + @Before + public void startContainer() throws Exception { + if (testContainer == null) { + ServerConfiguration sc = new ServerConfiguration(); + ExamSystem system = DefaultExamSystem.create(sc.config()); + testContainer = PaxExamRuntime.createContainer(system); + testContainer.start(); + new RetryLoop(new RetryLoop.Condition() { + public String getDescription() { + return "Check if MDCTestServlet is up"; + } + + public boolean isTrue() throws Exception { + RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl()); + executor.execute(rb.buildGetRequest("/mdc")).assertStatus(200); + return true; + } + },5,100); + } + } + + @Test + public void testDefault() throws Exception{ + RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl()); + // Add Sling POST options + RequestExecutor result = executor.execute( + rb.buildGetRequest("/mdc","foo","bar")); + + JSONObject jb = new JSONObject(result.getContent()); + assertEquals("/mdc", jb.getString("req.requestURI")); + assertEquals("foo=bar", jb.getString("req.queryString")); + assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL")); + log.info("Response {}",result.getContent()); + } + + @Test + public void testWihCustomData() throws Exception{ + RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl()); + + //Create test config via servlet + executor.execute(rb.buildGetRequest("/mdc", "createTestConfig", "true")); + TimeUnit.SECONDS.sleep(1); + + //Pass custom cookie + BasicClientCookie cookie = new BasicClientCookie("mdc-test-cookie", "foo-test-cookie"); + cookie.setPath("/"); + cookie.setDomain("localhost"); + httpClient.getCookieStore().addCookie(cookie); + + //Execute request + RequestExecutor result = executor.execute( + rb.buildGetRequest("/mdc", "mdc-test-param", "foo-test-param", "ignored-param", "ignored-value") + .withHeader("X-Forwarded-For", "foo-forwarded-for") + .withHeader("mdc-test-header", "foo-test-header") + ); + + JSONObject jb = new JSONObject(result.getContent()); + log.info("Response {}",result.getContent()); + + assertEquals("/mdc", jb.getString("req.requestURI")); + assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL")); + assertEquals("foo-forwarded-for", jb.getString("req.xForwardedFor")); + assertEquals("foo-test-header", jb.getString("mdc-test-header")); + assertEquals("foo-test-param", jb.getString("mdc-test-param")); + assertEquals("foo-test-cookie", jb.getString("mdc-test-cookie")); + + //Only configured params must be returned + assertFalse(jb.has("ignored-param")); + } + + + @AfterClass + public static void stopContainer() { + if (testContainer != null) { + testContainer.stop(); + testContainer = null; + } + } +} diff --git a/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java b/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java new file mode 100644 index 0000000..95f7156 --- /dev/null +++ b/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.extensions.mdc.integration; + +import org.apache.sling.extensions.mdc.integration.servlet.MDCStateServlet; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.OptionUtils; +import org.ops4j.pax.tinybundles.core.TinyBundle; +import org.osgi.framework.Constants; + +import java.io.File; + +import static org.ops4j.pax.exam.CoreOptions.cleanCaches; +import static org.ops4j.pax.exam.CoreOptions.frameworkProperty; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.provision; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; +import static org.ops4j.pax.exam.CoreOptions.wrappedBundle; +import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle; +import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd; + +public class ServerConfiguration { + + // the name of the system property providing the bundle file to be installed and tested + protected static final String BUNDLE_JAR_SYS_PROP = "project.bundle.file"; + + // the name of the system property which captures the jococo coverage agent command + //if specified then agent would be specified otherwise ignored + protected static final String COVERAGE_COMMAND = "coverage.command"; + + //Name of the property for port of server + public static final String HTTP_PORT_PROP = "http.port"; + + public static final String HTTP_SERVER__URL_PROP = "serverUrl"; + + // the default bundle jar file name + protected static final String BUNDLE_JAR_DEFAULT = "BUNDLE_JAR_NOT_SPECIFIED"; + + // the JVM option to set to enable remote debugging + @SuppressWarnings("UnusedDeclaration") + protected static final String DEBUG_VM_OPTION = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=31313"; + + // the actual JVM option set, extensions may implement a static + // initializer overwriting this value to have the configuration() + // method include it when starting the OSGi framework JVM + protected static String paxRunnerVmOption = null; +// protected static String paxRunnerVmOption = DEBUG_VM_OPTION; + + protected static String DEFAULT_PORT = "8080"; + + @Configuration + public Option[] config() { + final String bundleFileName = System.getProperty(BUNDLE_JAR_SYS_PROP, + BUNDLE_JAR_DEFAULT); + final File bundleFile = new File(bundleFileName); + if (!bundleFile.canRead()) { + throw new IllegalArgumentException("Cannot read from bundle file " + + bundleFileName + " specified in the " + BUNDLE_JAR_SYS_PROP + + " system property"); + } + Option[] base = options( + // the current project (the bundle under test) + CoreOptions.bundle(bundleFile.toURI().toString()), + mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.7.0").startLevel(2), + mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.7.0").startLevel(2), + mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject(), + mavenBundle("org.apache.felix", "org.apache.felix.http.jetty").versionAsInProject().startLevel(3), + mavenBundle("org.apache.felix", "org.apache.felix.http.whiteboard").versionAsInProject().startLevel(5), + mavenBundle("org.apache.felix", "org.apache.felix.scr").versionAsInProject(), + wrappedBundle(mavenBundle("org.json", "json").versionAsInProject()), + systemProperty("pax.exam.osgi.unresolved.fail").value("fail"), + systemProperty("org.osgi.service.http.port").value(getServerPort()), + cleanCaches(), + createTestBundle(), + addCodeCoverageOption()); + final Option vmOption = (paxRunnerVmOption != null) ? CoreOptions.vmOption(paxRunnerVmOption) + : null; + return OptionUtils.combine(base, vmOption); + } + + private Option createTestBundle() { + TinyBundle bundle = bundle() + .add(MDCStateServlet.class) + .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.sling.extensions.slf4j.mdc.testbundle") + .set(Constants.BUNDLE_ACTIVATOR , MDCStateServlet.class.getName()); + return provision(bundle.build(withBnd())); + } + + private static String getServerPort() { + return System.getProperty(HTTP_PORT_PROP, DEFAULT_PORT); + } + + private Option addCodeCoverageOption() { + String coverageCommand = System.getProperty(COVERAGE_COMMAND); + if (coverageCommand != null) { + return CoreOptions.vmOption(coverageCommand); + } + return null; + } + + public static String getServerUrl() { + String serverUrl = System.getProperty(HTTP_SERVER__URL_PROP); + if (serverUrl != null) { + return serverUrl; + } + + return String.format("http://localhost:%s", getServerPort()); + } +} diff --git a/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java b/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java new file mode 100644 index 0000000..e86d5ef --- /dev/null +++ b/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.extensions.mdc.integration.servlet; + +import org.json.JSONObject; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.util.tracker.ServiceTracker; +import org.slf4j.MDC; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.Properties; + +public class MDCStateServlet extends HttpServlet implements BundleActivator{ + private ServiceTracker configAdminTracker; + + public void start(BundleContext context) throws Exception { + Properties p = new Properties(); + p.setProperty("alias","/mdc"); + context.registerService(Servlet.class.getName(),this,p); + configAdminTracker = new ServiceTracker(context, ConfigurationAdmin.class.getName(),null); + configAdminTracker.open(); + } + + public void stop(BundleContext context) throws Exception { + + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + + if(req.getParameter("createTestConfig") != null){ + createTestConfig(); + pw.print("created"); + return; + } + + JSONObject jb = new JSONObject(MDC.getCopyOfContextMap()); + pw.print(jb.toString()); + } + + private void createTestConfig() throws IOException { + ConfigurationAdmin ca = (ConfigurationAdmin) configAdminTracker.getService(); + Configuration cfg = ca.getConfiguration("org.apache.sling.extensions.mdc.internal.MDCInsertingFilter",null); + + Dictionary<String,Object> dict = new Hashtable<String, Object>(); + dict.put("headers",new String[]{"mdc-test-header"}); + dict.put("parameters",new String[]{"mdc-test-param"}); + dict.put("cookies",new String[]{"mdc-test-cookie"}); + cfg.update(dict); + } +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
