Repository: incubator-juneau Updated Branches: refs/heads/master 0af286e95 -> 053b7c9ad
Allow REST microservices to try alternate ports when port is in use. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/053b7c9a Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/053b7c9a Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/053b7c9a Branch: refs/heads/master Commit: 053b7c9adf9ce4a9d63a3efa3a87b97102d6d561 Parents: 0af286e Author: JamesBognar <[email protected]> Authored: Sat Feb 25 14:20:27 2017 -0500 Committer: JamesBognar <[email protected]> Committed: Sat Feb 25 14:20:27 2017 -0500 ---------------------------------------------------------------------- juneau-core/src/main/javadoc/overview.html | 19 +++- juneau-examples-rest/examples.cfg | 5 +- .../apache/juneau/examples/rest/Constants.java | 28 ----- .../juneau/examples/rest/RootResourcesTest.java | 4 +- .../juneau/examples/rest/SamplesRestClient.java | 8 +- .../juneau/examples/rest/TestMicroservice.java | 19 +++- .../juneau/microservice/RestMicroservice.java | 104 ++++++++++++++++++- .../apache/juneau/rest/client/RestClient.java | 10 +- .../org/apache/juneau/rest/client/package.html | 2 +- juneau-rest-test/juneau-rest-test.cfg | 5 +- .../org/apache/juneau/rest/test/Constants.java | 53 ---------- .../juneau/rest/test/TestMicroservice.java | 16 ++- .../apache/juneau/rest/test/TestRestClient.java | 8 +- .../org/apache/juneau/rest/test/UrisTest.java | 24 ++--- 14 files changed, 183 insertions(+), 122 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-core/src/main/javadoc/overview.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/javadoc/overview.html b/juneau-core/src/main/javadoc/overview.html index c0c92ff..d1d3b4a 100644 --- a/juneau-core/src/main/javadoc/overview.html +++ b/juneau-core/src/main/javadoc/overview.html @@ -5667,6 +5667,23 @@ <li>Whitespace wasn't being ignored in some cases. </ul> </ul> + + <h6 class='topic'>org.apache.juneau.rest.client</h6> + <ul class='spaced-list'> + <li>{@link org.apache.juneau.rest.client.RestClient#setRootUrl(Object)} can now take in <code>URI</code> and <code>URL</code> objects. + </ul> + + <h6 class='topic'>org.apache.juneau.microservice</h6> + <ul class='spaced-list'> + <li><js>"REST/port"</js> configuration setting can now be a comma-limited list of port numbers to try. + <br>You can also specify one or more <code>0</code>s to try a random port. + <li>Methods added to {@link org.apache.juneau.microservice.RestMicroservice} class: + <ul> + <li>{@link org.apache.juneau.microservice.RestMicroservice#getPort()} + <li>{@link org.apache.juneau.microservice.RestMicroservice#getURI()} + <li>Override methods added from {@link org.apache.juneau.microservice.Microservice} class for easier method chaining. + </ul> + </ul> </div> @@ -6393,7 +6410,7 @@ <ul> <li>{@link org.apache.juneau.rest.client.RestClient#setBasicAuth(String,int,String,String)} <li>{@link org.apache.juneau.rest.client.RestClient#logTo(Level,Logger)} - <li>{@link org.apache.juneau.rest.client.RestClient#setRootUrl(String)} + <li><code><del>RestClient.setRootUrl(String)</del></code> <li>{@link org.apache.juneau.rest.client.RestClient#enableSSL(SSLOpts)} <li>{@link org.apache.juneau.rest.client.RestClient#enableLaxSSL()} <li>{@link org.apache.juneau.rest.client.RestClient#doCall(HttpMethod,Object,Object)} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-examples-rest/examples.cfg ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/examples.cfg b/juneau-examples-rest/examples.cfg index bee6b91..6b221b6 100755 --- a/juneau-examples-rest/examples.cfg +++ b/juneau-examples-rest/examples.cfg @@ -23,7 +23,10 @@ resources = org.apache.juneau.examples.rest.RootResources -port = 10000 +# Ports to try. +# 0 means try a random port. +# 3 0's means try 3 random ports. +port = 10000, 0, 0, 0 # Authentication: NONE, BASIC. authType = NONE http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/Constants.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/Constants.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/Constants.java deleted file mode 100644 index 48cea08..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/Constants.java +++ /dev/null @@ -1,28 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.examples.rest; - -public class Constants { - - private static String juneauSampleUrl = System.getProperty("JUNO_SAMPLE_URL"); - - /** - * Returns the value of the "JUNO_SAMPLE_URL" system property, or throws a {@link RuntimeException} - * if it's not set. - */ - public static String getSampleUrl() { - if (juneauSampleUrl == null) - return "http://localhost:10000"; - return juneauSampleUrl; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java index b3c7c98..0133292 100644 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java +++ b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java @@ -14,8 +14,6 @@ package org.apache.juneau.examples.rest; import static org.junit.Assert.*; -import java.net.*; - import org.apache.juneau.*; import org.apache.juneau.dto.swagger.*; import org.apache.juneau.html.*; @@ -27,7 +25,7 @@ import org.junit.*; public class RootResourcesTest extends RestTestcase { - private static String path = URI.create(Constants.getSampleUrl()).getPath(); // /jazz/juneau/sample + private static String path = TestMicroservice.getURI().getPath(); // /jazz/juneau/sample private static boolean debug = false; private static RestClient jsonClient; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesRestClient.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesRestClient.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesRestClient.java index 13083d7..b3abd2b 100644 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesRestClient.java +++ b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesRestClient.java @@ -29,21 +29,21 @@ public class SamplesRestClient extends RestClient { public SamplesRestClient(Class<? extends Serializer> s, Class<? extends Parser> p) throws InstantiationException { super(s,p); - setRootUrl(Constants.getSampleUrl()); + setRootUrl(TestMicroservice.getURI()); } public SamplesRestClient(Serializer s, Parser p) { super(s,p); - setRootUrl(Constants.getSampleUrl()); + setRootUrl(TestMicroservice.getURI()); } public SamplesRestClient() { - setRootUrl(Constants.getSampleUrl()); + setRootUrl(TestMicroservice.getURI()); } public SamplesRestClient(CloseableHttpClient c) { super(c); - setRootUrl(Constants.getSampleUrl()); + setRootUrl(TestMicroservice.getURI()); } public static SSLConnectionSocketFactory getSSLSocketFactory() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMicroservice.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMicroservice.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMicroservice.java index 8cedc99..c7877d7 100644 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMicroservice.java +++ b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMicroservice.java @@ -12,16 +12,21 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; +import java.net.*; import java.util.*; import org.apache.juneau.microservice.*; /** * Utility class for starting up the examples microservice. + * <p> + * This class is NOT thread safe. + * * @author james.bognar */ public class TestMicroservice { - static Microservice microservice; + static RestMicroservice microservice; + static URI microserviceURI; /** * Starts the microservice. @@ -34,7 +39,7 @@ public class TestMicroservice { try { Locale.setDefault(Locale.US); microservice = new RestMicroservice().setConfig("examples.cfg", false); - microservice.start(); + microserviceURI = microservice.start().getURI(); return true; } catch (Throwable e) { // Probably already started. @@ -44,6 +49,16 @@ public class TestMicroservice { } /** + * Returns the URI of the microservice. + * @return The URI of the microservice. + */ + public static URI getURI() { + if (microservice == null) + startMicroservice(); + return microserviceURI; + } + + /** * Stops the microservice. */ public static void stopMicroservice() { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-microservice/src/main/java/org/apache/juneau/microservice/RestMicroservice.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/src/main/java/org/apache/juneau/microservice/RestMicroservice.java b/juneau-microservice/src/main/java/org/apache/juneau/microservice/RestMicroservice.java index 36cef4e..56e9789 100755 --- a/juneau-microservice/src/main/java/org/apache/juneau/microservice/RestMicroservice.java +++ b/juneau-microservice/src/main/java/org/apache/juneau/microservice/RestMicroservice.java @@ -13,7 +13,9 @@ package org.apache.juneau.microservice; import java.io.*; +import java.net.*; import java.util.*; +import java.util.jar.*; import java.util.logging.*; import javax.servlet.*; @@ -69,6 +71,7 @@ public class RestMicroservice extends Microservice { Server server; int port; + String contextPath; Logger logger; /** @@ -143,6 +146,32 @@ public class RestMicroservice extends Microservice { //-------------------------------------------------------------------------------- // RestMicroservice API methods. //-------------------------------------------------------------------------------- + + /** + * Returns the port that this microservice started up on. + * @return The port that this microservice started up on. + */ + public int getPort() { + return port; + } + + /** + * Returns the URI where this microservice is listening on. + * @return The URI where this microservice is listening on. + */ + public URI getURI() { + String scheme = getConfig().getBoolean("REST/useSsl") ? "https" : "http"; + String hostname = "localhost"; + String ctx = "/".equals(contextPath) ? null : contextPath; + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) {} + try { + return new URI(scheme, null, hostname, port, ctx, null, null); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } /** * Initialize the logging for this microservice. @@ -259,12 +288,14 @@ public class RestMicroservice extends Microservice { * <cs>[REST]</cs> * * <cc># The HTTP port number to use. - * # Default is Rest-Port setting in manifest file, or 8000.</cc> + * # Default is Rest-Port setting in manifest file, or 8000. + * # Can also specify a comma-delimited lists of ports to try, including 0 meaning + * # try a random port.</cc> * <ck>port</ck> = 10000 * * <cc># The context root of the Jetty server. * # Default is Rest-ContextPath in manifest file, or "/".</cc> - * <ck>contextPath</ck> = 10000 + * <ck>contextPath</ck> = * * <cc># Authentication: NONE, BASIC. * # Default is Rest-AuthType in manifest file, or NONE.</cc> @@ -306,9 +337,16 @@ public class RestMicroservice extends Microservice { ConfigFile cf = getConfig(); ObjectMap mf = getManifest(); + + int[] ports = cf.getObject(int[].class, "REST/port", mf.get(int[].class, "Rest-Port", new int[]{8000})); - port = cf.getInt("REST/port", mf.getInt("Rest-Port", 8000)); - String contextPath = cf.getString("REST/contextPath", mf.getString("Rest-ContextPath", "/")); + port = findOpenPort(ports); + if (port == 0) { + System.err.println("Open port not found. Tried " + JsonSerializer.DEFAULT_LAX.toString(ports)); + System.exit(1); + } + + contextPath = cf.getString("REST/contextPath", mf.getString("Rest-ContextPath", "/")); if (cf.getBoolean("REST/useSsl")) { @@ -354,19 +392,35 @@ public class RestMicroservice extends Microservice { return server; } + + private int findOpenPort(int[] ports) { + for (int port : ports) { + try { + // If port is 0, try a random port between ports[0] and 32767. + if (port == 0) + port = new Random().nextInt(32767 - ports[0] + 1) + ports[0]; + ServerSocket ss = new ServerSocket(port); + ss.close(); + return port; + } catch (IOException e) {} + } + return 0; + } /** * Method used to start the Jetty server created by {@link #createServer()}. * <p> * Subclasses can override this method to customize server startup. * + * @return The port that this server started on. * @throws Exception */ - protected void startServer() throws Exception { + protected int startServer() throws Exception { onStartServer(); server.start(); logger.warning("Server started on port " + port); onPostStartServer(); + return port; } /** @@ -527,6 +581,46 @@ public class RestMicroservice extends Microservice { //-------------------------------------------------------------------------------- + // Overridden methods. + //-------------------------------------------------------------------------------- + + @Override /* Microservice */ + public RestMicroservice setConfig(String cfPath, boolean create) throws IOException { + super.setConfig(cfPath, create); + return this; + } + + @Override /* Microservice */ + public RestMicroservice setConfig(ConfigFile cf) { + super.setConfig(cf); + return this; + } + + @Override /* Microservice */ + public RestMicroservice setManifest(Manifest mf) { + super.setManifest(mf); + return this; + } + + @Override /* Microservice */ + public RestMicroservice setManifestContents(String...contents) throws IOException { + super.setManifestContents(contents); + return this; + } + + @Override /* Microservice */ + public RestMicroservice setManifest(File f) throws IOException { + super.setManifest(f); + return this; + } + + @Override /* Microservice */ + public RestMicroservice setManifest(Class<?> c) throws IOException { + super.setManifest(c); + return this; + } + + //-------------------------------------------------------------------------------- // Other methods. //-------------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java ---------------------------------------------------------------------- diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java index de99eb0..6f175cc 100644 --- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java +++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java @@ -532,12 +532,14 @@ public class RestClient extends CoreApi { * This root URL is ignored on those methods if you pass in a {@link URL}, {@link URI}, or an absolute URL string. * * @param rootUrl The root URL to prefix to relative URL strings. Trailing slashes are trimmed. + * Usually a <code>String<code> but you can also pass in <code>URI</code> and <code>URL</code> objects as well. * @return This object (for method chaining). */ - public RestClient setRootUrl(String rootUrl) { - if (rootUrl.endsWith("/")) - rootUrl = rootUrl.replaceAll("\\/$", ""); - this.rootUrl = rootUrl; + public RestClient setRootUrl(Object rootUrl) { + String s = rootUrl.toString(); + if (s.endsWith("/")) + s = s.replaceAll("\\/$", ""); + this.rootUrl = s; return this; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html index 7e9ee45..55797bb 100644 --- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html +++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html @@ -818,7 +818,7 @@ <h3 class='topic' onclick='toggle(this)'>1.8 - Other Useful Methods</h3> <div class='topic'> <p> - The {@link org.apache.juneau.rest.client.RestClient#setRootUrl(String)} method can be used to specify a root URL on + The {@link org.apache.juneau.rest.client.RestClient#setRootUrl(Object)} method can be used to specify a root URL on all requests so that you don't have to use absolute paths on individual calls. </p> <p class='bcode'> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-test/juneau-rest-test.cfg ---------------------------------------------------------------------- diff --git a/juneau-rest-test/juneau-rest-test.cfg b/juneau-rest-test/juneau-rest-test.cfg index 6d15a17..ff6d323 100644 --- a/juneau-rest-test/juneau-rest-test.cfg +++ b/juneau-rest-test/juneau-rest-test.cfg @@ -23,7 +23,10 @@ resources = org.apache.juneau.rest.test.Root -port = 10001 +# Ports to try. +# 0 means try a random port. +# 3 0's means try 3 random ports. +port = 10001, 0, 0, 0 # Authentication: NONE, BASIC. authType = NONE http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java deleted file mode 100644 index a996b3b..0000000 --- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/Constants.java +++ /dev/null @@ -1,53 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.rest.test; - -import java.net.*; - - -public class Constants extends RestTestcase { - - private static String juneauSampleUrl = System.getProperty("JUNO_SAMPLE_URL", "http://localhost:10000"); - private static URI juneauSampleUri = (juneauSampleUrl == null ? null : URI.create(juneauSampleUrl)); - - /** - * Returns the value of the "JUNO_SAMPLE_URL" system property, or throws a {@link RuntimeException} - * if it's not set. - */ - public static String getJuneauSamplesUrl() { - if (juneauSampleUrl == null) - throw new RuntimeException("'JUNO_SAMPLE_URL' system property not set to URL of juneau.sample.war location."); - return juneauSampleUrl; - } - - public static URI getJuneauSamplesUri() { - if (juneauSampleUri == null) - throw new RuntimeException("'JUNO_SAMPLE_URL' system property not set to URL of juneau.sample.war location."); - return juneauSampleUri; - } - - private static String juneauServerTestUrl = System.getProperty("JUNO_SERVER_TEST_URL", "http://localhost:10001"); - private static URI juneauServerTestUri = (juneauServerTestUrl == null ? null : URI.create(juneauServerTestUrl)); - - public static String getServerTestUrl() { - if (juneauServerTestUrl == null) - throw new RuntimeException("'JUNO_SERVER_TEST_URL' system property not set to URL of juneau.sample.war location."); - return juneauServerTestUrl; - } - - public static URI getServerTestUri() { - if (juneauServerTestUri == null) - throw new RuntimeException("'JUNO_SERVER_TEST_URL' system property not set to URL of juneau.sample.war location."); - return juneauServerTestUri; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestMicroservice.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestMicroservice.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestMicroservice.java index d7d45d9..84df9ec 100644 --- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestMicroservice.java +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestMicroservice.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.rest.test; +import java.net.*; import java.util.*; import org.apache.juneau.microservice.*; @@ -21,7 +22,8 @@ import org.apache.juneau.microservice.*; * @author james.bognar */ public class TestMicroservice { - static Microservice microservice; + static RestMicroservice microservice; + static URI microserviceURI; /** * Starts the microservice. @@ -38,7 +40,7 @@ public class TestMicroservice { .setManifestContents( "Test-Entry: test-value" ); - microservice.start(); + microserviceURI = microservice.start().getURI(); return true; } catch (Throwable e) { System.err.println(e); // NOT DEBUG @@ -47,6 +49,16 @@ public class TestMicroservice { } /** + * Returns the URI of the microservice. + * @return The URI of the microservice. + */ + public static URI getURI() { + if (microservice == null) + startMicroservice(); + return microserviceURI; + } + + /** * Stops the microservice. */ public static void stopMicroservice() { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestRestClient.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestRestClient.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestRestClient.java index 642d85d..05c491c 100644 --- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestRestClient.java +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/TestRestClient.java @@ -29,21 +29,21 @@ class TestRestClient extends RestClient { public TestRestClient(Class<? extends Serializer> s, Class<? extends Parser> p) throws InstantiationException { super(s,p); - setRootUrl(Constants.getServerTestUrl()); + setRootUrl(TestMicroservice.getURI()); } public TestRestClient(Serializer s, Parser p) { super(s,p); - setRootUrl(Constants.getServerTestUrl()); + setRootUrl(TestMicroservice.getURI()); } public TestRestClient() { - setRootUrl(Constants.getServerTestUrl()); + setRootUrl(TestMicroservice.getURI()); } public TestRestClient(CloseableHttpClient c) { super(c); - setRootUrl(Constants.getServerTestUrl()); + setRootUrl(TestMicroservice.getURI()); } public static SSLConnectionSocketFactory getSSLSocketFactory() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/053b7c9a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/UrisTest.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/UrisTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/UrisTest.java index 42ed4ab..57b929c 100644 --- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/UrisTest.java +++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/UrisTest.java @@ -14,8 +14,6 @@ package org.apache.juneau.rest.test; import static org.junit.Assert.*; -import java.util.regex.*; - import org.apache.juneau.*; import org.apache.juneau.json.*; import org.apache.juneau.rest.client.*; @@ -26,9 +24,9 @@ import org.junit.*; */ public class UrisTest extends RestTestcase { - private static String URL2 = Constants.getServerTestUrl() + "/testuris"; // /jazz/juneau/sample/testuris - private static int port = getPort(Constants.getServerTestUrl()); // 9443 - private static String path = Constants.getServerTestUri().getPath(); // /jazz/juneau/sample + private static String URL2 = TestMicroservice.getURI() + "/testuris"; // /jazz/juneau/sample/testuris + private static int port = TestMicroservice.getURI().getPort(); // 9443 + private static String path = TestMicroservice.getURI().getPath(); // /jazz/juneau/sample //==================================================================================================== // testRoot - http://localhost:8080/sample/testuris @@ -907,12 +905,12 @@ public class UrisTest extends RestTestcase { client.closeQuietly(); } - - private static int getPort(String url) { - Pattern p = Pattern.compile("\\:(\\d{2,5})"); - Matcher m = p.matcher(url); - if (m.find()) - return Integer.parseInt(m.group(1)); - return -1; - } +// +// private static int getPort(String url) { +// Pattern p = Pattern.compile("\\:(\\d{2,5})"); +// Matcher m = p.matcher(url); +// if (m.find()) +// return Integer.parseInt(m.group(1)); +// return -1; +// } }
