457696 - JMX implementation should not be overridden by WebApp classes
+ Adding integration tests for the jmx issues
This commit is contained in:
parent
3f08e54a23
commit
7d88ce8f27
|
@ -48,5 +48,6 @@
|
|||
<module>test-loginservice</module>
|
||||
<module>test-integration</module>
|
||||
<module>test-quickstart</module>
|
||||
<module>test-jmx</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
//
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
-->
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-jmx-parent</artifactId>
|
||||
<version>9.2.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jmx-webapp-it</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jetty Tests :: JMX :: WebApp Integration Tests</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<bundle-symbolic-name>${project.groupId}.jmx.webapp.it</bundle-symbolic-name>
|
||||
<scripts-dir>${project.basedir}/src/test/scripts</scripts-dir>
|
||||
<test-base-dir>${project.build.directory}/test-base</test-base-dir>
|
||||
<test-home-dir>${project.build.directory}/test-home</test-home-dir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-distribution</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>zip</type>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jmx-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-apps-for-testing</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeArtifactIds>jmx-webapp</includeArtifactIds>
|
||||
<includeScope>runtime</includeScope>
|
||||
<includeTypes>war</includeTypes>
|
||||
<overwriteSnapshots>true</overwriteSnapshots>
|
||||
<overwriteReleases>true</overwriteReleases>
|
||||
<stripVersion>true</stripVersion>
|
||||
<outputDirectory>${test-base-dir}/webapps</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>unpack-jetty-distro</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeArtifactIds>jetty-distribution</includeArtifactIds>
|
||||
<includeScope>runtime</includeScope>
|
||||
<includeTypes>zip</includeTypes>
|
||||
<outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
|
||||
<outputDirectory>${test-home-dir}</outputDirectory>
|
||||
<overWriteSnapshots>true</overWriteSnapshots>
|
||||
<overWriteIfNewer>true</overWriteIfNewer>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.17</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<property name="jetty.home" location="${test-home-dir}/jetty-distribution-${project.version}"/>
|
||||
<property name="jetty.base" location="${test-base-dir}"/>
|
||||
<echo>Integration Test : Setup Jetty</echo>
|
||||
<exec executable="${run.command}"
|
||||
dir="${scripts-dir}"
|
||||
spawn="false">
|
||||
<arg value="${run.command.xtra}"/>
|
||||
<arg value="${setup.script}"/>
|
||||
<arg file="${java.home}"/>
|
||||
<arg file="${jetty.home}"/>
|
||||
<arg file="${jetty.base}"/>
|
||||
</exec>
|
||||
|
||||
<echo>Integration Test : Starting Jetty ...</echo>
|
||||
<exec executable="${run.command}"
|
||||
dir="${scripts-dir}"
|
||||
spawn="true">
|
||||
<arg value="${run.command.xtra}"/>
|
||||
<arg value="${start.script}"/>
|
||||
<arg file="${java.home}"/>
|
||||
<arg file="${jetty.home}"/>
|
||||
<arg file="${jetty.base}"/>
|
||||
</exec>
|
||||
<waitfor maxwait="5" maxwaitunit="second"
|
||||
checkevery="100" checkeveryunit="millisecond">
|
||||
<http url="http://localhost:58080/jmx-webapp/"/>
|
||||
</waitfor>
|
||||
<echo>Integration Test : Jetty is now available</echo>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<property name="jetty.home" location="${test-home-dir}/jetty-distribution-${project.version}"/>
|
||||
<property name="jetty.base" location="${test-base-dir}"/>
|
||||
<echo>Integration Test : Stop Jetty</echo>
|
||||
<exec executable="${run.command}"
|
||||
dir="${scripts-dir}"
|
||||
spawn="false">
|
||||
<arg value="${run.command.xtra}"/>
|
||||
<arg value="${stop.script}"/>
|
||||
<arg file="${java.home}"/>
|
||||
<arg file="${jetty.home}"/>
|
||||
<arg file="${jetty.base}"/>
|
||||
</exec>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>it-windows</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>Windows</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<run.command>cmd</run.command>
|
||||
<run.command.xtra>/c</run.command.xtra>
|
||||
<start.script>start-jetty.bat</start.script>
|
||||
<stop.script>stop-jetty.bat</stop.script>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>it-unix</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>unix</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<run.command>sh</run.command>
|
||||
<run.command.xtra>--</run.command.xtra>
|
||||
<setup.script>setup-jetty.sh</setup.script>
|
||||
<start.script>start-jetty.sh</start.script>
|
||||
<stop.script>stop-jetty.sh</stop.script>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,144 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.management.AttributeNotFoundException;
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.ReflectionException;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Some JMX information tests.
|
||||
*/
|
||||
public class JmxIT
|
||||
{
|
||||
private static JMXConnector jmxc;
|
||||
private static MBeanServerConnection mbsc;
|
||||
|
||||
@BeforeClass
|
||||
public static void connectToMBeanServer() throws IOException
|
||||
{
|
||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi");
|
||||
jmxc = JMXConnectorFactory.connect(url,null);
|
||||
mbsc = jmxc.getMBeanServerConnection();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void disconnectFromMBeanServer() throws IOException
|
||||
{
|
||||
jmxc.close();
|
||||
}
|
||||
|
||||
private String getStringAttribute(ObjectName objName, String attrName) throws Exception
|
||||
{
|
||||
Object val = mbsc.getAttribute(objName,attrName);
|
||||
assertThat(attrName,val,notNullValue());
|
||||
assertThat(attrName,val,instanceOf(String.class));
|
||||
return (String)val;
|
||||
}
|
||||
|
||||
private int getIntegerAttribute(ObjectName objName, String attrName) throws Exception
|
||||
{
|
||||
Object val = mbsc.getAttribute(objName,attrName);
|
||||
assertThat(attrName,val,notNullValue());
|
||||
assertThat(attrName,val,instanceOf(Integer.class));
|
||||
return (Integer)val;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObtainRunningServerVersion() throws Exception
|
||||
{
|
||||
ObjectName serverName = new ObjectName("org.eclipse.jetty.server:type=server,id=0");
|
||||
String version = getStringAttribute(serverName,"version");
|
||||
System.err.println("Running version: " + version);
|
||||
assertThat("Version",version,startsWith("9.2."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObtainJmxWebAppState() throws Exception
|
||||
{
|
||||
ObjectName webappName = new ObjectName("org.eclipse.jetty.webapp:context=jmx-webapp,type=webappcontext,id=0");
|
||||
|
||||
String contextPath = getStringAttribute(webappName,"contextPath");
|
||||
String displayName = getStringAttribute(webappName,"displayName");
|
||||
|
||||
assertThat("Context Path",contextPath,is("/jmx-webapp"));
|
||||
assertThat("Display Name",displayName,is("Test JMX WebApp"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for directly annotated POJOs in the JMX tree
|
||||
*/
|
||||
@Test
|
||||
public void testAccessToCommonComponent() throws Exception
|
||||
{
|
||||
ObjectName commonName = new ObjectName("org.eclipse.jetty.test.jmx:type=commoncomponent,context=jmx-webapp,id=0");
|
||||
String name = getStringAttribute(commonName,"name");
|
||||
assertThat("Name",name,is("i am common"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for POJO (not annotated) that is supplemented with a MBean that
|
||||
* declares the annotations.
|
||||
*/
|
||||
@Test
|
||||
public void testAccessToPingerMBean() throws Exception
|
||||
{
|
||||
ObjectName pingerName = new ObjectName("org.eclipse.jetty.test.jmx:type=pinger,context=jmx-webapp,id=0");
|
||||
// Get initial count
|
||||
int count = getIntegerAttribute(pingerName,"count");
|
||||
// Operations
|
||||
Object val = mbsc.invoke(pingerName,"ping",null,null);
|
||||
assertThat("ping() return",val.toString(),startsWith("Pong"));
|
||||
// Attributes
|
||||
assertThat("count",getIntegerAttribute(pingerName,"count"),is(count+1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for POJO (annotated) that is merged with a MBean that
|
||||
* declares more annotations.
|
||||
*/
|
||||
@Test
|
||||
public void testAccessToEchoerMBean() throws Exception
|
||||
{
|
||||
ObjectName echoerName = new ObjectName("org.eclipse.jetty.test.jmx:type=echoer,context=jmx-webapp,id=0");
|
||||
// Get initial count
|
||||
int count = getIntegerAttribute(echoerName,"count");
|
||||
// Operations
|
||||
Object val = mbsc.invoke(echoerName,"echo",new Object[]{"Its Me"},new String[]{String.class.getName()});
|
||||
assertThat("echo() return",val.toString(),is("Its Me"));
|
||||
// Attributes
|
||||
assertThat("count",getIntegerAttribute(echoerName,"count"),is(count+1));
|
||||
assertThat("foo",getStringAttribute(echoerName,"foo"),is("foo-ish"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.SimpleRequest;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Basic tests for a simple Servlet with no JMX involved (yet)
|
||||
*/
|
||||
public class PingIT
|
||||
{
|
||||
@Test
|
||||
public void testBasic() throws Exception
|
||||
{
|
||||
URI serverURI = new URI("http://localhost:58080/jmx-webapp/");
|
||||
SimpleRequest req = new SimpleRequest(serverURI);
|
||||
assertThat(req.getString("ping"),startsWith("Servlet Pong at "));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
JAVA_HOME=$1
|
||||
JETTY_HOME=$2
|
||||
JETTY_BASE=$3
|
||||
|
||||
echo \${java.home} : $JAVA_HOME
|
||||
echo \${jetty.home} : $JETTY_HOME
|
||||
echo \${jetty.base} : $JETTY_BASE
|
||||
|
||||
cd "$JETTY_BASE"
|
||||
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
--approve-all-licenses \
|
||||
--add-to-start=deploy,http,annotations,jmx,jmx-remote,logging
|
||||
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
--version
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
JAVA_HOME=$1
|
||||
JETTY_HOME=$2
|
||||
JETTY_BASE=$3
|
||||
|
||||
echo \${java.home} : $JAVA_HOME
|
||||
echo \${jetty.home} : $JETTY_HOME
|
||||
echo \${jetty.base} : $JETTY_BASE
|
||||
|
||||
cd "$JETTY_BASE"
|
||||
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
jetty.port=58080 \
|
||||
STOP.PORT=58181 STOP.KEY=it
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
JAVA_HOME=$1
|
||||
JETTY_HOME=$2
|
||||
JETTY_BASE=$3
|
||||
|
||||
cd "$JETTY_BASE"
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
--stop STOP.PORT=58181 STOP.KEY=it
|
||||
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
//
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
-->
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-jmx-parent</artifactId>
|
||||
<version>9.2.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jmx-webapp</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>Jetty Tests :: JMX :: WebApp</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<bundle-symbolic-name>${project.groupId}.jmx.webapp</bundle-symbolic-name>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jmx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>jmx-webapp</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- DO NOT DEPLOY (or Release) -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
@ManagedObject("A common component available in the webapp")
|
||||
public class CommonComponent extends AbstractLifeCycle
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(CommonComponent.class);
|
||||
|
||||
public CommonComponent()
|
||||
{
|
||||
LOG.info("Created " + this.getClass().getName());
|
||||
}
|
||||
|
||||
private String name = "i am common";
|
||||
|
||||
@ManagedAttribute("The name being tracked")
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
|
||||
@ManagedObject("Echoer")
|
||||
public class Echoer
|
||||
{
|
||||
private int count = 0;
|
||||
|
||||
@ManagedAttribute("Number of echos")
|
||||
public int getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
@ManagedOperation("Echo a string")
|
||||
public String echo(@Name("val") String val)
|
||||
{
|
||||
count++;
|
||||
return val;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class MyContainerInitializer implements ServletContainerInitializer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(MyContainerInitializer.class);
|
||||
|
||||
@Override
|
||||
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException
|
||||
{
|
||||
// Directly annotated with @ManagedObject
|
||||
CommonComponent common = new CommonComponent();
|
||||
LOG.info("Initializing " + common.getClass().getName());
|
||||
ctx.setAttribute("org.eclipse.jetty.test.jmx.common",common);
|
||||
|
||||
// Indirectly managed via a MBean
|
||||
ctx.setAttribute("org.eclipse.jetty.test.jmx.ping",new Pinger());
|
||||
ctx.setAttribute("org.eclipse.jetty.test.jmx.echo",new Echoer());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* Simple ping into this webapp to see if it is here.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@ManagedObject("Ping Servlet")
|
||||
public class PingServlet extends HttpServlet
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(PingServlet.class);
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
{
|
||||
LOG.info("Adding {} to attribute {}", this, config.getServletName());
|
||||
config.getServletContext().setAttribute(config.getServletName(),this);
|
||||
super.init(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
{
|
||||
resp.setContentType("text/plain");
|
||||
resp.getWriter().println(ping());
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public String ping()
|
||||
{
|
||||
return "Servlet Pong at " + new Date().toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Bare POJO, intentionally has no managed annotations.
|
||||
*/
|
||||
public class Pinger
|
||||
{
|
||||
private int count = 0;
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
public String ping()
|
||||
{
|
||||
count++;
|
||||
return "Ponger at " + new Date().toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx.jmx;
|
||||
|
||||
import org.eclipse.jetty.jmx.ObjectMBean;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
|
||||
@ManagedObject("Echoer (mbean)")
|
||||
public class EchoerMBean extends ObjectMBean
|
||||
{
|
||||
public EchoerMBean(Object managedObject)
|
||||
{
|
||||
super(managedObject);
|
||||
}
|
||||
|
||||
@ManagedAttribute(value="Gets the value of foo",proxied=true)
|
||||
public String getFoo()
|
||||
{
|
||||
return "foo-ish";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jmx.jmx;
|
||||
|
||||
import org.eclipse.jetty.jmx.ObjectMBean;
|
||||
import org.eclipse.jetty.test.jmx.Pinger;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
|
||||
@ManagedObject("Pinger facility")
|
||||
public class PingerMBean extends ObjectMBean
|
||||
{
|
||||
public PingerMBean(Object managedObject)
|
||||
{
|
||||
super(managedObject);
|
||||
}
|
||||
|
||||
private Pinger getPinger()
|
||||
{
|
||||
return (Pinger)getManagedObject();
|
||||
}
|
||||
|
||||
@ManagedOperation("Issue Ping")
|
||||
public String ping()
|
||||
{
|
||||
return getPinger().ping();
|
||||
}
|
||||
|
||||
@ManagedAttribute("Count of pings")
|
||||
public int getCount()
|
||||
{
|
||||
return getPinger().getCount();
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.eclipse.jetty.test.jmx.MyContainerInitializer
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
metadata-complete="true"
|
||||
version="2.5">
|
||||
|
||||
<display-name>Test JMX WebApp</display-name>
|
||||
|
||||
<context-param>
|
||||
<param-name>org.eclipse.jetty.server.context.ManagedAttributes</param-name>
|
||||
<param-value>
|
||||
org.eclipse.jetty.test.jmx.common,
|
||||
org.eclipse.jetty.test.jmx.ping,
|
||||
org.eclipse.jetty.test.jmx.echo,
|
||||
Ping
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Ping</servlet-name>
|
||||
<servlet-class>org.eclipse.jetty.test.jmx.PingServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>Ping</servlet-name>
|
||||
<url-pattern>/ping</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
//
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
-->
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
<version>9.2.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-jmx-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>Jetty Tests :: JMX Parent</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<modules>
|
||||
<module>jmx-webapp</module>
|
||||
<module>jmx-webapp-it</module>
|
||||
</modules>
|
||||
</project>
|
Loading…
Reference in New Issue