當前位置: 首頁>>代碼示例>>Java>>正文


Java Endpoint.createExchange方法代碼示例

本文整理匯總了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());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:PullRequestCommentProducerTest.java

示例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());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:20,代碼來源:AbstractJdbcGeneratedKeysTest.java

示例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);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:JavaSpaceTransportSendReceiveTest.java

示例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());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:FromFtpDeleteFileTest.java

示例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);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:28,代碼來源:PullRequestStateProducerTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:33,代碼來源:MinaProducerShutdownMockTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:FtpConsumerLocalWorkDirectoryAsAbsolutePathTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:12,代碼來源:DefaultExchangeFormatterTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:12,代碼來源:DefaultExchangeFormatterTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:FromFtpToAsciiFileNoBodyConversionTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:12,代碼來源:FromFtpPassiveModeTest.java

示例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();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:33,代碼來源:DirectRouteTest.java

示例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);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:10,代碼來源:FileProduceTempFileNameTest.java

示例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));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:33,代碼來源:AbstractJdbcGeneratedKeysTest.java

示例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());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:14,代碼來源:FileProduceGeneratedFileNameTest.java


注:本文中的org.apache.camel.Endpoint.createExchange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。