| Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
| BeanInvocation |
|
| 2.0;2 |
| 1 | /** |
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
|
| 4 | * this work for additional information regarding copyright ownership. |
|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
| 6 | * (the "License"); you may not use this file except in compliance with |
|
| 7 | * the License. You may obtain a copy of the License at |
|
| 8 | * |
|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 10 | * |
|
| 11 | * Unless required by applicable law or agreed to in writing, software |
|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 14 | * See the License for the specific language governing permissions and |
|
| 15 | * limitations under the License. |
|
| 16 | */ |
|
| 17 | package org.apache.camel.component.bean; |
|
| 18 | ||
| 19 | import java.lang.reflect.InvocationTargetException; |
|
| 20 | import java.lang.reflect.Method; |
|
| 21 | ||
| 22 | import org.apache.camel.Exchange; |
|
| 23 | ||
| 24 | public class BeanInvocation { |
|
| 25 | ||
| 26 | private final Object proxy; |
|
| 27 | private final Method method; |
|
| 28 | private final Object[] args; |
|
| 29 | ||
| 30 | 18 | public BeanInvocation(Object proxy, Method method, Object[] args) { |
| 31 | 18 | this.proxy = proxy; |
| 32 | 18 | this.method = method; |
| 33 | 18 | this.args = args; |
| 34 | 18 | } |
| 35 | ||
| 36 | public Object[] getArgs() { |
|
| 37 | 18 | return args; |
| 38 | } |
|
| 39 | ||
| 40 | public Method getMethod() { |
|
| 41 | 18 | return method; |
| 42 | } |
|
| 43 | ||
| 44 | public Object getProxy() { |
|
| 45 | 0 | return proxy; |
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * This causes us to invoke the endpoint Pojo using reflection. |
|
| 50 | * |
|
| 51 | * @param pojo |
|
| 52 | */ |
|
| 53 | public void invoke(Object pojo, Exchange exchange) { |
|
| 54 | try { |
|
| 55 | 18 | Object response = getMethod().invoke(pojo, getArgs()); |
| 56 | 18 | exchange.getOut().setBody(response); |
| 57 | 0 | } catch (InvocationTargetException e) { |
| 58 | 0 | exchange.setException(e.getCause()); |
| 59 | 0 | } catch (RuntimeException e) { |
| 60 | 0 | throw e; |
| 61 | 0 | } catch (Throwable e) { |
| 62 | 0 | throw new RuntimeException(e); |
| 63 | 18 | } |
| 64 | 18 | } |
| 65 | ||
| 66 | } |