@Override
 public Map getMapping(String indexName, String type) {
   Assert.notNull(indexName, "No index defined for putMapping()");
   Assert.notNull(type, "No type defined for putMapping()");
   Map mappings = null;
   try {
     mappings =
         client
             .admin()
             .indices()
             .getMappings(new GetMappingsRequest().indices(indexName).types(type))
             .actionGet()
             .getMappings()
             .get(indexName)
             .get(type)
             .getSourceAsMap();
   } catch (Exception e) {
     throw new ElasticsearchException(
         "Error while getting mapping for indexName : "
             + indexName
             + " type : "
             + type
             + " "
             + e.getMessage());
   }
   return mappings;
 }
  public static String readFileFromClasspath(String url) {
    StringBuilder stringBuilder = new StringBuilder();

    BufferedReader bufferedReader = null;

    try {
      ClassPathResource classPathResource = new ClassPathResource(url);
      InputStreamReader inputStreamReader =
          new InputStreamReader(classPathResource.getInputStream());
      bufferedReader = new BufferedReader(inputStreamReader);
      String line;

      while ((line = bufferedReader.readLine()) != null) {
        stringBuilder.append(line);
      }
    } catch (Exception e) {
      logger.debug(String.format("Failed to load file from url: %s: %s", url, e.getMessage()));
      return null;
    } finally {
      if (bufferedReader != null)
        try {
          bufferedReader.close();
        } catch (IOException e) {
          logger.debug(String.format("Unable to close buffered reader.. %s", e.getMessage()));
        }
    }

    return stringBuilder.toString();
  }
Exemplo n.º 3
0
 private Resource getScriptResource(final String uri) {
   try {
     if (startsWithIgnoreCase(uri, "classpath:")) {
       final String classPathUri = substringAfter(uri, "classpath:");
       log.info("Loading route list from classpath uri {}.", classPathUri);
       Resource resource = new ClassPathResource(classPathUri);
       log.debug("Resolved '{}' to '{}'.", classPathUri, resource);
       return resource;
     }
     log.info("Loading route list from file system path {}.", uri);
     return new FileSystemResource(uri);
   } catch (Exception e) {
     throw new RuntimeException(e.getLocalizedMessage(), e);
   }
 }