Skip to content

Commit

Permalink
Fix for jigsaw service loading problem with webserver.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer committed Oct 8, 2018
1 parent b56b590 commit 25bb7a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions common/common/src/main/java/io/helidon/common/SpiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ private SpiHelper() {
* @param <T> service type
* @return the loaded service
* @throws IllegalStateException if none implementation found
* @deprecated Use direct access to {@link ServiceLoader} or have such a helper in your module, as from jigsaw this is not
* allowed
*/
@Deprecated
public static <T> T loadSpi(Class<T> service) {
ServiceLoader<T> servers = ServiceLoader.load(service);
Iterator<T> serversIt = servers.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package io.helidon.webserver;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;

import io.helidon.common.SpiHelper;
import io.helidon.common.http.ContextualRegistry;
import io.helidon.webserver.spi.WebServerFactory;

Expand Down Expand Up @@ -311,7 +312,7 @@ public WebServer build() {
throw new IllegalStateException("No server socket configuration found for named routings: " + unpairedRoutings);
}

WebServer result = SpiHelper.loadSpi(WebServerFactory.class)
WebServer result = loadFactory()
.newWebServer(configuration == null
? ServerBasicConfig.DEFAULT_CONFIGURATION
: configuration,
Expand All @@ -321,5 +322,14 @@ public WebServer build() {
}
return result;
}

private WebServerFactory loadFactory() {
Iterator<WebServerFactory> implementations = ServiceLoader.load(WebServerFactory.class).iterator();
if (implementations.hasNext()) {
return implementations.next();
}

throw new IllegalStateException("No implementation found for SPI: " + WebServerFactory.class.getName());
}
}
}

0 comments on commit 25bb7a1

Please sign in to comment.