Author: cmoulliard
Date: Wed Aug 8 16:38:58 2012
New Revision: 1370822
URL: http://svn.apache.org/viewvc?rev=1370822&view=rev
Log:
smx4-1205 : add a new features to allow to configure a JMS Appender with
ActiveMQ using Pax Logging Service
Added:
servicemix/smx4/features/trunk/osgi-logging/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/README.txt
servicemix/smx4/features/trunk/osgi-logging/jms-appender/pom.xml
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/logging/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/logging/JMSAppender.java
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/blueprint/
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/blueprint/config.xml
servicemix/smx4/features/trunk/osgi-logging/pom.xml
Modified:
servicemix/smx4/features/trunk/parent/pom.xml
servicemix/smx4/features/trunk/pom.xml
Added: servicemix/smx4/features/trunk/osgi-logging/jms-appender/README.txt
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/osgi-logging/jms-appender/README.txt?rev=1370822&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/osgi-logging/jms-appender/README.txt (added)
+++ servicemix/smx4/features/trunk/osgi-logging/jms-appender/README.txt Wed Aug
8 16:38:58 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+
+ServiceMix Pax JMS Appender
+===========================
+
+This ServiceMix features allows to configure a JMS appender with ActiveMQ.
When the bundle
+is deployed, a new OPS4J Pax logging appender will be registered using Pax
Logging OSGI service.
+This appender can be used next by modifying the org.ops4j.pax.logging.cfg file
and adding the
+following lines
+
+log4j.rootLogger=INFO, out, osgi:VmLogAppender, osgi:JMSLogAppender
+
+Procedure to install the bundle and configure it
+================================================
+
+ 1) Compile the project
+ mvn install
+
+ 2) Create config file under ${servicemix.home}/etc directory
+ touch org.apache.servicemix.logging.cfg
+ edit the file and add destinationName=logTopic
+
+ 3) Modify org.ops4j.pax.logging.cfg
+
+ log4j.rootLogger=INFO, out, osgi:VmLogAppender, osgi:JMSLogAppender
+ # Be sure that ActiveMQ messages are not logged to 'jms' appender
+ log4j.logger.org.apache.activemq=INFO, stdout
+ log4j.logger.org.apache.activemq.karaf.logging = INFO, stdout
+
+ 4) Start ServiceMix server
+ ./bin/servicemix or bin/servicemix.bat
+
+ 5) Deploy the bundle
+ install -s
mvn:org.apache.servicemix.logging/pax-jms-appender/${project.version}
+
+ 5) Check that topic logTopic contains entries !
Added: servicemix/smx4/features/trunk/osgi-logging/jms-appender/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/osgi-logging/jms-appender/pom.xml?rev=1370822&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/osgi-logging/jms-appender/pom.xml (added)
+++ servicemix/smx4/features/trunk/osgi-logging/jms-appender/pom.xml Wed Aug 8
16:38:58 2012
@@ -0,0 +1,81 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix.logging</groupId>
+ <artifactId>osgi-logging</artifactId>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>pax-jms-appender</artifactId>
+ <name>Apache ServiceMix :: Features :: Pax Logging Support :: JMS
Appender</name>
+
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ <version>${pax.logging.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-service</artifactId>
+ <version>${pax.logging.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>${activemq.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Import-Package>
+ org.ops4j.pax.logging;resolution:=optional,
+ org.osgi.service.blueprint;resolution:=optional,
+ org.ops4j.pax.logging.spi*;resolution:=optional,
+ org.slf4j,
+ javax.jms,
+ org.apache.activemq
+ </Import-Package>
+ <Export-Package>
+ org.apache.servicemix.logging
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
\ No newline at end of file
Added:
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/logging/JMSAppender.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/logging/JMSAppender.java?rev=1370822&view=auto
==============================================================================
---
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/logging/JMSAppender.java
(added)
+++
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/java/org/apache/servicemix/logging/JMSAppender.java
Wed Aug 8 16:38:58 2012
@@ -0,0 +1,133 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.logging;
+
+import org.ops4j.pax.logging.spi.PaxAppender;
+import org.ops4j.pax.logging.spi.PaxLoggingEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class JMSAppender implements PaxAppender {
+
+ private static final transient Logger LOG =
LoggerFactory.getLogger(JMSAppender.class);
+
+ private ConnectionFactory jmsConnectionFactory;
+ private Connection connection;
+ private Session session;
+ private MessageProducer publisher;
+ private Topic topic;
+ private String destinationName;
+
+ private SimpleDateFormat simpleDateFormat = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+
+ public void init() {
+ /*
+ * Create connection. Create session from connection; false means
+ * session is not transacted.
+ * Finally, close connection.
+ */
+ try {
+ connection = jmsConnectionFactory.createConnection();
+ session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ topic = session.createTopic(destinationName);
+ publisher = session.createProducer(topic);
+ publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ LOG.debug("Connection created with ActiveMQ for JMS Pax
Appender.");
+
+ } catch (JMSException e) {
+ LOG.error(e.getMessage());
+ }
+ }
+
+ public void close() {
+ if (connection != null) {
+ try {
+ connection.close();
+ LOG.debug("Connection closed with ActiveMQ for JMS Pax
Appender.");
+ } catch (JMSException e) {
+ LOG.error(e.getMessage());
+ }
+ }
+ }
+
+ public void doAppend(PaxLoggingEvent paxLoggingEvent) {
+
+ try {
+ StringBuilder writer = new StringBuilder();
+
+ writer.append("Error");
+ writer.append(",\n \"timestamp\" : " +
formatDate(paxLoggingEvent.getTimeStamp()));
+ writer.append(",\n \"level\" : " +
paxLoggingEvent.getLevel().toString());
+ writer.append(",\n \"logger\" : " +
paxLoggingEvent.getLoggerName());
+ writer.append(",\n \"thread\" : " +
paxLoggingEvent.getThreadName());
+ writer.append(",\n \"message\" : " +
paxLoggingEvent.getMessage());
+
+ String[] throwable = paxLoggingEvent.getThrowableStrRep();
+ if (throwable != null) {
+ writer.append(",\n \"exception\" : [");
+ for (int i = 0; i < throwable.length; i++) {
+ if (i != 0)
+ writer.append(", " + throwable[i]);
+ }
+ writer.append("]");
+ }
+
+ writer.append(",\n \"properties\" : { ");
+ boolean first = true;
+ for (Object key : paxLoggingEvent.getProperties().keySet()) {
+ if (first) {
+ first = false;
+ } else {
+ writer.append(", ");
+ }
+ writer.append("key : " + key.toString());
+ writer.append(": " +
paxLoggingEvent.getProperties().get(key).toString());
+ }
+ writer.append(" }");
+ writer.append("\n}");
+
+ // Send message to the destination
+ TextMessage message = session.createTextMessage();
+ message.setText(writer.toString());
+ publisher.send(message);
+
+ // System.out.println(">> Message created : " + writer.toString());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private String formatDate(long timestamp) {
+ return simpleDateFormat.format(new Date(timestamp));
+ }
+
+ public void setJmsConnectionFactory(ConnectionFactory
jmsConnectionFactory) {
+ this.jmsConnectionFactory = jmsConnectionFactory;
+ }
+
+ public void setDestinationName(String destinationName) {
+ this.destinationName = destinationName;
+ }
+
+}
Added:
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/blueprint/config.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1370822&view=auto
==============================================================================
---
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/blueprint/config.xml
(added)
+++
servicemix/smx4/features/trunk/osgi-logging/jms-appender/src/main/resources/OSGI-INF/blueprint/config.xml
Wed Aug 8 16:38:58 2012
@@ -0,0 +1,39 @@
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
+
+ <cm:property-placeholder persistent-id="org.apache.servicemix.logging"
update-strategy="reload"/>
+
+ <!-- Need OSGI JMS Connection Factory Service exposed -->
+ <reference id="jmsConnectionFactory"
interface="javax.jms.ConnectionFactory"/>
+
+ <bean id="appender" class="org.apache.servicemix.logging.JMSAppender"
init-method="init" destroy-method="close">
+ <property name="jmsConnectionFactory" ref="jmsConnectionFactory"/>
+ <property name="destinationName" value="${destinationName}" />
+ </bean>
+
+ <service ref="appender" interface="org.ops4j.pax.logging.spi.PaxAppender">
+ <service-properties>
+ <entry key="org.ops4j.pax.logging.appender.name"
value="JMSLogAppender"/>
+ </service-properties>
+ </service>
+
+</blueprint>
\ No newline at end of file
Added: servicemix/smx4/features/trunk/osgi-logging/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/osgi-logging/pom.xml?rev=1370822&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/osgi-logging/pom.xml (added)
+++ servicemix/smx4/features/trunk/osgi-logging/pom.xml Wed Aug 8 16:38:58 2012
@@ -0,0 +1,39 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>parent</artifactId>
+ <version>4.5.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.servicemix.logging</groupId>
+ <artifactId>osgi-logging</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache ServiceMix :: Features :: Pax Logging Support</name>
+
+ <modules>
+ <module>jms-appender</module>
+ </modules>
+
+</project>
Modified: servicemix/smx4/features/trunk/parent/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/parent/pom.xml?rev=1370822&r1=1370821&r2=1370822&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/parent/pom.xml (original)
+++ servicemix/smx4/features/trunk/parent/pom.xml Wed Aug 8 16:38:58 2012
@@ -46,6 +46,7 @@
<karaf.version>2.2.7</karaf.version>
<aries.version>0.3</aries.version>
+ <pax.logging.version>1.6.5</pax.logging.version>
<servicemix.components.version>2012.01-SNAPSHOT</servicemix.components.version>
<servicemix.nmr.version>1.5.0</servicemix.nmr.version>
Modified: servicemix/smx4/features/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/pom.xml?rev=1370822&r1=1370821&r2=1370822&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/pom.xml (original)
+++ servicemix/smx4/features/trunk/pom.xml Wed Aug 8 16:38:58 2012
@@ -40,6 +40,7 @@
<module>activiti</module>
<module>branding</module>
<module>camel</module>
+ <module>osgi-logging</module>
<module>cxf</module>
<module>examples</module>
<module>itests</module>