Author: richard.opalka(a)jboss.com
Date: 2011-08-13 11:39:22 -0400 (Sat, 13 Aug 2011)
New Revision: 14820
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/pom.xml
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogLevel.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecords.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadWriteLogStorage.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AbstractAtomBean.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullHandler.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushBean.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngine.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngineConfigurator.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushHandler.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/LoggingThread.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/Converter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/Deliverer.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/RetryingDeliverer.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/WebClientDeliverer.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/package-info.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/package-info.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/test/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/test/java/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/test/java/apache/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/test/java/apache/cxf/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/test/java/apache/cxf/management/
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/test/java/apache/cxf/management/web/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/pom.xml
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/MBServerConnectorFactory.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/Messages.properties
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanAssembler.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanInfoSupporter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataFilter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/StatusExchangeDataFilter.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/bus-extensions.xml
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf.extension
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/schemas/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/schemas/configuration/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/counters/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor2Test.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/utils/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/resources/
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/resources/managed-spring.xml
Log:
importing CXF 2.3.1 tag - (per partes) because of unreliable SVN RH repo :(
Added: thirdparty/cxf/branches/cxf-2.3.1/rt/management/pom.xml
===================================================================
--- thirdparty/cxf/branches/cxf-2.3.1/rt/management/pom.xml (rev
0)
+++ thirdparty/cxf/branches/cxf-2.3.1/rt/management/pom.xml 2011-08-13 15:39:22 UTC (rev
14820)
@@ -0,0 +1,126 @@
+<!--
+ 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.
+-->
+<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>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-management</artifactId>
+ <packaging>jar</packaging>
+ <version>2.3.1</version>
+ <name>Apache CXF Runtime Management</name>
+ <url>http://cxf.apache.org</url>
+
+ <parent>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-parent</artifactId>
+ <version>2.3.1</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-common-utilities</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-xjc-plugin</artifactId>
+ <version>${cxf.xjc-utils.version}</version>
+ <executions>
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
+ <xsdOptions>
+ <xsdOption>
+
<xsd>${basedir}/src/main/resources/schemas/configuration/instrumentation.xsd</xsd>
+ <extension>true</extension>
+ <extensionArgs>
+ <extensionArg>-Xdv</extensionArg>
+ </extensionArgs>
+ </xsdOption>
+ </xsdOptions>
+ </configuration>
+ <goals>
+ <goal>xsdtojava</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <extensions>
+
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:${cxf.xjc-utils.version}</extension>
+ </extensions>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+
+</project>
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,31 @@
+/**
+ * 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.cxf.management.counters;
+
+import org.apache.cxf.management.ManagedComponent;
+
+public interface Counter extends ManagedComponent {
+
+ String PERFORMANCE_COUNTER = "Performance.Counter";
+
+ void increase(MessageHandlingTimeRecorder mhtr);
+
+ Number getNumInvocations();
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,130 @@
+/**
+ * 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.cxf.management.counters;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.management.InstrumentationManager;
+import org.apache.cxf.management.interceptor.ResponseTimeMessageInInterceptor;
+import org.apache.cxf.management.interceptor.ResponseTimeMessageInvokerInterceptor;
+import org.apache.cxf.management.interceptor.ResponseTimeMessageOutInterceptor;
+
+/* Counters are created and managed by CounterRepository
+ * If a counter which is queried form the counterRepository is not exist,
+ * the CounterRepository will create a counter and expose it to the JMX
+ * Because we can get the instance of the counter object,
+ * it is not need to qurey the counter object from JMX
+ * */
+public class CounterRepository {
+ private static final Logger LOG = LogUtils.getL7dLogger(CounterRepository.class);
+
+ private Map<ObjectName, Counter> counters;
+ private Bus bus;
+ private Lock counterCreationLock = new ReentrantLock();
+
+ public CounterRepository() {
+ counters = new ConcurrentHashMap<ObjectName, Counter>();
+ }
+
+ @Resource(name = "cxf")
+ public void setBus(Bus b) {
+ bus = b;
+ }
+
+ public Bus getBus() {
+ return bus;
+ }
+
+ public Map<ObjectName, Counter> getCounters() {
+ return counters;
+ }
+
+ @PostConstruct
+ void registerInterceptorsToBus() {
+ ResponseTimeMessageInInterceptor in = new ResponseTimeMessageInInterceptor();
+ ResponseTimeMessageInvokerInterceptor invoker = new
ResponseTimeMessageInvokerInterceptor();
+ ResponseTimeMessageOutInterceptor out = new ResponseTimeMessageOutInterceptor();
+
+ bus.getInInterceptors().add(in);
+ bus.getInInterceptors().add(invoker);
+ bus.getOutInterceptors().add(out);
+ bus.setExtension(this, CounterRepository.class);
+
+ //create CounterRepositroyMoniter to writer the counter log
+
+ //if the service is stopped or removed, the counters should remove itself
+ }
+
+ public void increaseCounter(ObjectName on, MessageHandlingTimeRecorder mhtr) {
+ Counter counter = getCounter(on);
+ if (null == counter) {
+ counterCreationLock.lock();
+ try {
+ // check if the counter has been created during the locked time
+ counter = getCounter(on);
+ if (counter == null) {
+ counter = createCounter(on, mhtr);
+ counters.put(on, counter);
+ }
+ } finally {
+ counterCreationLock.unlock();
+ }
+ }
+ counter.increase(mhtr);
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Increase counter " + on + " with " + mhtr);
+ }
+ }
+
+ //find a counter
+ public Counter getCounter(ObjectName on) {
+ return counters.get(on);
+ }
+
+ public Counter createCounter(ObjectName on, MessageHandlingTimeRecorder mhtr) {
+ Counter counter = null;
+ counter = new ResponseTimeCounter(on);
+ InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
+ if (null != im) {
+ try {
+ im.register(counter);
+ } catch (JMException e) {
+ LOG.log(Level.WARNING, "INSTRUMENTATION_REGISTER_FAULT_MSG",
+ new Object[]{on, e});
+ }
+ }
+ return counter;
+ }
+
+
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,83 @@
+/**
+ * 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.cxf.management.counters;
+
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
+
+/* recoder the message actually handle begin and end time */
+public class MessageHandlingTimeRecorder {
+ private Exchange exchange;
+ private long beginTime;
+ private long endTime;
+ private FaultMode faultMode;
+ private boolean oneWay;
+
+ public MessageHandlingTimeRecorder(Exchange ex) {
+ exchange = ex;
+ exchange.put(MessageHandlingTimeRecorder.class, this);
+ }
+
+ public boolean isOneWay() {
+ return oneWay;
+ }
+
+ public void setOneWay(boolean ow) {
+ oneWay = ow;
+ }
+
+ public Exchange getHandleExchange() {
+ return exchange;
+ }
+
+ public void beginHandling() {
+ beginTime = System.nanoTime() / 1000;
+ }
+
+ public void endHandling() {
+ endTime = System.nanoTime() / 1000;
+ }
+
+ public long getEndTime() {
+ return endTime;
+ }
+
+ public long getHandlingTime() {
+ return endTime - beginTime;
+ }
+
+ public FaultMode getFaultMode() {
+ return faultMode;
+ }
+
+ public void setFaultMode(FaultMode faultMode) {
+ this.faultMode = faultMode;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
sb.append("MessageHandlingTimeRecorder(a)").append(Integer.toHexString(hashCode())).append("[");
+ sb.append("beginTime: ").append(beginTime).append(", ");
+ sb.append("endTime: ").append(endTime).append(", ");
+ sb.append("faultMode: ").append(faultMode).append("]");
+ return sb.toString();
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,25 @@
+#
+#
+# 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.
+#
+#
+CANNOT_FIND_THE_COUNTERREPOSITORY = CounterRepositoryMonitor can't find the
CounterRepository from bus.
+CANNOT_CREATE_LOGGER_FILE = Can''t create the logger file for the response time
counters. {0}
+CANNOT_FIND_THE_COUNTER_OBJECTNAME = Can''t find the counter object name. {0}
+CANNOT_FIND_STATUS = Can''t find the status. {0}
+INSTRUMENTATION_REGISTER_FAULT_MSG=Can''t register counter with object name {0}.
{1}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,48 @@
+/**
+ * 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.cxf.management.counters;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+public class PerformanceCounter implements PerformanceCounterMBean, Counter {
+ private AtomicInteger invocations = new AtomicInteger();
+ private ObjectName objectName;
+
+
+ public PerformanceCounter(ObjectName on) {
+ objectName = on;
+ }
+
+ public Number getNumInvocations() {
+ return invocations.get();
+ }
+
+ public void increase(MessageHandlingTimeRecorder mhtr) {
+ invocations.getAndIncrement();
+ }
+
+ public ObjectName getObjectName() throws JMException {
+ return objectName;
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,24 @@
+/**
+ * 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.cxf.management.counters;
+
+public interface PerformanceCounterMBean {
+ Number getNumInvocations();
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,140 @@
+/**
+ * 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.cxf.management.counters;
+
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.management.ObjectName;
+
+import org.apache.cxf.message.FaultMode;
+
+public class ResponseTimeCounter implements ResponseTimeCounterMBean, Counter {
+
+ private ObjectName objectName;
+ private AtomicInteger invocations = new AtomicInteger();
+ private AtomicInteger checkedApplicationFaults = new AtomicInteger();
+ private AtomicInteger unCheckedApplicationFaults = new AtomicInteger();
+ private AtomicInteger runtimeFaults = new AtomicInteger();
+ private AtomicInteger logicalRuntimeFaults = new AtomicInteger();
+ private long totalHandlingTime;
+ private long maxHandlingTime;
+ private long minHandlingTime = Integer.MAX_VALUE;
+
+ public ResponseTimeCounter(ObjectName on) {
+ objectName = on;
+ }
+
+ public void increase(MessageHandlingTimeRecorder mhtr) {
+ invocations.getAndIncrement();
+ FaultMode faultMode = mhtr.getFaultMode();
+ if (null == faultMode) {
+ // no exception occured
+ } else {
+ switch (faultMode) {
+ case CHECKED_APPLICATION_FAULT:
+ checkedApplicationFaults.incrementAndGet();
+ break;
+ case LOGICAL_RUNTIME_FAULT:
+ logicalRuntimeFaults.incrementAndGet();
+ break;
+ case RUNTIME_FAULT:
+ runtimeFaults.incrementAndGet();
+ break;
+ case UNCHECKED_APPLICATION_FAULT:
+ unCheckedApplicationFaults.incrementAndGet();
+ break;
+ default:
+ runtimeFaults.incrementAndGet();
+ break;
+ }
+ }
+
+ long handlingTime = 0;
+ if (mhtr.isOneWay()) {
+ // We can count the response time
+ if (mhtr.getEndTime() > 0) {
+ handlingTime = mhtr.getHandlingTime();
+ }
+ } else {
+ handlingTime = mhtr.getHandlingTime();
+ }
+
+ totalHandlingTime = totalHandlingTime + handlingTime;
+ if (maxHandlingTime < handlingTime) {
+ maxHandlingTime = handlingTime;
+ }
+ if (minHandlingTime > handlingTime) {
+ minHandlingTime = handlingTime;
+ }
+ }
+
+ public void reset() {
+ invocations.set(0);
+ checkedApplicationFaults.set(0);
+ unCheckedApplicationFaults.set(0);
+ runtimeFaults.set(0);
+ logicalRuntimeFaults.set(0);
+
+ totalHandlingTime = 0;
+ maxHandlingTime = 0;
+ minHandlingTime = Integer.MAX_VALUE;
+ }
+
+ public ObjectName getObjectName() {
+ return objectName;
+ }
+
+ public Number getAvgResponseTime() {
+ return (int)(totalHandlingTime / invocations.get());
+ }
+
+ public Number getMaxResponseTime() {
+ return maxHandlingTime;
+ }
+
+ public Number getMinResponseTime() {
+ return minHandlingTime;
+ }
+
+ public Number getNumInvocations() {
+ return invocations.get();
+ }
+
+ public Number getNumCheckedApplicationFaults() {
+ return checkedApplicationFaults.get();
+ }
+
+ public Number getNumLogicalRuntimeFaults() {
+ return logicalRuntimeFaults.get();
+ }
+
+ public Number getNumRuntimeFaults() {
+ return runtimeFaults.get();
+ }
+
+ public Number getNumUnCheckedApplicationFaults() {
+ return unCheckedApplicationFaults.get();
+ }
+
+ public Number getTotalHandlingTime() {
+ return totalHandlingTime;
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,31 @@
+/**
+ * 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.cxf.management.counters;
+
+public interface ResponseTimeCounterMBean {
+ Number getNumInvocations();
+ Number getNumCheckedApplicationFaults();
+ Number getNumLogicalRuntimeFaults();
+ Number getNumRuntimeFaults();
+ Number getNumUnCheckedApplicationFaults();
+ Number getAvgResponseTime();
+ Number getMaxResponseTime();
+ Number getMinResponseTime();
+ Number getTotalHandlingTime();
+}
\ No newline at end of file
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,150 @@
+/**
+ * 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.cxf.management.interceptor;
+
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.management.ManagementConstants;
+import org.apache.cxf.management.counters.Counter;
+import org.apache.cxf.management.counters.CounterRepository;
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.OperationInfo;
+
+public abstract class AbstractMessageResponseTimeInterceptor extends
AbstractPhaseInterceptor<Message> {
+ private static final Logger LOG =
LogUtils.getL7dLogger(AbstractMessageResponseTimeInterceptor.class);
+
+ AbstractMessageResponseTimeInterceptor(String phase) {
+ super(phase);
+ }
+
+ protected boolean isClient(Message msg) {
+ return msg == null ? false :
Boolean.TRUE.equals(msg.get(Message.REQUESTOR_ROLE));
+ }
+
+ protected void beginHandlingMessage(Exchange ex) {
+ if (null == ex) {
+ return;
+ }
+ MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class);
+ if (null != mhtr) {
+ mhtr.beginHandling();
+ } else {
+ mhtr = new MessageHandlingTimeRecorder(ex);
+ mhtr.beginHandling();
+ }
+ }
+
+ protected void endHandlingMessage(Exchange ex) {
+ if (null == ex) {
+ return;
+ }
+ MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class);
+ if (null != mhtr) {
+ mhtr.endHandling();
+ mhtr.setFaultMode(ex.get(FaultMode.class));
+ increaseCounter(ex, mhtr);
+
+ } // else can't get the MessageHandling Infor
+ }
+
+ protected void setOneWayMessage(Exchange ex) {
+ MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class);
+ if (null == mhtr) {
+ mhtr = new MessageHandlingTimeRecorder(ex);
+ } else {
+ mhtr.endHandling();
+ }
+ mhtr.setOneWay(true);
+ increaseCounter(ex, mhtr);
+ }
+
+ private void increaseCounter(Exchange ex, MessageHandlingTimeRecorder mhtr) {
+ Bus bus = ex.get(Bus.class);
+ if (null == bus) {
+ LOG.log(Level.INFO, "CAN_NOT_GET_BUS_FROM_EXCHANGE");
+ BusFactory.getThreadDefaultBus();
+ }
+
+ Message message = ex.getOutMessage();
+
+ CounterRepository cr = bus.getExtension(CounterRepository.class);
+
+ if (null == cr) {
+ LOG.log(Level.WARNING, "NO_COUNTER_REPOSITORY");
+ return;
+ } else {
+ Service service = ex.get(Service.class);
+ Endpoint endpoint = ex.get(Endpoint.class);
+
+ String serviceName = "\"" + service.getName() +
"\"";
+ String portName = "\"" +
endpoint.getEndpointInfo().getName().getLocalPart() + "\"";
+
+ OperationInfo opInfo = ex.get(OperationInfo.class);
+ String operationName = opInfo == null ? null : "\"" +
opInfo.getName().getLocalPart() + "\"";
+
+ if (operationName == null) {
+ Object nameProperty =
ex.get("org.apache.cxf.resource.operation.name");
+ if (nameProperty != null) {
+ operationName = "\"" + nameProperty.toString() +
"\"";
+ }
+ }
+
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME + ":");
+ buffer.append(ManagementConstants.BUS_ID_PROP + "=" + bus.getId() +
",");
+ if (isClient(message)) {
+ buffer.append(ManagementConstants.TYPE_PROP + "=" +
Counter.PERFORMANCE_COUNTER + ".Client,");
+ } else {
+ buffer.append(ManagementConstants.TYPE_PROP + "=" +
Counter.PERFORMANCE_COUNTER + ".Server,");
+ }
+ buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=" +
serviceName + ",");
+
+ buffer.append(ManagementConstants.PORT_NAME_PROP + "=" +
portName);
+ String serviceCounterName = buffer.toString();
+
+ try {
+ ObjectName serviceCounter =
+ new ObjectName(serviceCounterName);
+ cr.increaseCounter(serviceCounter, mhtr);
+ if (operationName != null) {
+ buffer.append("," + ManagementConstants.OPERATION_NAME_PROP
+ "=" + operationName);
+ String operationCounterName = buffer.toString();
+ ObjectName operationCounter = new ObjectName(operationCounterName);
+ cr.increaseCounter(operationCounter, mhtr);
+ }
+ } catch (Exception exception) {
+ LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED",
exception);
+ }
+ }
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,23 @@
+#
+#
+# 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.
+#
+#
+CAN_NOT_GET_BUS_FROM_EXCHANGE = Can't get bus instance from exchange, using default
bus instead
+CREATE_COUNTER_OBJECTNAME_FAILED = Create Counter''s ObjectName failed. {0}
+NO_COUNTER_REPOSITORY = Can't find the CounterRepository from default Bus
\ No newline at end of file
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,82 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.management.persistence.ExchangeData;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class PersistInInterceptor extends AbstractPhaseInterceptor<Message> {
+
+ public PersistInInterceptor() {
+ super(Phase.RECEIVE);
+ }
+
+ /**
+ * Copied from LoggingInInterceptor
+ *
+ * @param soapMessage
+ */
+ private void getSoapRequest(Message soapMessage, ExchangeData exchange) {
+ InputStream is = soapMessage.getContent(InputStream.class);
+ if (is != null) {
+ CachedOutputStream bos = new CachedOutputStream();
+ try {
+ IOUtils.copy(is, bos);
+
+ bos.flush();
+ is.close();
+
+ soapMessage.setContent(InputStream.class, bos.getInputStream());
+
+ StringBuilder builder = new StringBuilder();
+ bos.writeCacheTo(builder, bos.size());
+
+ bos.close();
+
+ exchange.setRequest(builder.toString());
+ exchange.setRequestSize(bos.size());
+
+ } catch (IOException e) {
+ throw new Fault(e);
+ }
+ }
+
+ }
+
+ public void handleMessage(Message message) throws Fault {
+
+ ExchangeData soapExchange = new ExchangeData();
+ soapExchange.setInDate(new Date());
+
+ message.setContent(ExchangeData.class, soapExchange);
+
+ getSoapRequest(message, soapExchange);
+
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,230 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.LoggingMessage;
+import org.apache.cxf.io.CacheAndWriteOutputStream;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.io.CachedOutputStreamCallback;
+import org.apache.cxf.management.persistence.ExchangeData;
+import org.apache.cxf.management.persistence.ExchangeDataDAO;
+import org.apache.cxf.management.persistence.ExchangeDataFilter;
+import org.apache.cxf.management.persistence.ExchangeDataProperty;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.OperationInfo;
+
+public class PersistOutInterceptor extends AbstractPhaseInterceptor<Message> {
+
+ public static final String CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX =
+ "org.apache.cxf.management.interceptor.prefix";
+
+ private ExchangeDataDAO exchangeDataDAO;
+
+ private ExchangeDataFilter exchangeDataFilter;
+
+ public PersistOutInterceptor() {
+ super(Phase.PRE_STREAM);
+ }
+
+ class PersistOutInterceptorCallback implements CachedOutputStreamCallback {
+
+ private final Message message;
+ private final OutputStream origStream;
+ private final ExchangeData exchange;
+
+ public PersistOutInterceptorCallback(final Message msg, final OutputStream os,
+ final ExchangeData ex) {
+ this.message = msg;
+ this.origStream = os;
+ this.exchange = ex;
+ }
+
+ public void onClose(CachedOutputStream cos) {
+ String id = (String)this.message.getExchange().get(LoggingMessage.ID_KEY);
+ if (id == null) {
+ id = LoggingMessage.nextId();
+ this.message.getExchange().put(LoggingMessage.ID_KEY, id);
+ }
+ try {
+ StringBuilder buffer = new StringBuilder();
+ cos.writeCacheTo(buffer, cos.size());
+ this.exchange.setResponseSize(cos.size());
+ this.exchange.setResponse(buffer.toString());
+ } catch (Exception ex) {
+ // ignore
+ }
+
+ try {
+ // empty out the cache
+ cos.lockOutputStream();
+ cos.resetOut(null, false);
+ } catch (Exception ex) {
+ // ignore
+ }
+ this.message.setContent(OutputStream.class, this.origStream);
+
+ if (PersistOutInterceptor.this.exchangeDataFilter == null
+ ||
PersistOutInterceptor.this.exchangeDataFilter.shouldPersist(this.exchange)) {
+ try {
+ PersistOutInterceptor.this.exchangeDataDAO.save(this.exchange);
+ } catch (Throwable e) {
+
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void onFlush(CachedOutputStream cos) {
+
+ }
+ }
+
+ private static void addProperty(ExchangeData exchange, String key, String value) {
+
+ ExchangeDataProperty exchangeProperty = new ExchangeDataProperty();
+ exchangeProperty.setExchangeData(exchange);
+ exchangeProperty.setName(key);
+ exchangeProperty.setValue(value);
+
+ if (exchange.getProperties() == null) {
+ exchange.setProperties(new ArrayList<ExchangeDataProperty>());
+ }
+ exchange.getProperties().add(exchangeProperty);
+ }
+
+ private void addPropertiesFrom(ExchangeData exchange, Message message) {
+ for (Map.Entry<String, Object> entry : message.entrySet()) {
+ if (entry.getKey().equals(org.apache.cxf.message.Message.ENCODING)) {
+ exchange.setEncoding((String)entry.getValue());
+ } else if (entry.getKey().equals(org.apache.cxf.message.Message.REQUEST_URI))
{
+ exchange.setUri((String)entry.getValue());
+ } else if
(entry.getKey().equals(org.apache.cxf.message.Message.PROTOCOL_HEADERS)) {
+
+ if (entry.getValue() instanceof Map) {
+ List userAgents =
(List)((Map)entry.getValue()).get("user-agent");
+ if (userAgents != null && !userAgents.isEmpty()) {
+ exchange.setUserAgent(userAgents.get(0).toString());
+ }
+ }
+ if (entry.getValue() != null) {
+ addProperty(exchange, entry.getKey(), entry.getValue().toString());
+ }
+
+ } else if
(entry.getKey().startsWith("org.apache.cxf.message.Message.")
+ && (entry.getValue() instanceof String || entry.getValue()
instanceof Integer || entry
+ .getValue() instanceof Boolean)) {
+ addProperty(exchange, entry.getKey(), entry.getValue().toString());
+
+ } else if (entry.getKey().startsWith(CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX))
{
+ addProperty(exchange, entry.getKey().substring(
+
CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX
+ .length()),
entry.getValue().toString());
+
+ }
+ }
+ }
+
+ public void handleMessage(Message message) throws Fault {
+
+ ExchangeData exchangeData =
message.getExchange().getInMessage().getContent(ExchangeData.class);
+ if (exchangeData != null) {
+
+ final OutputStream os = message.getContent(OutputStream.class);
+ if (os == null) {
+ return;
+ }
+
+ try {
+
+ Service service = message.getExchange().get(Service.class);
+
+ String serviceName = String.valueOf(service.getName());
+ OperationInfo opInfo = message.getExchange().get(OperationInfo.class);
+ String operationName = opInfo == null ? null :
opInfo.getName().getLocalPart();
+
+ if (operationName == null) {
+ Object nameProperty =
message.getExchange().get("org.apache.cxf.resource.operation.name");
+ if (nameProperty != null) {
+ operationName = "\"" + nameProperty.toString() +
"\"";
+ }
+ }
+
+ exchangeData.setServiceName(serviceName);
+ exchangeData.setOperation(operationName);
+
+ // add all additional properties
+
+ addPropertiesFrom(exchangeData, message.getExchange().getInMessage());
+ addPropertiesFrom(exchangeData, message);
+
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+
+ }
+
+ // Write the output while caching it for the log message
+ final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
+ message.setContent(OutputStream.class, newOut);
+ newOut.registerCallback(new PersistOutInterceptorCallback(message, os,
exchangeData));
+
+ exchangeData.setOutDate(new Date());
+
+ if (message.getContent(Exception.class) != null) {
+ exchangeData.setStatus("ERROR");
+
+ Exception exception = message.getContent(Exception.class);
+ StringWriter stringWriter = new StringWriter();
+ if (exception.getCause() != null) {
+
exchangeData.setExceptionType(exception.getCause().getClass().getName());
+ exception.getCause().printStackTrace(new PrintWriter(stringWriter));
+ } else {
+ exchangeData.setExceptionType(exception.getClass().getName());
+ exception.printStackTrace(new PrintWriter(stringWriter));
+ }
+ exchangeData.setStackTrace(stringWriter.toString());
+
+ } else {
+ exchangeData.setStatus("OK");
+ }
+
+ }
+ }
+
+ public void setExchangeDataDAO(ExchangeDataDAO exchangeDataDAO) {
+ this.exchangeDataDAO = exchangeDataDAO;
+ }
+
+ public void setExchangeDataFilter(ExchangeDataFilter exchangeDataFilter) {
+ this.exchangeDataFilter = exchangeDataFilter;
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,44 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+
+@NoJSR250Annotations
+public class ResponseTimeFeature extends AbstractFeature {
+ private static final ResponseTimeMessageInInterceptor IN =
+ new ResponseTimeMessageInInterceptor();
+ private static final ResponseTimeMessageInvokerInterceptor INVOKER =
+ new ResponseTimeMessageInvokerInterceptor();
+ private static final ResponseTimeMessageOutInterceptor OUT =
+ new ResponseTimeMessageOutInterceptor();
+
+ @Override
+ protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+ provider.getInInterceptors().add(IN);
+ provider.getInFaultInterceptors().add(IN);
+ provider.getInInterceptors().add(INVOKER);
+ provider.getOutInterceptors().add(OUT);
+
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,56 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+public class ResponseTimeMessageInInterceptor extends
AbstractMessageResponseTimeInterceptor {
+
+ public ResponseTimeMessageInInterceptor() {
+ super(Phase.POST_LOGICAL);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+
+ Exchange ex = message.getExchange();
+ if (isClient(message)) {
+ if (!ex.isOneWay()) {
+ endHandlingMessage(ex);
+ }
+ } else {
+ beginHandlingMessage(ex);
+ }
+ }
+
+ @Override
+ public void handleFault(Message message) {
+ Exchange ex = message.getExchange();
+ FaultMode mode = message.get(FaultMode.class);
+ if (mode == null) {
+ mode = FaultMode.RUNTIME_FAULT;
+ }
+ ex.put(FaultMode.class, mode);
+ endHandlingMessage(ex);
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,56 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.ServiceInvokerInterceptor;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+/* When the message get from the server side
+ * The exchange.isOneWay() is workable when the message
+ * handler by the binging interceptor
+ * */
+public class ResponseTimeMessageInvokerInterceptor extends
AbstractMessageResponseTimeInterceptor {
+
+ public ResponseTimeMessageInvokerInterceptor() {
+ super(Phase.INVOKE);
+ // this interceptor should be add before the serviceInvokerInterceptor
+ addBefore(ServiceInvokerInterceptor.class.getName());
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ Exchange ex = message.getExchange();
+ if (ex.isOneWay() && !isClient(message)) {
+ setOneWayMessage(ex);
+ }
+ }
+
+ @Override
+ public void handleFault(Message message) {
+ Exchange ex = message.getExchange();
+ ex.put(FaultMode.class, message.get(FaultMode.class));
+ if (ex.isOneWay() && !isClient(message)) {
+ endHandlingMessage(ex);
+ }
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,85 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class ResponseTimeMessageOutInterceptor extends
AbstractMessageResponseTimeInterceptor {
+ private EndingInterceptor ending = new EndingInterceptor();
+
+ public ResponseTimeMessageOutInterceptor() {
+ super(Phase.SEND);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ Exchange ex = message.getExchange();
+ if (Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE))) {
+ return;
+ }
+ if (isClient(message)) {
+ if (ex.isOneWay()) {
+ message.getInterceptorChain().add(ending);
+ }
+ beginHandlingMessage(ex);
+ } else { // the message is handled by server
+ endHandlingMessage(ex);
+ }
+ }
+
+ @Override
+ public void handleFault(Message message) {
+ Exchange ex = message.getExchange();
+ if (ex.isOneWay()) {
+ // do nothing, done by the ResponseTimeInvokerInterceptor
+ } else {
+ FaultMode faultMode = message.get(FaultMode.class);
+ if (faultMode == null) {
+ // client side exceptions don't have FaultMode set un the message
properties (as of 2.1.4)
+ faultMode = FaultMode.RUNTIME_FAULT;
+ }
+ ex.put(FaultMode.class, faultMode);
+ endHandlingMessage(ex);
+ }
+ }
+
+ EndingInterceptor getEndingInterceptor() {
+ return ending;
+ }
+
+ public class EndingInterceptor extends AbstractPhaseInterceptor<Message> {
+ public EndingInterceptor() {
+ super(Phase.PREPARE_SEND_ENDING);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ Exchange ex = message.getExchange();
+ endHandlingMessage(ex);
+ }
+
+ public void handleFault(Message message) throws Fault {
+ Exchange ex = message.getExchange();
+ endHandlingMessage(ex);
+ }
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,320 @@
+/**
+ * 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.cxf.management.jmx;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.RequiredModelMBean;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.ManagedBus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.management.InstrumentationManager;
+import org.apache.cxf.management.JMXConnectorPolicyType;
+import org.apache.cxf.management.ManagedComponent;
+import org.apache.cxf.management.ManagementConstants;
+import org.apache.cxf.management.jmx.export.runtime.ModelMBeanAssembler;
+
+/**
+ * The manager class for the JMXManagedComponent which hosts the JMXManagedComponents.
+ */
+public class InstrumentationManagerImpl extends JMXConnectorPolicyType
+ implements InstrumentationManager, BusLifeCycleListener {
+ private static final Logger LOG =
LogUtils.getL7dLogger(InstrumentationManagerImpl.class);
+
+ private Bus bus;
+ private MBServerConnectorFactory mcf;
+ private MBeanServer mbs;
+ private Set<ObjectName> busMBeans = new HashSet<ObjectName>();
+ private boolean connectFailed;
+ private String persistentBusId;
+
+ /**
+ * For backward compatibility, {@link #createMBServerConnectorFactory} is
<code>true</code> by default.
+ */
+ private boolean createMBServerConnectorFactory = true;
+ private String mbeanServerName = ManagementConstants.DEFAULT_DOMAIN_NAME;
+ private boolean usePlatformMBeanServer;
+
+ public InstrumentationManagerImpl() {
+ super();
+ }
+
+ public Bus getBus() {
+ return bus;
+ }
+
+ @Resource(name = "cxf")
+ public void setBus(Bus bus) {
+ this.bus = bus;
+ }
+
+ public void setServerName(String s) {
+ mbeanServerName = s;
+ }
+
+ public void setCreateMBServerConnectorFactory(boolean createMBServerConnectorFactory)
{
+ this.createMBServerConnectorFactory = createMBServerConnectorFactory;
+ }
+
+ public void setUsePlatformMBeanServer(Boolean flag) {
+ usePlatformMBeanServer = flag;
+ }
+
+ @PostConstruct
+ public void register() {
+ if (null != bus) {
+ bus.setExtension(this, InstrumentationManager.class);
+ BusLifeCycleManager blcm = bus.getExtension(BusLifeCycleManager.class);
+ if (null != blcm) {
+ blcm.registerLifeCycleListener(this);
+ }
+ }
+ }
+
+ @PostConstruct
+ public void init() {
+ if (isEnabled()) {
+
+ if (mbs == null) {
+ // return platform mbean server if the option is specified.
+ if (usePlatformMBeanServer) {
+ mbs = ManagementFactory.getPlatformMBeanServer();
+ } else {
+ List<MBeanServer> servers = CastUtils
+ .cast(MBeanServerFactory.findMBeanServer(mbeanServerName));
+ if (servers.size() <= 1) {
+ mbs = MBeanServerFactory.createMBeanServer(mbeanServerName);
+ } else {
+ mbs = (MBeanServer)servers.get(0);
+ }
+ }
+ }
+
+ if (createMBServerConnectorFactory) {
+ mcf = MBServerConnectorFactory.getInstance();
+ mcf.setMBeanServer(mbs);
+ mcf.setThreaded(isThreaded());
+ mcf.setDaemon(isDaemon());
+ mcf.setServiceUrl(getJMXServiceURL());
+ try {
+ mcf.createConnector();
+ } catch (IOException ex) {
+ connectFailed = true;
+ LOG.log(Level.SEVERE, "START_CONNECTOR_FAILURE_MSG", new
Object[] {ex});
+ }
+ }
+
+ if (!connectFailed && null != bus) {
+ try {
+ //Register Bus here since we can guarantee that Instrumentation
+ //infrastructure has been initialized.
+ ManagedBus mbus = new ManagedBus(bus);
+ register(mbus);
+ } catch (JMException jmex) {
+ LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new
Object[]{bus, jmex});
+ }
+ }
+ }
+ }
+
+ public void register(Object obj, ObjectName name) throws JMException {
+ register(obj, name, false);
+ }
+
+ public void register(Object obj, ObjectName name, boolean forceRegistration) throws
JMException {
+ if (!isEnabled() || connectFailed) {
+ return;
+ }
+ //Try to register as a Standard MBean
+ try {
+ registerMBeanWithServer(obj, persist(name), forceRegistration);
+ } catch (NotCompliantMBeanException e) {
+ //If this is not a "normal" MBean, then try to deploy it using JMX
annotations
+ ModelMBeanAssembler assembler = new ModelMBeanAssembler();
+ ModelMBeanInfo mbi = assembler.getModelMbeanInfo(obj.getClass());
+ register(obj, name, mbi, forceRegistration);
+ }
+ }
+
+ public ObjectName register(ManagedComponent i) throws JMException {
+ ObjectName name = register(i, false);
+
+ return name;
+ }
+
+ public ObjectName register(ManagedComponent i, boolean forceRegistration) throws
JMException {
+ ObjectName name = i.getObjectName();
+ register(i, name, forceRegistration);
+
+ return name;
+ }
+
+
+ public void unregister(ManagedComponent component) throws JMException {
+ ObjectName name = component.getObjectName();
+ unregister(persist(name));
+ }
+
+ public void unregister(ObjectName name) throws JMException {
+ if (!isEnabled() || connectFailed) {
+ return;
+ }
+
+ busMBeans.remove(name);
+ mbs.unregisterMBean(name);
+ }
+
+ public MBeanServer getMBeanServer() {
+ return mbs;
+ }
+
+ public void setServer(MBeanServer server) {
+ this.mbs = server;
+ }
+
+ public void shutdown() {
+ if (!isEnabled()) {
+ return;
+ }
+
+ if (mcf != null) {
+ try {
+ mcf.destroy();
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, "STOP_CONNECTOR_FAILURE_MSG", new
Object[] {ex});
+ }
+ }
+
+ //Using the array to hold the busMBeans to avoid the
CurrentModificationException
+ Object[] mBeans = busMBeans.toArray();
+ for (Object name : mBeans) {
+ busMBeans.remove((ObjectName)name);
+ try {
+ unregister((ObjectName)name);
+ } catch (JMException jmex) {
+ LOG.log(Level.SEVERE, "UNREGISTER_FAILURE_MSG", new
Object[]{name, jmex});
+ }
+ }
+ }
+
+ public void initComplete() {
+
+ }
+
+ public void preShutdown() {
+
+ }
+
+ public void postShutdown() {
+ this.shutdown();
+ }
+
+ private void register(Object obj, ObjectName name, ModelMBeanInfo mbi, boolean
forceRegistration)
+ throws JMException {
+ RequiredModelMBean rtMBean =
+
(RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
+ rtMBean.setModelMBeanInfo(mbi);
+ try {
+ rtMBean.setManagedResource(obj, "ObjectReference");
+ } catch (InvalidTargetObjectTypeException itotex) {
+ throw new JMException(itotex.getMessage());
+ }
+ registerMBeanWithServer(rtMBean, persist(name), forceRegistration);
+ }
+
+ private void registerMBeanWithServer(Object obj, ObjectName name, boolean
forceRegistration)
+ throws JMException {
+ ObjectInstance instance = null;
+ try {
+ instance = mbs.registerMBean(obj, name);
+ } catch (InstanceAlreadyExistsException e) {
+ if (forceRegistration) {
+ mbs.unregisterMBean(name);
+ instance = mbs.registerMBean(obj, name);
+ } else {
+ throw e;
+ }
+ }
+
+ if (instance != null) {
+ busMBeans.add(name);
+ }
+ }
+
+ public String getPersistentBusId() {
+ return persistentBusId;
+ }
+
+ public void setPersistentBusId(String id) {
+ persistentBusId = sanitize(id);
+ }
+
+ private ObjectName persist(ObjectName original) throws JMException {
+ ObjectName persisted = original;
+ if (!(persistentBusId == null
+ || "".equals(persistentBusId)
+ || persistentBusId.startsWith("${"))) {
+ String originalStr = original.toString();
+ if (originalStr.indexOf(ManagementConstants.BUS_ID_PROP) != -1) {
+ String persistedStr =
+ originalStr.replaceFirst(ManagementConstants.BUS_ID_PROP +
"=" + bus.getId(),
+ ManagementConstants.BUS_ID_PROP +
"=" + persistentBusId);
+ persisted = new ObjectName(persistedStr);
+ }
+ }
+ return persisted;
+ }
+
+ private String sanitize(String in) {
+ String result = null;
+ if (in != null) {
+ result = in.replace(':', '_');
+ result = result.replace('/', '_');
+ result = result.replace('\\', '_');
+ result = result.replace('?', '_');
+ result = result.replace('=', '_');
+ result = result.replace(',', '_');
+ }
+ return result;
+ }
+}
+
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/MBServerConnectorFactory.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/MBServerConnectorFactory.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/MBServerConnectorFactory.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,180 @@
+/**
+ * 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.cxf.management.jmx;
+
+import java.io.IOException;
+import java.rmi.registry.LocateRegistry;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.cxf.common.logging.LogUtils;
+
+
+
+/**
+ * Deal with the MBeanServer Connections
+ *
+ */
+public final class MBServerConnectorFactory {
+
+ public static final String DEFAULT_SERVICE_URL =
"service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi";
+
+ private static final Logger LOG =
LogUtils.getL7dLogger(MBServerConnectorFactory.class);
+
+ private static MBServerConnectorFactory factory;
+ private static MBeanServer server;
+
+ private static String serviceUrl = DEFAULT_SERVICE_URL;
+
+ private static Map<String, ?> environment;
+
+ private static boolean threaded;
+
+ private static boolean daemon;
+
+ private static JMXConnectorServer connectorServer;
+
+ private MBServerConnectorFactory() {
+
+ }
+
+ private int getURLLocalHostPort(String url) {
+ int portStart = url.indexOf("localhost") + 10;
+ int portEnd;
+ int port = 0;
+ if (portStart > 0) {
+ portEnd = indexNotOfNumber(url, portStart);
+ if (portEnd > portStart) {
+ final String portString = url.substring(portStart, portEnd);
+ port = Integer.parseInt(portString);
+ }
+ }
+ return port;
+ }
+
+ private static int indexNotOfNumber(String str, int index) {
+ int i = 0;
+ for (i = index; i < str.length(); i++) {
+ if (str.charAt(i) < '0' || str.charAt(i) > '9') {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public static MBServerConnectorFactory getInstance() {
+ if (factory == null) {
+ factory = new MBServerConnectorFactory();
+ }
+ return factory;
+ }
+
+ public void setMBeanServer(MBeanServer ms) {
+ server = ms;
+ }
+
+ public void setServiceUrl(String url) {
+ serviceUrl = url;
+ }
+
+ public void setEnvironment(Map<String, ?> env) {
+ environment = env;
+ }
+
+ public void setThreaded(boolean fthread) {
+ threaded = fthread;
+ }
+
+ public void setDaemon(boolean fdaemon) {
+ daemon = fdaemon;
+ }
+
+
+ public void createConnector() throws IOException {
+
+ if (server == null) {
+ server = MBeanServerFactory.createMBeanServer();
+ }
+
+ // Create the JMX service URL.
+ JMXServiceURL url = new JMXServiceURL(serviceUrl);
+
+ // if the URL is localhost, start up an Registry
+ if (serviceUrl.indexOf("localhost") > -1
+ && url.getProtocol().compareToIgnoreCase("rmi") == 0) {
+ try {
+ int port = getURLLocalHostPort(serviceUrl);
+ try {
+ LocateRegistry.createRegistry(port);
+ } catch (Exception ex) {
+ // the registry may had been created
+ LocateRegistry.getRegistry(port);
+ }
+
+ } catch (Exception ex) {
+ LOG.log(Level.SEVERE, "CREATE_REGISTRY_FAULT_MSG", new
Object[]{ex});
+ }
+ }
+
+ // Create the connector server now.
+ connectorServer =
+ JMXConnectorServerFactory.newJMXConnectorServer(url, environment, server);
+
+
+ if (threaded) {
+ // Start the connector server asynchronously (in a separate thread).
+ Thread connectorThread = new Thread() {
+ public void run() {
+ try {
+ connectorServer.start();
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, "START_CONNECTOR_FAILURE_MSG",
new Object[]{ex});
+ }
+ }
+ };
+
+ connectorThread.setName("JMX Connector Thread [" + serviceUrl +
"]");
+ connectorThread.setDaemon(daemon);
+ connectorThread.start();
+ } else {
+ // Start the connector server in the same thread.
+ connectorServer.start();
+ }
+
+ if (LOG.isLoggable(Level.INFO)) {
+ LOG.info("JMX connector server started: " + connectorServer);
+ }
+ }
+
+ public void destroy() throws IOException {
+ connectorServer.stop();
+ if (LOG.isLoggable(Level.INFO)) {
+ LOG.info("JMX connector server stopped: " + connectorServer);
+ }
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/Messages.properties
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/Messages.properties
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/Messages.properties 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,30 @@
+#
+#
+# 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.
+#
+#
+REGISTER_FAILURE_MSG = MBean Object {0} register to MBeanServer failed : {1}
+UNREGISTER_FAILURE_MSG = MBean Object {0} unregister to MBeanServer failed : {1}
+INSTANTIANTE_FAILURE_MSG = Instantiating the Model MBean in MBeanServer failed : {0}
+MBEAN_FAILURE_MSG = MBean option failed : {0}
+SET_MANAGED_RESOURCE_FAILURE_MSG = ModelMBean set managed resource failed : {0}
+START_CONNECTOR_FAILURE_MSG = Could not start JMX connector server : {0}
+STOP_CONNECTOR_FAILURE_MSG = Could not shutdown JMX connector server : {0}
+GET_MANAGED_INFORMATION_FAILURE_MSG = Could not get the instrumentation {0} managed
information
+CREATE_REGISTRY_FAULT_MSG = Exception starting RMI registry for JMX : {0}
+OBJECT_NAME_FALUE_MSG = Get the {0} ObjectName file failed : {1}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanAssembler.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanAssembler.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanAssembler.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,286 @@
+/**
+ * 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.cxf.management.jmx.export.runtime;
+
+import java.lang.reflect.Method;
+
+import javax.management.Descriptor;
+import javax.management.modelmbean.ModelMBeanInfo;
+
+import org.apache.cxf.management.annotation.ManagedAttribute;
+import org.apache.cxf.management.annotation.ManagedNotification;
+import org.apache.cxf.management.annotation.ManagedNotifications;
+import org.apache.cxf.management.annotation.ManagedOperation;
+import org.apache.cxf.management.annotation.ManagedOperationParameter;
+import org.apache.cxf.management.annotation.ManagedOperationParameters;
+import org.apache.cxf.management.annotation.ManagedResource;
+
+
+public class ModelMBeanAssembler {
+ private ModelMBeanInfoSupporter supporter = new ModelMBeanInfoSupporter();
+
+ public ManagedResource getManagedResource(Class<?> clazz) {
+ return clazz.getAnnotation(ManagedResource.class);
+ }
+
+ public ManagedAttribute getManagedAttribute(Method method) {
+ return method.getAnnotation(ManagedAttribute.class);
+ }
+
+ public ManagedOperation getManagedOperation(Method method) {
+ return method.getAnnotation(ManagedOperation.class);
+ }
+
+ public ManagedOperationParameter[] getManagedOperationParameters(Method method) {
+ ManagedOperationParameters params =
method.getAnnotation(ManagedOperationParameters.class);
+ ManagedOperationParameter[] result = null;
+ if (params == null) {
+ result = new ManagedOperationParameter[0];
+ } else {
+ result = params.value();
+ }
+ return result;
+ }
+
+ public ManagedNotification[] getManagedNotifications(Class<?> clazz) {
+ ManagedNotifications notificationsAnn =
+ clazz.getAnnotation(ManagedNotifications.class);
+ ManagedNotification[] result = null;
+ if (null == notificationsAnn) {
+ return new ManagedNotification[0];
+ }
+ result = notificationsAnn.value();
+ return result;
+ }
+
+ public String getAttributeName(String methodName) {
+ if (methodName.indexOf("set") == 0) {
+ return methodName.substring(3);
+ }
+ if (methodName.indexOf("get") == 0) {
+ return methodName.substring(3);
+ }
+ if (methodName.indexOf("is") == 0) {
+ return methodName.substring(2);
+ }
+ return null;
+ }
+
+ public static boolean checkMethod(Method[] methods, String methodName) {
+ boolean result = false;
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().compareTo(methodName) == 0) {
+ result = true;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public static String getAttributeType(Method[] methods, String attributeName) {
+ String result = null;
+ String searchMethod = "get" + attributeName;
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().compareTo(searchMethod) == 0) {
+ result = methods[i].getReturnType().getName();
+ break;
+ }
+ }
+ // check it is "is " attribute
+ if (null == result) {
+ searchMethod = "is" + attributeName;
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().compareTo(searchMethod) == 0) {
+ result = methods[i].getReturnType().getName();
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ class ManagedAttributeInfo {
+ String fname;
+ String ftype;
+ String description;
+ boolean read;
+ boolean write;
+ boolean is;
+ };
+
+
+ //get the attribut information for the method
+ public ManagedAttributeInfo getAttributInfo(Method[] methods,
+ String attributName,
+ String attributType,
+ ManagedAttribute managedAttribute) {
+ ManagedAttributeInfo mai = new ManagedAttributeInfo();
+ mai.fname = attributName;
+ mai.ftype = attributType;
+ mai.description = managedAttribute.description();
+ mai.is = checkMethod(methods, "is" + attributName);
+ mai.write = checkMethod(methods, "set" + attributName);
+
+ if (mai.is) {
+ mai.read = true;
+ } else {
+ mai.read = checkMethod(methods, "get" + attributName);
+ }
+
+ return mai;
+
+ }
+
+ Method findMethodByName(Method methods[], String methodName) {
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().compareTo(methodName) == 0) {
+ return methods[i];
+ } else {
+ continue;
+ }
+
+ }
+ return null;
+
+ }
+
+ void addAttributeOperation(Method method) {
+ Descriptor operationDescriptor =
+ supporter.buildAttributeOperationDescriptor(method.getName());
+
+ Class<?>[] types = method.getParameterTypes();
+
+ String[] paramTypes = new String[types.length];
+ String[] paramNames = new String[types.length];
+ String[] paramDescs = new String[types.length];
+
+ for (int j = 0; j < types.length; j++) {
+ paramTypes[j] = types[j].getName();
+ paramDescs[j] = "";
+ paramNames[j] = types[j].getName();
+ }
+
+ supporter.addModelMBeanMethod(method.getName(),
+ paramTypes,
+ paramNames,
+ paramDescs,
+ "",
+ method.getReturnType().getName(),
+ operationDescriptor);
+ }
+
+ public ModelMBeanInfo getModelMbeanInfo(Class<?> clazz) {
+ supporter.clear();
+ ManagedResource mr = getManagedResource(clazz);
+ if (mr == null) {
+ // the class is not need to expose to jmx
+ return null;
+ }
+ // Clazz get all the method which should be managemed
+ Descriptor mbeanDescriptor = supporter.buildMBeanDescriptor(mr);
+
+ // add the notification
+ ManagedNotification[] mns = getManagedNotifications(clazz);
+ for (int k = 0; k < mns.length; k++) {
+ supporter.addModelMBeanNotification(mns[k].notificationTypes(),
+ mns[k].name(),
+ mns[k].description(), null);
+ }
+
+ Method[] methods = clazz.getDeclaredMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ ManagedAttribute ma = getManagedAttribute(methods[i]);
+ //add Attribute to the ModelMBean
+ if (ma != null) {
+ String attributeName = getAttributeName(methods[i].getName());
+ if (!supporter.checkAttribute(attributeName)) {
+ String attributeType = getAttributeType(methods, attributeName);
+ ManagedAttributeInfo mai = getAttributInfo(methods,
+ attributeName,
+ attributeType,
+ ma);
+ Descriptor attributeDescriptor =
+ supporter.buildAttributeDescriptor(ma,
+ attributeName,
+ mai.is, mai.read, mai.write);
+
+ // should setup the description
+ supporter.addModelMBeanAttribute(mai.fname,
+ mai.ftype,
+ mai.read,
+ mai.write,
+ mai.is,
+ mai.description,
+ attributeDescriptor);
+
+ Method method;
+ // add the attribute methode to operation
+ if (mai.read) {
+ if (mai.is) {
+ method = findMethodByName(methods, "is" +
attributeName);
+ } else {
+ method = findMethodByName(methods, "get" +
attributeName);
+ }
+ addAttributeOperation(method);
+ }
+ if (mai.write) {
+ method = findMethodByName(methods, "set" +
attributeName);
+ addAttributeOperation(method);
+ }
+ }
+
+ } else {
+ // add Operation to the ModelMBean
+ ManagedOperation mo = getManagedOperation(methods[i]);
+
+ if (mo != null) {
+ Class<?>[] types = methods[i].getParameterTypes();
+ ManagedOperationParameter[] mop =
getManagedOperationParameters(methods[i]);
+ String[] paramTypes = new String[types.length];
+ String[] paramNames = new String[types.length];
+ String[] paramDescs = new String[types.length];
+
+ for (int j = 0; j < types.length; j++) {
+ paramTypes[j] = types[j].getName();
+ if (j < mop.length) {
+ paramDescs[j] = mop[j].description();
+ paramNames[j] = mop[j].name();
+ } else {
+ paramDescs[j] = "";
+ paramNames[j] = types[j].getName();
+ }
+ }
+ Descriptor operationDescriptor =
+ supporter.buildOperationDescriptor(mo, methods[i].getName());
+ supporter.addModelMBeanMethod(methods[i].getName(),
+ paramTypes,
+ paramNames,
+ paramDescs,
+ mo.description(),
+ methods[i].getReturnType().getName(),
+ operationDescriptor);
+ }
+ }
+
+ }
+ return supporter.buildModelMBeanInfo(mbeanDescriptor);
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanInfoSupporter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanInfoSupporter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/jmx/export/runtime/ModelMBeanInfoSupporter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,277 @@
+/**
+ * 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.cxf.management.jmx.export.runtime;
+
+import java.lang.reflect.Constructor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+import javax.management.Descriptor;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.modelmbean.DescriptorSupport;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
+import javax.management.modelmbean.ModelMBeanConstructorInfo;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.ModelMBeanInfoSupport;
+import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+
+import org.apache.cxf.management.annotation.ManagedAttribute;
+import org.apache.cxf.management.annotation.ManagedOperation;
+import org.apache.cxf.management.annotation.ManagedResource;
+
+public class ModelMBeanInfoSupporter {
+ protected Map<String, ModelMBeanAttributeInfo> attributes
+ = new HashMap<String, ModelMBeanAttributeInfo>();
+ protected Map<String, ModelMBeanNotificationInfo> notifications
+ = new HashMap<String, ModelMBeanNotificationInfo>();
+ protected Map<Constructor<?>, ModelMBeanConstructorInfo> constructors
+ = new HashMap<Constructor<?>, ModelMBeanConstructorInfo>();
+ protected Map<String, ModelMBeanOperationInfo> operations
+ = new HashMap<String, ModelMBeanOperationInfo>();
+
+ public ModelMBeanInfoSupporter() {
+
+ }
+
+ public void clear() {
+ attributes.clear();
+ notifications.clear();
+ constructors.clear();
+ operations.clear();
+ }
+ public void addModelMBeanMethod(String name,
+ String[] paramTypes,
+ String[] paramNames,
+ String[] paramDescs,
+ String description,
+ String rtype,
+ Descriptor desc) {
+ MBeanParameterInfo[] params = null;
+ if (paramTypes != null) {
+ params = new MBeanParameterInfo[ paramTypes.length ];
+ for (int i = 0; i < paramTypes.length; i++) {
+ params[i] = new MBeanParameterInfo(paramNames[i],
+ paramTypes[i], paramDescs[i]);
+ }
+ }
+
+ operations.put(name,
+ new ModelMBeanOperationInfo(name,
+ description,
+ params,
+ rtype,
+ MBeanOperationInfo.ACTION,
+ desc));
+ }
+
+ public void addModelMBeanNotification(String[] type,
+ String className,
+ String description,
+ Descriptor desc) {
+ notifications.put(className,
+ new ModelMBeanNotificationInfo(type, className, description,
desc));
+ }
+
+ public boolean checkAttribute(String attributeName) {
+ return attributes.containsKey(attributeName);
+ }
+
+ public void addModelMBeanAttribute(String fname,
+ String ftype,
+ boolean read,
+ boolean write,
+ boolean is,
+ String description,
+ Descriptor desc) {
+ attributes.put(fname, new ModelMBeanAttributeInfo(fname,
+ ftype,
+ description,
+ read,
+ write,
+ is,
+ desc));
+ }
+
+
+ public void addModelMBeanConstructor(Constructor<?> c,
+ String description,
+ Descriptor desc) {
+ this.constructors.put(c,
+ new ModelMBeanConstructorInfo(description,
+ c,
+ desc));
+ }
+
+ public ModelMBeanInfo buildModelMBeanInfo(Descriptor desc) {
+
+ ModelMBeanOperationInfo[] ops =
+ (ModelMBeanOperationInfo[])operations.values().toArray(new
ModelMBeanOperationInfo[0]);
+
+ ModelMBeanAttributeInfo[] atts =
+ (ModelMBeanAttributeInfo[])attributes.values().toArray(new
ModelMBeanAttributeInfo[0]);
+
+ ModelMBeanConstructorInfo[] cons =
+ (ModelMBeanConstructorInfo[])constructors.values().toArray(new
ModelMBeanConstructorInfo[0]);
+
+ ModelMBeanNotificationInfo[] notifs =
+ (ModelMBeanNotificationInfo[])notifications.values().toArray(new
ModelMBeanNotificationInfo[0]);
+
+ return new
ModelMBeanInfoSupport("javax.management.modelmbean.ModelMBeanInfo",
+ "description",
+ atts,
+ cons,
+ ops,
+ notifs, desc);
+ }
+
+
+ public Descriptor buildAttributeDescriptor(
+ ManagedAttribute ma, String attributeName, boolean is, boolean read, boolean
write) {
+
+ Descriptor desc = new DescriptorSupport();
+
+ desc.setField("name", attributeName);
+
+ desc.setField("descriptorType", "attribute");
+
+ if (read) {
+ if (is) {
+ desc.setField("getMethod", "is" + attributeName);
+ } else {
+ desc.setField("getMethod", "get" + attributeName);
+ }
+ }
+
+ if (write) {
+ desc.setField("setMethod", "set" + attributeName);
+ }
+
+
+ if (ma.currencyTimeLimit() >= -1) {
+ desc.setField("currencyTimeLimit", ma.currencyTimeLimit());
+ }
+
+ if (ma.persistPolicy().length() > 0) {
+ desc.setField("persistPolicy", ma.persistPolicy());
+ }
+
+ if (ma.persistPeriod() >= -1) {
+ desc.setField("persistPeriod", ma.persistPeriod());
+ }
+
+ if (ma.defaultValue() != null) {
+ desc.setField("default", ma.defaultValue());
+ }
+
+ return desc;
+ }
+
+ public Descriptor buildOperationDescriptor(ManagedOperation mo, String operationName)
{
+ Descriptor desc = new DescriptorSupport();
+
+ desc.setField("name", operationName);
+
+ desc.setField("descriptorType", "operation");
+
+ desc.setField("role", "operation");
+
+ if (mo.description() != null) {
+ desc.setField("displayName", mo.description());
+ }
+
+ if (mo.currencyTimeLimit() >= -1) {
+ desc.setField("currencyTimeLimit", mo.currencyTimeLimit());
+ }
+
+ return desc;
+ }
+
+ public Descriptor buildAttributeOperationDescriptor(String operationName) {
+
+ Descriptor desc = new DescriptorSupport();
+
+ desc.setField("name", operationName);
+
+ desc.setField("descriptorType", "operation");
+
+ if (operationName.indexOf("set") == 0) {
+ desc.setField("role", "setter");
+ } else {
+ desc.setField("role", "getter");
+ }
+
+ return desc;
+ }
+
+
+ public Descriptor buildMBeanDescriptor(ManagedResource mr) {
+ Descriptor desc = new DescriptorSupport();
+
+ if (mr.componentName() != null) {
+ desc.setField("name", mr.componentName());
+ }
+
+ desc.setField("descriptorType", "mbean");
+
+ if (mr.description() != null) {
+ desc.setField("displayName", mr.description());
+ }
+
+ if (mr.persistLocation() != null) {
+ desc.setField("persistLocation", mr.persistLocation());
+ }
+
+ if (mr.persistName() != null) {
+ desc.setField("persistName", mr.persistName());
+ }
+
+ if (mr.log()) {
+ desc.setField("log", "true");
+ } else {
+ desc.setField("log", "false");
+ }
+
+ if (mr.persistPolicy() != null) {
+ desc.setField("persistPolicy", mr.persistPolicy());
+ }
+
+ if (mr.persistPeriod() >= -1) {
+ desc.setField("persistPeriod", mr.persistPeriod());
+ }
+
+ if (mr.logFile() != null) {
+ desc.setField("logFile", mr.logFile());
+ }
+
+ if (mr.currencyTimeLimit() >= -1) {
+ desc.setField("currencyTimeLimit", mr.currencyTimeLimit());
+ }
+
+ return desc;
+
+ }
+
+
+}
+
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,186 @@
+/**
+ * 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.cxf.management.persistence;
+
+import java.util.Date;
+import java.util.List;
+
+public class ExchangeData {
+
+ private String encoding;
+
+ private String exceptionType;
+
+ private Integer id;
+
+ private Date inDate;
+
+ private String operation;
+
+ private Date outDate;
+
+ private List<ExchangeDataProperty> properties;
+
+ private String request;
+
+ private Integer requestSize;
+
+ private String response;
+
+ private Integer responseSize;
+
+ private String serviceName;
+
+ private String stackTrace;
+
+ private String status;
+
+ private String uri;
+
+ private String userAgent;
+
+ public String getEncoding() {
+ return this.encoding;
+ }
+
+ public String getExceptionType() {
+ return this.exceptionType;
+ }
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public Date getInDate() {
+ return this.inDate;
+ }
+
+ public String getOperation() {
+ return this.operation;
+ }
+
+ public Date getOutDate() {
+ return this.outDate;
+ }
+
+ public List<ExchangeDataProperty> getProperties() {
+ return this.properties;
+ }
+
+ public String getRequest() {
+ return this.request;
+ }
+
+ public Integer getRequestSize() {
+ return this.requestSize;
+ }
+
+ public String getResponse() {
+ return this.response;
+ }
+
+ public Integer getResponseSize() {
+ return this.responseSize;
+ }
+
+ public String getServiceName() {
+ return this.serviceName;
+ }
+
+ public String getStackTrace() {
+ return this.stackTrace;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+
+ public String getUri() {
+ return this.uri;
+ }
+
+ public String getUserAgent() {
+ return this.userAgent;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void setExceptionType(String exceptionType) {
+ this.exceptionType = exceptionType;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public void setInDate(Date inDate) {
+ this.inDate = inDate;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ public void setOutDate(Date outDate) {
+ this.outDate = outDate;
+ }
+
+ public void setProperties(List<ExchangeDataProperty> properties) {
+ this.properties = properties;
+ }
+
+ public void setRequest(String request) {
+ this.request = request;
+ }
+
+ public void setRequestSize(Integer requestSize) {
+ this.requestSize = requestSize;
+ }
+
+ public void setResponse(String response) {
+ this.response = response;
+ }
+
+ public void setResponseSize(Integer responseSize) {
+ this.responseSize = responseSize;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public void setStackTrace(String stackTrace) {
+ this.stackTrace = stackTrace;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ public void setUserAgent(String userAgent) {
+ this.userAgent = userAgent;
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,26 @@
+/**
+ * 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.cxf.management.persistence;
+
+
+public interface ExchangeDataDAO {
+
+ void save(ExchangeData exchangeData) throws Exception;
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataFilter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataFilter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataFilter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,32 @@
+/**
+ * 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.cxf.management.persistence;
+
+/**
+ * This interface can be implemented to indicate to PersistOutInterceptor
+ * if an ExchangeData should be persisted.
+ *
+ * @author remi
+ *
+ */
+public interface ExchangeDataFilter {
+
+ boolean shouldPersist(ExchangeData data);
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,63 @@
+/**
+ * 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.cxf.management.persistence;
+
+public class ExchangeDataProperty {
+
+ private Integer id;
+
+ private String name;
+
+ private ExchangeData exchangeData;
+
+ private String value;
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public ExchangeData getExchangeData() {
+ return this.exchangeData;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setExchangeData(ExchangeData exchangeData) {
+ this.exchangeData = exchangeData;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,130 @@
+/**
+ * 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.cxf.management.persistence;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.StringWriter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.logging.LogUtils;
+
+public class FilesystemExchangeDataDAO implements ExchangeDataDAO {
+
+ private static final Logger LOG =
LogUtils.getL7dLogger(FilesystemExchangeDataDAO.class);
+
+ private String directory;
+
+ private String extension = "txt";
+
+ public void setDirectory(String directory) {
+ this.directory = directory;
+ }
+
+ public void save(ExchangeData exchange) throws Exception {
+ File file = null;
+
+ if (this.directory == null) {
+ file = File.createTempFile("cxf-management-", "." +
this.extension);
+ } else {
+ file = File.createTempFile("cxf-management-", "." +
this.extension, new File(this.directory));
+ }
+
+ StringWriter stringWriter = new StringWriter();
+
+ stringWriter.append("Service : ");
+ stringWriter.append(exchange.getServiceName());
+ stringWriter.append("\n");
+
+ stringWriter.append("Operation : ");
+ stringWriter.append(exchange.getOperation());
+ stringWriter.append("\n");
+
+ stringWriter.append("Status : ");
+ stringWriter.append(exchange.getStatus());
+ stringWriter.append("\n");
+
+ stringWriter.append("URI : ");
+ stringWriter.append(exchange.getUri());
+ stringWriter.append("\n");
+
+ stringWriter.append("User agent : ");
+ stringWriter.append(exchange.getUserAgent());
+ stringWriter.append("\n");
+
+ stringWriter.append("Encoding : ");
+ stringWriter.append(exchange.getEncoding());
+ stringWriter.append("\n");
+
+ stringWriter.append("Date in : ");
+ stringWriter.append(exchange.getInDate().toString());
+ stringWriter.append("\n");
+
+ stringWriter.append("Date out : ");
+ stringWriter.append(exchange.getOutDate().toString());
+ stringWriter.append("\n");
+
+ stringWriter.append("Request size : ");
+ stringWriter.append(String.valueOf(exchange.getRequestSize()));
+ stringWriter.append("\n");
+
+ stringWriter.append("Response size : ");
+ stringWriter.append(String.valueOf(exchange.getResponseSize()));
+ stringWriter.append("\n");
+
+ stringWriter.append("\n\n\nRequest : \n\n\n");
+ stringWriter.append(exchange.getRequest());
+ stringWriter.append("\n\n\n\n");
+
+ stringWriter.append("\n\n\nResponse : \n\n\n");
+ stringWriter.append(exchange.getResponse());
+ stringWriter.append("\n\n\n\n");
+
+ if ("ERROR".equals(exchange.getStatus())) {
+ stringWriter.append("\n\n\nExcepttion : ");
+ stringWriter.append(exchange.getExceptionType());
+ stringWriter.append("\nStackTrace : ");
+ stringWriter.append(exchange.getStackTrace());
+ stringWriter.append("\n\n\n\n");
+ }
+
+ stringWriter.append("\n\nProperties : \n");
+
+ if (exchange.getProperties() != null) {
+ for (ExchangeDataProperty exchangeProperty : exchange.getProperties()) {
+ stringWriter.append(exchangeProperty.getName());
+ stringWriter.append(" : ");
+ stringWriter.append(exchangeProperty.getValue());
+ stringWriter.append("\n");
+ }
+ }
+
+ FileOutputStream fileOutputStream = new FileOutputStream(file);
+
+ fileOutputStream.write(stringWriter.getBuffer().toString().getBytes());
+
+ fileOutputStream.close();
+
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Exchange data saved in " + file.getAbsolutePath());
+ }
+
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/StatusExchangeDataFilter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/StatusExchangeDataFilter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/persistence/StatusExchangeDataFilter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,40 @@
+/**
+ * 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.cxf.management.persistence;
+
+/**
+ * This filter will only persist exchange data with a specific status.
+ *
+ * @author remi
+ *
+ */
+public class StatusExchangeDataFilter implements ExchangeDataFilter {
+
+ private String statusFilter = "ERROR";
+
+ public void setStatusFilter(String statusFilter) {
+ this.statusFilter = statusFilter;
+ }
+
+ public boolean shouldPersist(ExchangeData data) {
+
+ return data != null && this.statusFilter.equals(data.getStatus());
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,259 @@
+/**
+ * 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.cxf.management.utils;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.management.ManagementConstants;
+
+
+public final class ManagementConsole {
+ private static MBeanServerConnection mbsc;
+ private static final String DEFAULT_JMXSERVICE_URL =
+ "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
+ private static final Logger LOG = LogUtils.getL7dLogger(ManagementConsole.class);
+
+ String jmxServerURL;
+ String portName;
+ String serviceName;
+ String operationName;
+
+ ManagementConsole() {
+
+ }
+
+ public void getManagedObjectAttributes(ObjectName name) throws Exception {
+
+ if (mbsc == null) {
+ LOG.log(Level.SEVERE , "NO_MBEAN_SERVER");
+ return;
+ }
+ MBeanInfo info = mbsc.getMBeanInfo(name);
+ MBeanAttributeInfo[] attrs = info.getAttributes();
+ if (attrs == null) {
+ return;
+ }
+ for (int i = 0; i < attrs.length; i++) {
+ if (attrs[i].isReadable()) {
+ try {
+ Object o = mbsc.getAttribute(name, attrs[i].getName());
+ System.out.println("\t\t" + attrs[i].getName() + " =
" + o);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ void connectToMBserver() throws IOException {
+ jmxServerURL = jmxServerURL == null ? DEFAULT_JMXSERVICE_URL : jmxServerURL;
+ JMXServiceURL url = new JMXServiceURL(jmxServerURL);
+ JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
+ mbsc = jmxc.getMBeanServerConnection();
+ }
+
+ void listAllManagedEndpoint() {
+ try {
+ ObjectName queryEndpointName = new
ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
+ +
":type=Bus.Service.Endpoint,*");
+ Set<ObjectName> endpointNames =
CastUtils.cast(mbsc.queryNames(queryEndpointName, null));
+ System.out.println("The endpoints are : ");
+ for (ObjectName oName : endpointNames) {
+ System.out.println(oName);
+ getManagedObjectAttributes(oName);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "FAIL_TO_LIST_ENDPOINTS", new Object[]{e});
+ }
+ }
+
+ ObjectName getEndpointObjectName()
+ throws MalformedObjectNameException, NullPointerException {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME +
":type=Bus.Service.Endpoint,");
+ buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=\"" +
serviceName + "\",");
+ buffer.append(ManagementConstants.PORT_NAME_PROP + "=\"" +
portName + "\",*");
+ return new ObjectName(buffer.toString());
+ }
+
+ private void invokeEndpoint(String operation) {
+ ObjectName endpointName = null;
+ ObjectName queryEndpointName;
+ try {
+ queryEndpointName = getEndpointObjectName();
+ Set<ObjectName> endpointNames =
CastUtils.cast(mbsc.queryNames(queryEndpointName, null));
+ // now get the ObjectName with the busId
+ Iterator it = endpointNames.iterator();
+
+ if (it.hasNext()) {
+ // only deal with the first endpoint object which retrun from the list.
+ endpointName = (ObjectName)it.next();
+ mbsc.invoke(endpointName, operation, new Object[0], new String[0]);
+ System.out.println("invoke endpoint " + endpointName
+ + " operation " + operation + "
succeed!");
+ }
+
+ } catch (Exception e) {
+ if (null == endpointName) {
+ LOG.log(Level.SEVERE, "FAIL_TO_CREATE_ENDPOINT_OBEJCTNAME", new
Object[]{e});
+
+ } else {
+ LOG.log(Level.SEVERE,
"FAIL_TO_INVOKE_MANAGED_OBJECT_OPERATION",
+ new Object[]{endpointName, operation, e.toString()});
+ }
+ }
+ }
+
+ void startEndpoint() {
+ invokeEndpoint("start");
+ }
+
+ void stopEndpoint() {
+ invokeEndpoint("stop");
+ }
+
+ void restartEndpoint() {
+ invokeEndpoint("stop");
+ invokeEndpoint("start");
+ }
+
+
+ boolean parserArguments(String[] args) {
+ portName = "";
+ serviceName = "";
+ operationName = "";
+ boolean result = false;
+
+ int i;
+ String arg;
+ try {
+ for (i = 0; i < args.length; i++) {
+ arg = args[i];
+ if ("--port".equals(arg) || "-p".equals(arg)) {
+ portName = args[++i];
+ continue;
+ }
+ if ("--service".equals(arg) || "-s".equals(arg)) {
+ serviceName = args[++i];
+ continue;
+ }
+ if ("--jmx".equals(arg) || "-j".equals(arg)) {
+ jmxServerURL = args[++i];
+ continue;
+ }
+ if ("--operation".equals(arg) || "-o".equals(arg)) {
+ operationName = args[++i];
+ // it is the key option
+ result = true;
+ continue;
+ }
+ }
+ } catch (Exception ex) {
+ // can't paraser the argument rightly
+ return false;
+ }
+ return result;
+ }
+
+ private static void printUsage() {
+ System.out.println("Management Console for CXF Managed Endpoints");
+ System.out.println("You can start and stop the endpoints which export as JMX
managed objects");
+ System.out.println("Usage: -o list ");
+ System.out.println(" -o {start|stop|restart} -p PORTQNAME -s
SERVICEQNAME ");
+ System.out.println("Valid options:");
+ System.out.println(" -o [--operation] {list|start|stop|restart} call the
managed endpoint "
+ + "operation");
+ System.out.println(" list: show all the managed
endpoints' objectNames and");
+ System.out.println(" attributes");
+ System.out.println(" start: start the endpoint with
the -p and -s "
+ + "arguments");
+ System.out.println(" stop: stop the endpoint with
the -p and -s arguments");
+ System.out.println(" restart: restart the endpoint
with the -p and -s "
+ + "arguments");
+
+ System.out.println(" -p [--port] arg ARG: the port Qname of the
managed endpoint");
+ System.out.println(" -s [--service] arg ARG: the service Qname of the
managed endpoint");
+ System.out.println(" -j [--jmx] arg ARG: the JMXServerURL for
connecting to the mbean "
+ + "server");
+ System.out.println(" if not using this option, the
JMXServerURL will be "
+ + "set as");
+ System.out.println("
\"service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"
+ + "\"");
+
+
+ }
+
+ public void doManagement() {
+ try {
+ connectToMBserver();
+ if ("list".equalsIgnoreCase(operationName)) {
+ listAllManagedEndpoint();
+ return;
+ }
+ if ("start".equalsIgnoreCase(operationName)) {
+ startEndpoint();
+ return;
+ }
+ if ("stop".equalsIgnoreCase(operationName)) {
+ stopEndpoint();
+ return;
+ }
+ if ("restart".equalsIgnoreCase(operationName)) {
+ restartEndpoint();
+ return;
+ }
+ printUsage();
+ } catch (IOException e) {
+ LOG.log(Level.SEVERE, "FAIL_TO_CONNECT_TO_MBEAN_SERVER", new
Object[]{jmxServerURL});
+ }
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ ManagementConsole mc = new ManagementConsole();
+ if (mc.parserArguments(args)) {
+ mc.doManagement();
+ } else {
+ printUsage();
+ }
+
+ }
+
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,25 @@
+#
+#
+# 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.
+#
+#
+NO_MBEAN_SERVER = Can't find the MBeanServer, please connect to the MBeanServer
first.
+FAIL_TO_CONNECT_TO_MBEAN_SERVER = Failed to connect to the MBeanServer with url {0}
+FAIL_TO_LIST_ENDPOINTS = Failed to list the endpoints, the exception is {0}.
+FAIL_TO_CREATE_ENDPOINT_OBEJCTNAME = Failed to create the endpoints objectname, error is
{0}
+FAIL_TO_INVOKE_MANAGED_OBJECT_OPERATION = Failed to invoke the managed object
{0}''s operation {1}, the exception is {2}.
\ No newline at end of file
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/bus-extensions.xml
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/bus-extensions.xml
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/bus-extensions.xml 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<extensions
xmlns="http://cxf.apache.org/bus/extension">
+ <extension
class="org.apache.cxf.management.jmx.InstrumentationManagerImpl"
+ interface="org.apache.cxf.management.InstrumentationManager"/>
+</extensions>
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans
xmlns="http://www.springframework.org/schema/beans"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xmlns:foo="http://cxf.apache.org/configuration/foo"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="org.apache.cxf.management.InstrumentationManager"
+ class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
+ <property name="bus" ref="cxf"/>
+ <property name="enabled" value="false"/>
+ <property name="threaded" value="false"/>
+ <property name="daemon" value="false"/>
+ </bean>
+
+</beans>
\ No newline at end of file
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf.extension
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf.extension
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/META-INF/cxf/cxf.extension 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1 @@
+META-INF/cxf/cxf-extension-management.xml
\ No newline at end of file
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<xs:schema
targetNamespace="http://cxf.apache.org/management"
+
xmlns:tns="http://cxf.apache.org/management"
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ jaxb:version="2.0">
+
+ <xs:complexType name="JMXConnectorPolicyType">
+ <xs:attribute name="Enabled" type="xs:boolean"
use="required" />
+ <xs:attribute name="Threaded" type="xs:boolean"
use="required" />
+ <xs:attribute name="Daemon" type="xs:boolean"
use="required" />
+ <xs:attribute name="JMXServiceURL" type="xs:string"
default="service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi"/>
+ </xs:complexType>
+
+ <xs:element name="JMXConnectorPolicy"
type="tns:JMXConnectorPolicyType"/>
+
+</xs:schema>
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,88 @@
+/**
+ * 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.cxf.management;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.workqueue.WorkQueueManagerImpl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class InstrumentationManagerTest extends Assert {
+ InstrumentationManager im;
+ Bus bus;
+
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ //test case had done the bus.shutdown
+ bus.shutdown(true);
+ }
+
+ @Test
+ public void testInstrumentationNotEnabled() {
+ SpringBusFactory factory = new SpringBusFactory();
+ bus = factory.createBus();
+ im = bus.getExtension(InstrumentationManager.class);
+ assertTrue("Instrumentation Manager should not be null", im != null);
+ MBeanServer mbs = im.getMBeanServer();
+ assertNull("MBeanServer should not be available.", mbs);
+ }
+
+ @Test
+ // try to get WorkQueue information
+ public void testWorkQueueInstrumentation() throws Exception {
+ SpringBusFactory factory = new SpringBusFactory();
+ bus = factory.createBus("managed-spring.xml", true);
+ im = bus.getExtension(InstrumentationManager.class);
+ assertTrue("Instrumentation Manager should not be null", im != null);
+ WorkQueueManagerImpl wqm = new WorkQueueManagerImpl();
+ wqm.setBus(bus);
+ wqm.getAutomaticWorkQueue();
+
+ MBeanServer mbs = im.getMBeanServer();
+ assertNotNull("MBeanServer should be available.", mbs);
+ ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
+ + ":type=WorkQueues,*");
+ Set s = mbs.queryNames(name, null);
+ assertTrue(s.size() == 1);
+ Iterator it = s.iterator();
+ while (it.hasNext()) {
+ ObjectName n = (ObjectName)it.next();
+ Long result =
+ (Long)mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new
String[0]);
+ assertEquals(result, Long.valueOf(256));
+ }
+
+ bus.shutdown(true);
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,150 @@
+/**
+ * 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.cxf.management.counters;
+
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.management.InstrumentationManager;
+import org.easymock.classextension.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CounterRepositoryTest extends Assert {
+ private Bus bus;
+ //private InstrumentationManager im;
+ private ObjectName serviceCounter;
+ private ObjectName operationCounter;
+
+ @Before
+ public void setUp() throws Exception {
+
+ serviceCounter = new ObjectName("tandoori:type=counter,service=help");
+ operationCounter = new
ObjectName("tandoori:type=counter,service=help,operation=me");
+ bus = EasyMock.createMock(Bus.class);
+ bus.getExtension(InstrumentationManager.class);
+ EasyMock.expectLastCall().andReturn(null).anyTimes();
+ EasyMock.replay(bus);
+ }
+
+ @Test
+ public void testIncreaseOneWayResponseCounter() throws Exception {
+
+ CounterRepository cr = new CounterRepository();
+ cr.setBus(bus);
+ //cr.createCounter(operationCounter, true);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
+ EasyMock.expect(mhtr.getEndTime()).andReturn((long)100000000).anyTimes();
+ EasyMock.expect(mhtr.getHandlingTime()).andReturn((long)1000).anyTimes();
+ EasyMock.expect(mhtr.getFaultMode()).andReturn(null).anyTimes();
+ EasyMock.replay(mhtr);
+ cr.increaseCounter(serviceCounter, mhtr);
+ cr.increaseCounter(operationCounter, mhtr);
+ ResponseTimeCounter opCounter = (ResponseTimeCounter)
cr.getCounter(operationCounter);
+ ResponseTimeCounter sCounter = (ResponseTimeCounter)
cr.getCounter(serviceCounter);
+
+ assertEquals("The operation counter isn't increased",
opCounter.getNumInvocations(), 1);
+ assertEquals("The Service counter isn't increased",
sCounter.getNumInvocations(), 1);
+
+ EasyMock.verify(bus);
+ EasyMock.verify(mhtr);
+ }
+
+ @Test
+ public void testIncreaseOneWayNoResponseCounter() throws Exception {
+
+ CounterRepository cr = new CounterRepository();
+ cr.setBus(bus);
+ //cr.createCounter(operationCounter, true);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
+ EasyMock.expect(mhtr.getEndTime()).andReturn((long)0).anyTimes();
+ EasyMock.expect(mhtr.getFaultMode()).andReturn(null).anyTimes();
+ EasyMock.replay(mhtr);
+ cr.increaseCounter(serviceCounter, mhtr);
+ cr.increaseCounter(operationCounter, mhtr);
+ ResponseTimeCounter opCounter = (ResponseTimeCounter)
cr.getCounter(operationCounter);
+ ResponseTimeCounter sCounter = (ResponseTimeCounter)
cr.getCounter(serviceCounter);
+
+ assertEquals("The operation counter isn't increased",
opCounter.getNumInvocations(), 1);
+ assertEquals("The Service counter isn't increased",
sCounter.getNumInvocations(), 1);
+
+ EasyMock.verify(bus);
+ EasyMock.verify(mhtr);
+ }
+
+ @Test
+ public void testIncreaseResponseCounter() throws Exception {
+ CounterRepository cr = new CounterRepository();
+ cr.setBus(bus);
+
+ MessageHandlingTimeRecorder mhtr1 =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ EasyMock.expect(mhtr1.isOneWay()).andReturn(false).anyTimes();
+ EasyMock.expect(mhtr1.getHandlingTime()).andReturn((long)1000).anyTimes();
+ EasyMock.expect(mhtr1.getFaultMode()).andReturn(null).anyTimes();
+ EasyMock.replay(mhtr1);
+ cr.createCounter(operationCounter, mhtr1);
+ cr.increaseCounter(serviceCounter, mhtr1);
+ cr.increaseCounter(operationCounter, mhtr1);
+ ResponseTimeCounter opCounter = (ResponseTimeCounter)
cr.getCounter(operationCounter);
+ ResponseTimeCounter sCounter = (ResponseTimeCounter)
cr.getCounter(serviceCounter);
+
+ assertEquals("The operation counter isn't increased",
opCounter.getNumInvocations(), 1);
+ assertEquals("The operation counter's AvgResponseTime is wrong ",
+ opCounter.getAvgResponseTime(), 1000);
+ assertEquals("The operation counter's MaxResponseTime is wrong ",
+ opCounter.getMaxResponseTime(), (long)1000);
+ assertEquals("The operation counter's MinResponseTime is wrong ",
+ opCounter.getMinResponseTime(), (long)1000);
+ assertEquals("The Service counter isn't increased",
sCounter.getNumInvocations(), 1);
+
+ MessageHandlingTimeRecorder mhtr2 =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ EasyMock.expect(mhtr2.isOneWay()).andReturn(false).anyTimes();
+ EasyMock.expect(mhtr2.getHandlingTime()).andReturn((long)2000).anyTimes();
+ EasyMock.expect(mhtr2.getFaultMode()).andReturn(null).anyTimes();
+ EasyMock.replay(mhtr2);
+ cr.increaseCounter(serviceCounter, mhtr2);
+ cr.increaseCounter(operationCounter, mhtr2);
+ assertEquals("The operation counter isn't increased",
opCounter.getNumInvocations(), 2);
+ assertEquals("The operation counter's AvgResponseTime is wrong ",
+ opCounter.getAvgResponseTime(), 1500);
+ assertEquals("The operation counter's MaxResponseTime is wrong ",
+ opCounter.getMaxResponseTime(), (long)2000);
+ assertEquals("The operation counter's MinResponseTime is wrong ",
+ opCounter.getMinResponseTime(), (long)1000);
+ assertEquals("The Service counter isn't increased",
sCounter.getNumInvocations(), 2);
+
+ opCounter.reset();
+ assertTrue(opCounter.getNumCheckedApplicationFaults().intValue() == 0);
+ assertTrue(opCounter.getNumInvocations().intValue() == 0);
+ assertTrue(opCounter.getNumLogicalRuntimeFaults().intValue() == 0);
+ assertTrue(opCounter.getNumRuntimeFaults().intValue() == 0);
+ assertTrue(opCounter.getNumUnCheckedApplicationFaults().intValue() == 0);
+ assertTrue(opCounter.getTotalHandlingTime().intValue() == 0);
+ assertTrue(opCounter.getMinResponseTime().longValue() == Integer.MAX_VALUE);
+ assertTrue(opCounter.getMaxResponseTime().intValue() == 0);
+
+ EasyMock.verify(bus);
+ EasyMock.verify(mhtr1);
+ EasyMock.verify(mhtr2);
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,132 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.management.counters.CounterRepository;
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.easymock.classextension.EasyMock;
+
+import org.junit.Assert;
+import org.junit.Before;
+
+
+
+public class AbstractMessageResponseTestBase extends Assert {
+ protected static final QName SERVICE_NAME = new
QName("http://org.apache.cxf", "hello");
+ protected static final QName OPERATION_NAME = new
QName("http://org.apache.cxf", "world");
+ protected static final QName PORT_NAME = new QName("http://org.apache.cxf",
"port");
+
+ protected static final String CLIENT_SERVICE_ONAME =
+
"org.apache.cxf:type=Performance.Counter.Client,bus.id=cxf,service=\""
+ + SERVICE_NAME.toString() + "\",port=\""
+ + PORT_NAME.getLocalPart() + "\"";
+ protected static final String SERVER_SERVICE_ONAME =
+
"org.apache.cxf:type=Performance.Counter.Server,bus.id=cxf,service=\""
+ + SERVICE_NAME.toString() + "\",port=\""
+ + PORT_NAME.getLocalPart() + "\"";
+ protected ObjectName clientServiceCounterOName;
+ protected ObjectName serverServiceCounterOName;
+ protected ObjectName clientOperationCounterOName;
+ protected ObjectName serverOperationCounterOName;
+
+ protected Bus bus;
+ protected Message message;
+ protected Exchange exchange;
+ protected CounterRepository cRepository;
+
+ @Before
+ public void setUp() throws Exception {
+ message = EasyMock.createMock(Message.class);
+ exchange = EasyMock.createMock(Exchange.class);
+ bus = EasyMock.createMock(Bus.class);
+ cRepository = EasyMock.createMock(CounterRepository.class);
+ clientServiceCounterOName = new ObjectName(CLIENT_SERVICE_ONAME);
+ serverServiceCounterOName = new ObjectName(SERVER_SERVICE_ONAME);
+ clientOperationCounterOName = new ObjectName(CLIENT_SERVICE_ONAME
+ + ",operation=\"" + OPERATION_NAME.getLocalPart() +
"\"");
+ serverOperationCounterOName = new ObjectName(SERVER_SERVICE_ONAME
+ + ",operation=\"" + OPERATION_NAME.getLocalPart() +
"\"");
+ }
+
+ protected void setupCounterRepository(boolean increase, boolean isClient) {
+ ObjectName serviceCounterOName;
+ ObjectName operationCounterOName;
+ if (isClient) {
+ serviceCounterOName = clientServiceCounterOName;
+ operationCounterOName = clientOperationCounterOName;
+ } else {
+ serviceCounterOName = serverServiceCounterOName;
+ operationCounterOName = serverOperationCounterOName;
+ }
+ BusFactory.setDefaultBus(bus);
+ bus.getExtension(CounterRepository.class);
+ EasyMock.expectLastCall().andReturn(cRepository);
+ if (increase) {
+ EasyMock.expect(bus.getId()).andReturn(Bus.DEFAULT_BUS_ID);
+ cRepository.increaseCounter(EasyMock.eq(serviceCounterOName),
+ EasyMock.isA(MessageHandlingTimeRecorder.class));
+ EasyMock.expectLastCall();
+ cRepository.increaseCounter(EasyMock.eq(operationCounterOName),
+ EasyMock.isA(MessageHandlingTimeRecorder.class));
+ EasyMock.expectLastCall();
+ EasyMock.replay(cRepository);
+ }
+
+ EasyMock.replay(bus);
+ // increase the number
+ }
+
+ protected void setupExchangeForMessage() {
+ EasyMock.expect(exchange.get(Bus.class)).andReturn(bus);
+
+ Service service = EasyMock.createMock(Service.class);
+ EasyMock.expect(service.getName()).andReturn(SERVICE_NAME);
+ EasyMock.expect(exchange.get(Service.class)).andReturn(service);
+ EasyMock.replay(service);
+
+ Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+ EndpointInfo endpointInfo = EasyMock.createMock(EndpointInfo.class);
+ EasyMock.expect(endpointInfo.getName()).andReturn(PORT_NAME);
+ EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo);
+ EasyMock.expect(exchange.get(Endpoint.class)).andReturn(endpoint);
+ EasyMock.replay(endpointInfo);
+ EasyMock.replay(endpoint);
+ setupOperationForMessage();
+ }
+
+ protected void setupOperationForMessage() {
+ OperationInfo op = EasyMock.createMock(OperationInfo.class);
+ EasyMock.expect(op.getName()).andReturn(OPERATION_NAME);
+ EasyMock.expect(exchange.get(OperationInfo.class)).andReturn(op);
+ EasyMock.replay(op);
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor2Test.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor2Test.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor2Test.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,176 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.OperationInfo;
+import org.easymock.classextension.EasyMock;
+
+import org.junit.Test;
+
+public class ResponseTimeMessageInInterceptor2Test extends
AbstractMessageResponseTestBase {
+
+ private ResponseTimeMessageInInterceptor rtmii = new
ResponseTimeMessageInInterceptor();
+
+ @Test
+ public void testClientMessageIn() {
+ // need to increase the counter and is a client
+ setupCounterRepository(true, true);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
+ EasyMock.expect(exchange.isOneWay()).andReturn(false);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+ mhtr.setFaultMode(null);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+
+ }
+
+ @Test
+ public void testClientCheckedApplicationFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.CHECKED_APPLICATION_FAULT);
+ }
+
+ @Test
+ public void testClientLogicalFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.LOGICAL_RUNTIME_FAULT);
+ }
+
+ @Test
+ public void testClientRuntimeFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.RUNTIME_FAULT);
+ }
+
+ @Test
+ public void testClientUncheckedApplicationFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.UNCHECKED_APPLICATION_FAULT);
+ }
+
+ public void testClientFaultMessageIn(FaultMode faultMode) {
+ // need to increase the counter and is a client
+ setupCounterRepository(true, true);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ exchange.put(FaultMode.class, faultMode);
+ EasyMock.expectLastCall();
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+ mhtr.setFaultMode(faultMode);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleFault(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+
+ }
+
+
+ // it would not fire the counter increase action now
+ @Test
+ public void testServerOneWayMessageIn() {
+ // need to increase the counter and is not a client
+ //setupCounterRepository(false, false);
+ //setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+ //EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.beginHandling();
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ //EasyMock.expect(exchange.isOneWay()).andReturn(true);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ //EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ //EasyMock.verify(cRepository);
+ }
+
+ @Test
+ public void testServiceMessageIn() {
+ EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+ //EasyMock.expect(exchange.isOneWay()).andReturn(false);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);
+ exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class),
+ EasyMock.isA(MessageHandlingTimeRecorder.class));
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(exchange);
+
+ }
+
+ public void testIsClient() {
+ Message message1 = null;
+ Message message2 = new MessageImpl();
+ Message message3 = new MessageImpl();
+ message3.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+ assertTrue("the message should not be client",
!rtmii.isClient(message1));
+ assertTrue("the message should not be client",
!rtmii.isClient(message2));
+ assertTrue("the message should be client", rtmii.isClient(message3));
+ }
+
+ @Override
+ protected void setupOperationForMessage() {
+ EasyMock.expect(exchange.get(OperationInfo.class)).andReturn(null);
+
EasyMock.expect(exchange.get("org.apache.cxf.resource.operation.name"))
+ .andReturn(OPERATION_NAME.getLocalPart());
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,168 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class ResponseTimeMessageInInterceptorTest extends AbstractMessageResponseTestBase
{
+
+ private ResponseTimeMessageInInterceptor rtmii = new
ResponseTimeMessageInInterceptor();
+
+ @Test
+ public void testClientMessageIn() {
+ // need to increase the counter and is a client
+ setupCounterRepository(true, true);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
+ EasyMock.expect(exchange.isOneWay()).andReturn(false);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+ mhtr.setFaultMode(null);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+
+ }
+
+ @Test
+ public void testClientCheckedApplicationFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.CHECKED_APPLICATION_FAULT);
+ }
+
+ @Test
+ public void testClientLogicalFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.LOGICAL_RUNTIME_FAULT);
+ }
+
+ @Test
+ public void testClientRuntimeFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.RUNTIME_FAULT);
+ }
+
+ @Test
+ public void testClientUncheckedApplicationFaultMessageIn() {
+ testClientFaultMessageIn(FaultMode.UNCHECKED_APPLICATION_FAULT);
+ }
+
+ public void testClientFaultMessageIn(FaultMode faultMode) {
+ // need to increase the counter and is a client
+ setupCounterRepository(true, true);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ exchange.put(FaultMode.class, faultMode);
+ EasyMock.expectLastCall();
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+ mhtr.setFaultMode(faultMode);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleFault(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+
+ }
+
+
+ // it would not fire the counter increase action now
+ @Test
+ public void testServerOneWayMessageIn() {
+ // need to increase the counter and is not a client
+ //setupCounterRepository(false, false);
+ //setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+ //EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.beginHandling();
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ //EasyMock.expect(exchange.isOneWay()).andReturn(true);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ //EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ //EasyMock.verify(cRepository);
+ }
+
+ @Test
+ public void testServiceMessageIn() {
+ EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+ //EasyMock.expect(exchange.isOneWay()).andReturn(false);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);
+ exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class),
+ EasyMock.isA(MessageHandlingTimeRecorder.class));
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(exchange);
+
+ }
+
+ public void testIsClient() {
+ Message message1 = null;
+ Message message2 = new MessageImpl();
+ Message message3 = new MessageImpl();
+ message3.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+ assertTrue("the message should not be client",
!rtmii.isClient(message1));
+ assertTrue("the message should not be client",
!rtmii.isClient(message2));
+ assertTrue("the message should be client", rtmii.isClient(message3));
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,59 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+
+import org.apache.cxf.message.Message;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class ResponseTimeMessageInvokerInterceptorTest extends
AbstractMessageResponseTestBase {
+
+ private ResponseTimeMessageInvokerInterceptor rtmii = new
ResponseTimeMessageInvokerInterceptor();
+
+ @Test
+ public void testServerOneWayMessageIn() {
+ // need to increase the counter and is not a client
+ setupCounterRepository(true, false);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.setOneWay(true);
+ EasyMock.expectLastCall();
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.isOneWay()).andReturn(true);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmii.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,165 @@
+/**
+ * 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.cxf.management.interceptor;
+
+import org.apache.cxf.interceptor.InterceptorChain;
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.Message;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class ResponseTimeMessageOutInterceptorTest extends
AbstractMessageResponseTestBase {
+ private ResponseTimeMessageOutInterceptor rtmoi = new
ResponseTimeMessageOutInterceptor();
+
+ @Test
+ public void testServerMessageOut() {
+ // need to increase the counter and is not a client
+ setupCounterRepository(true, false);
+ setupExchangeForMessage();
+
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE).anyTimes();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.setFaultMode(null);
+ EasyMock.expectLastCall();
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmoi.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+
+ }
+
+ @Test
+ public void testServerCheckedApplicationFaultMessageOut() {
+ testServerFaultMessageOut(FaultMode.CHECKED_APPLICATION_FAULT);
+ }
+
+ @Test
+ public void testServerLogicalRuntimeFaultMessageOut() {
+ testServerFaultMessageOut(FaultMode.LOGICAL_RUNTIME_FAULT);
+ }
+
+ @Test
+ public void testServerRuntimeFaultMessageOut() {
+ testServerFaultMessageOut(FaultMode.RUNTIME_FAULT);
+ }
+
+ @Test
+ public void testServerUncheckedApplicationFaultMessageOut() {
+ testServerFaultMessageOut(FaultMode.UNCHECKED_APPLICATION_FAULT);
+ }
+
+ public void testServerFaultMessageOut(FaultMode faultMode) {
+ // need to increase the counter and is not a client
+ setupCounterRepository(true, false);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+ EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ exchange.put(FaultMode.class, faultMode);
+ EasyMock.expectLastCall();
+ EasyMock.expect(exchange.isOneWay()).andReturn(false);
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ mhtr.setFaultMode(faultMode);
+ EasyMock.expectLastCall();
+ mhtr.endHandling();
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmoi.handleFault(message);
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+
+ }
+
+ @Test
+ public void testClientOneWayMessageOut() {
+ //need to increase the counter and is a client
+ setupCounterRepository(true, true);
+ setupExchangeForMessage();
+ EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
+
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE).anyTimes();
+
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+ EasyMock.expect(exchange.get(FaultMode.class)).andReturn(null);
+ //MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+ //mhtr.setOneWay(true);
+ //EasyMock.expectLastCall();
+
+ //EasyMock.replay(mhtr);
+ EasyMock.expect(exchange.isOneWay()).andReturn(true).anyTimes();
+ MessageHandlingTimeRecorder mhtr =
EasyMock.createMock(MessageHandlingTimeRecorder.class);
+
EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr).anyTimes();
+ InterceptorChain chain = EasyMock.createMock(InterceptorChain.class);
+ EasyMock.expect(message.getInterceptorChain()).andReturn(chain);
+
chain.add(EasyMock.isA(ResponseTimeMessageOutInterceptor.EndingInterceptor.class));
+ EasyMock.expectLastCall();
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+
+ rtmoi.handleMessage(message);
+ rtmoi.getEndingInterceptor().handleMessage(message);
+
+ EasyMock.verify(message);
+ EasyMock.verify(bus);
+ EasyMock.verify(exchange);
+ //EasyMock.verify(mhtr);
+ EasyMock.verify(cRepository);
+ }
+
+ @Test
+ public void testClientMessageOut() {
+
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE).anyTimes();
+ EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
+ EasyMock.expect(message.getExchange()).andReturn(exchange);
+ EasyMock.expect(exchange.isOneWay()).andReturn(false);
+ EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);
+ exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class),
+ EasyMock.isA(MessageHandlingTimeRecorder.class));
+ EasyMock.replay(exchange);
+ EasyMock.replay(message);
+ rtmoi.handleMessage(message);
+ EasyMock.verify(message);
+ EasyMock.verify(exchange);
+
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,32 @@
+/**
+ * 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.cxf.management.jmx;
+
+public class HelloWorld implements HelloWorldMBean {
+ private String name;
+
+ public HelloWorld(String name) {
+ this.name = name;
+ }
+
+ public String sayHi() {
+ return "Wazzzuuup " + this.name;
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,24 @@
+/**
+ * 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.cxf.management.jmx;
+
+public interface HelloWorldMBean {
+ String sayHi();
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,184 @@
+/**
+ * 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.cxf.management.jmx;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JMXManagedComponentManagerTest extends Assert {
+
+ private static final String NAME_ATTRIBUTE = "Name";
+ private InstrumentationManagerImpl manager;
+
+ @Before
+ public void setUp() throws Exception {
+ manager = new InstrumentationManagerImpl();
+ manager.setDaemon(false);
+ manager.setThreaded(true);
+ manager.setEnabled(true);
+
manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+ manager.init();
+ //Wait for MBeanServer connector to be initialized on separate thread.
+ Thread.sleep(2000);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ manager.shutdown();
+ }
+
+ @Test
+ public void testRegisterInstrumentation() throws Exception {
+ //manager.setDaemon(false);
+ //manager.setThreaded(false);
+
//manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+ //manager.init();
+
+ AnnotationTestInstrumentation im = new AnnotationTestInstrumentation();
+ ObjectName name = new ObjectName("org.apache.cxf:type=foo,name=bar");
+ im.setName("John Smith");
+ manager.register(im, name);
+
+ Object val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+ assertEquals("Incorrect result", "John Smith", val);
+
+ try {
+ manager.register(im, name);
+ fail("Registering with existing name should fail.");
+ } catch (JMException jmex) {
+ //Expected
+ }
+
+ manager.register(im, name, true);
+
+ val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+ assertEquals("Incorrect result", "John Smith", val);
+ manager.unregister(name);
+
+ im.setName("Foo Bar");
+ name = manager.register(im);
+
+ val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+ assertEquals("Incorrect result", "Foo Bar", val);
+
+ try {
+ manager.register(im);
+ fail("Registering with existing name should fail.");
+ } catch (JMException jmex) {
+ //Expected
+ }
+
+ name = manager.register(im, true);
+
+ val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+ assertEquals("Incorrect result", "Foo Bar", val);
+
+ manager.unregister(im);
+ }
+
+ @Test
+ public void testRegisterStandardMBean() throws Exception {
+ ObjectName name = this.registerStandardMBean("yo!");
+ String result =
+ (String)manager.getMBeanServer().invoke(name, "sayHi", new
Object[0], new String[0]);
+ assertEquals("Wazzzuuup yo!", result);
+ }
+
+ /**
+ * Simulate repeated startup and shutdown of the CXF Bus in an environment
+ * where the container and MBeanServer are not shutdown between CXF restarts.
+ */
+ @Test
+ public void testBusLifecycleListener() throws Exception {
+ // We need to destroy the manager that is automatically setup by the test.
+ this.tearDown();
+
+ MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+
+ this.manager = new InstrumentationManagerImpl();
+ this.manager.setDaemon(false);
+ // Turn threading off so that we get the exception in this thread
+ // and the manager is set into a failed state if the connector
+ // cannot be created.
+ this.manager.setThreaded(false);
+ this.manager.setEnabled(true);
+
this.manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+ this.manager.setServer(server);
+ this.manager.register();
+ this.manager.init();
+
+ ObjectName name = this.registerStandardMBean("yo!");
+ String result =
+ (String)manager.getMBeanServer().invoke(name, "sayHi", new
Object[0], new String[0]);
+ assertEquals("Wazzzuuup yo!", result);
+
+ try {
+ name = this.registerStandardMBean("yo!");
+ fail("registered duplicate MBean");
+ } catch (InstanceAlreadyExistsException e) {
+ // expected
+ }
+
+ this.manager.preShutdown();
+ this.manager.postShutdown();
+
+ try {
+ this.manager.getMBeanServer().invoke(name, "sayHi", new Object[0],
new String[0]);
+ fail("MBean not unregistered on shutdown.");
+ } catch (InstanceNotFoundException e) {
+ // expected
+ }
+
+ this.manager = new InstrumentationManagerImpl();
+ this.manager.setDaemon(false);
+ // Turn threading off so that we get the exception in this thread
+ // and the manager is set into a failed state if the connector
+ // cannot be created.
+ this.manager.setThreaded(false);
+ this.manager.setEnabled(true);
+
this.manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+ this.manager.setServer(server);
+ this.manager.register();
+ this.manager.init();
+
+ name = this.registerStandardMBean("yoyo!");
+ result =
+ (String)manager.getMBeanServer().invoke(name, "sayHi", new
Object[0], new String[0]);
+ assertEquals("Wazzzuuup yoyo!", result);
+ }
+
+ private ObjectName registerStandardMBean(String name) throws Exception {
+ final HelloWorld hw = new HelloWorld(name);
+ final ObjectName oName = new
ObjectName("org.apache.cxf:type=foo,name=bar");
+ this.manager.register(hw, oName);
+ return oName;
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,54 @@
+/**
+ * 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.cxf.management.jmx;
+
+
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+public class MBServerConnectorTest extends Assert {
+
+ @Test
+ public void testMBServerConnector() {
+ MBServerConnectorFactory mcf;
+ MBeanServer mbs;
+ mbs = MBeanServerFactory.createMBeanServer("test");
+ mcf = MBServerConnectorFactory.getInstance();
+ mcf.setMBeanServer(mbs);
+ mcf.setThreaded(true);
+ mcf.setDaemon(true);
+
mcf.setServiceUrl("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+ try {
+ mcf.createConnector();
+ Thread.sleep(1000);
+ mcf.destroy();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ assertFalse("Some Exception happen to MBServerConnectorTest",
true);
+ }
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,110 @@
+/**
+ * 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.cxf.management.jmx.export;
+
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+import org.apache.cxf.management.ManagedComponent;
+import org.apache.cxf.management.annotation.ManagedAttribute;
+import org.apache.cxf.management.annotation.ManagedNotification;
+import org.apache.cxf.management.annotation.ManagedNotifications;
+import org.apache.cxf.management.annotation.ManagedOperation;
+import org.apache.cxf.management.annotation.ManagedOperationParameter;
+import org.apache.cxf.management.annotation.ManagedOperationParameters;
+import org.apache.cxf.management.annotation.ManagedResource;
+
+@ManagedResource(componentName = "AnnotationTest", description = "My
Managed Bean",
+ persistPolicy = "OnUpdate", currencyTimeLimit = 15 ,
+ log = false ,
+ logFile = "jmx.log", persistPeriod = 200,
+ persistLocation = "/local/work", persistName =
"bar.jmx")
+@ManagedNotifications({@ManagedNotification(name = "My Notification",
+ notificationTypes = {"type.foo",
"type.bar" }) })
+public class AnnotationTestInstrumentation implements ManagedComponent {
+
+ private String name;
+
+ private String nickName;
+
+ private int age;
+
+ private boolean isSuperman;
+
+
+ @ManagedAttribute(description = "The Age Attribute", currencyTimeLimit =
15)
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int a) {
+ this.age = a;
+ }
+
+ @ManagedOperation(currencyTimeLimit = 30)
+ public long myOperation() {
+ return 1L;
+ }
+
+ @ManagedAttribute(description = "The Name Attribute",
+ currencyTimeLimit = 20,
+ defaultValue = "bar",
+ persistPolicy = "OnUpdate")
+ public void setName(String n) {
+ this.name = n;
+ }
+
+ @ManagedAttribute(defaultValue = "bar", persistPeriod = 300)
+ public String getName() {
+ return name;
+ }
+
+ @ManagedAttribute(defaultValue = "barasd", description = "The Nick
Name Attribute")
+ public String getNickName() {
+ return this.nickName;
+ }
+
+ public void setNickName(String n) {
+ this.nickName = n;
+ }
+
+ @ManagedAttribute(description = "The Is Superman Attribute")
+ public void setSuperman(boolean superman) {
+ this.isSuperman = superman;
+ }
+
+ public boolean isSuperman() {
+ return isSuperman;
+ }
+
+ @ManagedOperation(description = "Add Two Numbers Together")
+ @ManagedOperationParameters({@ManagedOperationParameter(
+ name = "x", description = "Left
operand"),
+ @ManagedOperationParameter(
+ name = "y", description = "Right
operand") })
+ public int add(int x, int y) {
+ return x + y;
+ }
+
+ public ObjectName getObjectName() throws JMException {
+ return new
ObjectName("org.apache.cxf:type=AnnotationTestInstrumentation");
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,220 @@
+/**
+ * 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.cxf.management.jmx.export;
+
+
+import javax.management.Attribute;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+import javax.management.modelmbean.RequiredModelMBean;
+
+
+import org.apache.cxf.management.jmx.export.runtime.ModelMBeanAssembler;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+public class ModelMBeanAssemblerTest extends Assert {
+
+ protected static final String AGE_ATTRIBUTE = "Age";
+
+ protected static final String NAME_ATTRIBUTE = "Name";
+
+ protected static AnnotationTestInstrumentation ati = new
AnnotationTestInstrumentation();
+
+ protected MBeanServer server;
+
+ protected ObjectName ton;
+
+ @Before
+ public final void setUp() throws Exception {
+ this.server = MBeanServerFactory.createMBeanServer();
+ try {
+ onSetUp();
+ } catch (Exception e) {
+ releaseServer();
+ throw e;
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ releaseServer();
+ onTearDown();
+ }
+
+ private void releaseServer() {
+ MBeanServerFactory.releaseMBeanServer(this.getServer());
+ }
+
+ protected void onTearDown() throws Exception {
+ // unregister the mbean client
+ server.unregisterMBean(ton);
+ }
+
+ protected void onSetUp() throws Exception {
+
+ try {
+ ton = new ObjectName("org.apache.cxf:Type=testInstrumentation");
+ } catch (MalformedObjectNameException e) {
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
+
+
+ //create the mbean and register it
+ ModelMBeanInfo mbi = getMBeanInfoFromAssembler();
+
+ RequiredModelMBean rtMBean;
+
+ rtMBean = (RequiredModelMBean)server.instantiate(
+ "javax.management.modelmbean.RequiredModelMBean");
+
+ rtMBean.setModelMBeanInfo(mbi);
+
+ rtMBean.setManagedResource(ati, "ObjectReference");
+
+ server.registerMBean(rtMBean, ton);
+ }
+
+ public MBeanServer getServer() {
+ return server;
+ }
+
+ //the client get and set the ModelObject and setup the ManagerBean
+ @Test
+ public void testRegisterOperations() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+ assertEquals("Incorrect number of operations registered",
+ 10, info.getOperations().length);
+ }
+
+ @Test
+ public void testGetMBeanInfo() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+ assertNotNull("MBeanInfo should not be null", info);
+ }
+
+ @Test
+ public void testGetMBeanAttributeInfo() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+ MBeanAttributeInfo[] inf = info.getAttributes();
+ assertEquals("Invalid number of Attributes returned",
+ 4, inf.length);
+
+ for (int x = 0; x < inf.length; x++) {
+ assertNotNull("MBeanAttributeInfo should not be null", inf[x]);
+ assertNotNull("Description for MBeanAttributeInfo should not be
null",
+ inf[x].getDescription());
+ }
+ }
+
+ @Test
+ public void testGetMBeanOperationInfo() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+ MBeanOperationInfo[] inf = info.getOperations();
+ assertEquals("Invalid number of Operations returned",
+ 10, inf.length);
+
+ for (int x = 0; x < inf.length; x++) {
+ assertNotNull("MBeanOperationInfo should not be null", inf[x]);
+ assertNotNull("Description for MBeanOperationInfo should not be
null",
+ inf[x].getDescription());
+ }
+ }
+
+ @Test
+ public void testDescriptionNotNull() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+ assertNotNull("The MBean description should not be null",
+ info.getDescription());
+ }
+
+ @Test
+ public void testSetAttribute() throws Exception {
+ getServer().setAttribute(ton, new Attribute(AGE_ATTRIBUTE, 12));
+ assertEquals("The Age should be ", 12, ati.getAge());
+ getServer().setAttribute(ton, new Attribute(NAME_ATTRIBUTE, "Rob
Harrop"));
+ assertEquals("The name should be ", "Rob Harrop",
ati.getName());
+ }
+
+ @Test
+ public void testGetAttribute() throws Exception {
+ ati.setName("John Smith");
+ Object val = getServer().getAttribute(ton, NAME_ATTRIBUTE);
+ assertEquals("Incorrect result", "John Smith", val);
+ }
+
+ @Test
+ public void testOperationInvocation() throws Exception {
+ Object result = getServer().invoke(ton, "add",
+ new Object[] {new Integer(20), new Integer(30)}, new
String[] {"int", "int"});
+ assertEquals("Incorrect result", new Integer(50), result);
+ }
+
+ @Test
+ public void testAttributeHasCorrespondingOperations() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+
+ ModelMBeanOperationInfo myOperation =
info.getOperation("myOperation");
+ assertNotNull("get operation should not be null", myOperation);
+ assertEquals("Incorrect myOperation return type", "long",
myOperation.getReturnType());
+
+ ModelMBeanOperationInfo add = info.getOperation("add");
+ assertNotNull("set operation should not be null", add);
+ assertEquals("Incorrect add method description", "Add Two Numbers
Together", add.getDescription());
+
+ }
+
+ @Test
+ public void testNotificationMetadata() throws Exception {
+ ModelMBeanInfo info = getMBeanInfoFromAssembler();
+ MBeanNotificationInfo[] notifications = info.getNotifications();
+ assertEquals("Incorrect number of notifications", 1,
notifications.length);
+ assertEquals("Incorrect notification name", "My
Notification", notifications[0].getName());
+
+ String[] notifTypes = notifications[0].getNotifTypes();
+
+ assertEquals("Incorrect number of notification types", 2,
notifTypes.length);
+ assertEquals("Notification type.foo not found", "type.foo",
notifTypes[0]);
+ assertEquals("Notification type.bar not found", "type.bar",
notifTypes[1]);
+ }
+
+
+ protected ModelMBeanInfo getMBeanInfoFromAssembler() {
+ ModelMBeanAssembler assembler = new ModelMBeanAssembler();
+ return assembler.getModelMbeanInfo(AnnotationTestInstrumentation.class);
+ }
+
+
+
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,57 @@
+/**
+ * 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.cxf.management.utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ManagementConsoleTest extends Assert {
+ private ManagementConsole mc = new ManagementConsole();
+
+ @Test
+ public void paraserCommandTest() {
+ String[] listArgs = new String[] {"--operation", "list"};
+ mc.parserArguments(listArgs);
+ assertEquals("It is not right operation name", "list",
mc.operationName);
+ assertEquals("The portName should be cleared", "",
mc.portName);
+ String[] startArgs = new String[] {"-o", "start",
"--jmx",
+
"service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi",
+ "--service",
+
"\"{http://apache.org/hello_world_soap_http}SOAPService\"",
+ "--port",
+
"\"{http://apache.org/hello_world_soap_http}SoapPort\""};
+ mc.parserArguments(startArgs);
+ assertEquals("It is not right operation name", "start",
mc.operationName);
+ assertEquals("It is not right port name",
+
"\"{http://apache.org/hello_world_soap_http}SoapPort\"",
mc.portName);
+ assertEquals("It is not right service name",
+
"\"{http://apache.org/hello_world_soap_http}SOAPService\"",
mc.serviceName);
+ assertEquals("It is not a jmx url",
+ "service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi",
+ mc.jmxServerURL);
+
+ String[] errorArgs = new String[] {"--op", "listAll"};
+ assertFalse("the arguments are wrong", mc.parserArguments(errorArgs));
+
+ }
+
+
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/resources/managed-spring.xml
===================================================================
--- thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/resources/managed-spring.xml
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management/src/test/resources/managed-spring.xml 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans
xmlns="http://www.springframework.org/schema/beans"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xmlns:im="http://cxf.apache.org/management"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="org.apache.cxf.management.InstrumentationManager"
class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
+ <property name="bus" ref="cxf" />
+ <property name="enabled" value="true"/>
+ <property name="threaded" value="false"/>
+ <property name="daemon" value="false"/>
+ <property name="JMXServiceURL"
value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" />
+ </bean>
+
+</beans>
\ No newline at end of file
Added: thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/pom.xml
===================================================================
--- thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/pom.xml
(rev 0)
+++ thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/pom.xml 2011-08-13 15:39:22 UTC
(rev 14820)
@@ -0,0 +1,107 @@
+<!--
+ 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.
+-->
+<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>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-management-web</artifactId>
+ <packaging>jar</packaging>
+ <version>2.3.1</version>
+ <name>Apache CXF Runtime Web Management</name>
+ <url>http://cxf.apache.org</url>
+
+ <parent>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-parent</artifactId>
+ <version>2.3.1</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-core</artifactId>
+ <version>${cxf.abdera.version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-parser</artifactId>
+ <version>${cxf.abdera.version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-extensions-json</artifactId>
+ <version>${cxf.abdera.version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-common-utilities</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-management</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ </dependencies>
+
+
+</project>
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogLevel.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogLevel.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogLevel.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,89 @@
+/**
+ * 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.cxf.management.web.logging;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ * Log level of {@link LogRecord}. Based on SLF4J being popular facade for loggers like
JUL, Log4J, JCL and so
+ * on. Severities order is: FATAL > ERROR > WARN > INFO > DEBUG > TRACE.
+ * <p>
+ * Mapping of levels:
+ * <ol>
+ * <li>JUL - same as <a
href="http://www.slf4j.org/apidocs/org/slf4j/bridge/SLF4JBridgeHandl...
+ * approach</a>.</li>
+ * <li>Log4J - levels are identical</li>
+ * </ol>
+ */
+@XmlEnum
+public enum LogLevel {
+ ALL,
+ FATAL,
+ ERROR,
+ WARN,
+ INFO,
+ DEBUG,
+ TRACE,
+ OFF;
+
+ @XmlTransient
+ private static Map<Level, LogLevel> fromJul = new HashMap<Level,
LogLevel>();
+
+ @XmlTransient
+ private static Map<LogLevel, Level> toJul = new HashMap<LogLevel,
Level>();
+
+ static {
+ fromJul.put(Level.ALL, LogLevel.ALL);
+ fromJul.put(Level.SEVERE, LogLevel.ERROR);
+ fromJul.put(Level.WARNING, LogLevel.WARN);
+ fromJul.put(Level.INFO, LogLevel.INFO);
+ fromJul.put(Level.FINE, LogLevel.DEBUG);
+ fromJul.put(Level.FINER, LogLevel.DEBUG);
+ fromJul.put(Level.FINEST, LogLevel.TRACE);
+ fromJul.put(Level.OFF, LogLevel.OFF);
+
+ toJul.put(LogLevel.ALL, Level.ALL);
+ toJul.put(LogLevel.FATAL, Level.SEVERE);
+ toJul.put(LogLevel.ERROR, Level.SEVERE);
+ toJul.put(LogLevel.WARN, Level.WARNING);
+ toJul.put(LogLevel.INFO, Level.INFO);
+ toJul.put(LogLevel.DEBUG, Level.FINE);
+ toJul.put(LogLevel.TRACE, Level.FINEST);
+ toJul.put(LogLevel.OFF, Level.OFF);
+ }
+
+ /**
+ * Creates this enum from JUL {@link Level}.
+ */
+ public static LogLevel fromJUL(Level level) {
+ return fromJul.get(level);
+ }
+
+ /**
+ * Creates this JUL {@link Level} from this enum.
+ */
+ public static Level toJUL(LogLevel level) {
+ return toJul.get(level);
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,195 @@
+/**
+ * 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.cxf.management.web.logging;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.UUID;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.commons.lang.Validate;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+/**
+ * Log entry serializable to XML. Based on common set of {@link
java.util.logging.LogRecord} and
+ * {@link org.apache.log4j.spi.LoggingEvent} attributes.
+ * <p>
+ * LogRecord are never null; if some attributes are not set (e.g. logger name, or
rendered cause taken from
+ * Throwable) empty strings are returned.
+ */
+@XmlRootElement(namespace = "http://cxf.apache.org/log")
+public class LogRecord {
+
+ @XmlTransient
+ private String id = "uuid:" + UUID.randomUUID().toString();
+
+ private Date eventTimestamp = new Date();
+ private LogLevel level = LogLevel.INFO;
+ private String message = "";
+ private String loggerName = "";
+ private String threadName = "";
+ private String throwable = "";
+
+ public LogRecord() {
+
+ }
+
+ public LogRecord(String id) {
+ this.id = id;
+ }
+
+ public LogRecord(LogRecord copy) {
+ this.eventTimestamp = copy.getEventTimestamp();
+ this.level = copy.getLevel();
+ this.message = copy.getMessage();
+ this.loggerName = copy.getLoggerName();
+ this.threadName = copy.getThreadName();
+ this.throwable = copy.getThrowable();
+ }
+
+ /**
+ * Creates this object from JUL LogRecord. Most attributes are copied, others are
converted as follows:
+ * raw {@link java.util.logging.LogRecord#getMessage() message} is formatted with
+ * {@link java.util.logging.LogRecord#getParameters() parameters} using {@link
MessageFormat}, attached
+ * {@link java.util.logging.LogRecord#getThrown() throwable} has full stack trace
dumped, and log levels
+ * are mapped as specified in {@link LogRecord}.
+ *
+ * @param julRecord log record to convert.
+ * @return conversion result.
+ */
+ public static LogRecord fromJUL(java.util.logging.LogRecord julRecord) {
+ Validate.notNull(julRecord, "julRecord is null");
+ LogRecord record = new LogRecord();
+ record.setEventTimestamp(new Date(julRecord.getMillis()));
+ record.setLevel(LogLevel.fromJUL(julRecord.getLevel()));
+ record.setLoggerName(julRecord.getLoggerName());
+ if (julRecord.getThrown() != null) {
+ record.setThrowable(julRecord.getThrown());
+ }
+ if (julRecord.getParameters() != null) {
+ record.setMessage(MessageFormat.format(julRecord.getMessage(),
julRecord.getParameters()));
+ } else {
+ record.setMessage(julRecord.getMessage());
+ }
+ record.setThreadName(Integer.toString(julRecord.getThreadID()));
+ return record;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ @XmlElement(namespace = "http://cxf.apache.org/log")
+ public Date getEventTimestamp() {
+ return eventTimestamp;
+ }
+
+ public void setEventTimestamp(Date eventTimestamp) {
+ Validate.notNull(eventTimestamp, "eventTimestamp is null");
+ this.eventTimestamp = eventTimestamp;
+ }
+
+ @XmlElement(namespace = "http://cxf.apache.org/log")
+ public LogLevel getLevel() {
+ return level;
+ }
+
+ public void setLevel(LogLevel level) {
+ Validate.notNull(level, "level is null");
+ this.level = level;
+ }
+
+ /**
+ * Formatted message with parameters filled in.
+ */
+ @XmlElement(namespace = "http://cxf.apache.org/log")
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String renderedMessage) {
+ Validate.notNull(level, "message is null");
+ this.message = renderedMessage;
+ }
+
+ @XmlElement(namespace = "http://cxf.apache.org/log")
+ public String getLoggerName() {
+ return loggerName;
+ }
+
+ public void setLoggerName(String loggerName) {
+ Validate.notNull(level, "loggerName is null");
+ this.loggerName = loggerName;
+ }
+
+ @XmlElement(namespace = "http://cxf.apache.org/log")
+ public String getThreadName() {
+ return threadName;
+ }
+
+ public void setThreadName(String threadName) {
+ Validate.notNull(level, "threadName is null");
+ this.threadName = threadName;
+ }
+
+ /**
+ * Full stack trace of {@link Throwable} associated with log record.
+ */
+ @XmlElement(namespace = "http://cxf.apache.org/log")
+ public String getThrowable() {
+ return throwable;
+ }
+
+ public void setThrowable(String throwable) {
+ Validate.notNull(throwable, "throwable is null");
+ this.throwable = throwable;
+ }
+
+ public void setThrowable(Throwable thr) {
+ Validate.notNull(thr, "throwable is null");
+ StringWriter sw = new StringWriter();
+ thr.printStackTrace(new PrintWriter(sw));
+ this.throwable = sw.getBuffer().toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return EqualsBuilder.reflectionEquals(obj, this);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this);
+ }
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this,
ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecords.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecords.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecords.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,65 @@
+/**
+ * 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.cxf.management.web.logging;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.commons.lang.Validate;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+/**
+ * List of {@link LogRecord}s. Necessary wrapper for {@link List} used in JAXB context.
+ */
+@XmlRootElement(namespace = "http://cxf.apache.org/log")
+public class LogRecords {
+
+ private List<LogRecord> logRecords = new ArrayList<LogRecord>();
+
+ @XmlElement(name = "logRecord", namespace =
"http://cxf.apache.org/log")
+ public List<LogRecord> getLogRecords() {
+ return logRecords;
+ }
+
+ public void setLogRecords(List<LogRecord> logRecords) {
+ Validate.notNull(logRecords, "logRecords is null");
+ this.logRecords = logRecords;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return EqualsBuilder.reflectionEquals(obj, this);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this);
+ }
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this,
ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadWriteLogStorage.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadWriteLogStorage.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadWriteLogStorage.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,40 @@
+/**
+ * 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.cxf.management.web.logging;
+
+import java.util.List;
+
+/**
+ * Can be used by pull-style loggers to offload/save the records to some external storage
+ *
+ */
+public interface ReadWriteLogStorage extends ReadableLogStorage {
+
+ /**
+ * Save the records
+ * @param records log records to save
+ */
+ void save(List<LogRecord> records);
+
+ /**
+ * Clear the storage
+ */
+ void clear();
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,56 @@
+/**
+ * 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.cxf.management.web.logging;
+
+import java.util.List;
+
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+
+/**
+ * Can be used by pull-style loggers to read the records from some external storage
+ *
+ */
+public interface ReadableLogStorage {
+
+
+ /**
+ * Read the records and load them into a provided list
+ * @param list the list saved records should be added to
+ * @param condition the condition loaded records must meet, can be null
+ * @param loadFrom the initial index of the storage to have records loaded from
+ * @param int maxNumberOfRecords the max number of records to load from the storage
+ */
+ void load(List<LogRecord> list,
+ SearchCondition<LogRecord> condition,
+ int loadFrom,
+ int maxNumberOfRecords);
+
+
+ /**
+ * Get the size of storage (in records)
+ * @param the size, -1 if not known, for ex, when reading from an open file
containing log entries
+ */
+ int getSize();
+
+
+ /**
+ * Close the storage
+ */
+ void close();
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AbstractAtomBean.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AbstractAtomBean.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AbstractAtomBean.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,180 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.logging.Handler;
+import java.util.logging.Logger;
+
+import org.apache.commons.lang.Validate;
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.management.web.logging.LogLevel;
+
+
+public abstract class AbstractAtomBean {
+
+ private List<LoggerLevel> loggers = new ArrayList<LoggerLevel>();
+ private boolean initialized;
+ private Bus bus;
+
+ /**
+ * Creates unconfigured and uninitialized bean. To configure setters must be used,
then {@link #init()}
+ * must be called.
+ */
+ public AbstractAtomBean() {
+ initSingleLogger();
+ }
+
+ private void initSingleLogger() {
+ loggers = new ArrayList<LoggerLevel>();
+ loggers.add(new LoggerLevel("", "INFO"));
+ }
+
+ public void setBus(Bus bus) {
+ this.bus = bus;
+ }
+
+ public Bus getBus() {
+ return bus;
+ }
+
+ /**
+ * Set one or more loggers and levels descriptor. <br>
+ * Parsed input syntax is:
+ *
+ * <pre>
+ * loggers :=
<logger>(<separator><logger>)*
+ * logger := <name>[":"<level>]
+ * separator := "," | " " |
"\n"
+ * </pre>
+ *
+ * Examples:
+ * <p>
+ * Two loggers and two levels: <br>
+ * <tt>org.apache.cxf:INFO, org.apache.cxf.jaxrs:DEBUG</tt>
+ * <p>
+ * Three loggers, first with default "INFO" level: <br>
+ * <tt>org.apache.cxf, org.apache.cxf.jaxrs:DEBUG,
namedLogger:ERROR</tt><br>
+ * <p>
+ * One logger with default "INFO" level: <br>
+ * <tt>org.apache.cxf</tt><br>
+ */
+ public void setLoggers(String loggers) {
+ checkInit();
+ Validate.notNull(loggers, "loggers is null");
+ parseLoggers(loggers);
+ }
+
+ /**
+ * Name of logger to associate with ATOM push handler; empty string for root logger.
+ */
+ public void setLogger(String logger) {
+ checkInit();
+ Validate.notNull(logger, "logger is null");
+ if (loggers.size() != 1) {
+ initSingleLogger();
+ }
+ loggers.get(0).setLogger(logger);
+ }
+
+ /**
+ * Name of level that logger will use publishing log events to ATOM push handler;
empty string for default
+ * "INFO" level.
+ */
+ public void setLevel(String level) {
+ checkInit();
+ Validate.notNull(level, "level is null");
+ if (loggers.size() != 1) {
+ initSingleLogger();
+ }
+ loggers.get(0).setLevel(level);
+ }
+
+
+ /**
+ * Initializes bean; creates ATOM handler based on current properties state, and
attaches handler to
+ * logger(s).
+ */
+ public void init() {
+ checkInit();
+ initialized = true;
+ Handler h = createHandler();
+ for (int i = 0; i < loggers.size(); i++) {
+ Logger l = LogUtils.getL7dLogger(AbstractAtomBean.class, null,
loggers.get(i).getLogger());
+ l.addHandler(h);
+ l.setLevel(LogLevel.toJUL(LogLevel.valueOf(loggers.get(i).getLevel())));
+ }
+ }
+
+ protected abstract Handler createHandler();
+
+ protected void checkInit() {
+ if (initialized) {
+ throw new IllegalStateException("Bean is already initialized");
+ }
+ }
+
+ private void parseLoggers(String param) {
+ loggers = new ArrayList<LoggerLevel>();
+ StringTokenizer st1 = new StringTokenizer(param, ", \t\n\r\f");
+ while (st1.hasMoreTokens()) {
+ String tok = st1.nextToken();
+ int idx = tok.indexOf(":");
+ if (idx != -1) {
+ loggers.add(new LoggerLevel(tok.substring(0, idx), tok.substring(idx + 1,
tok.length())));
+ } else {
+ loggers.add(new LoggerLevel(tok, "INFO"));
+ }
+ }
+ }
+
+ protected List<LoggerLevel> getLoggers() {
+ return loggers;
+ }
+
+ protected static class LoggerLevel {
+ private String logger;
+ private String level;
+
+ public LoggerLevel(String logger, String level) {
+ this.logger = logger;
+ this.level = level;
+ }
+
+ public String getLogger() {
+ return logger;
+ }
+
+ public void setLogger(String logger) {
+ this.logger = logger;
+ }
+
+ public String getLevel() {
+ return level;
+ }
+
+ public void setLevel(String level) {
+ this.level = level;
+ }
+
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullHandler.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullHandler.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullHandler.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,61 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.util.logging.Handler;
+
+import org.apache.cxf.management.web.logging.LogRecord;
+
+
+public final class AtomPullHandler extends Handler {
+
+ private AtomPullServer engine;
+ /**
+ * Creates handler using (package private).
+ *
+ * @param engine configured engine.
+ */
+ AtomPullHandler(AtomPullServer engine) {
+ this.engine = engine;
+ }
+
+ @Override
+ public void publish(java.util.logging.LogRecord record) {
+ if (LoggingThread.isSilent()) {
+ return;
+ }
+ LoggingThread.markSilent(true);
+ try {
+ LogRecord rec = LogRecord.fromJUL(record);
+ engine.publish(rec);
+ } finally {
+ LoggingThread.markSilent(false);
+ }
+ }
+
+ @Override
+ public synchronized void close() throws SecurityException {
+ engine.close();
+ }
+
+ @Override
+ public synchronized void flush() {
+ // no-op
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,520 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.logging.Handler;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriBuilder;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.cxf.Bus;
+import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.search.ConditionType;
+import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
+import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.management.web.logging.LogLevel;
+import org.apache.cxf.management.web.logging.LogRecord;
+import org.apache.cxf.management.web.logging.ReadWriteLogStorage;
+import org.apache.cxf.management.web.logging.ReadableLogStorage;
+import org.apache.cxf.management.web.logging.atom.converter.StandardConverter;
+
+
+@Path("/logs")
+public class AtomPullServer extends AbstractAtomBean {
+
+ private List<LogRecord> records = new LinkedList<LogRecord>();
+ private WeakHashMap<Integer, Feed> feeds = new WeakHashMap<Integer,
Feed>();
+ private ReadableLogStorage storage;
+ private int pageSize = 40;
+ private int maxInMemorySize = 500;
+ private boolean useArchivedFeeds;
+ private int recordsSize;
+ private volatile boolean alreadyClosed;
+ private SearchCondition<LogRecord> condition;
+
+ @Context
+ private MessageContext context;
+
+ private List<String> endpointAddresses;
+ private String serverAddress;
+
+ public void setEndpointAddress(String address) {
+ setEndpointAddresses(Collections.singletonList(address));
+ }
+
+ public void setEndpointAddresses(List<String> addresses) {
+ this.endpointAddresses = addresses;
+ }
+
+ public void setServerAddress(String address) {
+ this.serverAddress = address;
+ }
+
+ @Override
+ public void init() {
+ // the storage might've been used to save previous records or it might
+ // point to a file log entries are added to
+ if (storage != null) {
+ //-1 can be returned by read-only storage if it does not know in advance
+ // a number of records it may contain
+ recordsSize = storage.getSize();
+ }
+
+ if (storage == null || storage instanceof ReadWriteLogStorage) {
+ super.init();
+ } else {
+ // super.init() results in the additional Handler being created and
publish()
+ // method being called as a result. If the storage is read-only it is assumed
it points to
+ // the external source of log records thus no need to get the publish events
here
+
+ // instead we create a SearchCondition the external storage will check
against when
+ // loading the matching records on request
+
+ List<SearchCondition<LogRecord>> list = new
LinkedList<SearchCondition<LogRecord>>();
+ for (LoggerLevel l : super.getLoggers()) {
+ LogRecord r = new LogRecord();
+ r.setLoggerName(l.getLogger());
+ r.setLevel(LogLevel.valueOf(l.getLevel()));
+ list.add(new SearchConditionImpl(r));
+ }
+ condition = new OrSearchCondition<LogRecord>(list);
+ }
+ initBusProperty();
+ }
+
+ @Override
+ protected Handler createHandler() {
+ return new AtomPullHandler(this);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void initBusProperty() {
+ if (endpointAddresses != null && serverAddress != null &&
getBus() != null) {
+ Bus bus = getBus();
+ synchronized (bus) {
+ Map<String, String> addresses =
+ (Map<String,
String>)bus.getProperty("org.apache.cxf.extensions.logging.atom.pull");
+ if (addresses == null) {
+ addresses = new HashMap<String, String>();
+ }
+ for (String address : endpointAddresses) {
+ addresses.put(address, serverAddress + "/logs");
+ }
+ bus.setProperty("org.apache.cxf.extensions.logging.atom.pull",
addresses);
+ }
+ }
+ }
+
+ @GET
+ @Produces("application/atom+xml")
+ public Feed getXmlFeed(@PathParam("id") int page) {
+ return getXmlFeedWithPage(1);
+ }
+
+ @GET
+ @Produces("application/atom+xml")
+ @Path("{id}")
+ public Feed getXmlFeedWithPage(@PathParam("id") int page) {
+
+ // lets check if the Atom reader is asking for a set of records which has already
been
+ // converted to Feed
+
+ synchronized (feeds) {
+ Feed f = feeds.get(page);
+ if (f != null) {
+ return f;
+ }
+ }
+
+ Feed feed = null;
+ synchronized (records) {
+ List<LogRecord> list = getSubList(page);
+ Collections.sort(list, new LogRecordComparator());
+ feed = (Feed)new CustomFeedConverter(page).convert(list).get(0);
+ setFeedPageProperties(feed, page);
+ }
+ // if at the moment we've converted n < pageSize number of records only
and
+ // persist a Feed keyed by a page then another reader requesting the same page
+ // may miss latest records which might've been added since the original
request
+ if (feed.getEntries().size() == pageSize) {
+ synchronized (feeds) {
+ feeds.put(page, feed);
+ }
+ }
+ return feed;
+ }
+
+ @GET
+ @Produces({"text/html", "application/xhtml+xml" })
+ @Path("alternate/{id}")
+ public String getAlternateFeed(@PathParam("id") int page) {
+ List<LogRecord> list = getSubList(page);
+ Collections.sort(list, new LogRecordComparator());
+ return convertEntriesToHtml(list);
+
+ }
+
+ @GET
+ @Path("entry/{id}")
+ @Produces("application/atom+xml;type=entry")
+ public Entry getEntry(@PathParam("id") int index) {
+ List<LogRecord> list = getLogRecords(index);
+ return (Entry)new CustomEntryConverter(index).convert(list).get(0);
+ }
+
+ @GET
+ @Path("entry/alternate/{id}")
+ @Produces({"text/html", "application/xhtml+xml" })
+ public String getAlternateEntry(@PathParam("id") int index) {
+ List<LogRecord> logRecords = getLogRecords(index);
+ return convertEntryToHtml(logRecords.get(0));
+ }
+
+ @GET
+ @Path("records")
+ @Produces("text/plain")
+ public int getNumberOfAvailableRecords() {
+ return recordsSize;
+ }
+
+ private List<LogRecord> getLogRecords(int index) {
+ List<LogRecord> list = new LinkedList<LogRecord>();
+ if (storage != null) {
+ int storageSize = storage.getSize();
+ if (recordsSize == -1 || index < storageSize) {
+ storage.load(list, condition, index, 1);
+ } else if (index < recordsSize) {
+ list.add(records.get(index - storageSize));
+ }
+ } else {
+ list.add(records.get(index));
+ }
+ if (list.size() != 1) {
+ throw new WebApplicationException(404);
+ }
+ return list;
+ }
+
+
+ protected List<LogRecord> getSubList(int page) {
+
+ if (recordsSize == -1) {
+ // let the external storage load the records it knows about
+ List<LogRecord> list = new LinkedList<LogRecord>();
+ storage.load(list, condition, page == 1 ? 0 : (page - 1) * pageSize,
pageSize);
+ return list;
+ }
+
+ if (recordsSize == 0) {
+ return records;
+ }
+
+ int fromIndex = 0;
+ int toIndex = 0;
+ // see
http://tools.ietf.org/html/draft-nottingham-atompub-feed-history-07
+ if (!useArchivedFeeds) {
+ fromIndex = page == 1 ? 0 : (page - 1) * pageSize;
+ if (fromIndex > recordsSize) {
+ // this should not happen really
+ page = 1;
+ fromIndex = 0;
+ }
+ toIndex = page == 1 ? pageSize : fromIndex + pageSize;
+ if (toIndex > recordsSize) {
+ toIndex = recordsSize;
+ }
+ } else {
+ fromIndex = recordsSize - pageSize * page;
+ if (fromIndex < 0) {
+ fromIndex = 0;
+ }
+ toIndex = pageSize < recordsSize ? recordsSize : pageSize;
+ }
+
+ // if we have the storage then try to load from it
+ if (storage != null) {
+ if (fromIndex < storage.getSize()) {
+ int storageSize = storage.getSize();
+ int maxQuantityToLoad = toIndex > storageSize ? toIndex - storageSize
: toIndex - fromIndex;
+ List<LogRecord> list = new LinkedList<LogRecord>();
+ storage.load(list, condition, fromIndex, maxQuantityToLoad);
+ int totalQuantity = toIndex - fromIndex;
+ if (list.size() < totalQuantity) {
+ int remaining = totalQuantity - list.size();
+ if (remaining > records.size()) {
+ remaining = records.size();
+ }
+ list.addAll(records.subList(0, remaining));
+ }
+ return list;
+ } else {
+ fromIndex -= storage.getSize();
+ toIndex -= storage.getSize();
+ }
+ }
+ return records.subList(fromIndex, toIndex);
+
+ }
+
+ protected void setFeedPageProperties(Feed feed, int page) {
+ String self = context.getUriInfo().getAbsolutePath().toString();
+ feed.addLink(self, "self");
+
+ String uri =
context.getUriInfo().getBaseUriBuilder().path("logs").build().toString();
+ feed.addLink(uri + "/alternate/" + page, "alternate");
+ if (!useArchivedFeeds) {
+ if (recordsSize != -1) {
+ if (page > 2) {
+ feed.addLink(uri, "first");
+ }
+
+ if (page * pageSize < recordsSize) {
+ feed.addLink(uri + "/" + (page + 1), "next");
+ }
+
+ if (page * (pageSize + 1) < recordsSize) {
+ feed.addLink(uri + "/" + (recordsSize / pageSize + 1),
"last");
+ }
+ } else if (feed.getEntries().size() == pageSize) {
+ feed.addLink(uri + "/" + (page + 1), "next");
+ }
+ if (page > 1) {
+ uri = page > 2 ? uri + "/" + (page - 1) : uri;
+ feed.addLink(uri, "previous");
+ }
+ } else {
+ feed.addLink(self, "current");
+ // TODO : add prev-archive and next-archive; next-archive should not be set
if it will point to
+ // current
+ // and
xmlns:fh="http://purl.org/syndication/history/1.0":archive
extension but only if
+ // it is not current
+ }
+
+ }
+
+
+ public void publish(LogRecord record) {
+ if (alreadyClosed) {
+ System.err.println("AtomPullServer has been closed, the following log
record can not be saved : "
+ + record.toString());
+ return;
+ }
+ synchronized (records) {
+ if (records.size() == maxInMemorySize) {
+ if (storage instanceof ReadWriteLogStorage) {
+ ((ReadWriteLogStorage)storage).save(records);
+ records.clear();
+ } else {
+ LogRecord oldRecord = records.remove(0);
+ System.err.println("The oldest log record is removed : " +
oldRecord.toString());
+ }
+ }
+ records.add(record);
+ ++recordsSize;
+ }
+ }
+
+ public void setPageSize(int size) {
+ pageSize = size;
+ }
+
+ public void setMaxInMemorySize(int maxInMemorySize) {
+ this.maxInMemorySize = maxInMemorySize;
+ }
+
+ public void setStorage(ReadableLogStorage storage) {
+ this.storage = storage;
+ }
+
+ public void close() {
+ if (alreadyClosed) {
+ return;
+ }
+ alreadyClosed = true;
+ if (storage instanceof ReadWriteLogStorage) {
+ ((ReadWriteLogStorage)storage).save(records);
+ }
+ }
+
+ // TODO : this all can be done later on in a simple xslt template
+ private String convertEntriesToHtml(List<LogRecord> rs) {
+ StringBuilder sb = new StringBuilder();
+ startHtmlHeadAndBody(sb, "CXF Service Log Entries");
+ addRecordToTable(sb, rs, true);
+ sb.append("</body></html>");
+ return sb.toString();
+ }
+ // TODO : this all can be done later on in a simple xslt template
+ private String convertEntryToHtml(LogRecord r) {
+ StringBuilder sb = new StringBuilder();
+ startHtmlHeadAndBody(sb, r.getLevel().toString());
+ addRecordToTable(sb, Collections.singletonList(r), false);
+ sb.append("</body></html>");
+ return sb.toString();
+ }
+
+ private void addRecordToTable(StringBuilder sb, List<LogRecord> list, boolean
forFeed) {
+ DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
+ sb.append("<table border=\"1\">");
+
sb.append("<tr><th>Date</th><th>Level</th><th>Logger</th><th>Message</th></tr>");
+ for (LogRecord lr : list) {
+ sb.append("<tr>");
+ sb.append("<td>" + df.format(lr.getEventTimestamp()) +
"</td>");
+ sb.append("<td>" + lr.getLevel().toString() +
"</td>");
+ sb.append("<td>" + lr.getLoggerName() +
"</td>");
+ String message = null;
+ if (lr.getMessage().length() > 0) {
+ message = lr.getThrowable().length() > 0 ? lr.getMessage() + " :
" + lr.getThrowable()
+ : lr.getMessage();
+ } else if (lr.getThrowable().length() > 0) {
+ message = lr.getThrowable();
+ } else {
+ message = " ";
+ }
+ if (forFeed && lr.getThrowable().length() > 0) {
+ message = message.substring(0, message.length() / 2);
+ }
+ sb.append("<td>" + message + "</td>");
+ sb.append("</tr>");
+ }
+ sb.append("</table><br/><br/>");
+
+ }
+
+ private void startHtmlHeadAndBody(StringBuilder sb, String title) {
+ sb.append("<html
xmlns=\"http://www.w3.org/1999/xhtml\">");
+ sb.append("<head>");
+ sb.append("<meta http-equiv=\"content-type\"
content=\"text/html;charset=UTF-8\"/>");
+ sb.append("<title>" + "Log record with level " + title
+ "</title>");
+ sb.append("</head>");
+ sb.append("<body>");
+ }
+
+ private static class SearchConditionImpl implements SearchCondition<LogRecord>
{
+ private LogRecord template;
+
+ public SearchConditionImpl(LogRecord l) {
+ this.template = l;
+ }
+
+ public boolean isMet(LogRecord pojo) {
+
+ return (template.getLevel() == LogLevel.ALL
+ || pojo.getLevel().compareTo(template.getLevel()) <= 0)
+ && template.getLoggerName().equals(pojo.getLoggerName());
+ }
+
+ public LogRecord getCondition() {
+ return new LogRecord(template);
+ }
+
+ public ConditionType getConditionType() {
+ return ConditionType.CUSTOM;
+ }
+
+ public List<SearchCondition<LogRecord>> getSearchConditions() {
+ return null;
+ }
+
+ public List<LogRecord> findAll(Collection<LogRecord> pojos) {
+ List<LogRecord> list = new LinkedList<LogRecord>();
+ for (LogRecord r : pojos) {
+ if (isMet(r)) {
+ list.add(r);
+ }
+ }
+ return list;
+ }
+
+ public PrimitiveStatement getStatement() {
+ return null;
+ }
+
+ public String toSQL(String table, String... columns) {
+ return null;
+ }
+
+
+ }
+
+ private static class LogRecordComparator implements Comparator<LogRecord> {
+
+ public int compare(LogRecord r1, LogRecord r2) {
+ return r1.getEventTimestamp().compareTo(r2.getEventTimestamp()) * -1;
+ }
+
+ }
+
+ private class CustomFeedConverter extends StandardConverter {
+ private int page;
+ public CustomFeedConverter(int page) {
+ super(Output.FEED, Multiplicity.MANY, Format.CONTENT);
+ this.page = page;
+ }
+
+ @Override
+ protected void setDefaultEntryProperties(Entry entry, List<LogRecord> rs,
int entryIndex) {
+ super.setDefaultEntryProperties(entry, rs, entryIndex);
+ UriBuilder builder =
context.getUriInfo().getAbsolutePathBuilder().path("entry");
+ Integer realIndex = page == 1 ? entryIndex : page * pageSize + entryIndex;
+
+ entry.addLink(builder.clone().path(realIndex.toString()).build().toString(),
"self");
+
entry.addLink(builder.path("alternate").path(realIndex.toString()).build().toString(),
+ "alternate");
+ }
+
+ }
+
+ private class CustomEntryConverter extends StandardConverter {
+ private String selfFragment;
+ private String altFragment;
+ public CustomEntryConverter(int index) {
+ super(Output.ENTRY, Multiplicity.ONE, Format.CONTENT);
+ this.selfFragment = "logs/entry/" + index;
+ this.altFragment = "logs/alternate/entry/" + index;
+ }
+
+ @Override
+ protected void setDefaultEntryProperties(Entry entry, List<LogRecord> rs,
int entryIndex) {
+ super.setDefaultEntryProperties(entry, rs, entryIndex);
+
entry.addLink(context.getUriInfo().getBaseUriBuilder().path(selfFragment).build().toString(),
+ "self");
+
entry.addLink(context.getUriInfo().getBaseUriBuilder().path(altFragment).build().toString(),
+ "alternate");
+ }
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushBean.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushBean.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushBean.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,194 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.util.logging.Handler;
+
+import org.apache.commons.lang.Validate;
+import org.apache.cxf.management.web.logging.atom.converter.Converter;
+import org.apache.cxf.management.web.logging.atom.deliverer.Deliverer;
+
+/**
+ * Bean used to configure {@link AtomPushHandler JUL handler} with Spring instead of
properties file. See
+ * {@link AtomPushHandler} class for detailed description of parameters. Next to
configuration of handler,
+ * Spring bean offers simple configuration of associated loggers that share ATOM
push-style handler.
+ * <p>
+ * General rules:
+ * <ul>
+ * <li>When {@link #setDeliverer(Deliverer) deliverer} property is not set
explicitly, URL must be set to
+ * create default deliverer.</li>
+ * <li>When {@link #setConverter(Converter) converter} property is not set
explicitly, default converter is
+ * created.</li>
+ * <li>When {@link #setLoggers(String) loggers} property is used, it overrides pair
of
+ * {@link #setLogger(String) logger} and {@link #setLevel(String) level} properties; and
vice versa.</li>
+ * <li>When logger is not set, handler is attached to root logger (named
""); when level is not set for
+ * logger, default "INFO" level is used.</li>
+ * <li>When {@link #setBatchSize(String) batchSize} property is not set or set to
wrong value, default batch
+ * size of "1" is used.</li>
+ * <li>When deliverer property is NOT set, use of "retryXxx" properties
causes creation of retrying default
+ * deliverer.</li>
+ * </ul>
+ * Examples:
+ * <p>
+ * ATOM push handler with registered with root logger for all levels or log events,
pushing one feed per event
+ * to specified URL, using default delivery and conversion methods:
+ *
+ * <pre>
+ * <bean
class="org.apache.cxf.jaxrs.ext.logging.atom.AtomPushBean"
+ * init-method="init">
+ * <property name="url"
value="http://localhost:9080/feed"/>
+ * <property name="level" value="ALL"
/>
+ * </bean>
+ * </pre>
+ *
+ * ATOM push handler registered with multiple loggers and listening for different levels
(see
+ * {@link #setLoggers(String) loggers} property description for syntax details). Custom
deliverer will take
+ * care of feeds, each of which carries batch of 10 log events:
+ *
+ * <pre>
+ * <bean id="soapDeliverer" ...
+ * ...
+ * <bean
class="org.apache.cxf.jaxrs.ext.logging.atom.AtomPushBean"
+ * init-method="init">
+ * <property name="deliverer">
+ * <ref bean="soapDeliverer"/>
+ * </property>
+ * <property name="loggers" value="
+ * org.apache.cxf:DEBUG,
+ * org.apache.cxf.jaxrs,
+ * org.apache.cxf.bus:ERROR" />
+ * <property name="batchSize" value="10"
/>
+ * </bean>
+ * </pre>
+ */
+public final class AtomPushBean extends AbstractAtomBean {
+
+ private AtomPushEngineConfigurator conf = new AtomPushEngineConfigurator();
+
+ /**
+ * Creates unconfigured and uninitialized bean. To configure setters must be used,
then {@link #init()}
+ * must be called.
+ */
+ public AtomPushBean() {
+ }
+
+ /**
+ * Set URL used when custom deliverer is not set (default deliverer is being
created).
+ */
+ public void setUrl(String url) {
+ checkInit();
+ Validate.notNull(url, "url is null");
+ conf.setUrl(url);
+ }
+
+ /**
+ * Set initialized deliverer.
+ */
+ public void setDeliverer(Deliverer deliverer) {
+ checkInit();
+ Validate.notNull(deliverer, "deliverer is null");
+ conf.setDeliverer(deliverer);
+ }
+
+ /**
+ * Set initialized converter.
+ */
+ public void setConverter(Converter converter) {
+ checkInit();
+ Validate.notNull(converter, "converter is null");
+ conf.setConverter(converter);
+ }
+
+ /**
+ * Size of batch; empty string for default one element batch.
+ */
+ public void setBatchSize(String batchSize) {
+ checkInit();
+ Validate.notNull(batchSize, "batchSize is null");
+ conf.setBatchSize(batchSize);
+ }
+
+ /**
+ * Batch cleanup time in minutes
+ */
+ public void setBatchCleanupTime(String batchCleanupTime) {
+ checkInit();
+ Validate.notNull(batchCleanupTime, "batchCleanup is null");
+ conf.setBatchCleanupTime(batchCleanupTime);
+ }
+
+ /**
+ * Retry pause calculation strategy, either "linear" or
"exponential".
+ */
+ public void setRetryPause(String retryPause) {
+ checkInit();
+ Validate.notNull(retryPause, "retryPause is null");
+ conf.setRetryPause(retryPause);
+ }
+
+ /**
+ * Retry pause time (in seconds).
+ */
+ public void setRetryPauseTime(String time) {
+ checkInit();
+ Validate.notNull(time, "time is null");
+ conf.setRetryPauseTime(time);
+ }
+
+ /**
+ * Retry timeout (in seconds).
+ */
+ public void setRetryTimeout(String timeout) {
+ checkInit();
+ Validate.notNull(timeout, "timeout is null");
+ conf.setRetryTimeout(timeout);
+ }
+
+ /**
+ * Conversion output type: "feed" or "entry".
+ */
+ public void setOutput(String output) {
+ checkInit();
+ Validate.notNull(output, "output is null");
+ conf.setOutput(output);
+ }
+
+ /**
+ * Multiplicity of subelement of output: "one" or "many".
+ */
+ public void setMultiplicity(String multiplicity) {
+ checkInit();
+ Validate.notNull(multiplicity, "multiplicity is null");
+ conf.setMultiplicity(multiplicity);
+ }
+
+ /**
+ * Entry data format: "content" or "extension".
+ */
+ public void setFormat(String format) {
+ checkInit();
+ Validate.notNull(format, "format is null");
+ conf.setFormat(format);
+ }
+
+ protected Handler createHandler() {
+ return new AtomPushHandler(conf.createEngine());
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngine.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngine.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngine.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,217 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.abdera.model.Element;
+import org.apache.commons.lang.Validate;
+import org.apache.cxf.management.web.logging.LogRecord;
+import org.apache.cxf.management.web.logging.atom.converter.Converter;
+import org.apache.cxf.management.web.logging.atom.deliverer.Deliverer;
+
+/**
+ * Package private ATOM push-style engine. Engine enqueues log records as they are {@link
#publish(LogRecord)
+ * published}. After queue size exceeds {@link #getBatchSize() batch size} processing of
collection of these
+ * records (in size of batch size) is triggered.
+ * <p>
+ * Processing is done in separate thread not to block publishing interface. Processing is
two step: first list
+ * of log records is transformed by {@link Converter converter} to ATOM {@link Element
element} and then it is
+ * pushed out by {@link Deliverer deliverer} to client. Next to transport deliverer is
indirectly responsible
+ * for marshaling ATOM element to XML.
+ * <p>
+ * Processing is done by single threaded {@link java.util.concurrent.Executor executor};
next batch of records
+ * is taken from queue only when currently processed batch finishes and queue has enough
elements to proceed.
+ * <p>
+ * First failure of any delivery shuts engine down. To avoid this situation engine must
have registered
+ * reliable deliverer or use wrapping
+ * {@link org.apache.cxf.jaxrs.ext.logging.atom.deliverer.RetryingDeliverer}.
+ */
+// TODO add internal diagnostics - log messages somewhere except for logger :D
+final class AtomPushEngine {
+ private List<LogRecord> queue = new ArrayList<LogRecord>();
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private int batchSize = 1;
+ private int batchTime;
+ private Converter converter;
+ private Deliverer deliverer;
+ private Timer timer;
+
+ /**
+ * Put record to publishing queue. Engine accepts published records only if is in
proper state - is
+ * properly configured (has deliverer and converter registered) and is not shot down;
otherwise calls to
+ * publish are ignored.
+ *
+ * @param record record to be published.
+ */
+ public synchronized void publish(LogRecord record) {
+ Validate.notNull(record, "record is null");
+ if (isValid()) {
+ if (batchSize > 1 && batchTime > 0 && timer == null) {
+ createTimerTask(batchTime * 60 * 1000);
+ }
+ queue.add(record);
+ if (queue.size() >= batchSize) {
+ publishAndReset();
+ }
+ } else {
+ handleUndeliveredRecords(Collections.singletonList(record),
+ deliverer == null ? "" :
deliverer.getEndpointAddress());
+ }
+ }
+
+ protected synchronized void publishAndReset() {
+ publishBatch(queue, deliverer, converter);
+ queue = new ArrayList<LogRecord>();
+ }
+
+ /**
+ * Shuts engine down.
+ */
+ public synchronized void shutdown() {
+ cancelTimerTask();
+ if (isValid() && queue.size() > 0) {
+ publishAndReset();
+ }
+ executor.shutdown();
+ }
+
+ private boolean isValid() {
+ if (deliverer == null) {
+ // TODO report cause
+ System.err.println("deliverer is not set");
+ return false;
+ }
+ if (converter == null) {
+ System.err.println("converter is not set");
+ return false;
+ }
+ if (executor.isShutdown()) {
+ System.err.println("engine shutdown");
+ return false;
+ }
+ return true;
+ }
+
+ private void publishBatch(final List<LogRecord> batch,
+ final Deliverer d,
+ final Converter c) {
+ executor.execute(new Runnable() {
+ public void run() {
+ try {
+ LoggingThread.markSilent(true);
+ List<? extends Element> elements = c.convert(batch);
+ for (int i = 0; i < elements.size(); i++) {
+ Element element = elements.get(i);
+ if (!d.deliver(element)) {
+ System.err.println("Delivery to " +
d.getEndpointAddress()
+ + " failed, shutting engine down");
+ List<LogRecord> undelivered = null;
+ if (i == 0) {
+ undelivered = batch;
+ } else {
+ int index = (batch.size() / elements.size()) * i;
+ // should not happen but just in case :-)
+ if (index < batch.size()) {
+ undelivered = batch.subList(index, batch.size());
+ }
+ }
+ handleUndeliveredRecords(undelivered,
d.getEndpointAddress());
+ shutdown();
+ break;
+ }
+ }
+ } catch (InterruptedException e) {
+ // no action
+ } finally {
+ LoggingThread.markSilent(false);
+ }
+ }
+ });
+ }
+
+ protected void handleUndeliveredRecords(List<LogRecord> records, String
address) {
+ // TODO : save them to some transient storage perhaps ?
+ System.err.println("The following records have been undelivered to " +
address + " : ");
+ for (LogRecord r : records) {
+ System.err.println(r.toString());
+ }
+ }
+
+ public int getBatchSize() {
+ return batchSize;
+ }
+
+ public void setBatchSize(int batchSize) {
+ Validate.isTrue(batchSize > 0, "batch size is not greater than
zero");
+ this.batchSize = batchSize;
+ }
+
+ public void setBatchTime(int batchTime) {
+ this.batchTime = batchTime;
+ }
+
+ /**
+ * Creates a timer task which will periodically flush the batch queue
+ * thus ensuring log records won't become too 'stale'.
+ * Ex, if we have a batch size 10 and only WARN records need to be delivered
+ * then without the periodic cleanup the consumers may not get prompt notifications
+ *
+ * @param timeout
+ */
+ protected void createTimerTask(long timeout) {
+ timer = new Timer();
+ timer.schedule(new TimerTask() {
+ public void run() {
+ publishAndReset();
+ }
+ }, timeout);
+ }
+
+ protected void cancelTimerTask() {
+ if (timer != null) {
+ timer.cancel();
+ timer = null;
+ }
+ }
+
+ public synchronized Converter getConverter() {
+ return converter;
+ }
+
+ public synchronized void setConverter(Converter converter) {
+ Validate.notNull(converter, "converter is null");
+ this.converter = converter;
+ }
+
+ public synchronized Deliverer getDeliverer() {
+ return deliverer;
+ }
+
+ public synchronized void setDeliverer(Deliverer deliverer) {
+ Validate.notNull(deliverer, "deliverer is null");
+ this.deliverer = deliverer;
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngineConfigurator.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngineConfigurator.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushEngineConfigurator.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,213 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.cxf.management.web.logging.atom.converter.Converter;
+import org.apache.cxf.management.web.logging.atom.converter.StandardConverter;
+import org.apache.cxf.management.web.logging.atom.converter.StandardConverter.Format;
+import
org.apache.cxf.management.web.logging.atom.converter.StandardConverter.Multiplicity;
+import org.apache.cxf.management.web.logging.atom.converter.StandardConverter.Output;
+import org.apache.cxf.management.web.logging.atom.deliverer.Deliverer;
+import org.apache.cxf.management.web.logging.atom.deliverer.RetryingDeliverer;
+import org.apache.cxf.management.web.logging.atom.deliverer.WebClientDeliverer;
+
+/**
+ * Package private interpreter of incomplete input of engine configuration. Used commonly
by
+ * {@link AtomPushHandler properties file} and {@link AtomPushBean spring} configuration
schemes.
+ */
+// TODO extract 'general rules' of interpretation in handler and bean and put
here
+final class AtomPushEngineConfigurator {
+
+ private Deliverer deliverer;
+ private Converter converter;
+ private String delivererClass;
+ private String converterClass;
+ private String batchSize;
+ private String batchCleanupTime;
+ private String delivererUrl;
+ private String retryTimeout;
+ private String retryPause;
+ private String retryPauseTime;
+ private String output;
+ private String multiplicity;
+ private String format;
+
+ public void setUrl(String url) {
+ this.delivererUrl = url;
+ }
+
+ public void setRetryTimeout(String retryTimeout) {
+ this.retryTimeout = retryTimeout;
+ }
+
+ public void setRetryPause(String retryPause) {
+ this.retryPause = retryPause;
+ }
+
+ public void setRetryPauseTime(String retryPauseTime) {
+ this.retryPauseTime = retryPauseTime;
+ }
+
+ public void setBatchCleanupTime(String cleanupTime) {
+ this.batchCleanupTime = cleanupTime;
+ }
+
+ public void setBatchSize(String batchSize) {
+ this.batchSize = batchSize;
+ }
+
+ public void setDeliverer(Deliverer deliverer) {
+ this.deliverer = deliverer;
+ }
+
+ public void setConverter(Converter converter) {
+ this.converter = converter;
+ }
+
+ public void setDelivererClass(String delivererClass) {
+ this.delivererClass = delivererClass;
+ }
+
+ public void setConverterClass(String converterClass) {
+ this.converterClass = converterClass;
+ }
+
+ public void setOutput(String output) {
+ this.output = output;
+ }
+
+ public void setMultiplicity(String multiplicity) {
+ this.multiplicity = multiplicity;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ public AtomPushEngine createEngine() {
+ Deliverer d = deliverer;
+ Converter c = converter;
+ int batch = parseInt(batchSize, 1, 1);
+ int batchTime = parseInt(batchCleanupTime, 0);
+ if (d == null) {
+ if (delivererUrl != null) {
+ if (delivererClass != null) {
+ d = createDeliverer(delivererClass, delivererUrl);
+ } else {
+ d = new WebClientDeliverer(delivererUrl);
+ }
+ } else {
+ throw new IllegalStateException("Either url, deliverer or "
+ + "deliverer class with url must be
setup");
+ }
+ }
+ if (c == null) {
+ if (converterClass != null) {
+ c = createConverter(converterClass);
+ } else {
+ Output out = parseEnum(output, Output.FEED, Output.class);
+ Multiplicity defaultMul = out == Output.FEED ? Multiplicity.MANY
+ : batch > 1 ? Multiplicity.MANY : Multiplicity.ONE;
+ Multiplicity mul = parseEnum(multiplicity, defaultMul,
Multiplicity.class);
+ Format form = parseEnum(format, Format.CONTENT, Format.class);
+ if (out == Output.FEED) {
+ c = new StandardConverter(out, mul, form);
+ } else {
+ c = new StandardConverter(out, mul, form);
+ }
+ if (retryPause != null) {
+ int timeout = parseInt(retryTimeout, 0, 0);
+ int pause = parseInt(retryPauseTime, 1, 30);
+ boolean linear =
!retryPause.equalsIgnoreCase("exponential");
+ d = new RetryingDeliverer(d, timeout, pause, linear);
+ }
+ }
+ }
+ AtomPushEngine engine = new AtomPushEngine();
+ engine.setDeliverer(d);
+ engine.setConverter(c);
+ engine.setBatchSize(batch);
+ engine.setBatchTime(batchTime);
+ return engine;
+ }
+
+ private Deliverer createDeliverer(String clazz, String url) {
+ try {
+ Constructor<Deliverer> ctor = loadClass(clazz,
Deliverer.class).getConstructor(String.class);
+ return ctor.newInstance(url);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ private Converter createConverter(String clazz) {
+ try {
+ Constructor<Converter> ctor = loadClass(clazz,
Converter.class).getConstructor();
+ return ctor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> Class<T> loadClass(String clazz, Class<T> ifaceClass)
throws ClassNotFoundException {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ return (Class<T>)cl.loadClass(clazz);
+ } catch (ClassNotFoundException e) {
+ try {
+ // clazz could be shorted (stripped package name) retry for interface
location
+ String pkg = ifaceClass.getPackage().getName();
+ String clazz2 = pkg + "." + clazz;
+ return (Class<T>)cl.loadClass(clazz2);
+ } catch (Exception e1) {
+ throw new ClassNotFoundException(e.getMessage() + " or " +
e1.getMessage());
+ }
+ }
+ }
+
+ private int parseInt(String property, int defaultValue) {
+ try {
+ return Integer.parseInt(property);
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+
+ private int parseInt(String property, int lessThan, int defaultValue) {
+ int ret = parseInt(property, defaultValue);
+ if (ret < lessThan) {
+ ret = defaultValue;
+ }
+ return ret;
+ }
+
+ private <T extends Enum<T>> T parseEnum(String value, T defaultValue,
Class<T> enumClass) {
+ if (value == null | "".equals(value)) {
+ return defaultValue;
+ }
+ try {
+ return Enum.valueOf(enumClass, value.toUpperCase());
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushHandler.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushHandler.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPushHandler.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,185 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+import java.util.logging.Handler;
+import java.util.logging.LogManager;
+
+import org.apache.cxf.management.web.logging.LogRecord;
+import org.apache.cxf.management.web.logging.atom.converter.Converter;
+import org.apache.cxf.management.web.logging.atom.deliverer.Deliverer;
+
+/**
+ * Handler pushing log records in batches as Atom Feeds or Entries to registered client.
Handler
+ * responsibility is to adapt to JUL framework while most of job is delegated to {@link
AtomPushEngine}.
+ * <p>
+ * For simple configuration using properties file (one global root-level handler of this
class) following
+ * properties prefixed with full name of this class can be used:
+ * <ul>
+ * <li><b>url</b> - URL where feeds will be pushed (mandatory
parameter)</li>
+ * <li><b>batchSize</b> - integer number specifying minimal number of
published log records that trigger
+ * processing and pushing ATOM document. If parameter is not set, is not greater than
zero or is not a number,
+ * batch size is set to 1.</li>
+ * </ul>
+ * Conversion of log records into ATOM Elements can be tuned up using following
parameters. Note that not all
+ * combinations are meaningful, see {@link
org.apache.cxf.jaxrs.ext.logging.atom.converter.StandardConverter}
+ * for details:
+ * <ul>
+ * <li><b>output</b> - ATOM Element type pushed out, either
"feed" or "entry"; when not specified or invalid
+ * value provided "feed" is used.</li>
+ * <li><b>multiplicity</b> - multiplicity of subelement(entries in feed
for output=="feed" or log records in
+ * entry for output=="entry"), either "one" or "many"; when
not specified or invalid value provided "one" is
+ * used.</li>
+ * <li><b>format</b> - method of embedding data in entry, either
"content" or "extension"; when not specified
+ * or invalid value provided "content" is used.</li>
+ * </ul>
+ * By default delivery is served by WebClientDeliverer which does not support reliability
of transport.
+ * Availability of any of this parameters enables retrying of default delivery. Detailed
explanation of these
+ * parameter, see {@link
org.apache.cxf.jaxrs.ext.logging.atom.deliverer.RetryingDeliverer} class description.
+ * <ul>
+ * <li><b>retry.pause</b> - pausing strategy of delivery retries,
either <b>linear</b> or <b>exponential</b>
+ * value (mandatory parameter). If mispelled linear is used.</li>
+ * <li><b>retry.pause.time</b> - pause time (in seconds) between
retries. If parameter is not set, pause is
+ * set to 30 seconds.</li>
+ * <li><b>retry.timeout</b> - maximum time (in seconds) retrying will
be continued. If not set timeout is not
+ * set (infinite loop of retries).</li>
+ * </ul>
+ * Ultimate control on conversion and delivery is obtained specifying own implementation
classes:
+ * <ul>
+ * <li><b>converter</b> - name of class implementing {@link Converter}
class replacing default conversion and
+ * its specific parameters ("output", "multiplicity" and
"format") are ignored. For classes located in same
+ * package as Converter interface only class name can be given e.g. instead of
+ * "org.apache.cxf.jaxrs.ext.logging.atom.converter.FooBarConverter" one can
specify "FooBarConverter".</li>
+ * <li><b>deliverer</b> - name of class implementing {@link Deliverer}
class replacing default delivery and
+ * its specific parameters ("retry.Xxx") are ignored. For classes located in
same package as Deliverer
+ * interface only class name can be given e.g. instead of
+ * "org.apache.cxf.jaxrs.ext.logging.atom.deliverer.WebClientDeliverer" one can
specify
+ * "WebClientDeliverer".</li>
+ * </ul>
+ * Example:
+ *
+ * <pre>
+ * handlers = org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler,
java.util.logging.ConsoleHandler
+ * .level = INFO
+ *
+ * # deliver to given URL triggering after each batch of 10 log records
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.url =
http://localhost:9080
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.batchSize = 10
+ *
+ * # enable retrying delivery every 10 seconds for 5 minutes
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.retry.pause = linear
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.retry.pause.time = 10
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.retry.timeout = 300
+ *
+ * # output for AtomPub: push entries not feeds, each entry with one log record as
"atom:extension"
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.output = entry
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.multiplicity = one
+ * org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.format = extension
+ * ...
+ * </pre>
+ */
+public final class AtomPushHandler extends Handler {
+
+ private AtomPushEngine engine;
+ private boolean lazyConfig;
+
+ /**
+ * Creates handler with configuration taken from properties file.
+ */
+ public AtomPushHandler() {
+ // deferred configuration: configure() called from here would use utilities that
attempt to log
+ // and create this handler instance in recursion; configure() will be called on
first publish()
+ lazyConfig = true;
+ }
+
+ /**
+ * Creates handler with custom parameters.
+ *
+ * @param batchSize batch size, see {@link AtomPushEngine#getBatchSize()}
+ * @param converter converter transforming logs into ATOM elements
+ * @param deliverer deliverer pushing ATOM elements to client
+ */
+ public AtomPushHandler(int batchSize, Converter converter, Deliverer deliverer) {
+ engine = new AtomPushEngine();
+ engine.setBatchSize(batchSize);
+ engine.setConverter(converter);
+ engine.setDeliverer(deliverer);
+ }
+
+ /**
+ * Creates handler using (package private).
+ *
+ * @param engine configured engine.
+ */
+ AtomPushHandler(AtomPushEngine engine) {
+ this.engine = engine;
+ }
+
+ @Override
+ public synchronized void publish(java.util.logging.LogRecord record) {
+ if (LoggingThread.isSilent()) {
+ return;
+ }
+ LoggingThread.markSilent(true);
+ try {
+ if (lazyConfig) {
+ lazyConfig = false;
+ configure();
+ }
+ LogRecord rec = LogRecord.fromJUL(record);
+ engine.publish(rec);
+ } finally {
+ LoggingThread.markSilent(false);
+ }
+ }
+
+ @Override
+ public synchronized void close() throws SecurityException {
+ engine.shutdown();
+ }
+
+ @Override
+ public synchronized void flush() {
+ // no-op
+ }
+
+ /**
+ * Configuration from properties. Aligned to JUL strategy - properties file is only
for simple
+ * configuration: it allows configure one root handler with its parameters. What is
even more dummy, JUL
+ * does not allow to iterate over configuration properties to make interpretation
automated (e.g. using
+ * commons-beanutils)
+ */
+ private void configure() {
+ LogManager manager = LogManager.getLogManager();
+ String cname = getClass().getName();
+ AtomPushEngineConfigurator conf = new AtomPushEngineConfigurator();
+ conf.setUrl(manager.getProperty(cname + ".url"));
+ conf.setDelivererClass(manager.getProperty(cname + ".deliverer"));
+ conf.setConverterClass(manager.getProperty(cname + ".converter"));
+ conf.setBatchSize(manager.getProperty(cname + ".batchSize"));
+ conf.setBatchCleanupTime(manager.getProperty(cname +
".batchCleanupTime"));
+ conf.setRetryPause(manager.getProperty(cname + ".retry.pause"));
+ conf.setRetryPauseTime(manager.getProperty(cname +
".retry.pause.time"));
+ conf.setRetryTimeout(manager.getProperty(cname + ".retry.timeout"));
+ conf.setOutput(manager.getProperty(cname + ".output"));
+ conf.setMultiplicity(manager.getProperty(cname + ".multiplicity"));
+ conf.setFormat(manager.getProperty(cname + ".format"));
+ engine = conf.createEngine();
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/LoggingThread.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/LoggingThread.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/LoggingThread.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,51 @@
+/**
+ * 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.cxf.management.web.logging.atom;
+
+/**
+ * Helps disable logging from calls of the same thread. Motivation: log handlers in this
package causes other
+ * threads (from executor) to start logging (by using JAXB that itself uses JUL) which in
turn can be caught
+ * by the same handler leading to infinite loop.
+ * <p>
+ * Other approach than using thread local storage would be scanning of stack trace of
current thread to see if
+ * root of call comes from same package as package of handler - it's less effective
so TLS is using here.
+ */
+final class LoggingThread {
+
+ private static ThreadLocal<LoggingThread> threadLocal = new
ThreadLocal<LoggingThread>() {
+ @Override
+ protected LoggingThread initialValue() {
+ return new LoggingThread();
+ }
+ };
+
+ private boolean isSilent;
+
+ private LoggingThread() {
+ }
+
+ public static void markSilent(boolean silent) {
+ LoggingThread lt = threadLocal.get();
+ lt.isSilent = silent;
+ }
+
+ public static boolean isSilent() {
+ return threadLocal.get().isSilent;
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/Converter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/Converter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/Converter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,38 @@
+/**
+ * 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.cxf.management.web.logging.atom.converter;
+
+import java.util.List;
+
+import org.apache.abdera.model.Element;
+import org.apache.cxf.management.web.logging.LogRecord;
+
+/**
+ * Converts batch of log records into one or more ATOM Elements to deliver.
+ */
+public interface Converter {
+
+ /**
+ * Converts given collection.
+ *
+ * @param records not-null collection of records
+ * @return non-empty collection of ATOM Elements that represent log records
+ */
+ List<? extends Element> convert(List<LogRecord> records);
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,356 @@
+/**
+ * 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.cxf.management.web.logging.atom.converter;
+
+import java.io.StringWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensibleElement;
+import org.apache.abdera.model.Feed;
+import org.apache.commons.lang.Validate;
+import org.apache.cxf.jaxrs.ext.atom.AbstractEntryBuilder;
+import org.apache.cxf.jaxrs.ext.atom.AbstractFeedBuilder;
+import org.apache.cxf.management.web.logging.LogRecord;
+import org.apache.cxf.management.web.logging.LogRecords;
+
+/**
+ * Converter producing ATOM Feeds on standalone Entries with LogRecords or
LogRecordsLists embedded as content
+ * or extension. For configuration details see constructor documentation.
+ */
+public class StandardConverter implements Converter {
+
+ /** Conversion output */
+ public enum Output {
+ FEED,
+ ENTRY
+ }
+
+ /** Quantities of entries in feed or logrecords in entry */
+ public enum Multiplicity {
+ ONE,
+ MANY
+ }
+
+ /** Entity format */
+ public enum Format {
+ CONTENT,
+ EXTENSION
+ }
+
+ private Factory factory;
+ private JAXBContext context;
+ private DateFormat df;
+ private Converter worker;
+ private AbstractFeedBuilder<List<LogRecord>> feedBuilder;
+ private AbstractEntryBuilder<List<LogRecord>> entryBuilder;
+
+ /**
+ * Creates configured converter with default post-processing of feeds/entries
mandatory properties.
+ * Regardless of "format", combination of "output" and
"multiplicity" flags can be interpreted as follow:
+ * <ul>
+ * <li>ENTRY ONE - for each log record one entry is produced, converter returns
list of entries</li>
+ * <li>ENTRY MANY - list of log records is packed in one entry, converter
return one entry.</li>
+ * <li>FEED ONE - list of log records is packed in one entry, entry is inserted
to feed, converter returns
+ * one feed.</li>
+ * <li>FEED MANY - for each log record one entry is produced, entries are
collected in one feed, converter
+ * returns one feed.</li>
+ * </ul>
+ *
+ * @param output whether root elements if Feed or Entry (e.g. for AtomPub).
+ * @param multiplicity for output==FEED it is multiplicity of entities in feed for
output==ENTITY it is
+ * multiplicity of log records in entity.
+ * @param format log records embedded as entry content or extension.
+ */
+ public StandardConverter(Output output, Multiplicity multiplicity, Format format) {
+ this(output, multiplicity, format, null, null);
+ }
+
+ /**
+ * Creates configured converter with feeds/entries post-processing based on data
provided by feed and
+ * entry builders.
+ */
+ public StandardConverter(Output output, Multiplicity multiplicity, Format format,
+ AbstractFeedBuilder<List<LogRecord>>
feedBuilder,
+ AbstractEntryBuilder<List<LogRecord>>
entryBuilder) {
+ Validate.notNull(output, "output is null");
+ Validate.notNull(multiplicity, "multiplicity is null");
+ Validate.notNull(format, "format is null");
+ this.feedBuilder = feedBuilder;
+ this.entryBuilder = entryBuilder;
+
+ configure(output, multiplicity, format); //NOPMD
+ df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+ factory = Abdera.getNewFactory();
+ try {
+ context = JAXBContext.newInstance(LogRecords.class, LogRecord.class);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public List<? extends Element> convert(List<LogRecord> records) {
+ return worker.convert(records);
+ }
+
+ private void configure(final Output output, final Multiplicity multiplicity, final
Format format) {
+ if (output == Output.ENTRY && multiplicity == Multiplicity.ONE) {
+ worker = new Converter() {
+ public List<Entry> convert(List<LogRecord> records) {
+ return createEntries(format, records);
+ }
+ };
+ }
+ if (output == Output.ENTRY && multiplicity == Multiplicity.MANY) {
+ worker = new Converter() {
+ public List<Entry> convert(List<LogRecord> records) {
+ // produces one entry with list of all log records
+ return Arrays.asList(createEntryFromList(format, records));
+ }
+ };
+ }
+ if (output == Output.FEED && multiplicity == Multiplicity.ONE) {
+ worker = new Converter() {
+ public List<Feed> convert(List<LogRecord> records) {
+ // produces one feed with one entry with list of all log records
+ return Arrays.asList(createFeedWithSingleEntry(format, records));
+ }
+ };
+ }
+ if (output == Output.FEED && multiplicity == Multiplicity.MANY) {
+ worker = new Converter() {
+ public List<Feed> convert(List<LogRecord> records) {
+ // produces one feed with many entries, each entry with one log
record
+ return Arrays.asList(createFeed(format, records));
+ }
+ };
+ }
+ if (worker == null) {
+ throw new IllegalArgumentException("Unsupported configuration");
+ }
+ }
+
+ private List<Entry> createEntries(Format format, List<LogRecord> records)
{
+ List<Entry> entries = new ArrayList<Entry>();
+ for (int i = 0; i < records.size(); i++) {
+ entries.add(createEntryFromRecord(format, records.get(i), i));
+ }
+ return entries;
+ }
+
+ private Entry createEntryFromList(Format format, List<LogRecord> records) {
+ Entry e = createEntry(records, 0);
+ if (format == Format.CONTENT) {
+ setEntryContent(e, createContent(records));
+ } else {
+ setEntryContent(e, createExtension(records));
+ }
+ return e;
+ }
+
+ private Entry createEntryFromRecord(Format format, LogRecord record, int entryIndex)
{
+ Entry e = createEntry(Collections.singletonList(record), entryIndex);
+ if (format == Format.CONTENT) {
+ setEntryContent(e, createContent(record));
+ } else {
+ setEntryContent(e, createExtension(record));
+ }
+ return e;
+ }
+
+ private String createContent(LogRecord record) {
+ StringWriter writer = new StringWriter();
+ try {
+ context.createMarshaller().marshal(record, writer);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ return writer.toString();
+ }
+
+ private String createContent(List<LogRecord> records) {
+ StringWriter writer = new StringWriter();
+ LogRecords list = new LogRecords();
+ list.setLogRecords(records);
+ try {
+ context.createMarshaller().marshal(list, writer);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ return writer.toString();
+ }
+
+ private ExtensibleElement createExtension(LogRecord record) {
+ ExtensibleElement erec = factory.newExtensionElement(qn("logRecord"));
+
+ // forget about single line "addExtension().setText()" since
+ // javac failure "org.apache.abdera.model.Element cannot be
dereferenced"
+ Element e = erec.addExtension(qn("eventTimestamp"));
+ e.setText(toAtomDateFormat(record.getEventTimestamp()));
+ e = erec.addExtension(qn("level"));
+ e.setText(record.getLevel().toString());
+ e = erec.addExtension(qn("loggerName"));
+ e.setText(record.getLoggerName());
+ e = erec.addExtension(qn("message"));
+ e.setText(record.getMessage());
+ e = erec.addExtension(qn("threadName"));
+ e.setText(record.getThreadName());
+ e = erec.addExtension(qn("throwable"));
+ e.setText(record.getThrowable());
+ return erec;
+ }
+
+ private String toAtomDateFormat(Date d) {
+ String date = df.format(d);
+ // timezone in date does not have semicolon as XML Date requires
+ // e.g we have "2009-11-23T22:03:53.996+0100"
+ // instead of "2009-11-23T22:03:53.996+01:00"
+ return date.substring(0, date.length() - 2) + ":" +
date.substring(date.length() - 2);
+ }
+
+ private QName qn(String name) {
+ return new
QName("http://cxf.apache.org/log", name, "log");
+ }
+
+ private ExtensibleElement createExtension(List<LogRecord> records) {
+ ExtensibleElement list =
factory.newExtensionElement(qn("logRecords"));
+ for (LogRecord rec : records) {
+ list.addExtension(createExtension(rec));
+ }
+ return list;
+ }
+
+ private Entry createEntry(List<LogRecord> records, int entryIndex) {
+ Entry entry = factory.newEntry();
+ setDefaultEntryProperties(entry, records, entryIndex);
+
+ return entry;
+ }
+
+ private void setEntryContent(Entry e, String content) {
+ e.setContent(content, Content.Type.XML);
+ }
+
+ private void setEntryContent(Entry e, ExtensibleElement ext) {
+ e.addExtension(ext);
+ }
+
+ private Feed createFeedWithSingleEntry(Format format, List<LogRecord> records)
{
+
+ Feed feed = factory.newFeed();
+ feed.addEntry(createEntryFromList(format, records));
+ setDefaultFeedProperties(feed, records);
+ return feed;
+ }
+
+ private Feed createFeed(Format format, List<LogRecord> records) {
+
+ Feed feed = factory.newFeed();
+ List<Entry> entries = createEntries(format, records);
+ for (Entry entry : entries) {
+ feed.addEntry(entry);
+ }
+ setDefaultFeedProperties(feed, records);
+ return feed;
+ }
+
+ protected void setDefaultFeedProperties(Feed feed, List<LogRecord> records) {
+ if (feedBuilder != null) {
+ feed.setId(feedBuilder.getId(records));
+ feed.addAuthor(feedBuilder.getAuthor(records));
+ feed.setTitle(feedBuilder.getTitle(records));
+ feed.setUpdated(feedBuilder.getUpdated(records));
+ feed.setBaseUri(feedBuilder.getBaseUri(records));
+ List<String> categories = feedBuilder.getCategories(records);
+ if (categories != null) {
+ for (String category : categories) {
+ feed.addCategory(category);
+ }
+ }
+ Map<String, String> links = feedBuilder.getLinks(records);
+ if (links != null) {
+ for (java.util.Map.Entry<String, String> mapEntry :
links.entrySet()) {
+ feed.addLink(mapEntry.getKey(), mapEntry.getValue());
+ }
+ }
+ } else {
+ feed.setId("uuid:" + UUID.randomUUID().toString());
+ feed.addAuthor("CXF");
+ feed.setTitle("CXF Service Log Entries");
+ feed.setUpdated(new Date());
+ }
+ }
+
+ protected void setDefaultEntryProperties(Entry entry, List<LogRecord> records,
+ int entryIndex) {
+ if (entryBuilder != null) {
+ entry.setId(entryBuilder.getId(records));
+ entry.addAuthor(entryBuilder.getAuthor(records));
+ entry.setTitle(entryBuilder.getTitle(records));
+ entry.setUpdated(entryBuilder.getUpdated(records));
+ entry.setBaseUri(entryBuilder.getBaseUri(records));
+ entry.setSummary(entryBuilder.getSummary(records));
+ List<String> categories = entryBuilder.getCategories(records);
+ if (categories != null) {
+ for (String category : categories) {
+ entry.addCategory(category);
+ }
+ }
+ Map<String, String> links = entryBuilder.getLinks(records);
+ if (links != null) {
+ for (java.util.Map.Entry<String, String> mapEntry :
links.entrySet()) {
+ entry.addLink(mapEntry.getKey(), mapEntry.getValue());
+ }
+ }
+ entry.setPublished(entryBuilder.getPublished(records));
+ entry.setSummary(entryBuilder.getSummary(records));
+ } else {
+ entry.addAuthor("CXF");
+ if (records.size() != 1) {
+ entry.setId("uuid:" + UUID.randomUUID().toString());
+ entry.setTitle(String.format("Entry with %d log record(s)",
+ records.size()));
+ } else {
+ entry.setId(records.get(0).getId());
+ entry.setTitle("Log record with level " +
records.get(0).getLevel().toString());
+ entry.setSummary(records.get(0).getLoggerName() + " : " +
records.get(0).getMessage());
+ }
+ if (records.size() > 0) {
+ entry.setUpdated(toAtomDateFormat(records.get(0).getEventTimestamp()));
+ }
+ }
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/Deliverer.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/Deliverer.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/Deliverer.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,42 @@
+/**
+ * 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.cxf.management.web.logging.atom.deliverer;
+
+import org.apache.abdera.model.Element;
+
+/**
+ * ATOM element deliverer. Represents transport strategy e.g. using
+ * {@link org.apache.cxf.jaxrs.client.WebClient}, SOAP reliable messaging etc.
+ */
+public interface Deliverer {
+
+ /**
+ * Delivers ATOM element.
+ *
+ * @param element element to deliver.
+ * @return true if delivery successful, false otherwise.
+ */
+ boolean deliver(Element element) throws InterruptedException;
+
+ /**
+ * Returns the address of the remote endpoint this deliverer send elements to
+ * @return
+ */
+ String getEndpointAddress();
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/RetryingDeliverer.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/RetryingDeliverer.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/RetryingDeliverer.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,143 @@
+/**
+ * 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.cxf.management.web.logging.atom.deliverer;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.abdera.model.Element;
+import org.apache.commons.lang.Validate;
+
+/**
+ * Wrapper on other deliverer retrying delivery in case of failure. Delivery attempts
repeat in loop with some
+ * pause time between retries until successful delivery or exceeding time limit. Time
delay between delivery
+ * is configurable strategy. Two predefined strategies are given: each time pause same
amount of time (linear)
+ * and each next time pause time doubles (exponential).
+ */
+public final class RetryingDeliverer implements Deliverer {
+
+ private Deliverer deliverer;
+ private PauseCalculator pauser;
+ private int timeout;
+
+ /**
+ * Creates retrying deliverer with predefined retry strategy.
+ *
+ * @param worker real deliverer used to push data out.
+ * @param timeout maximum time range (in seconds) that retrial is continued; time
spent on delivery call
+ * is included. No timeout (infinite loop) if set to zero.
+ * @param pause time of pause (in seconds) greater than zero.
+ * @param linear if true linear strategy (each time pause same amount of time),
exponential otherwise
+ * (each next time pause time doubles).
+ */
+ public RetryingDeliverer(Deliverer worker, int timeout, int pause, boolean linear) {
+ Validate.notNull(worker, "worker is null");
+ Validate.isTrue(timeout >= 0, "timeout is negative");
+ Validate.isTrue(pause > 0, "pause is not greater than zero");
+ deliverer = worker;
+ this.timeout = timeout;
+ this.pauser = linear ? new ConstantPause(pause) : new ExponentialPause(pause);
+ }
+
+ /**
+ * Creates retrying deliverer with custom retry strategy.
+ *
+ * @param worker real deliverer used to push data out.
+ * @param timeout maximum time range (in seconds) that retrial is continued; time
spent on delivery call
+ * is included. No timeout (infinite loop) if set to zero.
+ * @param strategy custom retry pausing strategy.
+ */
+ public RetryingDeliverer(Deliverer worker, int timeout, PauseCalculator strategy) {
+ Validate.notNull(worker, "worker is null");
+ Validate.notNull(strategy, "strategy is null");
+ Validate.isTrue(timeout >= 0, "timeout is negative");
+ deliverer = worker;
+ pauser = strategy;
+ this.timeout = timeout;
+ }
+
+ public boolean deliver(Element element) throws InterruptedException {
+ Calendar cal = Calendar.getInstance();
+ cal.add(Calendar.SECOND, timeout);
+ Date timeoutDate = cal.getTime();
+ while (!deliverer.deliver(element)) {
+ int sleep = pauser.nextPause();
+ cal = Calendar.getInstance();
+ cal.add(Calendar.SECOND, sleep);
+ if (timeout == 0 || timeoutDate.after(cal.getTime())) {
+ Thread.sleep(sleep * 1000);
+ } else {
+ pauser.reset();
+ return false;
+ }
+ }
+ pauser.reset();
+ return true;
+ }
+
+ /** Calculates time of subsequent pauses between delivery attempts. */
+ public interface PauseCalculator {
+
+ /** Time of next pause (in seconds). */
+ int nextPause();
+
+ /** Restarts calculation. */
+ void reset();
+ }
+
+ private static class ConstantPause implements PauseCalculator {
+ private int pause;
+
+ public ConstantPause(int pause) {
+ this.pause = pause;
+ }
+
+ public int nextPause() {
+ return pause;
+ }
+
+ public void reset() {
+ }
+ }
+
+ private static class ExponentialPause implements PauseCalculator {
+ private int pause;
+ private int current;
+
+ public ExponentialPause(int pause) {
+ this.pause = pause;
+ current = pause;
+ }
+
+ public int nextPause() {
+ int c = current;
+ current *= 2;
+ return c;
+ }
+
+ public void reset() {
+ current = pause;
+ }
+ }
+
+ public String getEndpointAddress() {
+ return deliverer.getEndpointAddress();
+ }
+
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/WebClientDeliverer.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/WebClientDeliverer.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/deliverer/WebClientDeliverer.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,62 @@
+/**
+ * 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.cxf.management.web.logging.atom.deliverer;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Feed;
+import org.apache.commons.lang.Validate;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.provider.AtomEntryProvider;
+import org.apache.cxf.jaxrs.provider.AtomFeedProvider;
+
+/**
+ * Marshaling and delivering based on JAXRS' WebClient.
+ */
+public final class WebClientDeliverer implements Deliverer {
+ private WebClient wc;
+
+ @SuppressWarnings("unchecked")
+ public WebClientDeliverer(String deliveryAddress) {
+ Validate.notEmpty(deliveryAddress, "deliveryAddress is empty or
null");
+ List<?> providers = Arrays.asList(new AtomFeedProvider(), new
AtomEntryProvider());
+ wc = WebClient.create(deliveryAddress, providers);
+ }
+
+ public WebClientDeliverer(WebClient wc) {
+ Validate.notNull(wc, "wc is null");
+ this.wc = wc;
+ }
+
+ public boolean deliver(Element element) {
+ String type = element instanceof Feed ? "application/atom+xml" :
"application/atom+xml;type=entry";
+ wc.type(type);
+ Response res = wc.post(element);
+ int status = res.getStatus();
+ return status >= 200 && status <= 299;
+ }
+
+ public String getEndpointAddress() {
+ return wc.getBaseURI().toString();
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/package-info.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/package-info.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/package-info.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,27 @@
+/**
+ * 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.
+ */
+
+/**
+ * Support for producing logs in
+ * <a
href="http://tools.ietf.org/html/rfc4287">ATOM Syndication
Format</a>.
+ * Allows to configure <tt>java.util.logging</tt> (JUL) loggers to use
+ * handlers producing ATOM feeds that are either pushed to or pulled by client.
+ */
+package org.apache.cxf.management.web.logging.atom;
+
Added:
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/package-info.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/package-info.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.3.1/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/package-info.java 2011-08-13
15:39:22 UTC (rev 14820)
@@ -0,0 +1,31 @@
+/**
+ * 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.
+ */
+
+/**
+ * CXF specific logging support. Based on <tt>java.util.logging</tt> (JUL)
+ * with use of different logging frameworks factored out; assumes that client
+ * with source code logging to other systems, like Log4J, can bridge
+ * to this implementation applying <a
href="www.slf4j.org">SLF4J</a>
+ * that JAXRS already depends on.
+ */
+(a)javax.xml.bind.annotation.XmlSchema(xmlns = {
+ @javax.xml.bind.annotation.XmlNs(namespaceURI =
"http://cxf.apache.org/log", prefix = "log")
+ })
+package org.apache.cxf.management.web.logging;
+