org.apache.camel.Message.getMandatoryBody()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(280)

本文整理了Java中org.apache.camel.Message.getMandatoryBody()方法的一些代码示例,展示了Message.getMandatoryBody()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getMandatoryBody()方法的具体详情如下:
包路径:org.apache.camel.Message
类名称:Message
方法名:getMandatoryBody

Message.getMandatoryBody介绍

暂无

代码示例

代码示例来源:origin: org.apache.camel/camel-test

  1. /**
  2. * Asserts that the given exchange has an OUT message of the given body value
  3. *
  4. * @param exchange the exchange which should have an OUT message
  5. * @param expected the expected value of the OUT message
  6. * @throws InvalidPayloadException is thrown if the payload is not the expected class type
  7. */
  8. public static void assertInMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException {
  9. assertNotNull("Should have a response exchange!", exchange);
  10. Object actual;
  11. if (expected == null) {
  12. actual = exchange.getIn().getMandatoryBody();
  13. assertEquals("in body of: " + exchange, expected, actual);
  14. } else {
  15. actual = exchange.getIn().getMandatoryBody(expected.getClass());
  16. }
  17. assertEquals("in body of: " + exchange, expected, actual);
  18. LOG.debug("Received response: " + exchange + " with in: " + exchange.getIn());
  19. }

代码示例来源:origin: org.apache.camel/camel-test

  1. /**
  2. * Asserts that the given exchange has an OUT message of the given body value
  3. *
  4. * @param exchange the exchange which should have an OUT message
  5. * @param expected the expected value of the OUT message
  6. * @throws InvalidPayloadException is thrown if the payload is not the expected class type
  7. */
  8. public static void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException {
  9. assertNotNull("Should have a response exchange!", exchange);
  10. Object actual;
  11. if (expected == null) {
  12. actual = exchange.getOut().getMandatoryBody();
  13. assertEquals("output body of: " + exchange, expected, actual);
  14. } else {
  15. actual = exchange.getOut().getMandatoryBody(expected.getClass());
  16. }
  17. assertEquals("output body of: " + exchange, expected, actual);
  18. LOG.debug("Received response: " + exchange + " with out: " + exchange.getOut());
  19. }

代码示例来源:origin: org.apache.camel/camel-hipchat

  1. private Map<String, String> getCommonHttpPostParam(Exchange exchange) throws InvalidPayloadException {
  2. String format = exchange.getIn().getHeader(HipchatConstants.MESSAGE_FORMAT, "text", String.class);
  3. String notify = exchange.getIn().getHeader(HipchatConstants.TRIGGER_NOTIFY, String.class);
  4. Map<String, String> jsonMap = new HashMap<>(4);
  5. jsonMap.put(HipchatApiConstants.API_MESSAGE, exchange.getIn().getMandatoryBody(String.class));
  6. if (notify != null) {
  7. jsonMap.put(HipchatApiConstants.API_MESSAGE_NOTIFY, notify);
  8. }
  9. jsonMap.put(HipchatApiConstants.API_MESSAGE_FORMAT, format);
  10. return jsonMap;
  11. }

代码示例来源:origin: org.apache.camel/camel-azure

  1. private CloudQueueMessage getCloudQueueMessage(Exchange exchange) throws Exception {
  2. Object body = exchange.getIn().getMandatoryBody();
  3. CloudQueueMessage message = null;
  4. if (body instanceof CloudQueueMessage) {
  5. message = (CloudQueueMessage)body;
  6. } else if (body instanceof String) {
  7. message = new CloudQueueMessage((String)body);
  8. }
  9. if (message == null) {
  10. throw new IllegalArgumentException("Unsupported queue message type:" + body.getClass().getName());
  11. }
  12. return message;
  13. }

代码示例来源:origin: org.apache.camel/camel-beanstalk

  1. @Override
  2. public void act(final Client client, final Exchange exchange) throws NoSuchHeaderException, InvalidPayloadException {
  3. final Integer jobs = exchange.getIn().getMandatoryBody(Integer.class);
  4. final int result = client.kick(jobs);
  5. if (LOG.isDebugEnabled()) {
  6. LOG.debug(String.format("Kick %d jobs. Kicked %d actually.", jobs, result));
  7. }
  8. final Message answer = getAnswerMessage(exchange);
  9. answer.setBody(result, Integer.class);
  10. }
  11. }

代码示例来源:origin: org.apache.camel/camel-couchdb

  1. JsonElement getBodyAsJsonElement(Exchange exchange) throws InvalidPayloadException {
  2. Object body = exchange.getIn().getMandatoryBody();
  3. if (body instanceof String) {
  4. try {
  5. return new JsonParser().parse((String) body);
  6. } catch (JsonSyntaxException jse) {
  7. throw new InvalidPayloadException(exchange, body.getClass());
  8. }
  9. } else if (body instanceof JsonElement) {
  10. return (JsonElement) body;
  11. } else {
  12. throw new InvalidPayloadException(exchange, body != null ? body.getClass() : null);
  13. }
  14. }

代码示例来源:origin: org.apache.camel/camel-mongodb

  1. private Function<Exchange, Object> createDoCommand() {
  2. return exchange -> {
  3. try {
  4. MongoDatabase db = calculateDb(exchange);
  5. BasicDBObject cmdObj = exchange.getIn().getMandatoryBody(BasicDBObject.class);
  6. return db.runCommand(cmdObj);
  7. } catch (InvalidPayloadException e) {
  8. throw new CamelMongoDbException("Invalid payload for command", e);
  9. }
  10. };
  11. }

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-ihe-fhir-pixpdq

  1. /**
  2. * Returns a processor for translating HL7v2 messages to FHIR
  3. * using the given translator instance.
  4. */
  5. public static Processor translatorHL7v2ToFhir(final TranslatorHL7v2ToFhir translator) {
  6. return exchange -> {
  7. // String initial = exchange.getProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, String.class);
  8. ca.uhn.hl7v2.model.Message msg = exchange.getIn().getMandatoryBody(ca.uhn.hl7v2.model.Message.class);
  9. Map<String, Object> parameters = exchange.getIn().getHeaders();
  10. // exchange.setProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, msg);
  11. org.apache.camel.Message resultMessage = Exchanges.resultMessage(exchange);
  12. resultMessage.getHeaders().putAll(exchange.getIn().getHeaders());
  13. resultMessage.setBody(translator.translateHL7v2ToFhir(msg, parameters));
  14. };
  15. }

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-ihe-fhir-dstu2-pixpdq

  1. /**
  2. * Returns a processor for translating HL7v2 messages to FHIR
  3. * using the given translator instance.
  4. */
  5. public static Processor translatorHL7v2ToFhir(final ToFhirTranslator<Message> translator) {
  6. return exchange -> {
  7. // String initial = exchange.getProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, String.class);
  8. ca.uhn.hl7v2.model.Message msg = exchange.getIn().getMandatoryBody(ca.uhn.hl7v2.model.Message.class);
  9. Map<String, Object> parameters = exchange.getIn().getHeaders();
  10. // exchange.setProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, msg);
  11. org.apache.camel.Message resultMessage = Exchanges.resultMessage(exchange);
  12. resultMessage.getHeaders().putAll(exchange.getIn().getHeaders());
  13. resultMessage.setBody(translator.translateToFhir(msg, parameters));
  14. };
  15. }

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-ihe-hl7v2

  1. /**
  2. * Converts outgoing request to a {@link Message}
  3. * and performs some exchange configuration.
  4. */
  5. @Override
  6. public void process(Exchange exchange) throws Exception {
  7. Message msg = exchange.getIn().getMandatoryBody(Message.class);
  8. messageTracer.sendMessage(msg, getEndpoint().getEndpointUri(), (message, span) -> {
  9. exchange.getIn().setBody(message, Message.class);
  10. getWrappedProcessor().process(exchange);
  11. });
  12. }

代码示例来源:origin: org.apache.camel/camel-consul

  1. @InvokeOnHeader(ConsulSessionActions.CREATE)
  2. protected void create(Message message) throws Exception {
  3. setBodyAndResult(
  4. message,
  5. getClient().createSession(
  6. message.getMandatoryBody(Session.class),
  7. message.getHeader(ConsulConstants.CONSUL_DATACENTER, String.class)
  8. )
  9. );
  10. }

代码示例来源:origin: org.apache.camel/camel-mongodb

  1. private Function<Exchange, Object> createDoBulkWrite() {
  2. return exchange -> {
  3. try {
  4. MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange);
  5. Boolean ordered = exchange.getIn().getHeader(MongoDbConstants.BULK_ORDERED, Boolean.TRUE, Boolean.class);
  6. BulkWriteOptions options = new BulkWriteOptions().ordered(ordered);
  7. @SuppressWarnings("unchecked")
  8. List<WriteModel<BasicDBObject>> requests = exchange.getIn().getMandatoryBody((Class<List<WriteModel<BasicDBObject>>>)(Class<?>)List.class);
  9. BulkWriteResult result = dbCol.bulkWrite(requests, options);
  10. return result;
  11. } catch (InvalidPayloadException e) {
  12. throw new CamelMongoDbException("Invalid payload for bulk write", e);
  13. }
  14. };
  15. }

代码示例来源:origin: org.apache.camel/camel-lucene

  1. public void index(Exchange exchange) throws Exception {
  2. LOG.debug("Indexing {}", exchange);
  3. openIndexWriter();
  4. Map<String, Object> headers = exchange.getIn().getHeaders();
  5. add("exchangeId", exchange.getExchangeId(), true);
  6. for (Entry<String, Object> entry : headers.entrySet()) {
  7. String field = entry.getKey();
  8. String value = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, entry.getValue());
  9. add(field, value, true);
  10. }
  11. add("contents", exchange.getIn().getMandatoryBody(String.class), true);
  12. closeIndexWriter();
  13. }

代码示例来源:origin: org.apache.camel/camel-mongodb

  1. private Function<Exchange, Object> createDoSave() {
  2. return exchange -> {
  3. try {
  4. MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange);
  5. BasicDBObject saveObj = exchange.getIn().getMandatoryBody(BasicDBObject.class);
  6. UpdateOptions options = new UpdateOptions().upsert(true);
  7. BasicDBObject queryObject = new BasicDBObject("_id", saveObj.get("_id"));
  8. UpdateResult result = dbCol.replaceOne(queryObject, saveObj, options);
  9. exchange.getIn().setHeader(MongoDbConstants.OID, saveObj.get("_id"));
  10. return result;
  11. } catch (InvalidPayloadException e) {
  12. throw new CamelMongoDbException("Body incorrect type for save", e);
  13. }
  14. };
  15. }

代码示例来源:origin: org.apache.camel/camel-dropbox

  1. private FileMetadata putSingleBody(Exchange exchange, String dropboxPath, DropboxUploadMode mode) throws Exception {
  2. byte[] data = exchange.getIn().getMandatoryBody(byte[].class);
  3. InputStream is = new ByteArrayInputStream(data);
  4. try {
  5. FileMetadata uploadedFile;
  6. WriteMode uploadMode;
  7. if (mode == DropboxUploadMode.force) {
  8. uploadMode = WriteMode.OVERWRITE;
  9. } else {
  10. uploadMode = WriteMode.ADD;
  11. }
  12. uploadedFile = client.files().uploadBuilder(dropboxPath).withMode(uploadMode).uploadAndFinish(is, data.length);
  13. return uploadedFile;
  14. } finally {
  15. IOHelper.close(is);
  16. }
  17. }

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-ihe-hl7v2

  1. @Override
  2. public void process(Exchange exchange) throws Exception {
  3. Message msg = exchange.getIn().getMandatoryBody(Message.class);
  4. messageTracer.receiveMessage(msg, getEndpoint().getEndpointUri(), (message, span) ->
  5. getWrappedProcessor().process(exchange));
  6. }

代码示例来源:origin: org.apache.camel/camel-consul

  1. @InvokeOnHeader(ConsulSessionActions.DESTROY)
  2. protected void destroy(Message message) throws Exception {
  3. String sessionId = message.getHeader(ConsulConstants.CONSUL_SESSION, String.class);
  4. if (ObjectHelper.isEmpty(sessionId)) {
  5. getClient().destroySession(
  6. message.getMandatoryBody(String.class),
  7. message.getHeader(ConsulConstants.CONSUL_DATACENTER, String.class)
  8. );
  9. } else {
  10. getClient().destroySession(
  11. sessionId,
  12. message.getHeader(ConsulConstants.CONSUL_DATACENTER, String.class)
  13. );
  14. }
  15. setBodyAndResult(message, null, true);
  16. }

代码示例来源:origin: org.apache.camel/camel-consul

  1. @InvokeOnHeader(ConsulCatalogActions.DEREGISTER)
  2. protected void deregister(Message message) throws Exception {
  3. getClient().deregister(message.getMandatoryBody(CatalogDeregistration.class));
  4. setBodyAndResult(message, null);
  5. }

代码示例来源:origin: org.apache.camel/camel-consul

  1. @InvokeOnHeader(ConsulPreparedQueryActions.CREATE)
  2. protected void create(Message message) throws Exception {
  3. setBodyAndResult(
  4. message,
  5. getClient().createPreparedQuery(
  6. message.getMandatoryBody(PreparedQuery.class)
  7. )
  8. );
  9. }

代码示例来源:origin: org.apache.camel/camel-consul

  1. @InvokeOnHeader(ConsulCatalogActions.REGISTER)
  2. protected void register(Message message) throws Exception {
  3. getClient().register(message.getMandatoryBody(CatalogRegistration.class));
  4. setBodyAndResult(message, null);
  5. }

相关文章