本文整理汇总了Java中org.apache.camel.Processor类的典型用法代码示例。如果您正苦于以下问题:Java Processor类的具体用法?Java Processor怎么用?Java Processor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Processor类属于org.apache.camel包,在下文中一共展示了Processor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRouteBuilder
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(fromURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
QName faultCode = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server");
SoapFault fault = new SoapFault("Get the null value of person name", faultCode);
Element details = StaxUtils.read(new StringReader(DETAILS)).getDocumentElement();
fault.setDetail(details);
exchange.setException(fault);
}
});
}
};
}
示例2: wrapProcessorInInterceptors
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
public Processor wrapProcessorInInterceptors(CamelContext context,
final ProcessorDefinition<?> definition, final Processor target,
final Processor nextTarget) throws Exception {
return new DelegateAsyncProcessor(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// if(!camelConfig.isRunning()){
// System.err.println("系统将关闭,不在处理任务");
// return ;
// }
System.out.println("defainition :"+definition);
System.out.println("nextTarget :"+nextTarget);
target.process(exchange);
}
});
}
示例3: getAfterProducer
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
public Processor getAfterProducer() {
@SuppressWarnings("unchecked")
final Processor processor = exchange -> {
String jsonBean = "";
if (exchange.getIn().getBody(List.class) != null) {
//Only grabbing the first record (map) in the list
@SuppressWarnings("rawtypes")
List<Map> maps = exchange.getIn().getBody(List.class);
jsonBean = JSONBeanUtil.toJSONBean(maps.iterator().next());
} else {
jsonBean = JSONBeanUtil.toJSONBean(exchange.getIn().getBody(Map.class));
}
exchange.getIn().setBody(jsonBean);
};
return processor;
}
示例4: createEndpoint
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected final Endpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters)
throws Exception {
final DefaultConnectorEndpoint connectorEndpoint = (DefaultConnectorEndpoint) super.createEndpoint(uri, remaining, parameters);
final DataType inputDataType = connectorEndpoint.getInputDataType();
final UnmarshallProcessor unmarshallInputProcessor = new UnmarshallInputProcessor(inputDataType);
final Processor existingBeforeProducer = connectorEndpoint.getBeforeProducer();
if (existingBeforeProducer == null) {
connectorEndpoint.setBeforeProducer(unmarshallInputProcessor);
} else {
connectorEndpoint.setBeforeProducer(Pipeline.newInstance(getCamelContext(), unmarshallInputProcessor, existingBeforeProducer));
}
final DataType outputDataType = connectorEndpoint.getOutputDataType();
final UnmarshallProcessor unmarshallOutputProcessor = new UnmarshallOutputProcessor(outputDataType);
final Processor existingAfterProducer = connectorEndpoint.getAfterProducer();
if (existingAfterProducer == null) {
connectorEndpoint.setAfterProducer(unmarshallOutputProcessor);
} else {
connectorEndpoint.setAfterProducer(Pipeline.newInstance(getCamelContext(), unmarshallOutputProcessor, existingAfterProducer));
}
return connectorEndpoint;
}
示例5: shouldNotRemoveExistingProcessors
import org.apache.camel.Processor; //导入依赖的package包/类
@Test
public void shouldNotRemoveExistingProcessors() throws Exception {
final DefaultConnectorEndpoint endpoint = (DefaultConnectorEndpoint) connectorWithExistingProcessors
.createEndpoint("salesforce-connector");
final Processor createdBeforeProducer = endpoint.getBeforeProducer();
assertThat(createdBeforeProducer).isInstanceOf(Pipeline.class);
final Pipeline beforePipeline = (Pipeline) createdBeforeProducer;
assertThat(beforePipeline.getProcessors()).isInstanceOf(List.class).hasSize(2);
assertThat(((List<Processor>) beforePipeline.getProcessors()).get(0)).isInstanceOf(UnmarshallInputProcessor.class);
assertThat(((List<Processor>) beforePipeline.getProcessors()).get(1)).isSameAs(beforeProcessor);
final Processor createdAfterProducer = endpoint.getAfterProducer();
assertThat(createdAfterProducer).isInstanceOf(Pipeline.class);
final Pipeline afterPipeline = (Pipeline) createdAfterProducer;
assertThat(afterPipeline.getProcessors()).isInstanceOf(List.class).hasSize(2);
assertThat(((List<Processor>) afterPipeline.getProcessors()).get(0)).isInstanceOf(UnmarshallOutputProcessor.class);
assertThat(((List<Processor>) afterPipeline.getProcessors()).get(1)).isSameAs(afterProcessor);
}
示例6: configure
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
public void configure() throws Exception {
String jsonBody = "{\"a\":20,\"b\":30}";
from("timer://myTimer?period=1000")
.setBody().constant(jsonBody)
.to("sql-stored-connector:DEMO_ADD( "
+ "INTEGER ${body[a]}, "
+ "INTEGER ${body[b]}, "
+ "OUT INTEGER c)")
.process(new Processor() {
public void process(Exchange exchange)
throws Exception {
System.out.println(exchange.getIn()
.getBody().getClass());
System.out.println(exchange.getIn()
.getBody());
}
});
}
示例7: configure
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
public void configure() throws Exception {
from("sql-stored-start-connector:DEMO_OUT( "
+ "OUT INTEGER C )?schedulerPeriod=5000")
.process(new Processor() {
public void process(Exchange exchange)
throws Exception {
System.out.println(exchange.getIn()
.getBody().getClass());
System.out.println(exchange.getIn()
.getBody());
}
});
}
示例8: testMultipartToString
import org.apache.camel.Processor; //导入依赖的package包/类
@Test
public void testMultipartToString() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.send("direct:a", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(MailConstants.MAIL_ALTERNATIVE_BODY, "Alternative World");
}
});
assertMockEndpointsSatisfied();
Message mailMessage = mock.getReceivedExchanges().get(0).getIn().getBody(MailMessage.class).getMessage();
assertNotNull(mailMessage);
Object content = mailMessage.getContent();
Multipart mp = assertIsInstanceOf(Multipart.class, content);
String s = MailConverters.toString(mp);
assertEquals("Alternative World", s);
}
示例9: createRouteBuilder
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// leverage the fact that we can limit to max 50 files per poll
// this will result in polling again and potentially picking up files
// that already are in progress
from("file:target/filestress?maxMessagesPerPoll=50&readLock=fileLock").routeId("foo").noAutoStartup()
.threads(10)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// simulate some work with random time to complete
Random ran = new Random();
int delay = ran.nextInt(250) + 10;
Thread.sleep(delay);
}
}).to("mock:result");
}
};
}
示例10: testPutAndGetMultiColumns
import org.apache.camel.Processor; //导入依赖的package包/类
@Test
public void testPutAndGetMultiColumns() throws Exception {
testPutMultiColumns();
if (systemReady) {
Exchange resp = template.request("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(HBaseConstants.OPERATION, HBaseConstants.GET);
for (int col = 0; col < column[0].length; col++) {
exchange.getIn().setHeader(HBaseAttribute.HBASE_ROW_ID.asHeader(col + 1), key[0]);
exchange.getIn().setHeader(HBaseAttribute.HBASE_FAMILY.asHeader(col + 1), family[0]);
exchange.getIn().setHeader(HBaseAttribute.HBASE_QUALIFIER.asHeader(col + 1), column[0][col]);
}
}
});
for (int col = 0; col < column[0].length; col++) {
assertEquals(body[0][col][0], resp.getOut().getHeader(HBaseAttribute.HBASE_VALUE.asHeader(col + 1)));
}
}
}
示例11: createRouteBuilder
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws URISyntaxException {
JettyHttpComponent componentJetty = (JettyHttpComponent) context.getComponent("jetty");
componentJetty.setSslPassword(pwd);
componentJetty.setSslKeyPassword(pwd);
URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
componentJetty.setKeystore(keyStoreUrl.toURI().getPath());
from("jetty:https://localhost:" + port1 + "/test").to("mock:a");
Processor proc = new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody("<b>Hello World</b>");
}
};
from("jetty:https://localhost:" + port1 + "/hello").process(proc);
from("jetty:https://localhost:" + port2 + "/test").to("mock:b");
}
};
}
示例12: createRouteBuilder
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
port = AvailablePortFinder.getNextAvailable(8000);
return new RouteBuilder() {
public void configure() {
from("jetty:http://localhost:" + port + "/test")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String name = exchange.getIn().getHeader("name", String.class);
ObjectHelper.notNull(name, "name");
name = "org/apache/camel/itest/jetty/" + name;
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), name);
String xml = exchange.getContext().getTypeConverter().convertTo(String.class, is);
exchange.getOut().setBody(xml);
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/xml");
}
});
}
};
}
示例13: divideByValueOf
import org.apache.camel.Processor; //导入依赖的package包/类
private Processor divideByValueOf(final ValueBuilder valueBuilder) {
return new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
BigDecimal sum = new BigDecimal(checkNotNull(
in.getBody(Number.class), "Body of %s is null", in)
.toString());
BigDecimal divisor = new BigDecimal(checkNotNull(
valueBuilder.evaluate(exchange, Integer.class),
"No %s set in exchange %s", valueBuilder, exchange)
.toString());
in.setBody(sum.divide(divisor, HALF_UP));
}
};
}
示例14: createRouteBuilder
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:a").recipientList(header("slip"));
from("jetty://http://localhost:{{port}}/myapp").process(new Processor() {
public void process(Exchange exchange) throws Exception {
int foo = exchange.getIn().getHeader("foo", Integer.class);
String bar = exchange.getIn().getHeader("bar", String.class);
exchange.getOut().setHeader("foo", foo * 2);
exchange.getOut().setBody("Bye " + bar);
}
});
}
};
}
示例15: createRouteBuilder
import org.apache.camel.Processor; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("netty4:udp://localhost:{{port}}?sync=true")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
Poetry poetry = (Poetry) exchange.getIn().getBody();
poetry.setPoet("Dr. Sarojini Naidu");
exchange.getOut().setBody(poetry);
}
});
}
};
}