| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.spring.remoting; |
| 18 |
|
|
| 19 |
|
import org.apache.camel.CamelContext; |
| 20 |
|
import org.apache.camel.CamelContextAware; |
| 21 |
|
import org.apache.camel.Endpoint; |
| 22 |
|
import org.apache.camel.component.bean.ProxyHelper; |
| 23 |
|
|
| 24 |
|
import org.springframework.beans.factory.FactoryBean; |
| 25 |
|
import org.springframework.remoting.support.UrlBasedRemoteAccessor; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
6 |
public class CamelProxyFactoryBean extends UrlBasedRemoteAccessor implements FactoryBean, CamelContextAware { |
| 33 |
|
private CamelContext camelContext; |
| 34 |
|
private Endpoint endpoint; |
| 35 |
|
private Object serviceProxy; |
| 36 |
|
|
| 37 |
|
@Override |
| 38 |
|
public void afterPropertiesSet() { |
| 39 |
6 |
super.afterPropertiesSet(); |
| 40 |
|
try { |
| 41 |
6 |
if (endpoint == null) { |
| 42 |
6 |
if (getServiceUrl() == null || camelContext == null) { |
| 43 |
3 |
throw new IllegalArgumentException("If endpoint is not specified, the serviceUrl and camelContext must be specified."); |
| 44 |
|
} |
| 45 |
|
|
| 46 |
3 |
endpoint = camelContext.getEndpoint(getServiceUrl()); |
| 47 |
3 |
if (endpoint == null) { |
| 48 |
0 |
throw new IllegalArgumentException("Could not resolve endpoint: " + getServiceUrl()); |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
|
| 52 |
3 |
this.serviceProxy = ProxyHelper.createProxy(endpoint, getServiceInterface()); |
| 53 |
3 |
} catch (Exception e) { |
| 54 |
3 |
throw new IllegalArgumentException(e); |
| 55 |
3 |
} |
| 56 |
3 |
} |
| 57 |
|
|
| 58 |
|
public Class getServiceInterface() { |
| 59 |
12 |
return super.getServiceInterface(); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
public String getServiceUrl() { |
| 63 |
15 |
return super.getServiceUrl(); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
public Object getObject() throws Exception { |
| 67 |
3 |
return serviceProxy; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
public Class getObjectType() { |
| 71 |
9 |
return getServiceInterface(); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
public boolean isSingleton() { |
| 75 |
6 |
return true; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
public Endpoint getEndpoint() { |
| 79 |
0 |
return endpoint; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
public void setEndpoint(Endpoint endpoint) { |
| 83 |
0 |
this.endpoint = endpoint; |
| 84 |
0 |
} |
| 85 |
|
|
| 86 |
|
public CamelContext getCamelContext() { |
| 87 |
0 |
return camelContext; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
public void setCamelContext(CamelContext camelContext) { |
| 91 |
3 |
this.camelContext = camelContext; |
| 92 |
3 |
} |
| 93 |
|
} |