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


Java DefaultExchange类代码示例

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


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

示例1: testSDPParseOffer

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testSDPParseOffer() throws Exception {
    Exchange ex = new DefaultExchange(new DefaultCamelContext());
    ex.getIn().setBody(offerSdp);
    processor.process(ex);
    assertEquals(ex.getIn().getBody().getClass(),Offer.class);

    Offer offer = (Offer)ex.getIn().getBody();

    MediaDescription mediaDescription = (MediaDescription) offer.getSdp().getMediaDescriptions(true).get(0);

    String icePwd = mediaDescription.getAttribute("ice-pwd");
    String iceUfrag = mediaDescription.getAttribute("ice-ufrag");
    String fingerprint = offer.getSdp().getAttribute("fingerprint");

    assertEquals(icePwd,"c490fef46f74bdbe64edd636bc49a259");
    assertEquals(iceUfrag,"64dc2277");
    assertEquals(fingerprint,"sha-256 99:45:B1:94:7E:97:AE:F2:A5:75:86:89:B5:AD:06:BB:63:02:FA:05:04:B2:83:1B:52:C9:EF:0E:61:8F:38:73");
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:20,代码来源:ProcessSignalsTest.java

示例2: testConfirmExist

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testConfirmExist() {
    // Given
    for (int i = 1; i < 4; i++) {
        String key = "Confirm_" + i;
        Exchange exchange = new DefaultExchange(camelContext);
        exchange.setExchangeId("Exchange_" + i);
        aggregationRepository.add(camelContext, key, exchange);
        assertTrue(exists(key));
    }
    // When
    aggregationRepository.confirm(camelContext, "Confirm_2");
    // Then
    assertTrue(exists("Confirm_1"));
    assertFalse(exists("Confirm_2"));
    assertTrue(exists("Confirm_3"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:InfinispanLocalAggregationRepositoryOperationsTest.java

示例3: doTestOutOutOfBandHeaderCamelTemplate

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
protected void doTestOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
    // START SNIPPET: sending
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<Object> params = new ArrayList<Object>();
    Me me = new Me();
    me.setFirstName("john");
    me.setLastName("Doh");

    params.add(me);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "outOutOfBandHeader");

    Exchange exchange = template.send(producerUri, senderExchange);

    org.apache.camel.Message out = exchange.getOut();
    MessageContentsList result = (MessageContentsList)out.getBody();
    assertTrue("Expected the out of band header to propagate but it didn't", 
               result.get(0) != null && ((Me)result.get(0)).getFirstName().equals("pass"));
    Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
    assertNotNull(responseContext);
    validateReturnedOutOfBandHeader(responseContext);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CxfMessageHeadersRelayTest.java

示例4: evaluate

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
/**
 * Evaluates the given xpath using the provided body as a String return type.
 *
 * @param context the camel context
 * @param body    the body
 * @return result of the evaluation
 */
public String evaluate(CamelContext context, Object body) {
    ObjectHelper.notNull(context, "CamelContext");

    // create a dummy Exchange to use during evaluation
    Exchange dummy = new DefaultExchange(context);
    dummy.getIn().setBody(body);

    setResultQName(XPathConstants.STRING);
    setResultType(String.class);
    try {
        return evaluate(dummy, String.class);
    } finally {
        // remove the thread local after usage
        this.exchange.remove();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:XPathBuilder.java

示例5: testXsltOutputFileDelete

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
public void testXsltOutputFileDelete() throws Exception {
    URL styleSheet = getClass().getResource("example.xsl");

    XsltBuilder builder = XsltBuilder.xslt(styleSheet).outputFile().deleteOutputFile();

    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("<hello>world!</hello>");
    exchange.getIn().setHeader(Exchange.XSLT_FILE_NAME, "target/xslt/xsltout.xml");

    builder.process(exchange);
    assertIsInstanceOf(File.class, exchange.getOut().getBody());

    File file = new File("target/xslt/xsltout.xml");
    assertTrue("Output file should exist", file.exists());

    String body = exchange.getOut().getBody(String.class);
    assertTrue(body.endsWith("<goodbye>world!</goodbye>"));

    // now done the exchange
    List<Synchronization> onCompletions = exchange.handoverCompletions();
    UnitOfWorkHelper.doneSynchronizations(exchange, onCompletions, log);

    // the file should be deleted
    assertFalse("Output file should be deleted", file.exists());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:XsltBuilderTest.java

示例6: testPopupalteExchangeFromCxfResponseOfNullBody

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testPopupalteExchangeFromCxfResponseOfNullBody() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> responseContext = new HashMap<String, Object>();
    responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    cxfExchange.setInMessage(cxfMessage);
    
    cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);

    CxfPayload<?> cxfPayload = exchange.getOut().getBody(CxfPayload.class);

    assertNotNull(cxfPayload);
    List<?> body = cxfPayload.getBody(); 
    assertNotNull(body);
    assertEquals(0, body.size());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:DefaultCxfBindingTest.java

示例7: testFallbackConverterWithoutObjectFactory

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testFallbackConverterWithoutObjectFactory() throws Exception {
    TypeConverter converter = context.getTypeConverter();
    Foo foo = converter.convertTo(Foo.class, "<foo><zot name=\"bar1\" value=\"value\" otherValue=\"otherValue\"/></foo>");
    assertNotNull("foo should not be null", foo);
    assertEquals("value", foo.getBarRefs().get(0).getValue());

    foo.getBarRefs().clear();
    Bar bar = new Bar();
    bar.setName("myName");
    bar.setValue("myValue");
    foo.getBarRefs().add(bar);

    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");

    String value = converter.convertTo(String.class, exchange, foo);

    assertTrue("Should get a right marshalled string", value.indexOf("<bar name=\"myName\" value=\"myValue\"/>") > 0);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:CamelJaxbFallbackConverterTest.java

示例8: testFailNullBody

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
public void testFailNullBody() throws Exception {
    URL styleSheet = getClass().getResource("example.xsl");

    XsltBuilder builder = XsltBuilder.xslt(styleSheet);
    builder.setFailOnNullBody(true);

    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(null);

    try {
        builder.process(exchange);
        fail("Should thrown an exception");
    } catch (ExpectedBodyTypeException e) {
        // expected
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:XsltBuilderTest.java

示例9: testExpressionField

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testExpressionField() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(new File("src/test/resources/type.json"));

    Language lan = context.resolveLanguage("jsonpath");
    Expression exp = lan.createExpression("$.kind");
    String kind = exp.evaluate(exchange, String.class);

    assertNotNull(kind);
    assertEquals("full", kind);

    exp = lan.createExpression("$.type");
    String type = exp.evaluate(exchange, String.class);
    assertNotNull(type);
    assertEquals("customer", type);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:JsonPathLanguageTest.java

示例10: testmakeAsyncApiCall

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testmakeAsyncApiCall() {
    try {
        getMockEndpoint("mock:seda:start").expectedHeaderReceived("username", "admin123");
        getMockEndpoint("mock:seda:start").expectedBodiesReceived("Hello");
        DefaultExchange dfex = new DefaultExchange(context);
        dfex.getIn().setHeader("username", "admin123");
        dfex.getIn().setHeader("password", "admin");
        dfex.getIn().setBody("Hello");
        template.asyncSend("seda:start", dfex);
        assertMockEndpointsSatisfied();
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue("Failed to make async call to api", false);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:AsyncSendMockTest.java

示例11: execute

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void execute() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    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.SCHEDULE_DELIVERY_TIME, new Date(1111111));
    exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    exchange.getIn().setBody("new short message body");
    session.replaceShortMessage(eq("1"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), eq("-300101001831100+"), eq("-300101003702200+"),
            eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq((byte) 0), aryEq("new short message body".getBytes()));
    
    replay(session);
    
    command.execute(exchange);
    
    verify(session);
    
    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:SmppReplaceSmCommandTest.java

示例12: executeWithConfigurationData

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void executeWithConfigurationData() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "QuerySm");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    expect(session.queryShortMessage("1", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1616"))
            .andReturn(new QuerySmResult("-300101010000004+", MessageState.DELIVERED, (byte) 0));
    
    replay(session);
    
    command.execute(exchange);
    
    verify(session);
    
    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals("DELIVERED", exchange.getOut().getHeader(SmppConstants.MESSAGE_STATE));
    assertEquals((byte) 0, exchange.getOut().getHeader(SmppConstants.ERROR));
    assertNotNull(exchange.getOut().getHeader(SmppConstants.FINAL_DATE));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:SmppQuerySmCommandTest.java

示例13: testExpressionArray

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
@Test
public void testExpressionArray() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(new File("src/test/resources/books.json"));

    Language lan = context.resolveLanguage("jsonpath");
    Expression exp = lan.createExpression("$.store.book[*].author");
    List<?> authors = exp.evaluate(exchange, List.class);
    log.debug("Authors {}", authors);

    assertNotNull(authors);
    assertEquals(2, authors.size());
    assertEquals("Nigel Rees", authors.get(0));
    assertEquals("Evelyn Waugh", authors.get(1));

    exp = lan.createExpression("$.store.bicycle.price");
    String price = exp.evaluate(exchange, String.class);
    assertEquals("Got a wrong result", "19.95", price);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:JsonPathLanguageTest.java

示例14: testHandleErrorsResult

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
public void testHandleErrorsResult() throws Exception {
    DefaultValidationErrorHandler eh = new DefaultValidationErrorHandler();

    eh.error(new SAXParseException("foo", createLocator(3, 5)));
    eh.error(new SAXParseException("bar", createLocator(9, 12)));

    assertEquals(false, eh.isValid());

    Exchange exchange = new DefaultExchange(context);
    try {
        eh.handleErrors(exchange, createScheme(), new SAXResult());
        fail("Should have thrown an exception");
    } catch (SchemaValidationException e) {
        assertEquals(2, e.getErrors().size());
        assertEquals(0, e.getFatalErrors().size());
        assertEquals(0, e.getWarnings().size());
        assertNotNull(e.getSchema());
        assertNotNull(e.getExchange());

        assertTrue(e.getMessage().startsWith("Validation failed for: org.apache.camel.processor.validation.DefaultValidationErrorHandlerTest"));
        assertTrue(e.getMessage().contains("errors: ["));
        assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: foo, Line : 3, Column : 5"));
        assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: bar, Line : 9, Column : 12"));
        assertTrue(e.getMessage().contains("Exchange[]"));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:DefaultValidationErrorHandlerTest.java

示例15: testLogStringDurationIsNotZero

import org.apache.camel.impl.DefaultExchange; //导入依赖的package包/类
public void testLogStringDurationIsNotZero() throws Exception {
    CamelContext camel = new DefaultCamelContext();
    camel.start();

    Logger logger = EasyMock.createMock(Logger.class);
    logger.isInfoEnabled();
    EasyMock.expectLastCall().andReturn(true).atLeastOnce();
    logger.info(EasyMock.startsWith("Received: 10"));
    EasyMock.expectLastCall().once();
    logger.info(EasyMock.startsWith("Received: 20"));
    EasyMock.expectLastCall().once();
    EasyMock.replay(logger);
    ThroughputLogger underTest = new ThroughputLogger(new CamelLogger(logger));
    underTest.setGroupSize(10);
    for (int i = 0; i < 25; i++) {
        underTest.process(new DefaultExchange(camel));
    }
    EasyMock.verify(logger);

    camel.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:ThroughPutLoggerTest.java


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