You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/03 13:36:41 UTC
svn commit: r562415 - in
/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring:
converter/ remoting/SendBeforeInterceptor.java spi/SpringConverters.java
Author: jstrachan
Date: Fri Aug 3 04:36:40 2007
New Revision: 562415
URL: http://svn.apache.org/viewvc?view=rev&rev=562415
Log:
added a spring interceptor for also notifying a camel endpoint of a method invocation
Added:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/SendBeforeInterceptor.java
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java (contents, props changed)
- copied, changed from r562161, activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java
Removed:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/converter/
Added: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/SendBeforeInterceptor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/SendBeforeInterceptor.java?view=auto&rev=562415
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/SendBeforeInterceptor.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/SendBeforeInterceptor.java Fri Aug 3 04:36:40 2007
@@ -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.camel.spring.remoting;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.camel.component.bean.CamelInvocationHandler;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.NoSuchEndpointException;
+import org.apache.camel.Producer;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.DisposableBean;
+
+/**
+ * A Spring interceptor which sends a message exchange to an endpoint before the method is invoked
+ *
+ * @version $Revision: $
+ */
+public class SendBeforeInterceptor implements MethodInterceptor, CamelContextAware, InitializingBean, DisposableBean {
+
+ private String uri;
+ private CamelContext camelContext;
+ private CamelInvocationHandler invocationHandler;
+ private Producer producer;
+
+ public Object invoke(MethodInvocation invocation) throws Throwable {
+ invocationHandler.invoke(invocation.getThis(), invocation.getMethod(), invocation.getArguments());
+ return invocation.proceed();
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ if (camelContext == null) {
+ throw new IllegalArgumentException("No CamelContext injected");
+ }
+ if (uri == null) {
+ throw new IllegalArgumentException("No uri injected");
+ }
+ Endpoint endpoint = camelContext.getEndpoint(uri);
+ if (endpoint == null) {
+ throw new NoSuchEndpointException(uri);
+ }
+ producer = endpoint.createProducer();
+ producer.start();
+ invocationHandler = new CamelInvocationHandler(endpoint, producer);
+ }
+
+ public void destroy() throws Exception {
+ if (producer != null) {
+ producer.stop();
+ }
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ // Properties
+ //-----------------------------------------------------------------------
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+}
Copied: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java (from r562161, activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java?view=diff&rev=562415&p1=activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java&r1=562161&p2=activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java&r2=562415
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java Fri Aug 3 04:36:40 2007
@@ -15,13 +15,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.spring.converter;
+package org.apache.camel.spring.spi;
import org.apache.camel.Converter;
+import org.apache.camel.component.bean.BeanInvocation;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
+import org.aopalliance.intercept.MethodInvocation;
import java.io.File;
import java.io.IOException;
@@ -35,7 +37,7 @@
* @version $Revision$
*/
@Converter
-public class ResourceConverter {
+public class SpringConverters {
@Converter
public static InputStream toInputStream(Resource resource) throws IOException {
return resource.getInputStream();
@@ -69,5 +71,10 @@
@Converter
public static ByteArrayResource toResource(byte[] data) throws IOException {
return new ByteArrayResource(data);
+ }
+
+ @Converter
+ public static BeanInvocation toBeanInvocation(MethodInvocation invocation) {
+ return new BeanInvocation(invocation.getThis(), invocation.getMethod(), invocation.getArguments());
}
}
Propchange: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringConverters.java
------------------------------------------------------------------------------
svn:mime-type = text/plain