本文整理汇总了Java中org.apache.camel.Endpoint.createExchange方法的典型用法代码示例。如果您正苦于以下问题:Java Endpoint.createExchange方法的具体用法?Java Endpoint.createExchange怎么用?Java Endpoint.createExchange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.Endpoint
的用法示例。
在下文中一共展示了Endpoint.createExchange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPullRequestCommentProducer
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void testPullRequestCommentProducer() throws Exception {
PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
latestPullRequestId = pullRequest.getId();
Endpoint commentProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
Exchange exchange = commentProducerEndpoint.createExchange();
String commentText = "Pushed this comment at " + new Date();
exchange.getIn().setBody(commentText);
template.send(commentProducerEndpoint, exchange);
Thread.sleep(1 * 1000);
// Verify that the mock pull request service received this comment.
List<CommitComment> commitComments = pullRequestService.getComments(null, (int) pullRequest.getId());
assertEquals(1, commitComments.size());
CommitComment commitComment = commitComments.get(0);
assertEquals("Commit IDs did not match ", Long.toString(pullRequest.getId()), commitComment.getCommitId());
assertEquals("Comment text did not match ", commentText, commitComment.getBodyText());
}
示例2: testGivenAnInvalidGeneratedColumnsHeaderThenAnExceptionIsThrown
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
protected void testGivenAnInvalidGeneratedColumnsHeaderThenAnExceptionIsThrown(String query,
Map<String, Object> parameters) throws Exception {
// first we create our exchange using the endpoint
Endpoint endpoint = context.getEndpoint("direct:hello");
Exchange exchange = endpoint.createExchange();
// then we set the SQL on the in body and add possible parameters
exchange.getIn().setBody(query);
exchange.getIn().setHeader(JdbcConstants.JDBC_RETRIEVE_GENERATED_KEYS, true);
setHeaders(exchange, parameters);
// set wrong data type for generated columns
exchange.getIn().setHeader(JdbcConstants.JDBC_GENERATED_COLUMNS, new Object[]{});
// now we send the exchange to the endpoint, and receives the response from Camel
template.send(endpoint, exchange);
assertTrue(exchange.isFailed());
}
示例3: testJavaSpaceTransportSendReceive
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void testJavaSpaceTransportSendReceive() throws Exception {
Endpoint directEndpoint = context.getEndpoint("direct:input");
Exchange exchange = directEndpoint.createExchange(ExchangePattern.InOnly);
Message message = exchange.getIn();
message.setBody("DAVID".getBytes(), byte[].class);
Producer producer = directEndpoint.createProducer();
int nummsg = 1;
countLatch = new CountDownLatch(nummsg);
long start = System.currentTimeMillis();
producer.start();
for (int i = 0; i < nummsg; ++i) {
producer.process(exchange);
}
countLatch.await();
long stop = System.currentTimeMillis();
log.info("{} took {} milliseconds", getTestMethodName(), stop - start);
}
示例4: prepareFtpServer
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server that we want to unit
// test that we can pool and store as a local file
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World this file will be deleted");
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
// assert file is created
File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt");
assertTrue("The file should exists", file.exists());
}
示例5: testPullRequestStateProducer
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void testPullRequestStateProducer() throws Exception {
commitsha = commitService.getNextSha();
Endpoint stateProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
Exchange exchange = stateProducerEndpoint.createExchange();
String text = "Message sent at " + new Date();
exchange.getIn().setBody(text);
Exchange response = template.send(stateProducerEndpoint, exchange);
assertNotNull(response.getOut().getBody());
if (!(response.getOut().getBody() instanceof CommitStatus)) {
fail("Expecting CommitStatus");
}
CommitStatus status = response.getOut().getBody(CommitStatus.class);
// Check status set on commit service
if (commitService.getCommitStatus(commitsha) != status) {
fail("Commit status sent to service is different from response");
}
assertEquals(status.getState(), "success");
assertEquals(status.getDescription(), text);
}
示例6: testProducerShutdownTestingWithMock
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void testProducerShutdownTestingWithMock() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
// create our mock and record expected behavior = that worker timeout should be set to 0
SocketConnector mockConnector = createMock(SocketConnector.class);
mockConnector.setWorkerTimeout(0);
replay(mockConnector);
// normal camel code to get a producer
Endpoint endpoint = context.getEndpoint("mina:tcp://localhost:{{port}}?textline=true&sync=false");
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
// insert our mock instead of real MINA IoConnector
Field field = producer.getClass().getDeclaredField("connector");
field.setAccessible(true);
field.set(producer, mockConnector);
// stop using our mock
producer.stop();
verify(mockConnector);
assertMockEndpointsSatisfied();
}
示例7: prepareFtpServer
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server that we want to unit
// test that we can pool
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
示例8: testSendExchangeWithException
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testSendExchangeWithException() throws Exception {
Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showException=true");
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.setException(new IllegalArgumentException("Damn"));
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
示例9: testSendCaughtExchangeWithException
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testSendCaughtExchangeWithException() throws Exception {
Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true");
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
示例10: prepareFtpServer
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server that we want to unit
// test that we can pool and store as a local file
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello ASCII from FTPServer");
exchange.getIn().setHeader(Exchange.FILE_NAME, "ascii.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
示例11: prepareFtpServer
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
示例12: testSedaQueue
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testSedaQueue() throws Exception {
CamelContext container = new DefaultCamelContext();
final AtomicBoolean invoked = new AtomicBoolean();
// lets add some routes
container.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:test.a").to("direct:test.b");
from("direct:test.b").process(new Processor() {
public void process(Exchange e) {
invoked.set(true);
}
});
}
});
container.start();
// now lets fire in a message
Endpoint endpoint = container.getEndpoint("direct:test.a");
Exchange exchange = endpoint.createExchange();
exchange.getIn().setHeader("cheese", 123);
Producer producer = endpoint.createProducer();
producer.process(exchange);
// now lets sleep for a while
assertTrue("Did not receive the message!", invoked.get());
container.stop();
}
示例13: testCreateTempFileName
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testCreateTempFileName() throws Exception {
Endpoint endpoint = context.getEndpoint(fileUrl);
GenericFileProducer<?> producer = (GenericFileProducer<?>) endpoint.createProducer();
Exchange exchange = endpoint.createExchange();
exchange.getIn().setHeader(Exchange.FILE_NAME, "claus.txt");
String tempFileName = producer.createTempFileName(exchange, "target/tempandrename/claus.txt");
assertDirectoryEquals("target/tempandrename/inprogress-claus.tmp", tempFileName);
}
示例14: testRetrieveGeneratedKeysWithStringGeneratedColumns
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void testRetrieveGeneratedKeysWithStringGeneratedColumns(String query,
Map<String, Object> parameters) throws Exception {
// first we create our exchange using the endpoint
Endpoint endpoint = context.getEndpoint("direct:hello");
Exchange exchange = endpoint.createExchange();
// then we set the SQL on the in body and add possible parameters
exchange.getIn().setBody(query);
exchange.getIn().setHeader(JdbcConstants.JDBC_RETRIEVE_GENERATED_KEYS, true);
exchange.getIn().setHeader(JdbcConstants.JDBC_GENERATED_COLUMNS, new String[]{"ID"});
setHeaders(exchange, parameters);
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
// assertions of the response
assertNotNull(out);
assertNotNull(out.getOut());
assertNotNull(out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_DATA));
assertNotNull(out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to an ArrayList - was: "
+ out.getOut().getBody(), generatedKeys);
assertEquals(1, generatedKeys.size());
Map<String, Object> row = generatedKeys.get(0);
assertEquals("auto increment value should be 2", BigDecimal.valueOf(2), row.get("1"));
assertEquals("generated keys row count should be one", 1, out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT));
}
示例15: testGeneratedFileName
import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testGeneratedFileName() throws Exception {
Endpoint endpoint = context.getEndpoint("direct:a");
FileEndpoint fileEndpoint = resolveMandatoryEndpoint("file://target", FileEndpoint.class);
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
String id = fileEndpoint.getGeneratedFileName(exchange.getIn());
template.send(endpoint, exchange);
File file = new File("target/" + id);
assertEquals("The generated file should exists: " + file, true, file.exists());
}