org.apache.camel.Message类的使用及代码示例

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

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

Message介绍

暂无

代码示例

代码示例来源: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: 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-test

public static Object assertMessageHeader(Message message, String name, Object expected) {
  Object value = message.getHeader(name);
  assertEquals("Header: " + name + " on Message: " + message, expected, value);
  return value;
}

代码示例来源: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: stackoverflow.com

Session session = Session.getInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("mail@tovare.com"));;
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("tov.are.jacobsen@iss.no", false));
msg.setSubject("Heisann "+System.currentTimeMillis());
msg.setText("Med vennlig hilsennTov Are Jacobsen");
msg.setHeader("X-Mailer", "Tov Are's program");
msg.setSentDate(new Date());
SMTPTransport t =
  (SMTPTransport)session.getTransport("smtps");
t.connect("smtp.gmail.com", "admin@tovare.com", "<insert password here>");
t.sendMessage(msg, msg.getAllRecipients());
System.out.println("Response: " + t.getLastServerResponse());
t.close();

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

private void restoreDroplet(Exchange exchange) throws Exception {
  if (ObjectHelper.isEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID))) {
    throw new IllegalArgumentException(DigitalOceanHeaders.IMAGE_ID + " must be specified");
  }
  Action action = getEndpoint().getDigitalOceanClient().restoreDroplet(dropletId, exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID, Integer.class));
  LOG.trace("DropletAction Restore [{}] ", action);
  exchange.getOut().setBody(action);
}

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

protected void doGetHPA(Exchange exchange, String operation) throws Exception {
  HorizontalPodAutoscaler hpa = null;
  String podName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_HPA_NAME, String.class);
  String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
  if (ObjectHelper.isEmpty(podName)) {
    LOG.error("Get a specific hpa require specify an hpa name");
    throw new IllegalArgumentException("Get a specific hpa require specify an hpa name");
  }
  if (ObjectHelper.isEmpty(namespaceName)) {
    LOG.error("Get a specific hpa require specify a namespace name");
    throw new IllegalArgumentException("Get a specific hpa require specify a namespace name");
  }
  hpa = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers().inNamespace(namespaceName).withName(podName).get();
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(hpa);
}

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

protected void doDeleteConfigMap(Exchange exchange, String operation) throws Exception {
    String configMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(configMapName)) {
      LOG.error("Delete a specific config map require specify a config map name");
      throw new IllegalArgumentException("Delete a specific config map require specify a config map name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
      LOG.error("Delete a specific config map require specify a namespace name");
      throw new IllegalArgumentException("Delete a specific config map require specify a namespace name");
    }
    boolean cfMapDeleted = getEndpoint().getKubernetesClient().configMaps().inNamespace(namespaceName).withName(configMapName).delete();

    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(cfMapDeleted);
  }
}

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

protected void doGetNamespace(Exchange exchange, String operation) {
  String namespaceName = exchange.getIn().getHeader(
      KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
  if (ObjectHelper.isEmpty(namespaceName)) {
    LOG.error("Get a specific namespace require specify a namespace name");
    throw new IllegalArgumentException(
        "Get a specific namespace require specify a namespace name");
  }
  Namespace namespace = getEndpoint().getKubernetesClient().namespaces()
      .withName(namespaceName).get();
  
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(namespace);
}

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

protected void doDeleteDeployment(Exchange exchange, String operation) {
  String deploymentName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_NAME, String.class);
  String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
  if (ObjectHelper.isEmpty(deploymentName)) {
    LOG.error("Delete a specific deployment require specify a deployment name");
    throw new IllegalArgumentException("Delete a specific deployment require specify a deployment name");
  }
  if (ObjectHelper.isEmpty(namespaceName)) {
    LOG.error("Delete a specific deployment require specify a namespace name");
    throw new IllegalArgumentException("Delete a specific deployment require specify a namespace name");
  }
  Boolean deployment = getEndpoint().getKubernetesClient().apps().deployments().inNamespace(namespaceName).withName(deploymentName).delete();
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(deployment);
}

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

protected void doGetJob(Exchange exchange, String operation) throws Exception {
  Job job = null;
  String jobName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_JOB_NAME, String.class);
  String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
  if (ObjectHelper.isEmpty(jobName)) {
    LOG.error("Get a specific job require specify a job name");
    throw new IllegalArgumentException("Get a specific job require specify a job name");
  }
  if (ObjectHelper.isEmpty(namespaceName)) {
    LOG.error("Get a specific job require specify a namespace name");
    throw new IllegalArgumentException("Get a specific job require specify a namespace name");
  }
  job = getEndpoint().getKubernetesClient().batch().jobs().inNamespace(namespaceName).withName(jobName).get();
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(job);
}

代码示例来源: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-kubernetes

protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception {
  ConfigMapList configMapsList = null;
  Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
  FilterWatchListMultiDeletable<ConfigMap, ConfigMapList, Boolean, Watch, Watcher<ConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps().inAnyNamespace();
  for (Map.Entry<String, String> entry : labels.entrySet()) {
    configMaps.withLabel(entry.getKey(), entry.getValue());
  }
  configMapsList = configMaps.list();
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(configMapsList.getItems());
}

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

protected static boolean hasParameter(String nextParam, Exchange exchange, Object body) {
  Map<?, ?> bodyMap = safeMap(exchange.getContext().getTypeConverter().tryConvertTo(Map.class, body));
  Map<?, ?> headersMap = safeMap(exchange.getIn().getHeaders());
  if ((nextParam.startsWith("$simple{") || nextParam.startsWith("${")) && nextParam.endsWith("}")) {
    return true;
  } else if (bodyMap.containsKey(nextParam)) {
    return true;
  } else if (headersMap.containsKey(nextParam)) {
    return true;
  }
  return false;
}

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

private Object getMultiInsertBody(Exchange exchange) {
  Object insert;
  // we try List first, because it should be the common case
  insert = exchange.getIn().getBody(List.class);
  if (insert != null) {
    // if the body of type List was obtained, ensure that all items are of type DBObject and cast the List to List<DBObject>
    insert = attemptConvertToList((List<?>) insert, exchange);
  } else {
    insert = exchange.getContext().getTypeConverter().tryConvertTo(BasicDBList.class, exchange, exchange.getIn().getBody());
  }
  if (insert == null) {
    throw new CamelMongoDbException("MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject>");
  }
  return insert;
}

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

protected void doGetBuild(Exchange exchange, String operation) throws Exception {
    Build build = null;
    String buildName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(buildName)) {
      LOG.error("Get a specific Build require specify a Build name");
      throw new IllegalArgumentException("Get a specific Build require specify a Build name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
      LOG.error("Get a specific Build require specify a namespace name");
      throw new IllegalArgumentException("Get a specific Build require specify a namespace name");
    }
    build = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().inNamespace(namespaceName).withName(buildName).get();

    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(build);
  }
}

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

protected void doGetNode(Exchange exchange, String operation) throws Exception {
    Node node = null;
    String pvName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NODE_NAME, String.class);
    if (ObjectHelper.isEmpty(pvName)) {
      LOG.error("Get a specific Node require specify a Node name");
      throw new IllegalArgumentException("Get a specific Node require specify a Node name");
    }
    node = getEndpoint().getKubernetesClient().nodes().withName(pvName).get();

    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(node);
  }
}

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

protected void doGetPersistentVolume(Exchange exchange, String operation)
      throws Exception {
    PersistentVolume pv = null;
    String pvName = exchange.getIn().getHeader(
        KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_NAME,
        String.class);
    if (ObjectHelper.isEmpty(pvName)) {
      LOG.error("Get a specific Persistent Volume require specify a Persistent Volume name");
      throw new IllegalArgumentException(
          "Get a specific Persistent Volume require specify a Persistent Volume name");
    }
    pv = getEndpoint().getKubernetesClient().persistentVolumes().withName(pvName).get();
    
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pv);
  }
}

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

private void compare(long expected, Exchange exchange) {
  long update = exchange.getIn().getBody(Long.class);
  if (ObjectHelper.isEmpty(expected)) {
    throw new IllegalArgumentException("Expected value must be specified");
  }
  exchange.getOut().setBody(this.atomicnumber.compareAndSet(expected, update));
}

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

protected void doList(Exchange exchange, String operation) throws Exception {
  ServiceList servicesList = null;
  String namespaceName = exchange.getIn().getHeader(
      KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
  if (!ObjectHelper.isEmpty(namespaceName)) {
    servicesList = getEndpoint().getKubernetesClient().services()
        .inNamespace(namespaceName).list();
  } else {
    servicesList = getEndpoint().getKubernetesClient().services().inAnyNamespace()
        .list();
  }
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(servicesList.getItems());
}

相关文章