Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load ExceptionMapper from config placed in resources #187

Open
donduni opened this issue Feb 21, 2017 · 0 comments
Open

Load ExceptionMapper from config placed in resources #187

donduni opened this issue Feb 21, 2017 · 0 comments

Comments

@donduni
Copy link

donduni commented Feb 21, 2017

Hi,

If I understand the source code correctly, it should be possible to specify custom ExceptionMappers from the config file inflector.yaml. I am referring to the Configuration.java class and the following code, where the ExceptionMappers would be loaded iside the read(configLocation) method call.

      ...
        String configLocation = System.getProperty("config", "inflector.yaml");
        System.out.println("loading inflector config from " + configLocation);
        if(configLocation != null) {
          try {
            return read(configLocation);
          }
          catch (Exception e) {
            // continue
            LOGGER.warn("couldn't read inflector config from system property");
          }
        }
      ...

If the config couldn't load from from system property, but instead from resources in the next block, it seems the ExceptionMappers are not loaded at all (as this would happen inside the read(configLocation) method).

      ...
        try {
            // try to load from resources
            URL url = Configuration.class.getClassLoader().getResource("inflector.yaml");
            if(url != null) {
                try {
                    Configuration config = Yaml.mapper().readValue(new File(url.getFile()), Configuration.class);
                    return config;
                } catch (Exception e) {
                  LOGGER.warn("couldn't read inflector config from resource stream");
                  // continue
                }
            }
        } catch (Exception e) {
          LOGGER.warn("Returning default configuration!");
        }
      ...

I am correct here? Would be glad for a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant