本文整理匯總了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());
}
示例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;
}
示例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);
}
}
示例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);
}
示例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());
}
示例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();
}
}
示例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());
}
}
}
示例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;
}
示例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");
}
示例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);
}
}
示例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);
}
示例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();
}
示例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());
}
});
}
示例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());
}