This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch mock
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3082c33ff47bb233dec259e540242b7d3e548fe1
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Apr 16 09:57:55 2019 +0200

    CAMEL-13421: Remove BeanInvocation from camel-bean
---
 .../apache/camel/builder/ExpressionBuilder.java    |  74 -------------
 .../org/apache/camel/builder/ProxyBuilder.java     |  17 ---
 .../component/bean/AbstractBeanProcessor.java      |  37 -------
 .../bean/AbstractCamelInvocationHandler.java       |  12 ++-
 .../apache/camel/component/bean/BeanConverter.java |  65 ------------
 .../camel/component/bean/BeanInvocation.java       | 118 ---------------------
 .../bean/BeanInvocationSerializeTest.java          |  66 ------------
 .../component/bean/BeanProxyNoBindingTest.java     |   6 +-
 .../component/bean/MyAuditServiceProxyTest.java    |   3 +-
 9 files changed, 12 insertions(+), 386 deletions(-)

diff --git 
a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java 
b/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index ebbe476..cda166d 100644
--- 
a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ 
b/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -37,19 +37,14 @@ import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelExecutionException;
-import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
-import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.NoSuchLanguageException;
 import org.apache.camel.NoTypeConversionAvailableException;
-import org.apache.camel.Producer;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.RuntimeExchangeException;
-import org.apache.camel.component.bean.BeanInvocation;
-import org.apache.camel.language.bean.BeanLanguage;
 import org.apache.camel.language.simple.SimpleLanguage;
 import org.apache.camel.model.language.MethodCallExpression;
 import org.apache.camel.spi.ExchangeFormatter;
@@ -1269,17 +1264,6 @@ public final class ExpressionBuilder {
                     if (exchange.getIn().getBody() == null) {
                         return null;
                     }
-
-                    // if its a bean invocation then if it has no arguments 
then it should be threaded as null body allowed
-                    if (exchange.getIn().getBody() instanceof BeanInvocation) {
-                        // BeanInvocation would be stored directly as the 
message body
-                        // do not force any type conversion attempts as it 
would just be unnecessary and cost a bit performance
-                        // so a regular instanceof check is sufficient
-                        BeanInvocation bi = (BeanInvocation) 
exchange.getIn().getBody();
-                        if (bi.getArgs() == null || bi.getArgs().length == 0 
|| bi.getArgs()[0] == null) {
-                            return null;
-                        }
-                    }
                 }
 
                 try {
@@ -2023,64 +2007,6 @@ public final class ExpressionBuilder {
         };
     }
 
-    @Deprecated
-    public static Expression beanExpression(final Class<?> beanType, final 
String methodName) {
-        return BeanLanguage.bean(beanType, methodName);
-    }
-
-    @Deprecated
-    public static Expression beanExpression(final Object bean, final String 
methodName) {
-        return BeanLanguage.bean(bean, methodName);
-    }
-
-    @Deprecated
-    public static Expression beanExpression(final String beanRef, final String 
methodName) {
-        String expression = methodName != null ? beanRef + "." + methodName : 
beanRef;
-        return beanExpression(expression);
-    }
-
-    /**
-     * Returns an expression processing the exchange to the given endpoint uri
-     *
-     * @param uri endpoint uri to send the exchange to
-     * @return an expression object which will return the OUT body
-     * @deprecated not in use, and not available in XML DSL
-     */
-    @Deprecated
-    public static Expression toExpression(final String uri) {
-        return new ExpressionAdapter() {
-            public Object evaluate(Exchange exchange) {
-                String text = simpleExpression(uri).evaluate(exchange, 
String.class);
-                Endpoint endpoint = exchange.getContext().getEndpoint(text);
-                if (endpoint == null) {
-                    throw new NoSuchEndpointException(text);
-                }
-
-                Producer producer;
-                try {
-                    producer = endpoint.createProducer();
-                    producer.start();
-                    producer.process(exchange);
-                    producer.stop();
-                } catch (Exception e) {
-                    throw RuntimeCamelException.wrapRuntimeCamelException(e);
-                }
-
-                // return the OUT body, but check for exchange pattern
-                if (ExchangeHelper.isOutCapable(exchange)) {
-                    return exchange.getOut().getBody();
-                } else {
-                    return exchange.getIn().getBody();
-                }
-            }
-
-            @Override
-            public String toString() {
-                return "to(" + uri + ")";
-            }
-        };
-    }
-
     public static Expression fileNameExpression() {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
diff --git 
a/core/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java 
b/core/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java
index 8ad7a60..13e874a 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java
@@ -57,23 +57,6 @@ public final class ProxyBuilder {
     }
 
     /**
-     * Whether to use binding or not.
-     * <p/>
-     * Binding is enabled by default. Set this to <tt>false</tt> to use old 
behavior without binding.
-     * <p/>
-     * If binding is enabled then Camel will bind the method parameters to the 
input {@link org.apache.camel.Message}
-     * on the {@link org.apache.camel.Exchange} when invoking the proxy.
-     *
-     * @param binding <tt>true</tt> to use binding, <tt>false</tt> to use the 
old behavior with using a {@link org.apache.camel.component.bean.BeanInvocation}
-     *                as a provisional message body
-     * @return the builder
-     */
-    public ProxyBuilder binding(boolean binding) {
-        this.binding = binding;
-        return this;
-    }
-
-    /**
      * Builds the proxy.
      *
      * @param interfaceClass  the service interface
diff --git 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
 
b/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
index e7781e9..2bf8b63 100644
--- 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
+++ 
b/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
@@ -118,43 +118,6 @@ public abstract class AbstractBeanProcessor extends 
AsyncProcessorSupport {
 
         Message in = exchange.getIn();
 
-        // is the message proxied using a BeanInvocation?
-        BeanInvocation beanInvoke = null;
-        if (in.getBody() instanceof BeanInvocation) {
-            // BeanInvocation would be stored directly as the message body
-            // do not force any type conversion attempts as it would just be 
unnecessary and cost a bit performance
-            // so a regular instanceof check is sufficient
-            beanInvoke = (BeanInvocation) in.getBody();
-        }
-        if (beanInvoke != null) {
-            // Now it gets a bit complicated as ProxyHelper can proxy beans 
which we later
-            // intend to invoke (for example to proxy and invoke using spring 
remoting).
-            // and therefore the message body contains a BeanInvocation object.
-            // However this can causes problem if we in a Camel route invokes 
another bean,
-            // so we must test whether BeanHolder and BeanInvocation is the 
same bean or not
-            if (log.isTraceEnabled()) {
-                log.trace("Exchange IN body is a BeanInvocation instance: {}", 
beanInvoke);
-            }
-            Class<?> clazz = beanInvoke.getMethod().getDeclaringClass();
-            boolean sameBean = clazz.isInstance(bean);
-            if (log.isDebugEnabled()) {
-                log.debug("BeanHolder bean: {} and beanInvocation bean: {} is 
same instance: {}", bean.getClass(), clazz, sameBean);
-            }
-            if (sameBean) {
-                try {
-                    beanInvoke.invoke(bean, exchange);
-                    if (exchange.hasOut()) {
-                        // propagate headers
-                        
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
-                    }
-                } catch (Throwable e) {
-                    exchange.setException(e);
-                }
-                callback.done(true);
-                return true;
-            }
-        }
-
         // set explicit method name to invoke as a header, which is how 
BeanInfo can detect it
         if (explicitMethodName != null) {
             in.setHeader(Exchange.BEAN_METHOD_NAME, explicitMethodName);
diff --git 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
 
b/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
index 6f9b178..ec92342 100644
--- 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
+++ 
b/core/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
@@ -159,15 +159,19 @@ public abstract class AbstractCamelInvocationHandler 
implements InvocationHandle
                 index++;
             }
         } else {
-            // no binding so use the old behavior with BeanInvocation as the 
body
-            BeanInvocation invocation = new BeanInvocation(method, args);
-            exchange.getIn().setBody(invocation);
+            if (args != null) {
+                if (args.length == 1) {
+                    exchange.getIn().setBody(args[0]);
+                } else {
+                    exchange.getIn().setBody(args);
+                }
+            }
         }
 
         if (binding) {
             LOG.trace("Binding to service interface as 
@Body,@Header,@ExchangeProperty detected when calling proxy method: {}", 
method);
         } else {
-            LOG.trace("No binding to service interface as 
@Body,@Header,@ExchangeProperty not detected. Using BeanInvocation as message 
body when calling proxy method: {}", method);
+            LOG.trace("No binding to service interface as 
@Body,@Header,@ExchangeProperty not detected when calling proxy method: {}", 
method);
         }
 
         return doInvoke(method, exchange);
diff --git 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
 
b/core/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
deleted file mode 100644
index c4f0227..0000000
--- 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.bean;
-
-import org.apache.camel.Converter;
-import org.apache.camel.Exchange;
-import org.apache.camel.TypeConverter;
-import org.apache.camel.spi.TypeConverterRegistry;
-
-import static org.apache.camel.TypeConverter.MISS_VALUE;
-
-/**
- * A set of converter methods for working with beans
- */
-@Converter(loader = true)
-public final class BeanConverter {
-
-    private BeanConverter() {
-        // Helper Class
-    }
-
-    @Converter(fallback = true)
-    public static Object convertTo(Class<?> type, Exchange exchange, Object 
value, TypeConverterRegistry registry) {
-        // use a fallback type converter so we can convert the embedded body 
if the value is BeanInvocation
-        if (BeanInvocation.class.isAssignableFrom(value.getClass())) {
-
-            BeanInvocation bi = (BeanInvocation) value;
-            if (bi.getArgs() == null || bi.getArgs().length != 1) {
-                // not possible to convert at this time as we try to convert 
the data passed in at first argument
-                return MISS_VALUE;
-            }
-
-            Class<?> from = bi.getArgs()[0].getClass();
-            Object body = bi.getArgs()[0];
-
-            // maybe from is already the type we want
-            if (type.isAssignableFrom(from)) {
-                return body;
-            }
-
-            // no then try to lookup a type converter
-            TypeConverter tc = registry.lookup(type, from);
-            if (tc != null) {
-                return tc.convertTo(type, exchange, body);
-            }
-        }
-
-        return null;
-    }
-
-}
diff --git 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java
 
b/core/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java
deleted file mode 100644
index de37421..0000000
--- 
a/core/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.bean;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.converter.ToStringTypeConverter;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Invocation of beans that can handle being serialized.
- */
-public class BeanInvocation implements Externalizable {
-    private static final Logger LOG = 
LoggerFactory.getLogger(BeanInvocation.class);
-    private Object[] args;
-    private MethodBean methodBean;
-    private transient Method method;
-
-    static {
-        ToStringTypeConverter.registerMissType(BeanInvocation.class);
-    }
-
-    public BeanInvocation() {
-    }
-
-    public BeanInvocation(Method method, Object[] args) {
-        this.method = method;
-        this.args = args;
-    }
-
-    @Override
-    public String toString() {
-        Object list = null;
-        if (args != null) {
-            list = Arrays.asList(args);
-        }
-        return "BeanInvocation " + method + " with " + list + "]";
-    }
-
-    public Object[] getArgs() {
-        return args;
-    }
-
-    public Method getMethod() {
-        return method;
-    }
-
-    public void setMethod(Method method) {
-        this.method = method;
-    }
-
-    public void setArgs(Object[] args) {
-        this.args = args;
-    }
-
-    /**
-     * This causes us to invoke the endpoint Pojo using reflection.
-     *
-     * @param pojo     the bean on which to perform this invocation
-     * @param exchange the exchange carrying the method invocation
-     */
-    public void invoke(Object pojo, Exchange exchange) {
-        try {
-            Method method = getMethod();
-            Object[] args = getArgs();
-            LOG.trace("Invoking method: {} with args: {}", method, args);
-            Object response = 
org.apache.camel.support.ObjectHelper.invokeMethodSafe(method, pojo, args);
-            LOG.trace("Got response: {}", response);
-            exchange.getOut().setBody(response);
-        } catch (InvocationTargetException e) {
-            
exchange.setException(RuntimeCamelException.wrapRuntimeCamelException(e.getCause()));
-        } catch (Exception e) {
-            throw RuntimeCamelException.wrapRuntimeCamelException(e);
-        }
-    }
-
-    public void readExternal(ObjectInput objectInput) throws IOException, 
ClassNotFoundException {
-        methodBean = ObjectHelper.cast(MethodBean.class, 
objectInput.readObject());
-        try {
-            method = methodBean.getMethod();
-        } catch (NoSuchMethodException e) {
-            throw new IOException(e);
-        }
-        args = ObjectHelper.cast(Object[].class, objectInput.readObject());
-    }
-
-    public void writeExternal(ObjectOutput objectOutput) throws IOException {
-        if (methodBean == null) {
-            methodBean = new MethodBean(method);
-        }
-        objectOutput.writeObject(methodBean);
-        objectOutput.writeObject(args);
-    }
-}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvocationSerializeTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvocationSerializeTest.java
deleted file mode 100644
index 74518ff..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvocationSerializeTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.bean;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.Method;
-
-import org.apache.camel.TestSupport;
-import org.junit.Test;
-
-public class BeanInvocationSerializeTest extends TestSupport {
-
-    @Test
-    public void testSerialize() throws Exception {
-        Method method = getClass().getMethod("cheese", String.class, 
String.class);
-        BeanInvocation invocation = new BeanInvocation(method, new Object[] 
{"a", "b"});
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream(buffer);
-        out.writeObject(invocation);
-        out.close();
-
-        ObjectInputStream in = new ObjectInputStream(new 
ByteArrayInputStream(buffer.toByteArray()));
-        Object object = in.readObject();
-        BeanInvocation actual = assertIsInstanceOf(BeanInvocation.class, 
object);
-        log.debug("Received " + actual);
-    }
-
-    @Test
-    public void testSerializeCtr() throws Exception {
-        Method method = getClass().getMethod("cheese", String.class, 
String.class);
-        BeanInvocation invocation = new BeanInvocation();
-        invocation.setArgs(new Object[] {"a", "b"});
-        invocation.setMethod(method);
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream(buffer);
-        out.writeObject(invocation);
-        out.close();
-
-        ObjectInputStream in = new ObjectInputStream(new 
ByteArrayInputStream(buffer.toByteArray()));
-        Object object = in.readObject();
-        BeanInvocation actual = assertIsInstanceOf(BeanInvocation.class, 
object);
-        log.debug("Received " + actual);
-    }
-
-    public void cheese(String a, String b) {
-        log.debug("Called with a: {} b: {}", a, b);
-    }
-
-}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyNoBindingTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyNoBindingTest.java
index d00e091..4b206d7 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyNoBindingTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyNoBindingTest.java
@@ -133,7 +133,7 @@ public class BeanProxyNoBindingTest extends 
ContextTestSupport {
     @Test
     public void testProxyBuilderProxyCallAnotherBean() throws Exception {
         // use ProxyBuilder to easily create the proxy
-        OrderService service = new 
ProxyBuilder(context).endpoint("direct:bean").binding(false).build(OrderService.class);
+        OrderService service = new 
ProxyBuilder(context).endpoint("direct:bean").build(OrderService.class);
 
         String reply = service.submitOrderStringReturnString("World");
         assertEquals("Hello World", reply);
@@ -152,7 +152,7 @@ public class BeanProxyNoBindingTest extends 
ContextTestSupport {
     @Test
     public void testProxyBuilderProxyCallAnotherBeanWithNoArgs() throws 
Exception {
         Endpoint endpoint = context.getEndpoint("direct:bean");
-        OrderService service = new 
ProxyBuilder(context).endpoint(endpoint).binding(false).build(OrderService.class);
+        OrderService service = new 
ProxyBuilder(context).endpoint(endpoint).build(OrderService.class);
 
         String reply = service.doAbsolutelyNothing();
         assertEquals("Hi nobody", reply);
@@ -174,7 +174,7 @@ public class BeanProxyNoBindingTest extends 
ContextTestSupport {
     @Test
     public void testProxyBuilderVoidAsInOut() throws Exception {
         // will by default let all exchanges be InOut
-        OrderService service = new 
ProxyBuilder(context).endpoint("seda:delay").binding(false).build(OrderService.class);
+        OrderService service = new 
ProxyBuilder(context).endpoint("seda:delay").build(OrderService.class);
 
         getMockEndpoint("mock:delay").expectedBodiesReceived("Hello World", 
"Bye World");
         service.doNothing("Hello World");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/MyAuditServiceProxyTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/MyAuditServiceProxyTest.java
index 02f233b..2ef3090 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/MyAuditServiceProxyTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/MyAuditServiceProxyTest.java
@@ -28,8 +28,7 @@ public class MyAuditServiceProxyTest extends 
ContextTestSupport {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
         getMockEndpoint("mock:result").expectedHeaderReceived("uuid", "1234");
 
-        // must enable binding on proxy
-        MyAuditService service = new 
ProxyBuilder(context).endpoint("direct:proxy").binding(true).build(MyAuditService.class);
+        MyAuditService service = new 
ProxyBuilder(context).endpoint("direct:proxy").build(MyAuditService.class);
 
         service.auditMessage("1234", "Hello World");
 

Reply via email to