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

Fix for jigsaw service loading problem with webserver. #99

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}