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

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

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

Message.setBody介绍

暂无

代码示例

代码示例来源:origin: deeplearning4j/nd4j

@Override
  public void process(Exchange exchange) throws Exception {
    byte[] body2 = (byte[]) exchange.getIn().getBody();
    String body = new String(body2);
    INDArray arr = Nd4jBase64.fromBase64(body);
    exchange.getIn().setBody(arr);
  }
}).to("direct:receive");

代码示例来源:origin: deeplearning4j/nd4j

@Override
  public void process(Exchange exchange) throws Exception {
    final INDArray arr = (INDArray) exchange.getIn().getBody();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    Nd4j.write(arr, dos);
    byte[] bytes = bos.toByteArray();
    String base64 = Base64.encodeBase64String(bytes);
    exchange.getIn().setBody(base64, String.class);
    String id = UUID.randomUUID().toString();
    exchange.getIn().setHeader(KafkaConstants.KEY, id);
    exchange.getIn().setHeader(KafkaConstants.PARTITION_KEY, id);
  }
}).to(kafkaUri);

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

protected void setBodyAndResult(Message message, Object body, boolean result) throws Exception {
  message.setHeader(ConsulConstants.CONSUL_RESULT, result);
  if (body != null) {
    message.setBody(body);
  }
}

代码示例来源:origin: org.apache.camel/camel-example-loan-broker

public void process(Exchange exchange) throws Exception {
  String bankName = exchange.getIn().getHeader(Constants.PROPERTY_BANK, String.class);
  String ssn = exchange.getIn().getHeader(Constants.PROPERTY_SSN, String.class);
  Double rate = exchange.getIn().getHeader(Constants.PROPERTY_RATE, Double.class);
  String answer = "The best rate is [ssn:" + ssn + " bank:" + bankName + " rate:" + rate + "]";
  exchange.getOut().setBody(answer);
}

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

private void add(Exchange exchange) {
    final Object body = exchange.getIn().getBody();
    exchange.getOut().setBody(ringbuffer.add(body));
  }
}

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

@Override
public void onResponse(Object response, Map<String, String> responseHeaders) {
  // producer returns a single response, even for methods with List return types
  exchange.getOut().setBody(response);
  // copy headers
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  
  // Add http response headers
  exchange.getOut().setHeader(Olingo2Constants.PROPERTY_PREFIX + RESPONSE_HTTP_HEADERS, responseHeaders);
  interceptResult(response, exchange);
  callback.done(false);
}

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

@Override
  void execute(Cache<Object, Object> cache, Exchange exchange) {
    exchange.getIn().setBody(
      cache.get(exchange.getIn().getHeader(JCacheConstants.KEY))
    );
  }
},

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

private void setResult(Message message, Object result) {
    String resultHeader = message.getHeader(InfinispanConstants.RESULT_HEADER, configuration::getResultHeader, String.class);
    if (resultHeader != null) {
      message.setHeader(resultHeader, result);
    } else {
      message.setBody(result);
    }
  }
}

代码示例来源:origin: org.metaeffekt.dcc/dcc-agent-core

/**
 * {@inheritDoc}
 */
protected void doHandleFailedExchange(Exchange exchange, Throwable t) {
  final int errorCode = mapToHttpErrorCode(t);
  exchange.getOut().setBody(String.format("Exception [%s] occured. Message was [%s]", t.getClass().getName(), t.getMessage()));
  exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, (int) errorCode);
}

代码示例来源:origin: OpenNMS/opennms

@Test(timeout=60000)
public void checkDefinedTimeout() throws Exception {
  System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "12345");
  CamelContext context = getContext();
  CamelRpcRequest<EchoRequest,EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest());
  CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor();
  DefaultExchange defaultExchange = new DefaultExchange(context);
  defaultExchange.getIn().setBody(wrapper);
  camelRpcClientPreProcessor.process(defaultExchange);
  context.stop();
  assertEquals(12345L, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER));
}

代码示例来源:origin: eu.limetri.platform/platform-server

@Override
public void process(Exchange exchange) throws Exception {
  Object object = exchange.getIn().getBody();
  String xml = marshall(object);
  exchange.getOut().setBody(xml);
  exchange.getOut().setHeader("Content-Type", MediaType.APPLICATION_XML);
}

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

/**
 * A strategy method to populate an exchange with some example values for use
 * by language plugins
 */
protected void populateExchange(Exchange exchange) {
  Message in = exchange.getIn();
  in.setHeader("foo", "abc");
  in.setHeader("bar", 123);
  in.setBody("<hello id='m123'>world!</hello>");
}

代码示例来源:origin: org.switchyard.quickstarts/switchyard-soap-mtom

@Override
public void process(Exchange exchange) throws Exception {
  String newFileName = "internal-resized-switchyard.jpeg";
  Image input = exchange.getIn().getBody(Image.class);
  exchange.getOut().addAttachment(newFileName, new DataHandler(input, "image/jpeg"));
  exchange.getOut().setBody(newFileName);
}

代码示例来源:origin: redhat-developer-demos/istio-tutorial

private void handleHttpFailure(Exchange exchange) {
    HttpOperationFailedException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class);
    exchange.getOut().setHeaders(exchange.getIn().getHeaders());
    exchange.getOut().setBody(String.format(RESPONSE_STRING_FORMAT,
        String.format("%d %s", e.getStatusCode(), e.getResponseBody())
    ));
  }
}

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

@Override
  void execute(Cache<Object, Object> cache, Exchange exchange) {
    exchange.getIn().setBody(
      cache.getAll(
        exchange.getIn().getHeader(JCacheConstants.KEYS, Set.class))
    );
  }
},

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

public void process(Exchange exchange) {
    Message in = exchange.getIn();
    in.setBody(body);
  }
});

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

private void processAndTransferResult(Object result, Exchange exchange, MongoDbOperation operation) {
  // determine where to set the WriteResult: as the OUT body or as an IN message header
  if (isWriteOperation(operation) && endpoint.isWriteResultAsHeader()) {
    exchange.getOut().setHeader(MongoDbConstants.WRITERESULT, result);
  } else {
    exchange.getOut().setBody(result);
  }
}

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

private void setResult(Message message, boolean success, Object result, Object oldValue) {
    message.setHeader(CaffeineConstants.ACTION_SUCCEEDED, success);
    message.setHeader(CaffeineConstants.ACTION_HAS_RESULT, oldValue != null || result != null);

    if (oldValue != null) {
      message.setHeader(CaffeineConstants.OLD_VALUE, oldValue);
    }
    if (result != null) {
      message.setBody(result);
    }
  }
}

代码示例来源:origin: eu.limetri.platform/platform-server

@Override
public void process(Exchange exchange) throws Exception {
  Object object = exchange.getIn().getBody();
  String json = marshall(object);
  exchange.getOut().setHeader("Content-Type", MediaType.APPLICATION_JSON);
  exchange.getOut().setBody(json);
}

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

public void process(Exchange exchange) {
    Message in = exchange.getIn();
    in.setBody(body);
    for (Map.Entry<String, Object> entry : headers.entrySet()) {
      in.setHeader(entry.getKey(), entry.getValue());
    }
  }
});

相关文章