Skip to content

Commit

Permalink
Make the loading of the app data more tolerant to the class loading b…
Browse files Browse the repository at this point in the history
…y falling

back to the BootstrapDataProducer.class.getResource(String) method if TCCL fails.

Signed-off-by: Scott Stark <[email protected]>
  • Loading branch information
starksm64 committed Sep 27, 2017
1 parent 1d21f2f commit ec565e1
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package io.microprofile.showcase.bootstrap;

import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -29,12 +30,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 ec565e1

Please sign in to comment.