Repository: tomee Updated Branches: refs/heads/master 87fbc5038 -> 31e6388f4
TOMEE-1893 ensure to deploy only the expected context (jaxrs) Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/31e6388f Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/31e6388f Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/31e6388f Branch: refs/heads/master Commit: 31e6388f4700556200c503215a916354050a923b Parents: 87fbc50 Author: Romain manni-Bucau <[email protected]> Authored: Tue Aug 2 11:17:24 2016 +0200 Committer: Romain manni-Bucau <[email protected]> Committed: Tue Aug 2 11:17:24 2016 +0200 ---------------------------------------------------------------------- .../apache/openejb/server/rest/RESTService.java | 24 ++++++++-- .../rest/RESTServiceDeployedServiceTest.java | 47 ++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/31e6388f/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java ---------------------------------------------------------------------- diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java index 08ca23b..a10b1a7 100644 --- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java +++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java @@ -1056,9 +1056,27 @@ public abstract class RESTService implements ServerService, SelfManaging { } public boolean isInWebApp(final String appId, final WebAppInfo webApp) { // we support paralell deployments so we need app (versionned) + webapp check - return !(appId == null && this.appId != null) && !(appId != null && !appId.equals(this.appId)) - && ((webApp.contextRoot != null && - webApp.contextRoot.equals(webapp)) || (webapp != null && webapp.startsWith(webApp.contextRoot != null ? webApp.contextRoot : ""))); + final boolean appTest = !(appId == null && this.appId != null) && !(appId != null && !appId.equals(this.appId)); + return appTest && cleanWeb(webapp).equals(cleanWeb(webApp.contextRoot)); + } + + private String cleanWeb(final String s) { + if (s == null) { + return ""; + } + if (s.startsWith("/")) { + return cleanWeb(s.substring(1)); + } + + final int i = s.indexOf("##"); + if (i > 0) { + return cleanWeb(s.substring(0, i)); + } + + if ("ROOT".equals(s)) { + return ""; + } + return s; } } http://git-wip-us.apache.org/repos/asf/tomee/blob/31e6388f/server/openejb-rest/src/test/java/org/apache/openejb/server/rest/RESTServiceDeployedServiceTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-rest/src/test/java/org/apache/openejb/server/rest/RESTServiceDeployedServiceTest.java b/server/openejb-rest/src/test/java/org/apache/openejb/server/rest/RESTServiceDeployedServiceTest.java new file mode 100644 index 0000000..ae984d1 --- /dev/null +++ b/server/openejb-rest/src/test/java/org/apache/openejb/server/rest/RESTServiceDeployedServiceTest.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.server.rest; + +import org.apache.openejb.assembler.classic.WebAppInfo; +import org.junit.Test; + +import static java.util.Arrays.asList; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class RESTServiceDeployedServiceTest { + @Test + public void isInWebAppContextMatching() { + for (final String sc : asList("foo", "/foo", "/foo##1234")) { + final RESTService.DeployedService service = new RESTService.DeployedService("http://localhost", sc, null, "1"); + for (final String c : new String[]{ + "foo", "/foo", "/foo##1234" + }) { + assertTrue(sc + " ? " + c, service.isInWebApp("1", new WebAppInfo() {{ + contextRoot = c; + }})); + } + for (final String c : new String[]{ + "bar", "/bar", "", "ROOT", "/ROOT", "foo2", "/foo2" + }) { + assertFalse(sc + " ? " + c, service.isInWebApp("1", new WebAppInfo() {{ + contextRoot = c; + }})); + } + } + } +}
