Author: gnodet
Date: Wed Dec 22 16:34:21 2010
New Revision: 1051973
URL: http://svn.apache.org/viewvc?rev=1051973&view=rev
Log:
Add a pax-logging camel component
Added:
camel/trunk/components/camel-paxlogging/
camel/trunk/components/camel-paxlogging/pom.xml
camel/trunk/components/camel-paxlogging/src/
camel/trunk/components/camel-paxlogging/src/main/
camel/trunk/components/camel-paxlogging/src/main/java/
camel/trunk/components/camel-paxlogging/src/main/java/org/
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/Activator.java
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponent.java
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponentResolver.java
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingConsumer.java
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingEndpoint.java
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingServiceFactory.java
Modified:
camel/trunk/components/pom.xml
Added: camel/trunk/components/camel-paxlogging/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/pom.xml?rev=1051973&view=auto
==============================================================================
--- camel/trunk/components/camel-paxlogging/pom.xml (added)
+++ camel/trunk/components/camel-paxlogging/pom.xml Wed Dec 22 16:34:21 2010
@@ -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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-paxlogging</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Pax Logging</name>
+ <description>Camel PaxLogging support</description>
+
+ <properties>
+
<camel.osgi.activator>org.apache.camel.component.paxlogging.Activator</camel.osgi.activator>
+
<camel.osgi.private.pkg>org.apache.camel.component.paxlogging</camel.osgi.private.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ <version>1.5.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-service</artifactId>
+ <version>1.5.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added:
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/Activator.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/Activator.java?rev=1051973&view=auto
==============================================================================
---
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/Activator.java
(added)
+++
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/Activator.java
Wed Dec 22 16:34:21 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.camel.component.paxlogging;
+
+import java.util.Properties;
+
+import org.apache.camel.spi.ComponentResolver;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The activator which register the ComponentResolver as a ServiceFactory.
+ */
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration registration;
+
+ public void start(BundleContext bundleContext) throws Exception {
+ Properties props = new Properties();
+ props.put("component", PaxLoggingComponent.NAME);
+ registration = bundleContext.registerService(
+ ComponentResolver.class.getName(),
+ new PaxLoggingServiceFactory(),
+ props);
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ registration.unregister();
+ }
+
+}
Added:
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponent.java?rev=1051973&view=auto
==============================================================================
---
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponent.java
(added)
+++
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponent.java
Wed Dec 22 16:34:21 2010
@@ -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.
+ */
+package org.apache.camel.component.paxlogging;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The pax-logging component allows receiving log events from OPS4j PaxLogging
+ * and send them to camel routes.
+ */
+public class PaxLoggingComponent extends DefaultComponent {
+
+ public static final String NAME = "paxlogging";
+
+ private final BundleContext bundleContext;
+
+ public PaxLoggingComponent(CamelContext context, BundleContext
bundleContext) {
+ super(context);
+ this.bundleContext = bundleContext;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
+ PaxLoggingEndpoint endpoint = new PaxLoggingEndpoint(uri, this,
remaining);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+
+}
Added:
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponentResolver.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponentResolver.java?rev=1051973&view=auto
==============================================================================
---
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponentResolver.java
(added)
+++
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingComponentResolver.java
Wed Dec 22 16:34:21 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.camel.component.paxlogging;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.spi.ComponentResolver;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Component resolver for the paxlogging component
+ */
+public class PaxLoggingComponentResolver implements ComponentResolver {
+
+ private final BundleContext bundleContext;
+
+ public PaxLoggingComponentResolver(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public Component resolveComponent(String name, CamelContext context)
throws Exception {
+ if (PaxLoggingComponent.NAME.equals(name)) {
+ return new PaxLoggingComponent(context, bundleContext);
+ }
+ return null;
+ }
+}
Added:
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingConsumer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingConsumer.java?rev=1051973&view=auto
==============================================================================
---
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingConsumer.java
(added)
+++
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingConsumer.java
Wed Dec 22 16:34:21 2010
@@ -0,0 +1,104 @@
+/*
+ * 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.camel.component.paxlogging;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+import org.ops4j.pax.logging.spi.PaxAppender;
+import org.ops4j.pax.logging.spi.PaxLoggingEvent;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+/**
+ * Paxlogging consumer.
+ * This camel consumer will register a paxlogging appender and will
+ * receive all logging events and send them into the route.
+ * To avoid generating new logging events from sending the message,
+ * an MDC attribute is set in the sending thread, and all log events
+ * from this thread are ignored.
+ * Camel exchanges are actually sent from a specific thread to make
+ * sure the log events are cleanly separated.
+ */
+public class PaxLoggingConsumer extends DefaultConsumer implements PaxAppender
{
+
+ private static final transient Logger LOG =
LoggerFactory.getLogger(PaxLoggingConsumer.class);
+ private final PaxLoggingEndpoint endpoint;
+ private ExecutorService executor;
+ private ServiceRegistration registration;
+
+ public PaxLoggingConsumer(PaxLoggingEndpoint endpoint, Processor
processor) {
+ super(endpoint, processor);
+ this.endpoint = endpoint;
+ }
+
+ public void doAppend(final PaxLoggingEvent paxLoggingEvent) {
+ executor.execute(new Runnable() {
+ public void run() {
+ sendExchange(paxLoggingEvent);
+ }
+ });
+ }
+
+ protected void sendExchange(PaxLoggingEvent paxLoggingEvent) {
+ MDC.put(PaxLoggingConsumer.class.getName(), endpoint.getName());
+ if
(paxLoggingEvent.getProperties().containsKey(PaxLoggingConsumer.class.getName()))
{
+ return;
+ }
+
+ Exchange exchange = endpoint.createExchange();
+ // TODO: populate exchange headers
+ exchange.getIn().setBody(paxLoggingEvent);
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("PaxLogging " + endpoint.getName() + " is firing");
+ }
+ try {
+ getProcessor().process(exchange);
+ // log exception if an exception occurred and was not handled
+ if (exchange.getException() != null) {
+ getExceptionHandler().handleException("Error processing
exchange", exchange, exchange.getException());
+ }
+ } catch (Exception e) {
+ getExceptionHandler().handleException("Error processing exchange",
exchange, exchange.getException());
+ }
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ Properties props = new Properties();
+ props.put("org.ops4j.pax.logging.appender.name", endpoint.getName());
+ registration =
endpoint.getComponent().getBundleContext().registerService(PaxAppender.class.getName(),
this, props);
+ executor = Executors.newSingleThreadExecutor();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (registration != null) {
+ registration.unregister();
+ }
+ executor.shutdown();
+ super.doStop();
+ }
+}
Added:
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingEndpoint.java?rev=1051973&view=auto
==============================================================================
---
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingEndpoint.java
(added)
+++
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingEndpoint.java
Wed Dec 22 16:34:21 2010
@@ -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.camel.component.paxlogging;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Paxlogging endpoint.
+ */
+public class PaxLoggingEndpoint extends DefaultEndpoint {
+
+ private final String name;
+
+ public PaxLoggingEndpoint(String uri, PaxLoggingComponent component,
String name) {
+ super(uri, component);
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public PaxLoggingComponent getComponent() {
+ return (PaxLoggingComponent) super.getComponent();
+ }
+
+ public Producer createProducer() throws Exception {
+ throw new RuntimeCamelException("Cannot produce to a
PaxLoggingEndpoint: " + getEndpointUri());
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new PaxLoggingConsumer(this, processor);
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+}
Added:
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingServiceFactory.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingServiceFactory.java?rev=1051973&view=auto
==============================================================================
---
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingServiceFactory.java
(added)
+++
camel/trunk/components/camel-paxlogging/src/main/java/org/apache/camel/component/paxlogging/PaxLoggingServiceFactory.java
Wed Dec 22 16:34:21 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.camel.component.paxlogging;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * This service factory only purpose is to know which bundle is requesting the
component
+ * so that the pax logging appender can be registered from the correct bundle
context.
+ */
+public class PaxLoggingServiceFactory implements ServiceFactory {
+
+ public Object getService(Bundle bundle, ServiceRegistration
serviceRegistration) {
+ return new PaxLoggingComponentResolver(bundle.getBundleContext());
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration
serviceRegistration, Object o) {
+ }
+
+}
Modified: camel/trunk/components/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1051973&r1=1051972&r2=1051973&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Wed Dec 22 16:34:21 2010
@@ -86,6 +86,7 @@
<module>camel-netty</module>
<module>camel-nagios</module>
<module>camel-ognl</module>
+ <module>camel-paxlogging</module>
<module>camel-printer</module>
<module>camel-protobuf</module>
<module>camel-quartz</module>