All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.appcrossings.config.AppConfigServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.appcrossings.config;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

@Service
public class AppConfigServiceImpl implements AppConfigService {

  private static final Logger logger = LoggerFactory.getLogger(AppConfigService.class);

  @Value("${filesystem.root:classpath:/configs}")
  private String filesystemRoot;

  @Override
  public Response getRawProperties(String path) {

    logger.debug("Requested path" + path);

    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource r = loader.getResource(filesystemRoot + "/" + path);

    try {

      byte[] content = IOUtils.toByteArray(r.getInputStream());
      return Response.status(Status.OK).entity(content).build();

    } catch (FileNotFoundException not) {

      logger.info(not.getMessage());
      return Response.status(Status.NOT_FOUND).build();

    } catch (IOException io) {

      logger.error(io.getMessage());
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();

    }


  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy