本文整理汇总了Java中org.apache.camel.component.bean.ProxyHelper类的典型用法代码示例。如果您正苦于以下问题:Java ProxyHelper类的具体用法?Java ProxyHelper怎么用?Java ProxyHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProxyHelper类属于org.apache.camel.component.bean包,在下文中一共展示了ProxyHelper类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPojoRoutes
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
@Test
public void testPojoRoutes() throws Exception {
JndiContext jndctx = new JndiContext();
jndctx.bind("bye", new SayService("Good Bye!"));
CamelContext camelContext = new DefaultCamelContext(jndctx);
camelContext.addRoutes(createRouteBuilder(camelContext));
camelContext.start();
try {
Endpoint endpoint = camelContext.getEndpoint("direct:hello");
ISay proxy = ProxyHelper.createProxy(endpoint, false, ISay.class);
String rc = proxy.say();
Assert.assertEquals("Good Bye!", rc);
} finally {
camelContext.stop();
}
}
示例2: getInjectionValue
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
/**
* Creates the object to be injected for an {@link org.apache.camel.EndpointInject} or {@link org.apache.camel.Produce} injection point
*/
public Object getInjectionValue(Class<?> type, String endpointUri, String endpointRef, String endpointProperty,
String injectionPointName, Object bean, String beanName) {
if (type.isAssignableFrom(ProducerTemplate.class)) {
return createInjectionProducerTemplate(endpointUri, endpointRef, endpointProperty, injectionPointName, bean);
} else if (type.isAssignableFrom(ConsumerTemplate.class)) {
return createInjectionConsumerTemplate(endpointUri, endpointRef, endpointProperty, injectionPointName);
} else {
Endpoint endpoint = getEndpointInjection(bean, endpointUri, endpointRef, endpointProperty, injectionPointName, true);
if (endpoint != null) {
if (type.isInstance(endpoint)) {
return endpoint;
} else if (type.isAssignableFrom(Producer.class)) {
return createInjectionProducer(endpoint, bean, beanName);
} else if (type.isAssignableFrom(PollingConsumer.class)) {
return createInjectionPollingConsumer(endpoint, bean, beanName);
} else if (type.isInterface()) {
// lets create a proxy
try {
return ProxyHelper.createProxy(endpoint, type);
} catch (Exception e) {
throw createProxyInstantiationRuntimeException(type, endpoint, e);
}
} else {
throw new IllegalArgumentException("Invalid type: " + type.getName()
+ " which cannot be injected via @EndpointInject/@Produce for: " + endpoint);
}
}
return null;
}
}
示例3: testJavaSpaceRequestReply
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
@Test
public void testJavaSpaceRequestReply() throws Exception {
Endpoint endpoint = context.getEndpoint("direct:input");
ITestPojo proxy = ProxyHelper.createProxy(endpoint, ITestPojo.class);
Request req = new Request();
long start = System.currentTimeMillis();
for (int i = 0; i < 100; ++i) {
req.setPayload("REQUEST " + i);
Reply reply = proxy.method(req);
assertTrue(reply.getPayload().equals("REPLY for REQUEST " + i));
}
long stop = System.currentTimeMillis();
log.info("{} took {} milliseconds", getTestMethodName(), stop - start);
}
示例4: afterPropertiesSet
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
public void afterPropertiesSet() throws Exception {
if (endpoint == null) {
getCamelContext();
if (getServiceUrl() == null && getServiceRef() == null) {
throw new IllegalArgumentException("serviceUrl or serviceRef must be specified.");
}
if (getServiceInterface() == null) {
throw new IllegalArgumentException("serviceInterface must be specified.");
}
// lookup endpoint or we have the url for it
if (getServiceRef() != null) {
endpoint = getCamelContext().getRegistry().lookupByNameAndType(getServiceRef(), Endpoint.class);
} else {
endpoint = getCamelContext().getEndpoint(getServiceUrl());
}
if (endpoint == null) {
throw new IllegalArgumentException("Could not resolve endpoint: " + getServiceUrl());
}
}
// binding is enabled by default
boolean bind = getBinding() != null ? getBinding() : true;
try {
// need to start endpoint before we create producer
ServiceHelper.startService(endpoint);
producer = endpoint.createProducer();
// add and start producer
getCamelContext().addService(producer, true, true);
Class<?> clazz = blueprintContainer.loadClass(getServiceInterface());
serviceProxy = ProxyHelper.createProxy(endpoint, bind, producer, clazz);
} catch (Exception e) {
throw new FailedToCreateProducerException(endpoint, e);
}
}
示例5: afterPropertiesSet
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
if (endpoint == null) {
if (ObjectHelper.isNotEmpty(camelContextId)) {
camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
}
if (camelContext == null) {
throw new IllegalArgumentException("camelContext or camelContextId must be specified");
}
if (getServiceUrl() == null && getServiceRef() == null) {
throw new IllegalArgumentException("serviceUrl or serviceRef must be specified.");
}
// lookup endpoint or we have the url for it
if (getServiceRef() != null) {
endpoint = camelContext.getRegistry().lookupByNameAndType(getServiceRef(), Endpoint.class);
} else {
endpoint = camelContext.getEndpoint(getServiceUrl());
}
if (endpoint == null) {
throw new IllegalArgumentException("Could not resolve endpoint: " + getServiceUrl());
}
}
// binding is enabled by default
boolean bind = getBinding() != null ? getBinding() : true;
try {
// need to start endpoint before we create producer
ServiceHelper.startService(endpoint);
producer = endpoint.createProducer();
// add and start producer
camelContext.addService(producer, true, true);
serviceProxy = ProxyHelper.createProxy(endpoint, bind, producer, getServiceInterface());
} catch (Exception e) {
throw new FailedToCreateProducerException(endpoint, e);
}
}
示例6: testPojoRoutes
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
@Test
public void testPojoRoutes() throws Exception {
if (classPathHasSpaces()) {
return;
}
// Boot up a local RMI registry
LocateRegistry.createRegistry(getPort());
// START SNIPPET: register
JndiContext context = new JndiContext();
context.bind("bye", new SayService("Good Bye!"));
CamelContext camelContext = new DefaultCamelContext(context);
// END SNIPPET: register
camelContext.addRoutes(getRouteBuilder(camelContext));
camelContext.start();
// START SNIPPET: invoke
Endpoint endpoint = camelContext.getEndpoint("direct:hello");
ISay proxy = ProxyHelper.createProxy(endpoint, false, ISay.class);
String rc = proxy.say();
assertEquals("Good Bye!", rc);
// END SNIPPET: invoke
camelContext.stop();
}
示例7: calculator
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
@Produces
@Named("calculatorProxy")
public Calculator calculator(CamelContext context) throws Exception {
Endpoint endpoint = context.getEndpoint("direct:calculatorProxy");
Calculator proxy = ProxyHelper.createProxy(endpoint, Calculator.class);
return proxy;
}
示例8: testEcho
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
public void testEcho() throws Exception {
Echo service = ProxyHelper.createProxy(context.getEndpoint("direct:echo"), Echo.class);
assertEquals("Hello World", service.echo("Hello World"));
}
示例9: testEchoNull
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
public void testEchoNull() throws Exception {
Echo service = ProxyHelper.createProxy(context.getEndpoint("direct:echo"), Echo.class);
assertEquals(null, service.echo(null));
}
示例10: build
import org.apache.camel.component.bean.ProxyHelper; //导入依赖的package包/类
/**
* Builds the proxy.
*
* @param interfaceClasses the service interface(s)
* @return the proxied bean
* @throws Exception is thrown if error creating the proxy
*/
public <T> T build(Class<T>... interfaceClasses) throws Exception {
ObjectHelper.notNull(endpoint, "endpoint");
return ProxyHelper.createProxy(endpoint, binding, interfaceClasses);
}