本文整理汇总了Java中org.apache.camel.Message.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getBody方法的具体用法?Java Message.getBody怎么用?Java Message.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.Message
的用法示例。
在下文中一共展示了Message.getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.camel.Message; //导入方法依赖的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);
}
}
示例2: process
import org.apache.camel.Message; //导入方法依赖的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);
}
}
示例3: sendOutMessage
import org.apache.camel.Message; //导入方法依赖的package包/类
private void sendOutMessage(Exchange exchange) throws QFJException {
Message camelMessage = exchange.getOut();
quickfix.Message quickfixjMessage = camelMessage.getBody(quickfix.Message.class);
log.debug("Sending FIX message reply: {}", quickfixjMessage);
SessionID messageSessionID = exchange.getIn().getHeader("SessionID", SessionID.class);
Session session = getSession(messageSessionID);
if (session == null) {
throw new IllegalStateException("Unknown session: " + messageSessionID);
}
if (!session.send(quickfixjMessage)) {
throw new CannotSendException("Could not send FIX message reply: " + quickfixjMessage.toString());
}
}
示例4: process
import org.apache.camel.Message; //导入方法依赖的package包/类
@SuppressWarnings({"unused", "unchecked"})
public void process(Exchange exchange) {
Message in = exchange.getIn();
Map<String, String> exchangeData = in.getBody(Map.class);
String content_header = exchangeData.get("content_header");
StringBuilder data = new StringBuilder();
if(content_header != null) {
data.append(START_DIV).append(HEADER_STYLE).append(content_header).append(END_DIV);
}
data.append(exchangeData.get("body"));
String content_footer = exchangeData.get("content_footer");
if(content_footer != null) {
data.append(START_DIV).append(FOOTER_STYLE).append(content_footer).append(END_DIV);
}
exchangeData.put("body", data.toString());
in.setBody(exchangeData);
}
示例5: process
import org.apache.camel.Message; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
Message inMessage = exchange.getIn();
// Get the operation name from in message
String operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);
if ("getCustomer".equals(operationName)) {
processGetCustomer(exchange);
} else if ("updateCustomer".equals(operationName)) {
assertEquals("Get a wrong customer message header", "header1;header2", inMessage.getHeader("test"));
String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
assertEquals("Get a wrong http method", "PUT", httpMethod);
Customer customer = inMessage.getBody(Customer.class);
assertNotNull("The customer should not be null.", customer);
// Now you can do what you want on the customer object
assertEquals("Get a wrong customer name.", "Mary", customer.getName());
// set the response back
exchange.getOut().setBody(Response.ok().build());
}
}
示例6: testCamel
import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void testCamel() throws Exception {
results.expectedMessageCount(4);
results.assertIsSatisfied();
int counter = 0;
List<Exchange> list = results.getReceivedExchanges();
for (Exchange exchange : list) {
Message in = exchange.getIn();
Map<?, ?> body = in.getBody(Map.class);
assertNotNull("Should have found body as a Map but was: " + ObjectHelper.className(in.getBody()), body);
assertEquals("ITEM_DESC result(" + counter + ")", expectedItemDesc[counter], body.get("ITEM_DESC"));
LOG.info("Result: " + counter + " = " + body);
counter++;
}
}
示例7: notify
import org.apache.camel.Message; //导入方法依赖的package包/类
public Object notify(String eventId, Long docId, Message request, int delay) {
try {
String requestStr = null;
if ("org.apache.camel.component.cxf.CxfPayload".equals(request.getBody().getClass().getName())) {
// special handling to extract XML
@SuppressWarnings("rawtypes")
CxfPayload cxfPayload = (CxfPayload) request.getBody();
requestStr = DomHelper.toXml((Node)cxfPayload.getBody().get(0));
}
else {
requestStr = request.getBody(String.class);
}
notifyProcesses(eventId, docId, requestStr, delay);
return getResponse(0, "Success");
}
catch (Exception ex) {
logger.severeException(ex.getMessage(), ex);
return getResponse(1, ex.toString());
}
}
示例8: testCamel
import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void testCamel() throws Exception {
results.expectedMessageCount(4);
results.assertIsSatisfied();
int counter = 0;
List<Exchange> list = results.getReceivedExchanges();
for (Exchange exchange : list) {
Message in = exchange.getIn();
assertEquals("counter", in.getHeader("camelFlatpackCounter"), counter);
Map<?, ?> body = in.getBody(Map.class);
assertNotNull("Should have found body as a Map but was: " + ObjectHelper.className(in.getBody()), body);
assertEquals("ITEM_DESC", expectedItemDescriptions[counter], body.get("ITEM_DESC"));
LOG.info("Result: " + counter + " = " + body);
counter++;
}
}
示例9: consumeStockQuoteWebserviceInOnly
import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void consumeStockQuoteWebserviceInOnly() throws Exception {
inOnlyEndpoint.expectedExchangePattern(ExchangePattern.InOnly);
inOnlyEndpoint.expectedMessageCount(1);
template.sendBodyAndHeader("direct:stockQuoteWebserviceInOnly", xmlRequestForGoogleStockQuote, "foo", "bar");
inOnlyEndpoint.assertIsSatisfied();
Message in = inOnlyEndpoint.getReceivedExchanges().get(0).getIn();
Object result = in.getBody();
assertNotNull(result);
assertTrue(result instanceof String);
String resultMessage = (String) result;
assertTrue(resultMessage.contains("Google Inc."));
Object bar = in.getHeader("foo");
assertEquals("The header value should have been preserved", "bar", bar);
}
示例10: determineAlphabet
import org.apache.camel.Message; //导入方法依赖的package包/类
private Alphabet determineAlphabet(Message message) {
String body = message.getBody(String.class);
byte alphabet = getProvidedAlphabet(message);
Charset charset = getCharsetForMessage(message);
if (charset == null) {
charset = defaultCharset;
}
Alphabet alphabetObj;
if (alphabet == SmppConstants.UNKNOWN_ALPHABET) {
alphabetObj = Alphabet.ALPHA_UCS2;
if (isLatin1Compatible(charset)) {
byte[] messageBytes = body.getBytes(charset);
if (SmppUtils.isGsm0338Encodeable(messageBytes)) {
alphabetObj = Alphabet.ALPHA_DEFAULT;
}
}
} else {
alphabetObj = Alphabet.valueOf(alphabet);
}
return alphabetObj;
}
示例11: jsonMarshalIfRequired
import org.apache.camel.Message; //导入方法依赖的package包/类
/**
* Lets marshal the body to JSON using Jackson if we require it.
* <br>
* The current rules are to only marshal to JSON if we don't have a {@link Exchange#CONTENT_TYPE} header.
* If we can convert the body to a String then we test if its already JSON and if not we marshal it using the JSON
* data format with the Jackson library
*/
public void jsonMarshalIfRequired(Exchange exchange) throws Exception {
Message in = exchange.getIn();
if (in == null) {
return;
}
String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
if (!Strings.isEmpty(contentType)) {
// lets preserve existing content types as it could be XML, YAML or something else
return;
}
Object body = in.getBody();
if (body != null) {
if (isPossibleJsonClass(exchange, body.getClass(), body)) {
try {
String text = in.getBody(String.class);
if (text != null) {
if (isJsonLookingString(text.trim())) {
in.setHeader(Exchange.CONTENT_TYPE, JSON_CONTENT_TYPE);
}
in.setBody(text);
return;
}
} catch (Exception e) {
// ignore
}
}
in.setHeader(Exchange.CONTENT_TYPE, JSON_CONTENT_TYPE);
jsonMarshalProducer.process(exchange);
}
}
示例12: process
import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(final Exchange exchange) throws Exception {
final Message in = exchange.getIn();
final String body = in.getBody(String.class);
if (body == null) {
return;
}
final JsonNode payload;
try {
payload = MAPPER.readTree(body);
} catch (final JsonProcessingException e) {
LOG.warn("Unable to parse payload, continuing without conversion", e);
return;
}
payload.with("parameters").fields().forEachRemaining(e -> in.setHeader(e.getKey(), e.getValue().asText()));
final JsonNode requestBody = payload.get("body");
if (requestBody == null) {
in.setBody(null);
} else {
in.setBody(MAPPER.writeValueAsString(requestBody));
}
}
示例13: process
import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(final Exchange exchange) throws Exception {
// parse input json and extract Id field
final Message in = exchange.getIn();
final String body = in.getBody(String.class);
if (body == null) {
return;
}
final ObjectNode node = (ObjectNode) MAPPER.readTree(body);
final String idPropertyName = determineIdProperty(exchange);
final JsonNode idProperty = node.remove(idPropertyName);
if (idProperty == null) {
exchange.setException(
new SalesforceException("Missing option value for Id or " + SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, 404));
return;
}
final String idValue = idProperty.textValue();
if ("Id".equals(idPropertyName)) {
in.setHeader(SalesforceEndpointConfig.SOBJECT_ID, idValue);
} else {
in.setHeader(SalesforceEndpointConfig.SOBJECT_EXT_ID_VALUE, idValue);
}
// base fields are not allowed to be updated
clearBaseFields(node);
// update input json
in.setBody(MAPPER.writeValueAsString(node));
}
示例14: process
import org.apache.camel.Message; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
Map<String,Object> tuple= (Map<String, Object>) in.getBody();
MoneyTransfer mt = new MoneyTransfer();
mt.setId((Long)tuple.get(MoneyTransfer.FIELD_ID));
mt.setKeycode((String)tuple.get(MoneyTransfer.FIELD_KEYCODE));
mt.setPaymentMethod((String)tuple.get(MoneyTransfer.FIELD_PAYMENT_METHOD));
mt.setAmount_hf_sender_currency((BigDecimal)tuple.get(MoneyTransfer.FIELD_AMOUNT_HF_SENDER_CUR));
mt.setStatus((String)tuple.get(MoneyTransfer.FIELD_STATUS));
in.setBody(mt);
in.setHeader(InfinispanConstants.KEY, mt.getKeycode());
}
示例15: render
import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public String render(PlatformMessage message) {
Message input = message.getExchange().getIn();
if (input.getBody() instanceof InputStream) {
return render((InputStream)input.getBody());
} else {
return input.getBody(String.class);
}
}