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


Java Exchange类代码示例

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


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

示例1: multipleCities

import org.apache.camel.Exchange; //导入依赖的package包/类
@Test
public void multipleCities() throws Exception {
	mockGlobalWeatherResponseBody = "<NewDataSet><Table><Country>TEST</Country><City>AA</City></Table><Table><Country>TEST</Country><City>BB</City></Table></NewDataSet>";

	Exchange response =  fluentProducerTemplate.send();
	String responseBody = response.getIn().getBody(String.class);
	CitiesResponse citiesResponse = objectMapper.readValue(responseBody,CitiesResponse.class);

	assertEquals(200, response.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE));
	assertEquals("TEST", citiesResponse.getCountry());

	List<City> expectedCities = Arrays.asList(
			new City("AA", Arrays.asList("ZIP-AA")),
			new City("BB", Arrays.asList("ZIP-BB1","ZIP-BB2"))
	);
	//Sort response list by city name
	citiesResponse.getCities().sort(Comparator.comparing(City::getName));
	assertEquals(expectedCities, citiesResponse.getCities());
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:20,代码来源:StoredProcTest.java

示例2: aggregate

import org.apache.camel.Exchange; //导入依赖的package包/类
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    Exchange exchange = super.aggregate(oldExchange, newExchange);

    List<Exchange> aggregatedExchanges = exchange.getProperty("CamelGroupedExchange", List.class);

    // Complete aggregation if we have "numberOfSystems" (currently 3) different messages (where "system" headers are different)
    // https://github.com/apache/camel/blob/master/camel-core/src/main/docs/eips/aggregate-eip.adoc#completing-current-group-decided-from-the-aggregationstrategy
    if (numberOfSystems == aggregatedExchanges.stream().map(e -> e.getIn().getHeader("system", String.class)).distinct().count()) {
        exchange.setProperty(Exchange.AGGREGATION_COMPLETE_CURRENT_GROUP, true);
    }

    return exchange;
}
 
开发者ID:mgyongyosi,项目名称:camel-cookbook,代码行数:15,代码来源:SignalAggregationStrategy.java

示例3: process

import org.apache.camel.Exchange; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    Address address = in.getHeader(Constants.ADDRESS_HEADER, Address.class);
    Class<?> datatype = in.getHeader(Constants.DATATYPE_HEADER, Class.class);
    Object value = in.getBody(Object.class);
    PlcWriteRequest plcSimpleWriteRequest = new PlcWriteRequest(datatype, address, value);
    PlcWriter plcWriter = plcConnection.getWriter().orElseThrow(() -> new IllegalArgumentException("Writer for driver not found"));
    CompletableFuture<PlcWriteResponse> completableFuture = plcWriter.write(plcSimpleWriteRequest);
    int currentlyOpenRequests = openRequests.incrementAndGet();
    try {
        log.debug("Currently open requests including {}:{}", exchange, currentlyOpenRequests);
        PlcWriteResponse plcWriteResponse = completableFuture.get();
        if (exchange.getPattern().isOutCapable()) {
            Message out = exchange.getOut();
            out.copyFrom(exchange.getIn());
            out.setBody(plcWriteResponse);
        } else {
            in.setBody(plcWriteResponse);
        }
    } finally {
        int openRequestsAfterFinish = openRequests.decrementAndGet();
        log.trace("Open Requests after {}:{}", exchange, openRequestsAfterFinish);
    }
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:27,代码来源:PLC4XProducer.java

示例4: onCompletion

import org.apache.camel.Exchange; //导入依赖的package包/类
@Override
public void onCompletion(Exchange exchange) {
	if (wrappedAggregationStrategy != null
			&& wrappedAggregationStrategy instanceof CompletionAwareAggregationStrategy) {
		((CompletionAwareAggregationStrategy) wrappedAggregationStrategy).onCompletion(exchange);
	}

	// Remove exception, fault and redelivery info from exchange
	exchange.setException(null);
	exchange.removeProperty(Exchange.FAILURE_HANDLED);
	exchange.removeProperty(Exchange.FAILURE_ENDPOINT);
	exchange.removeProperty(Exchange.FAILURE_ROUTE_ID);
	exchange.removeProperty(Exchange.ERRORHANDLER_CIRCUIT_DETECTED);
	exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED);
	exchange.removeProperty(Exchange.EXCEPTION_HANDLED);
	exchange.removeProperty(Exchange.EXCEPTION_CAUGHT);

	Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
	message.setFault(false);
	message.removeHeader(Exchange.REDELIVERED);
	message.removeHeader(Exchange.REDELIVERY_COUNTER);
	message.removeHeader(Exchange.REDELIVERY_DELAY);
	message.removeHeader(Exchange.REDELIVERY_EXHAUSTED);
	message.removeHeader(Exchange.REDELIVERY_MAX_COUNTER);
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:26,代码来源:ContinueOnExceptionStrategy.java

示例5: process

import org.apache.camel.Exchange; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    String key = (String)exchange.getIn().getHeader(WebsocketConstants.CONNECTION_KEY);

    MDC.clear();
    MDC.put("WebsocketConstants.CONNECTION_KEY",key);

    logger.info("Headers: {}",exchange.getIn().getHeaders());
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:9,代码来源:SimpleSignalingExample.java

示例6: process

import org.apache.camel.Exchange; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    String header = (String) exchange.getIn().getHeader("Authorization");

    if (header == null) {
        throw new UnauthorizedException();
    }

    Set<ITokenValidation> providers =
            exchange.getContext().getRegistry().findByType(ITokenValidation.class);

    if (providers.isEmpty()) {
        throw new UnauthorizedException();
    }

    ITokenValidation tokenProvider = providers.iterator().next();

    String token = header.replace("TOKEN", "");
    token = token.trim();
    boolean isvalid = tokenProvider.isTokenvalid(token);

    if (!isvalid) {
        throw new UnauthorizedException();
    }
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:26,代码来源:SecurityProcessor.java

示例7: process

import org.apache.camel.Exchange; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setRepository(new File(System.getProperty("java.io.tmpdir")));

    ExchangeFileUpload upload = new ExchangeFileUpload(factory);

    java.util.List<FileItem> items = upload.parseExchange(exchange);

    if(items.size() >= 1){
        exchange.getIn().setBody(items.get(0).getInputStream());

        for (int i = 1; i < items.size(); i++) {
            exchange.setProperty(items.get(i).getName(), items.get(i).getInputStream());
        }
    }
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:18,代码来源:FileUploadProcessor.java

示例8: convertTo

import org.apache.camel.Exchange; //导入依赖的package包/类
@FallbackConverter
public static <T> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) {

    try {
        if (value != null && value.getClass().equals(String.class)) {
            if (value.toString().startsWith("{") || value.toString().startsWith("[")) {
                T result = new UnirestJacksonObjectMapper().readValue(value.toString(), type);

                return result;
            }
        }
    }
    catch(Exception ex){
        return null;
    }
    return null;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:18,代码来源:CustomCamelConverters.java

示例9: testSDPParseOffer

import org.apache.camel.Exchange; //导入依赖的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

示例10: process

import org.apache.camel.Exchange; //导入依赖的package包/类
@Override
public final void process(final Exchange exchange) throws Exception {
    if (exchange.isFailed()) {
        return;
    }

    if (type == null) {
        return;
    }

    final Message message = message(exchange);
    final String bodyAsString = message.getBody(String.class);

    if (bodyAsString == null) {
        return;
    }

    try {
        final Object output = MAPPER.readValue(bodyAsString, type);
        message.setBody(output);
    } catch (final IOException e) {
        exchange.setException(e);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:25,代码来源:UnmarshallProcessor.java

示例11: process

import org.apache.camel.Exchange; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {


    if (exchange.getIn().getHeader("X-Request-ID") == null || exchange.getIn().getHeader("X-Request-ID").toString().isEmpty()) {
        exchange.getIn().removeHeader("X-Request-ID");
    }

    if (exchange.getIn().getHeader("X-Forwarded-For") == null || exchange.getIn().getHeader("X-Forwarded-For").toString().isEmpty()) {
        exchange.getIn().removeHeader("X-Forwarded-For");
    }

    if (exchange.getIn().getHeader("X-Forwarded-Host") == null || exchange.getIn().getHeader("X-Forwarded-Host").toString().isEmpty()) {
        exchange.getIn().removeHeader("X-Forwarded-Host");
    }

}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:18,代码来源:GatewayCamelPostProcessor.java

示例12: evaluateSplitRule

import org.apache.camel.Exchange; //导入依赖的package包/类
private Iterable evaluateSplitRule(Exchange origExchange) {
    final Object splitResult = splitRule.evaluate(origExchange, Object.class);

    if (null == splitResult) {
        return Collections.emptySet();
    }

    if (splitResult instanceof Iterable) {
        return (Iterable) splitResult;
    }

    if (splitResult instanceof Iterator) {
        return () -> (Iterator) splitResult;
    }

    if (splitResult.getClass().isArray()) {
        return Arrays.asList((Object[]) splitResult);
    }

    return Collections.singleton(splitResult);
}
 
开发者ID:oehf,项目名称:ipf-flow-manager,代码行数:22,代码来源:CoreSplitter.java

示例13: testReplayUnhandled

import org.apache.camel.Exchange; //导入依赖的package包/类
@Test
public void testReplayUnhandled() throws InterruptedException {
    mock.expectedMessageCount(0);
    error.expectedMessageCount(0);
    Exchange result = producerTemplate.send("direct:flow-test-5", createExchange("test"));
    mock.assertIsSatisfied();
    error.assertIsSatisfied();
    Long flowId = flowId(result); 
    mock.reset();
    error.reset();
    mock.expectedMessageCount(0);
    error.expectedMessageCount(0);
    flowManager.replayFlow(flowId);
    mock.assertIsSatisfied();
    error.assertIsSatisfied();
}
 
开发者ID:oehf,项目名称:ipf-flow-manager,代码行数:17,代码来源:AbstractFlowReplayTest.java

示例14: configure

import org.apache.camel.Exchange; //导入依赖的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());
        }
    });
}
 
开发者ID:syndesisio,项目名称:connectors,代码行数:17,代码来源:SqlStoredStartRoute.java

示例15: noZipCity

import org.apache.camel.Exchange; //导入依赖的package包/类
@Test
public void noZipCity() throws Exception {
	mockGlobalWeatherResponseBody = "<NewDataSet><Table><Country>TEST</Country><City>XX</City></Table></NewDataSet>";

       Exchange response =  fluentProducerTemplate.send();
       String responseBody = response.getIn().getBody(String.class);
       CitiesResponse citiesResponse = objectMapper.readValue(responseBody,CitiesResponse.class);

       assertEquals(200, response.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE));
       assertEquals("TEST", citiesResponse.getCountry());

       List<City> expectedCities = Arrays.asList(
               new City("XX", Arrays.asList())
       );
       assertEquals(expectedCities, citiesResponse.getCities());
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:17,代码来源:StoredProcTest.java


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