/**
  * 填充数据
  *
  * @param list 数据库有效数据列表
  * @return 填充的数据
  */
 private <T extends TrendValue> List<T> fulldata(
     List<T> list, DateFormat format, int field, Date start, Date end, Class<T> clazz) {
   Map<String, T> map = tomap(list);
   Calendar calendar = Calendar.getInstance();
   calendar.setTime(start);
   List<T> nlist = new ArrayList<>();
   while (calendar.getTime().before(end)) {
     String keytime = format.format(calendar.getTime());
     T value = map.get(keytime);
     if (value == null) {
       value = AfReflecter.newInstance(clazz);
       value.setEmpty();
       value.setDate(keytime);
       value.setTime(calendar.getTime());
       nlist.add(value);
     } else {
       nlist.add(value);
       map.remove(keytime);
     }
     calendar.add(field, 1);
   }
   for (Map.Entry<String, T> entry : map.entrySet()) {
     nlist.add(entry.getValue());
   }
   return nlist;
 }
Пример #2
0
  /**
   * Checks for collection typed header values and convert them to comma delimited String. We need
   * this for further header processing e.g when forwarding headers to JMS queues.
   *
   * @param headers the http request headers.
   */
  private Map<String, Object> convertHeaderTypes(Map<String, ?> headers) {
    Map<String, Object> convertedHeaders = new HashMap<String, Object>();

    for (Entry<String, ?> header : headers.entrySet()) {
      if (header.getValue() instanceof Collection<?>) {
        Collection<?> value = (Collection<?>) header.getValue();
        convertedHeaders.put(header.getKey(), StringUtils.collectionToCommaDelimitedString(value));
      } else if (header.getValue() instanceof MediaType) {
        convertedHeaders.put(header.getKey(), header.getValue().toString());
      } else {
        convertedHeaders.put(header.getKey(), header.getValue());
      }
    }

    return convertedHeaders;
  }
Пример #3
0
  /**
   * Generates the Http response message from given Spring Integration message.
   *
   * @param responseMessage message received from the message handler
   * @return an HTTP entity as response
   */
  private ResponseEntity<String> generateResponse(Message<?> responseMessage) {
    if (responseMessage == null) {
      return new ResponseEntity<String>(HttpStatus.OK);
    }

    HttpHeaders httpHeaders = new HttpHeaders();
    headerMapper.fromHeaders(responseMessage.getHeaders(), httpHeaders);

    Map<String, ?> messageHeaders = responseMessage.getHeaders();
    for (Entry<String, ?> header : messageHeaders.entrySet()) {
      if (!header.getKey().startsWith(CitrusMessageHeaders.PREFIX)
          && !MessageUtils.isSpringInternalHeader(header.getKey())
          && !httpHeaders.containsKey(header.getKey())) {
        httpHeaders.add(header.getKey(), header.getValue().toString());
      }
    }

    if (httpHeaders.getContentType() == null) {
      httpHeaders.setContentType(
          MediaType.parseMediaType(
              contentType.contains("charset") ? contentType : contentType + ";charset=" + charset));
    }

    HttpStatus status = HttpStatus.OK;
    if (responseMessage.getHeaders().containsKey(CitrusHttpMessageHeaders.HTTP_STATUS_CODE)) {
      status =
          HttpStatus.valueOf(
              Integer.valueOf(
                  responseMessage
                      .getHeaders()
                      .get(CitrusHttpMessageHeaders.HTTP_STATUS_CODE)
                      .toString()));
    }

    responseCache =
        new ResponseEntity<String>(responseMessage.getPayload().toString(), httpHeaders, status);

    return responseCache;
  }