aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2018-09-05 10:49:21 +0200
committerGitHub <noreply@github.com>2018-09-05 10:49:21 +0200
commit245d4aa6cda2c635c28dd8d7f2f64fb6de1c6d94 (patch)
treeec7676d3c35133d433fd10b3d8e9351fabd03170
parent57bf51e7af39a0df3807bba7f00a56a08cf6d62d (diff)
parent83df858b6637e76051854e15a1c9e5423a36e1a8 (diff)
Merge pull request #6792 from vespa-engine/gjoranv/remove-jersey1
Remove unsupported Jersey 1 and convert unit test to Jersey 2.
-rwxr-xr-xconfig-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java22
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/jersey/JerseyHandler.java28
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java54
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java6
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java5
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/MultipleRestApisTest.java121
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java156
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java8
-rw-r--r--container-disc/src/main/resources/configdefinitions/jersey-init.def8
9 files changed, 58 insertions, 350 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
index 8c6c13d810f..5fbf1efd0ea 100755
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
@@ -41,8 +41,6 @@ import com.yahoo.search.config.IndexInfoConfig;
import com.yahoo.search.config.QrStartConfig;
import com.yahoo.search.pagetemplates.PageTemplatesConfig;
import com.yahoo.search.query.profile.config.QueryProfilesConfig;
-import com.yahoo.searchdefinition.RankProfileRegistry;
-import com.yahoo.searchdefinition.derived.AttributeFields;
import com.yahoo.searchdefinition.derived.RankProfileList;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import com.yahoo.vespa.configdefinition.IlscriptsConfig;
@@ -66,11 +64,9 @@ import com.yahoo.vespa.model.container.docproc.ContainerDocproc;
import com.yahoo.vespa.model.container.docproc.DocprocChains;
import com.yahoo.vespa.model.container.http.Http;
import com.yahoo.vespa.model.container.jersey.Jersey2Servlet;
-import com.yahoo.vespa.model.container.jersey.JerseyHandler;
import com.yahoo.vespa.model.container.jersey.RestApi;
import com.yahoo.vespa.model.container.processing.ProcessingChains;
import com.yahoo.vespa.model.container.search.ContainerSearch;
-import com.yahoo.vespa.model.container.search.QueryProfiles;
import com.yahoo.vespa.model.container.search.searchchain.SearchChains;
import com.yahoo.vespa.model.content.Content;
import com.yahoo.vespa.model.search.AbstractSearchCluster;
@@ -79,7 +75,6 @@ import com.yahoo.vespaclient.config.FeederConfig;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
-
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
@@ -562,10 +557,6 @@ public final class ContainerCluster
@Override
public final void getConfig(JdiscBindingsConfig.Builder builder) {
builder.handlers.putAll(DiscBindingsConfigGenerator.generate(getHandlers()));
-
- allJersey1Handlers().forEach(handler ->
- builder.handlers.putAll(DiscBindingsConfigGenerator.generate(handler))
- );
}
@Override
@@ -573,10 +564,6 @@ public final class ContainerCluster
clusterVerifier.getConfig(builder);
}
- private Stream<JerseyHandler> allJersey1Handlers() {
- return restApiGroup.getComponents().stream().flatMap(streamOf(RestApi::getJersey1Handler));
- }
-
@Override
public void getConfig(ServletPathsConfig.Builder builder) {
allServlets().forEach(servlet ->
@@ -591,14 +578,7 @@ public final class ContainerCluster
}
private Stream<Jersey2Servlet> allJersey2Servlets() {
- return restApiGroup.getComponents().stream().flatMap(streamOf(RestApi::getJersey2Servlet));
- }
-
- private <T, R> Function<T, Stream<R>> streamOf(Function<T, Optional<R>> f) {
- return t ->
- f.apply(t).
- <Stream<R>>map(Stream::of).
- orElse(Stream.empty());
+ return restApiGroup.getComponents().stream().map(RestApi::getJersey2Servlet);
}
@Override
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/JerseyHandler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/JerseyHandler.java
deleted file mode 100644
index 737882b703d..00000000000
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/JerseyHandler.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.model.container.jersey;
-
-import com.yahoo.config.model.producer.AbstractConfigProducer;
-import com.yahoo.container.bundle.BundleInstantiationSpecification;
-import com.yahoo.osgi.provider.model.ComponentModel;
-import com.yahoo.vespa.model.container.component.Handler;
-
-/**
- * @author gjoranv
- * @since 5.6
- */
-public class JerseyHandler extends Handler<AbstractConfigProducer<?>> {
-
- public static final String BUNDLE = "container-jersey";
- public static final String CLASS = "com.yahoo.container.jdisc.jersey.JerseyHandler";
-
- public JerseyHandler(String bindingPath) {
- super(new ComponentModel(bundleSpec(CLASS, BUNDLE, bindingPath)));
- }
-
- public static BundleInstantiationSpecification bundleSpec(String className, String bundle, String bindingPath) {
- return BundleInstantiationSpecification.getFromStrings(
- className + "-" + RestApi.idFromPath(bindingPath),
- className,
- bundle);
- }
-}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java
index 63825aa2a1b..be8209bcc4e 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java
@@ -2,32 +2,24 @@
package com.yahoo.vespa.model.container.jersey;
import com.yahoo.config.model.producer.AbstractConfigProducer;
-import com.yahoo.container.config.jersey.JerseyInitConfig;
-import com.yahoo.vespa.model.container.component.Component;
-
-import java.util.Optional;
/**
+ * Represents a rest-api
+ *
* @author gjoranv
- * @since 5.6
*/
-public class RestApi extends AbstractConfigProducer<AbstractConfigProducer<?>> implements
- JerseyInitConfig.Producer
-{
- public final boolean isJersey2;
+public class RestApi extends AbstractConfigProducer<AbstractConfigProducer<?>> {
+
private final String bindingPath;
- private final Component<?, ?> jerseyHandler;
+ private final Jersey2Servlet jerseyServlet;
private RestApiContext restApiContext;
- public RestApi(String bindingPath, boolean isJersey2) {
+ public RestApi(String bindingPath) {
super(idFromPath(bindingPath));
this.bindingPath = bindingPath;
- this.isJersey2 = isJersey2;
- jerseyHandler = isJersey2 ?
- createJersey2Servlet(this.bindingPath):
- createJersey1Handler(this.bindingPath);
- addChild(jerseyHandler);
+ jerseyServlet = createJersey2Servlet(this.bindingPath);
+ addChild(jerseyServlet);
}
public static String idFromPath(String path) {
@@ -38,44 +30,20 @@ public class RestApi extends AbstractConfigProducer<AbstractConfigProducer<?>> i
return new Jersey2Servlet(bindingPath);
}
- private static JerseyHandler createJersey1Handler(String bindingPath) {
- JerseyHandler jerseyHandler = new JerseyHandler(bindingPath);
- jerseyHandler.addServerBindings(getBindings(bindingPath));
- return jerseyHandler;
- }
-
public String getBindingPath() {
return bindingPath;
}
- @Override
- public void getConfig(JerseyInitConfig.Builder builder) {
- builder.jerseyMapping(bindingPath);
- }
-
public void setRestApiContext(RestApiContext restApiContext) {
this.restApiContext = restApiContext;
addChild(restApiContext);
- jerseyHandler.inject(restApiContext);
+ jerseyServlet.inject(restApiContext);
}
public RestApiContext getContext() { return restApiContext; }
- public Optional<JerseyHandler> getJersey1Handler() {
- return isJersey2 ?
- Optional.empty():
- Optional.of((JerseyHandler)jerseyHandler);
- }
-
- public Optional<Jersey2Servlet> getJersey2Servlet() {
- return isJersey2 ?
- Optional.of((Jersey2Servlet)jerseyHandler) :
- Optional.empty();
- }
-
- private static String[] getBindings(String bindingPath) {
- String bindingWithoutScheme = "://*/" + bindingPath + "/*";
- return new String[] {"http" + bindingWithoutScheme, "https" + bindingWithoutScheme};
+ public Jersey2Servlet getJersey2Servlet() {
+ return jerseyServlet;
}
public void prepare() {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java
index 5e48a1b1951..7fce9d2b636 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java
@@ -22,7 +22,6 @@ import java.util.logging.Logger;
/**
* @author gjoranv
- * @since 5.16
*/
public class RestApiContext extends SimpleComponent implements
JerseyBundlesConfig.Producer,
@@ -87,10 +86,6 @@ public class RestApiContext extends SimpleComponent implements
}
}
- public void addInjections(Map<String, String> injections) {
- injectComponentForClass.putAll(injections);
- }
-
@Override
public void validate() throws Exception {
super.validate();
@@ -117,7 +112,6 @@ public class RestApiContext extends SimpleComponent implements
private Predicate<Component> isCycleGeneratingComponent = component -> {
switch (component.getClassId().getName()) {
case CONTAINER_CLASS:
- case JerseyHandler.CLASS:
case Jersey2Servlet.CLASS:
case "com.yahoo.jdisc.http.server.jetty.JettyHttpServer":
case "com.yahoo.container.handler.observability.ApplicationStatusHandler":
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java
index 245db3c014f..6728f0be29f 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java
@@ -13,8 +13,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import static com.yahoo.config.model.builder.xml.XmlHelper.getOptionalAttribute;
-
/**
* @author gjoranv
* @since 5.6
@@ -24,8 +22,7 @@ public class RestApiBuilder extends VespaDomBuilder.DomConfigProducerBuilder<Res
@Override
protected RestApi doBuild(AbstractConfigProducer ancestor, Element spec) {
String bindingPath = spec.getAttribute("path");
- boolean jersey2 = Boolean.parseBoolean(getOptionalAttribute(spec, "jersey2").orElse("false"));
- RestApi restApi = new RestApi(bindingPath, jersey2);
+ RestApi restApi = new RestApi(bindingPath);
restApi.setRestApiContext(
createRestApiContext(ancestor, spec, bindingPath));
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/MultipleRestApisTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/MultipleRestApisTest.java
deleted file mode 100644
index d36ab74c6f1..00000000000
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/MultipleRestApisTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.model.container.jersey.xml;
-
-import com.yahoo.component.ComponentId;
-import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
-import com.yahoo.container.ComponentsConfig;
-import com.yahoo.container.di.config.JerseyBundlesConfig;
-import com.yahoo.container.jdisc.JdiscBindingsConfig;
-import com.yahoo.vespa.model.container.jersey.JerseyHandler;
-import com.yahoo.vespa.model.container.jersey.RestApi;
-import com.yahoo.vespa.model.container.jersey.RestApiContext;
-import com.yahoo.vespa.model.container.xml.ContainerModelBuilderTestBase;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author bjorncs
- */
-public class MultipleRestApisTest extends ContainerModelBuilderTestBase {
-
- private static final String CLUSTER_ID = "container";
- private static final String PATH_1 = "rest_1";
- private static final String PATH_2 = "rest_2";
- private static final String HTTP_BINDING_1 = "http://*/" + PATH_1 + "/*";
- private static final String HTTPS_BINDING_1 = "https://*/" + PATH_1 + "/*";
- private static final String HTTP_BINDING_2 = "http://*/" + PATH_2 + "/*";
- private static final String HTTPS_BINDING_2 = "https://*/" + PATH_2 + "/*";
- private static final String HANDLER_ID_1 = JerseyHandler.CLASS + "-" + PATH_1;
- private static final String HANDLER_ID_2 = JerseyHandler.CLASS + "-" + PATH_2;
- private static final String REST_API_CONTEXT_ID_1 = RestApiContext.CONTAINER_CLASS + "-" + PATH_1;
- private static final String REST_API_CONTEXT_ID_2 = RestApiContext.CONTAINER_CLASS + "-" + PATH_2;
- private static final String REST_API_XML =
- "<container version=\"1.0\" id=\"" + CLUSTER_ID + "\">\n" +
- " <rest-api path=\"" + PATH_1 + "\">\n" +
- " <components bundle=\"bundle1\" />\n" +
- " </rest-api>\n" +
- " <rest-api path=\"" + PATH_2 + "\">\n" +
- " <components bundle=\"bundle2\" />\n" +
- " </rest-api>\n" +
- "</container>";
-
-
- private JerseyHandler handler1;
- private JerseyHandler handler2;
- private Map<ComponentId, RestApi> restApis;
-
- @Before
- public void setup() throws Exception {
- createModel(root, DomBuilderTest.parse(REST_API_XML));
- handler1 = (JerseyHandler)getContainerComponentNested(CLUSTER_ID, HANDLER_ID_1);
- handler2 = (JerseyHandler)getContainerComponentNested(CLUSTER_ID, HANDLER_ID_2);
- restApis = getContainerCluster(CLUSTER_ID).getRestApiMap();
- }
-
- @Test
- public void cluster_has_all_rest_apis() {
- assertThat(restApis.size(), is(2));
- }
-
- @Test
- public void rest_apis_have_path_as_component_id() {
- assertTrue(restApis.get(ComponentId.fromString(PATH_1)) instanceof RestApi);
- assertTrue(restApis.get(ComponentId.fromString(PATH_2)) instanceof RestApi);
- }
-
- @Test
- public void jersey_handler_has_correct_bindings() {
- assertThat(handler1, not(nullValue()));
- assertThat(handler1.getServerBindings(), hasItems(HTTP_BINDING_1, HTTPS_BINDING_1));
-
- assertThat(handler2, not(nullValue()));
- assertThat(handler2.getServerBindings(), hasItems(HTTP_BINDING_2, HTTPS_BINDING_2));
- }
-
- @Test
- public void jersey_bindings_are_included_in_config() {
- JdiscBindingsConfig config = root.getConfig(JdiscBindingsConfig.class, CLUSTER_ID);
- assertThat(config.handlers(HANDLER_ID_1).serverBindings(), hasItems(HTTP_BINDING_1, HTTPS_BINDING_1));
- assertThat(config.handlers(HANDLER_ID_2).serverBindings(), hasItems(HTTP_BINDING_2, HTTPS_BINDING_2));
- }
-
-
- @Test
- public void jersey_handler_for_each_rest_api_is_included_in_components_config() {
- ComponentsConfig config = root.getConfig(ComponentsConfig.class, CLUSTER_ID);
- assertThat(config.toString(), containsString(".id \"" + HANDLER_ID_1 + "\""));
- assertThat(config.toString(), containsString(".id \"" + HANDLER_ID_2 + "\""));
- }
-
- @Test
- public void jersey_bundles_component_for_each_rest_api_is_included_in_components_config() {
-
- ComponentsConfig config = root.getConfig(ComponentsConfig.class, CLUSTER_ID);
- assertThat(config.toString(), containsString(".id \"" + REST_API_CONTEXT_ID_1 + "\""));
- assertThat(config.toString(), containsString(".id \"" + REST_API_CONTEXT_ID_2 + "\""));
- }
-
- @Test
- public void each_rest_api_has_correct_bundle() {
- RestApiContext restApiContext1 = restApis.get(ComponentId.fromString(PATH_1)).getContext();
- RestApiContext restApiContext2 = restApis.get(ComponentId.fromString(PATH_2)).getContext();
-
- JerseyBundlesConfig bundlesConfig1 = root.getConfig(JerseyBundlesConfig.class, restApiContext1.getConfigId());
- assertThat(bundlesConfig1.toString(), containsString("bundle1"));
- assertThat(bundlesConfig1.toString(), not(containsString("bundle2")));
-
- JerseyBundlesConfig bundlesConfig2 = root.getConfig(JerseyBundlesConfig.class, restApiContext2.getConfigId());
- assertThat(bundlesConfig2.toString(), containsString("bundle2"));
- assertThat(bundlesConfig2.toString(), not(containsString("bundle1")));
- }
-}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java
index 4b28dfa0b9d..503b38b79b4 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java
@@ -2,28 +2,24 @@
package com.yahoo.vespa.model.container.jersey.xml;
import com.yahoo.component.ComponentId;
-import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
+import com.yahoo.config.model.test.TestUtil;
import com.yahoo.container.ComponentsConfig;
-import com.yahoo.container.config.jersey.JerseyInitConfig;
import com.yahoo.container.di.config.JerseyBundlesConfig;
-import com.yahoo.container.di.config.JerseyInjectionConfig;
-import com.yahoo.container.jdisc.JdiscBindingsConfig;
+import com.yahoo.jdisc.http.ServletPathsConfig;
import com.yahoo.vespa.model.container.component.Component;
-import com.yahoo.vespa.model.container.component.Handler;
-import com.yahoo.vespa.model.container.jersey.JerseyHandler;
+import com.yahoo.vespa.model.container.jersey.Jersey2Servlet;
import com.yahoo.vespa.model.container.jersey.RestApi;
import com.yahoo.vespa.model.container.jersey.RestApiContext;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilderTestBase;
-import org.junit.Ignore;
+import org.junit.Before;
import org.junit.Test;
+import org.w3c.dom.Element;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -32,103 +28,86 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
/**
+ * @author gjoranv
* @author bjorncs
*/
public class RestApiTest extends ContainerModelBuilderTestBase {
- private static final String Path = "rest/api";
- private static final String HttpBinding = "http://*/" + Path + "/*";
- private static final String HttpsBinding = "https://*/" + Path + "/*";
- private static final String HandlerId = JerseyHandler.CLASS + "-" + RestApi.idFromPath(Path);
- private static final String RestApiContextId = RestApiContext.CONTAINER_CLASS + "-" + RestApi.idFromPath(Path);
- private static final String InjectedComponentId = "injectedHandler";
-
- private static final String ClusterId = "container";
-
- private static final String restApiXml =
- "<container version=\"1.0\" id=\"" + ClusterId + "\" jetty=\"true\">\n" +
- " <rest-api path=\"" + Path + "\">\n" +
- " <components bundle=\"my-jersey-bundle:1.0\">\n" +
- " <package>com.yahoo.foo</package>\n" +
- " </components>\n" +
- " </rest-api>\n" +
- " <handler id=\"" + InjectedComponentId + "\" />\n" +
- "</container>";
+ private static final String PATH = "rest/api";
+ private static final String REST_API_CONTEXT_ID = RestApiContext.CONTAINER_CLASS + "-" + RestApi.idFromPath(PATH);
+ private static final String INJECTED_COMPONENT_ID = "injectedHandler";
+ private static final String CLUSTER_ID = "container";
+
+ private static final Element restApiXml = TestUtil.parse(
+ "<container version=\"1.0\" id=\"" + CLUSTER_ID + "\">",
+ " <rest-api path=\"" + PATH + "\">",
+ " <components bundle=\"my-jersey-bundle:1.0\">",
+ " <package>com.yahoo.foo</package>",
+ " </components>",
+ " </rest-api>",
+ " <handler id=\"" + INJECTED_COMPONENT_ID + "\" />",
+ "</container>");
private RestApi restApi;
- private JerseyHandler handler;
+ private Jersey2Servlet servlet;
private RestApiContext context;
+ @Before
public void setup() throws Exception {
- createModel(root, DomBuilderTest.parse(restApiXml));
+ createModel(root, restApiXml);
root.validate();
- getContainerCluster(ClusterId).prepare();
- restApi = getContainerCluster(ClusterId).getRestApiMap().values().iterator().next();
- handler = (JerseyHandler) getContainerComponentNested(ClusterId, HandlerId);
+ getContainerCluster(CLUSTER_ID).prepare();
+ restApi = getContainerCluster(CLUSTER_ID).getRestApiMap().values().iterator().next();
+ servlet = restApi.getJersey2Servlet();
context = restApi.getContext();
}
@Test
- public void jersey_handler_has_correct_bindings() throws Exception {
- setup();
- assertThat(handler, not(nullValue()));
- assertThat(handler.getServerBindings(), hasItems(HttpBinding, HttpsBinding));
+ public void jersey2_servlet_has_correct_binding_path() {
+ assertThat(servlet, not(nullValue()));
+ assertThat(servlet.bindingPath, is(PATH + "/*"));
}
@Test
- public void jersey_bindings_are_included_in_config() throws Exception {
- setup();
- JdiscBindingsConfig config = root.getConfig(JdiscBindingsConfig.class, ClusterId);
- assertThat(config.handlers(HandlerId).serverBindings(), hasItems(HttpBinding, HttpsBinding));
+ public void jersey2_servlet_has_correct_bundle_spec() {
+ assertThat(servlet.model.bundleInstantiationSpec.bundle.stringValue(), is(Jersey2Servlet.BUNDLE));
}
@Test
- public void jersey_handler_has_correct_bundle_spec() throws Exception {
- setup();
- assertThat(handler.model.bundleInstantiationSpec.bundle.stringValue(), is(JerseyHandler.BUNDLE));
+ public void rest_api_path_is_included_in_servlet_config() {
+ ServletPathsConfig config = root.getConfig(ServletPathsConfig.class, servlet.getConfigId());
+ assertThat(config.servlets(servlet.getComponentId().stringValue()).path(), is(PATH + "/*"));
}
@Test
- public void config_has_correct_jersey_mapping() throws Exception {
- setup();
- JerseyInitConfig config = root.getConfig(JerseyInitConfig.class, handler.getConfigId());
- assertThat(config.jerseyMapping(), is(Path));
- }
-
- @Test
- public void resource_bundles_are_included_in_config() throws Exception {
- setup();
+ public void resource_bundles_are_included_in_config() {
JerseyBundlesConfig config = root.getConfig(JerseyBundlesConfig.class, context.getConfigId());
assertThat(config.bundles().size(), is(1));
assertThat(config.bundles(0).spec(), is("my-jersey-bundle:1.0"));
}
@Test
- public void packages_to_scan_are_included_in_config() throws Exception {
- setup();
+ public void packages_to_scan_are_included_in_config() {
JerseyBundlesConfig config = root.getConfig(JerseyBundlesConfig.class, context.getConfigId());
assertThat(config.bundles(0).packages(), contains("com.yahoo.foo"));
}
@Test
- public void jersey_handler_is_included_in_components_config() throws Exception {
- setup();
- ComponentsConfig config = root.getConfig(ComponentsConfig.class, ClusterId);
- assertThat(config.toString(), containsString(".id \"" + HandlerId + "\""));
+ public void jersey2_servlet_is_included_in_components_config() {
+ ComponentsConfig config = root.getConfig(ComponentsConfig.class, CLUSTER_ID);
+ assertThat(config.toString(), containsString(".id \"" + servlet.getComponentId().stringValue() + "\""));
}
@Test
- public void restApiContext_is_included_in_components_config() throws Exception {
- setup();
- ComponentsConfig config = root.getConfig(ComponentsConfig.class, ClusterId);
- assertThat(config.toString(), containsString(".id \"" + RestApiContextId + "\""));
+ public void restApiContext_is_included_in_components_config() {
+ ComponentsConfig config = root.getConfig(ComponentsConfig.class, CLUSTER_ID);
+ assertThat(config.toString(), containsString(".id \"" + REST_API_CONTEXT_ID + "\""));
}
@Test
public void all_non_restApi_components_are_injected_to_RestApiContext() throws Exception {
- setup();
- ComponentsConfig componentsConfig = root.getConfig(ComponentsConfig.class, ClusterId);
+ ComponentsConfig componentsConfig = root.getConfig(ComponentsConfig.class, CLUSTER_ID);
- Set<ComponentId> clusterChildrenComponentIds = getContainerCluster(ClusterId).getAllComponents().stream()
+ Set<ComponentId> clusterChildrenComponentIds = getContainerCluster(CLUSTER_ID).getAllComponents().stream()
.map(Component::getComponentId)
.collect(Collectors.toSet());
@@ -136,7 +115,7 @@ public class RestApiTest extends ContainerModelBuilderTestBase {
.map(child -> ((Component<?, ?>) child).getComponentId())
.collect(Collectors.toSet());
- //TODO: Review: replace with filtering against RestApiContext.isCycleGeneratingComponent
+ //TODO: try replacing with filtering against RestApiContext.isCycleGeneratingComponent
ComponentId cycleInducingComponents = ComponentId.fromString("com.yahoo.container.handler.observability.ApplicationStatusHandler");
Set<ComponentId> expectedInjectedConfigIds = new HashSet<>(clusterChildrenComponentIds);
@@ -165,49 +144,4 @@ public class RestApiTest extends ContainerModelBuilderTestBase {
.get();
}
- @Ignore // TODO: use for naming components instead
- @Test
- public void jdisc_components_can_be_injected() throws Exception {
- setup();
- JerseyInjectionConfig config = root.getConfig(JerseyInjectionConfig.class, context.getConfigId());
- assertThat(config.inject(0).instance(), is("injectedHandler"));
- assertThat(config.inject(0).forClass(), is("com.yahoo.handler.Handler"));
- }
-
- @Ignore // TODO: use for naming a non-existent component instead
- @Test(expected = IllegalArgumentException.class)
- public void injecting_non_existent_component() throws Exception {
- String restApiXml =
- "<container version=\"1.0\" id=\"" + ClusterId + "\">\n" +
- " <rest-api path=\"" + Path + "\">\n" +
- " <components bundle=\"my-jersey-bundle:1.0\" />\n" +
- " <inject jdisc-component=\"non-existent\" for-class=\"foo\" />\n" +
- " </rest-api>\n" +
- "</container>";
- createModel(root, DomBuilderTest.parse(restApiXml));
- root.validate();
- }
-
- @Test
- public void legacy_syntax_should_produce_valid_model() throws Exception {
- String legacyXml =
- "<container version=\"1.0\" >\n" +
- " <handler id=\"" + JerseyHandler.CLASS + "\" >\n" +
- " <binding>" + HttpBinding + "</binding>\n" +
- " <config name=\"jdisc.jersey.jersey-handler\">\n" +
- " <jerseyMapping>jersey</jerseyMapping>\n" +
- " </config>\n" +
- " </handler>\n" +
- "</container>";
-
- createModel(root, DomBuilderTest.parse(legacyXml));
-
- Handler<?> handler = (Handler<?>) getContainerComponent("container", JerseyHandler.CLASS);
- assertThat(handler, not(nullValue()));
- assertThat(handler.getServerBindings(), hasItem(HttpBinding));
-
- JdiscBindingsConfig bindingsConfig = root.getConfig(JdiscBindingsConfig.class, ClusterId);
- assertThat(bindingsConfig.handlers(JerseyHandler.CLASS).serverBindings(), hasItem(HttpBinding));
- }
-
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java
index e46e736dcd6..6a5611a7279 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java
@@ -78,12 +78,4 @@ public abstract class ContainerModelBuilderTestBase {
ComponentId.fromString(componentId));
}
- // TODO: will not work with multiple instances of the same class
- public Component<?, ?> getContainerComponentNested(String clusterId, String componentId) {
- ComponentId id = ComponentId.fromString(componentId);
- for (Component<?,?> component : getContainerCluster(clusterId).getAllComponents())
- if (id.equals(component.getComponentId()))
- return component;
- return null;
- }
}
diff --git a/container-disc/src/main/resources/configdefinitions/jersey-init.def b/container-disc/src/main/resources/configdefinitions/jersey-init.def
deleted file mode 100644
index 95ec9f23906..00000000000
--- a/container-disc/src/main/resources/configdefinitions/jersey-init.def
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-## Do NOT move this file to the container-jersey module. If system bundles
-## like config-model import packages from container-jersey, new class
-## loaders for these bundles will be created after reconfig.
-namespace=container.config.jersey
-
-# Controlled by the config framework, do not set this from services.xml!
-jerseyMapping string