当前位置: 首页>>代码示例>>Java>>正文


Java ExchangePattern类代码示例

本文整理汇总了Java中org.apache.camel.ExchangePattern的典型用法代码示例。如果您正苦于以下问题:Java ExchangePattern类的具体用法?Java ExchangePattern怎么用?Java ExchangePattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExchangePattern类属于org.apache.camel包,在下文中一共展示了ExchangePattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configure

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Override
public void configure() throws Exception {
    from("direct:STATUS")
            .onException(Exception.class)
                .maximumRedeliveries(0)
                .handled(true)
                .process(exchange -> {
                    Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
                    exchange.getOut().setBody(new ResponseMessage(ResponseCode.ERROR, exception.getMessage()));
                })
                .to("direct:marshal-response")
            .end()
            .setExchangePattern(ExchangePattern.InOut)
            .bean(hacep, "status()", false)
            .process(exchange -> {
                Object body = exchange.getIn().getBody();
                ResponseMessage output = new ResponseMessage(ResponseCode.SUCCESS, (String) body);
                exchange.getOut().setBody(output);
            })
            .to("direct:marshal-response");
}
 
开发者ID:redhat-italy,项目名称:hacep,代码行数:22,代码来源:StatusCommandRoute.java

示例2: configure

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
/**
 * Generates a Camel route, that listens from any HTTP request made (GET or POST) regardless
 * of the path. The response resolution is delegated towards the response processor.
 */
@Override
public void configure() throws Exception {

    onException(Exception.class)
        .handled(true)
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
        .transform(simple("An error occurred: ${exception.message}"));

    from(generateJettyEndpoint())
        .routeId(ROUTE_ID_JETTY)
        .id(ROUTE_ID_JETTY)
        .log(LoggingLevel.DEBUG, LOGGER, "Received request...")
        .setExchangePattern(ExchangePattern.InOut)
        .to(DIRECT_MAIN);

    from(DIRECT_MAIN)
        .routeId(ROUTE_ID_MAIN)
        .id(ROUTE_ID_MAIN)
        .log(LoggingLevel.DEBUG, LOGGER, "Current headers: ${headers}")
        .process(this.responseProcessor);
}
 
开发者ID:Technolords,项目名称:microservice-mock,代码行数:26,代码来源:MockRoute.java

示例3: configure

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
/**
 * Configure the message route workflow.
 */
public void configure() throws Exception {

    // Distribute message based on headers.
    from("{{input.stream}}")
            .routeId("MessageBroadcaster")
            .description("Broadcast messages from one queue/topic to other queues/topics")
            .log(INFO, LOGGER,
                    "Distributing message: ${headers[JMSMessageID]} with timestamp ${headers[JMSTimestamp]}")
            .filter(header("IslandoraExchangePattern"))
                .process(exchange -> {
                    final String patternName = exchange.getIn().getHeader("IslandoraExchangePattern", String.class);
                    try {
                        exchange.setPattern(ExchangePattern.asEnum(patternName));
                    } catch (IllegalArgumentException e) {
                        LOGGER.warn("Ignoring malformed exchange pattern: " + patternName);
                    }
                })
                .end()
            .routingSlip(header("IslandoraBroadcastRecipients")).ignoreInvalidEndpoints();
}
 
开发者ID:Islandora-CLAW,项目名称:Alpaca,代码行数:24,代码来源:BroadcastRouter.java

示例4: apply

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Override
public boolean apply(Event event) {
    Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly);
    Message in = exchange.getIn();
    in.setBody(event);
    try {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Processing Ignite Event: {}.", event);
        }
        getAsyncProcessor().process(exchange, new AsyncCallback() {
            @Override
            public void done(boolean doneSync) {
                // do nothing
            }
        });
    } catch (Exception e) {
        LOG.error(String.format("Exception while processing Ignite Event: %s.", event), e);
    }
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:IgniteEventsConsumer.java

示例5: apply

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Override
public boolean apply(UUID uuid, Object payload) {
    Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly);
    Message in = exchange.getIn();
    in.setBody(payload);
    in.setHeader(IgniteConstants.IGNITE_MESSAGING_TOPIC, endpoint.getTopic());
    in.setHeader(IgniteConstants.IGNITE_MESSAGING_UUID, uuid);
    try {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Processing Ignite message for subscription {} with payload {}.", uuid, payload);
        }
        getProcessor().process(exchange);
    } catch (Exception e) {
        LOG.error(String.format("Exception while processing Ignite Message from topic %s", endpoint.getTopic()), e);
    }
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:IgniteMessagingConsumer.java

示例6: testInvokingSimpleServerWithParams

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Test
public void testInvokingSimpleServerWithParams() throws Exception {
 // START SNIPPET: sending
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<String> params = new ArrayList<String>();
    // Prepare the request message for the camel-cxf procedure
    params.add(TEST_MESSAGE);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);

    Exchange exchange = template.send("direct:EndpointA", senderExchange);

    org.apache.camel.Message out = exchange.getOut();
    // The response message's body is an MessageContentsList which first element is the return value of the operation,
    // If there are some holder parameters, the holder parameter will be filled in the reset of List.
    // The result will be extract from the MessageContentsList with the String class type
    MessageContentsList result = (MessageContentsList)out.getBody();
    LOG.info("Received output text: " + result.get(0));
    Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
    assertNotNull(responseContext);
    assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING));
    assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0));
 // END SNIPPET: sending
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CxfProducerRouterTest.java

示例7: createOnAcceptAlertNotificationExchangeWithExchangePattern

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Test
public void createOnAcceptAlertNotificationExchangeWithExchangePattern() {
    AlertNotification alertNotification = createMock(AlertNotification.class);
    SmppMessage message = createMock(SmppMessage.class);
    expect(binding.createSmppMessage(alertNotification)).andReturn(message);
    message.setExchange(isA(Exchange.class));
    
    replay(alertNotification, binding, message);
    
    Exchange exchange = endpoint.createOnAcceptAlertNotificationExchange(ExchangePattern.InOut, alertNotification);
    
    verify(alertNotification, binding, message);
    
    assertSame(binding, exchange.getProperty(Exchange.BINDING));
    assertSame(message, exchange.getIn());
    assertSame(ExchangePattern.InOut, exchange.getPattern());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SmppEndpointTest.java

示例8: toExchange

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
public static Exchange toExchange(Endpoint endpoint, SessionID sessionID, Message message, QuickfixjEventCategory eventCategory, ExchangePattern exchangePattern) {
    Exchange exchange = endpoint.createExchange(exchangePattern);

    org.apache.camel.Message camelMessage = exchange.getIn();
    camelMessage.setHeader(EVENT_CATEGORY_KEY, eventCategory);
    camelMessage.setHeader(SESSION_ID_KEY, sessionID);

    if (message != null) {
        try {
            camelMessage.setHeader(MESSAGE_TYPE_KEY, message.getHeader().getString(MsgType.FIELD));
        } catch (FieldNotFound e) {
            LOG.warn("Message type field not found in QFJ message: {}, continuing...", message);
        }
    }
    camelMessage.setBody(message);

    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:QuickfixjConverters.java

示例9: testAsyncProducerWait

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
public void testAsyncProducerWait() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    // using the new async API we can fire a real async message
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("Hello World");
    exchange.setPattern(ExchangePattern.InOut);
    exchange.setProperty(Exchange.ASYNC_WAIT, WaitForTaskToComplete.IfReplyExpected);
    template.send("direct:start", exchange);

    // I should not happen before mock
    route = route + "send";

    assertMockEndpointsSatisfied();

    assertEquals("Send should occur before processor", "processsend", route);

    String response = exchange.getOut().getBody(String.class);
    assertEquals("Bye World", response);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:SedaAsyncProducerTest.java

示例10: testXPath

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Test
public void testXPath() throws Exception {
    Endpoint directEndpoint = context.getEndpoint("direct:input");
    Exchange exchange = directEndpoint.createExchange(ExchangePattern.InOnly);
    Message message = exchange.getIn();
    String str1 = "<person name='David' city='Rome'/>";
    message.setBody(str1, byte[].class);
    Producer producer = directEndpoint.createProducer();
    producer.start();
    producer.process(exchange);
    String str2 = "<person name='James' city='London'/>";
    message.setBody(str2, byte[].class);
    producer.process(exchange);
    latch = new CountDownLatch(1);
    latch.await();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:JavaspacesXPathTest.java

示例11: testConsumer

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Test
public void testConsumer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
        return;
    }

    context.createProducerTemplate().send("cxf:bean:consumerEndpoint", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            assertEquals("Get a wrong Content-Type header", "application/xop+xml", exchange.getIn().getHeader("Content-Type"));
            List<Source> elements = new ArrayList<Source>();
            elements.add(new DOMSource(StaxUtils.read(new StringReader(getRequestMessage())).getDocumentElement()));
            CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
                elements, null);
            exchange.getIn().setBody(body);
            exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, 
                new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));

            exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, 
                new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
        }
    });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CxfMtomConsumerPayloadModeTest.java

示例12: createRouteBuilder

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
private RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() {
            CometdComponent component = (CometdComponent) context.getComponent("cometds");
            component.setSslPassword(pwd);
            component.setSslKeyPassword(pwd);
            File file = new File("./src/test/resources/jsse/localhost.ks");
            URI keyStoreUrl = file.toURI();
            component.setSslKeystore(keyStoreUrl.getPath());

            from(URI, URIS).setExchangePattern(ExchangePattern.InOut).process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    Message out = new DefaultMessage();
                    out.setBody("reply: " + exchange.getIn().getBody());
                    exchange.setOut(out);
                }
            });
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:CometdProducerConsumerInOutInteractiveMain.java

示例13: dispatchAsync

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
public Exchange dispatchAsync(RouteboxEndpoint endpoint, Exchange exchange) throws Exception {
    URI dispatchUri;
    Exchange reply;

    if (LOG.isDebugEnabled()) {
        LOG.debug("Dispatching exchange {} to endpoint {}", exchange, endpoint.getEndpointUri());
    }
    
    dispatchUri = selectDispatchUri(endpoint, exchange);
    
    if (exchange.getPattern() == ExchangePattern.InOnly) {
        producer.asyncSend(dispatchUri.toASCIIString(), exchange);
        reply = exchange;
    } else {
        Future<Exchange> future = producer.asyncCallback(dispatchUri.toASCIIString(), exchange, new SynchronizationAdapter());
        reply = future.get(endpoint.getConfig().getConnectionTimeout(), TimeUnit.MILLISECONDS);
    }
    
    return reply;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:RouteboxDispatcher.java

示例14: execute

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Test
public void execute() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
    exchange.getIn().setHeader(SmppConstants.SERVICE_TYPE, "XXX");
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919");
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    expect(session.dataShortMessage(eq("XXX"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"),
            eq(TypeOfNumber.INTERNATIONAL), eq(NumberingPlanIndicator.INTERNET), eq("1919"), eq(new ESMClass()),
            eq(new RegisteredDelivery((byte) 2)), eq(DataCodings.newInstance((byte) 0))))
        .andReturn(new DataSmResult(new MessageId("1"), null));

    replay(session);

    command.execute(exchange);

    verify(session);

    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    assertNull(exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:SmppDataSmCommandTest.java

示例15: process

import org.apache.camel.ExchangePattern; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    exchange.setPattern(ExchangePattern.InOut);
    Message inMessage = exchange.getIn();
    setupDestinationURL(inMessage);
    // using the http central client API
    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
    // set the Http method
    inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
    // set the relative path
    inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
    // Specify the response class , cxfrs will use InputStream as the response object type
    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
    // set a customer header
    inMessage.setHeader("key", "value");
    // since we use the Get method, so we don't need to set the message body
    inMessage.setBody(null);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:CxfRsSslProducerTest.java


注:本文中的org.apache.camel.ExchangePattern类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。