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

x33g5p2x  于2022-01-18 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(124)

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

Converter介绍

暂无

代码示例

代码示例来源:origin: org.nhind/direct-msg-monitor

/**
   * Converts an Exchange to a collection of Tx objects.
   * @param exchange The exchange that contains a collection of Tx object in the "in" body.
   * @return The collections of Tx objects contained in the exchange.
   */
  @Converter 
  public static Collection<Tx> toTxCollection(Exchange exchange)
  {
    @SuppressWarnings("unchecked")
    final Collection<Tx> txs = exchange.getIn().getBody(Collection.class);
    
    return txs;
  }
}

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

@Converter
public static StAXSource toStAXSource(ByteBuf buffer, Exchange exchange) {
  InputStream is = toInputStream(buffer, exchange);
  return exchange.getContext().getTypeConverter().convertTo(StAXSource.class, exchange, is);
}

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

@Converter
public final class ResourceConverter {

  private ResourceConverter() {
  }

  @Converter
  public static InputStream convertToInputStream(Resource resource) throws IOException {
    return resource.getInputStream();
  }

}

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

/**
 * A transformation method to convert a person document into a customer
 * entity
 */
@Converter
public static CustomerEntity toCustomer(PersonDocument doc, Exchange exchange) throws Exception {
  EntityManager entityManager = exchange.getProperty(JpaConstants.ENTITY_MANAGER, EntityManager.class);
  TransactionTemplate transactionTemplate = exchange.getContext().getRegistry().lookupByNameAndType("transactionTemplate", TransactionTemplate.class);
  String user = doc.getUser();
  CustomerEntity customer = findCustomerByName(transactionTemplate, entityManager, user);
  // let's convert information from the document into the entity bean
  customer.setUserName(user);
  customer.setFirstName(doc.getFirstName());
  customer.setSurname(doc.getLastName());
  customer.setCity(doc.getCity());
  LOG.info("Created object customer: {}", customer);
  return customer;
}

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

@Converter
public static InputStream toInputStream(ClinicalDocument document, Exchange exchange) {
  Charset charset = Charset.defaultCharset();
  if (exchange != null) {
    String charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
    if (charsetName != null) {
      charset = Charset.forName(charsetName);
    }
  }
  return new ByteArrayInputStream(renderer.render(document, (Object[]) null).getBytes(charset));
}

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

@Converter
public static InputStream toInputStream(Response response, Exchange exchange) {
  Object obj = response.getEntity();
  
  if (obj == null) {
    return null;
  }
  
  if (obj instanceof InputStream) {
    // short circuit the lookup
    return (InputStream)obj;
  }
  
  TypeConverterRegistry registry = exchange.getContext().getTypeConverterRegistry();
  TypeConverter tc = registry.lookup(InputStream.class, obj.getClass());
  
  if (tc != null) {
    return tc.convertTo(InputStream.class, exchange, obj);
  }
  
  return null;
}

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

@Converter
public FaultException convertExchangeToFaultException(Exchange exchange) {
  Exception exception = exchange.getException();
  if (exception == null) {
    return new FaultException("Unknown error", JbiBinding.getMessageExchange(exchange), null);
  } else {
    FaultException result = new FaultException(exception.getMessage(), JbiBinding.getMessageExchange(exchange), null);
    result.setStackTrace(exception.getStackTrace());
    return result;
  }
}

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

@Converter
public static BasicDBObject fromInputStreamToDBObject(InputStream is, Exchange exchange) throws Exception {
  BasicDBObject answer;
  try {
    byte[] input = IOConverter.toBytes(is);
    
    if (isBson(input)) {
      BSONCallback callback = new JSONCallback();
      new BasicBSONDecoder().decode(input, callback);
      answer = (BasicDBObject) callback.get();
    } else {
      answer = (BasicDBObject) JSON.parse(IOConverter.toString(input, exchange));
    }
  } finally {
    // we need to make sure to close the input stream
    IOHelper.close(is, "InputStream", LOG);
  }
  return answer;
}

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

@Converter
public static String soapMessageToString(final SOAPMessage soapMessage, Exchange exchange) throws SOAPException, IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  soapMessage.writeTo(baos);
  return baos.toString(IOHelper.getCharsetName(exchange));
}

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

@Converter
public static Document toDocument(ByteBuf buffer, Exchange exchange) {
  InputStream is = toInputStream(buffer, exchange);
  return exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, is);
}

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

@Converter
public static InputStream convertToInputStream(Resource resource) throws IOException {
  return resource.getInputStream();
}

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

@Converter
public static InputStream toInputStream(HttpServletRequest request, Exchange exchange) throws IOException {
  if (request == null) {
    return null;
  }
  InputStream is = request.getInputStream();
  if (is != null && is.available() <= 0) {
    // there is no data, so we cannot uncompress etc.
    return is;
  }
  if (exchange == null || !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
    String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING);
    return GZIPHelper.uncompressGzip(contentEncoding, is);
  } else {
    return is;
  }
}

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

@Converter
public static Payload toPayload(String str, Exchange ex) throws UnsupportedEncodingException {
  return toPayload(str.getBytes(IOHelper.getCharsetName(ex)));
}

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

@Converter
public static String toString(ChannelBuffer buffer, Exchange exchange) throws UnsupportedEncodingException {
  byte[] bytes = toByteArray(buffer, exchange);
  // use type converter as it can handle encoding set on the Exchange
  if (exchange != null) {
    return exchange.getContext().getTypeConverter().convertTo(String.class, exchange, bytes);
  }
  return new String(bytes, "UTF-8");
}

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

/**
 * Fallback converter for any unlisted object, using String default mapping.
 */
@Converter
public static OutgoingMessage toOutgoingMessage(Object message, Exchange exchange) {
  String content = exchange.getIn().getBody(String.class);
  return toOutgoingMessage(content, exchange);
}

代码示例来源:origin: io.rhiot/camel-pubnub

@Converter
public static JSONObject toJsonObject(String json) {
  try {
    return new JSONObject(json);
  } catch (JSONException e) {
    return null;
  }
}

代码示例来源:origin: org.milyn/milyn-smooks-all

@SuppressWarnings("rawtypes")
@Converter
public static List toList(JavaResult.ResultMap javaResult, Exchange exchange)
{
  String resultKey = (String) exchange.getProperty(SMOOKS_RESULT_KEY);
  if (resultKey != null)
  {
    return (List) getResultsFromJavaResult(javaResult, resultKey);
  } else
  {
    return (List) getSingleObjectFromJavaResult(javaResult);
  }
}

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

@Converter
public static Document toDocument(ChannelBuffer buffer, Exchange exchange) {
  InputStream is = toInputStream(buffer, exchange);
  return exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, is);
}

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

@Converter
public static IndexRequest toIndexRequest(Object document, Exchange exchange) {
  return createIndexRequest(document, exchange)
    .id(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_ID, String.class));
}

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

@Converter
public static HttpServletResponse toServletResponse(Message message) {
  if (message == null) {
    return null;
  }
  return message.getHeader(Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class);
}

相关文章

微信公众号

最新文章

更多

Converter类方法