Skip to content

Commit

Permalink
Merge pull request eclipse#174 from MicroProfileJWT/master
Browse files Browse the repository at this point in the history
Make the loading of the app data more tolerant to the class loading
  • Loading branch information
Andy Gumbrecht authored Sep 27, 2017
2 parents 1d21f2f + 7186fba commit 6bb443e
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package io.microprofile.showcase.bootstrap;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -29,12 +31,23 @@
public class BootstrapDataProducer {

@Produces
public BootstrapData load() {
final URL schedule = Thread.currentThread().getContextClassLoader().getResource("schedule.json");
assert schedule !=null : "Failed to load 'schedule.json'";

final URL speaker = Thread.currentThread().getContextClassLoader().getResource("speaker.json");
assert speaker !=null : "Failed to load 'speaker.json'";
public BootstrapData load() throws IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL schedule = loader.getResource("schedule.json");
if (schedule == null) {
schedule = BootstrapDataProducer.class.getResource("/schedule.json");
if (schedule == null) {
throw new IllegalStateException("Failed to load 'schedule.json'");
}
}

URL speaker = loader.getResource("speaker.json");
if (speaker == null) {
speaker = BootstrapDataProducer.class.getResource("/speaker.json");
if (speaker == null) {
throw new IllegalStateException("Failed to load 'speaker.json'");
}
}

final Parser parser = new Parser();
final BootstrapData data = parser.parse(schedule, speaker);
Expand Down

0 comments on commit 6bb443e

Please sign in to comment.