diff --git a/http-api/src/main/java/net/runelite/http/api/RuneliteAPI.java b/http-api/src/main/java/net/runelite/http/api/RuneliteAPI.java index 4f193d08a9..f3f0cbbeaa 100644 --- a/http-api/src/main/java/net/runelite/http/api/RuneliteAPI.java +++ b/http-api/src/main/java/net/runelite/http/api/RuneliteAPI.java @@ -24,10 +24,12 @@ */ package net.runelite.http.api; +import com.google.gson.Gson; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +37,9 @@ public class RuneliteAPI { private static final Logger logger = LoggerFactory.getLogger(RuneliteAPI.class); + public static final OkHttpClient CLIENT = new OkHttpClient(); + public static final Gson GSON = new Gson(); + private static final String BASE = "https://api.runelite.net/runelite-"; private static final String WSBASE = "wss://api.runelite.net/runelite-"; private static final Properties properties = new Properties(); diff --git a/http-api/src/main/java/net/runelite/http/api/account/LoginClient.java b/http-api/src/main/java/net/runelite/http/api/account/LoginClient.java index 60947380c2..4e8209d3d9 100644 --- a/http-api/src/main/java/net/runelite/http/api/account/LoginClient.java +++ b/http-api/src/main/java/net/runelite/http/api/account/LoginClient.java @@ -24,13 +24,11 @@ */ package net.runelite.http.api.account; -import com.google.gson.Gson; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import net.runelite.http.api.RuneliteAPI; import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; @@ -41,9 +39,6 @@ public class LoginClient { private static final Logger logger = LoggerFactory.getLogger(LoginClient.class); - private final OkHttpClient client = new OkHttpClient(); - private final Gson gson = new Gson(); - public OAuthResponse login() throws IOException { HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder() @@ -58,12 +53,12 @@ public class LoginClient .url(url) .build(); - Response response = client.newCall(request).execute(); + Response response = RuneliteAPI.CLIENT.newCall(request).execute(); try (ResponseBody body = response.body()) { InputStream in = body.byteStream(); - return gson.fromJson(new InputStreamReader(in), OAuthResponse.class); + return RuneliteAPI.GSON.fromJson(new InputStreamReader(in), OAuthResponse.class); } } } diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java index 7832c6b42c..5ac42e4779 100644 --- a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java @@ -24,13 +24,11 @@ */ package net.runelite.http.api.hiscore; -import com.google.gson.Gson; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import net.runelite.http.api.RuneliteAPI; import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; @@ -41,9 +39,6 @@ public class HiscoreClient { private static final Logger logger = LoggerFactory.getLogger(HiscoreClient.class); - private final OkHttpClient client = new OkHttpClient(); - private final Gson gson = new Gson(); - public HiscoreResult lookup(String username) throws IOException { HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder() @@ -58,12 +53,12 @@ public class HiscoreClient .url(url) .build(); - Response response = client.newCall(request).execute(); + Response response = RuneliteAPI.CLIENT.newCall(request).execute(); try (ResponseBody body = response.body()) { InputStream in = body.byteStream(); - return gson.fromJson(new InputStreamReader(in), HiscoreResult.class); + return RuneliteAPI.GSON.fromJson(new InputStreamReader(in), HiscoreResult.class); } } } diff --git a/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java b/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java index 1fe82a19fa..c32630fa65 100644 --- a/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java +++ b/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java @@ -24,12 +24,10 @@ */ package net.runelite.http.api.xtea; -import com.google.gson.Gson; import java.io.IOException; import net.runelite.http.api.RuneliteAPI; import okhttp3.HttpUrl; import okhttp3.MediaType; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -42,9 +40,6 @@ public class XteaClient private static final Logger logger = LoggerFactory.getLogger(XteaClient.class); - private final OkHttpClient client = new OkHttpClient(); - private final Gson gson = new Gson(); - public Response submit(int revision, int region, int[] keys) throws IOException { XteaRequest xteaRequest = new XteaRequest(); @@ -56,7 +51,7 @@ public class XteaClient xteaRequest.addKey(xteaKey); - String json = gson.toJson(xteaRequest); + String json = RuneliteAPI.GSON.toJson(xteaRequest); HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder() .addPathSegment("xtea"); @@ -70,6 +65,6 @@ public class XteaClient .url(url) .build(); - return client.newCall(request).execute(); + return RuneliteAPI.CLIENT.newCall(request).execute(); } } diff --git a/http-service/src/main/java/net/runelite/http/service/account/AccountService.java b/http-service/src/main/java/net/runelite/http/service/account/AccountService.java index 732a52d111..33a30471e3 100644 --- a/http-service/src/main/java/net/runelite/http/service/account/AccountService.java +++ b/http-service/src/main/java/net/runelite/http/service/account/AccountService.java @@ -101,7 +101,7 @@ public class AccountService public void init() { - try (Connection con = sql2o.beginTransaction()) + try (Connection con = sql2o.open()) { con.createQuery(CREATE_SESSIONS) .executeUpdate(); diff --git a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java b/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java index e88ff4144b..5f265343e8 100644 --- a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java +++ b/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java @@ -26,10 +26,10 @@ package net.runelite.http.service.hiscore; import java.io.IOException; import java.net.URISyntaxException; +import net.runelite.http.api.RuneliteAPI; import net.runelite.http.api.hiscore.HiscoreResult; import net.runelite.http.api.hiscore.Skill; import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; @@ -41,7 +41,6 @@ public class HiscoreService { private static final HttpUrl RUNESCAPE_HISCORE_SERVICE = HttpUrl.parse("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws"); - private final OkHttpClient client = new OkHttpClient(); private HttpUrl url = RUNESCAPE_HISCORE_SERVICE; public HiscoreResult lookup(String username) throws IOException, URISyntaxException @@ -53,7 +52,7 @@ public class HiscoreService .url(builder.build()) .build(); - Response response = client.newCall(request).execute(); + Response response = RuneliteAPI.CLIENT.newCall(request).execute(); String responseStr; try (ResponseBody body = response.body()) diff --git a/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java b/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java index e27b381e56..f31c1b0cf1 100644 --- a/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java +++ b/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java @@ -29,10 +29,10 @@ import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; +import net.runelite.http.api.RuneliteAPI; import net.runelite.http.api.worlds.World; import net.runelite.http.api.worlds.WorldResult; import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; @@ -41,7 +41,6 @@ public class WorldsService { private static final HttpUrl WORLD_URL = HttpUrl.parse("http://www.runescape.com/g=oldscape/slr.ws?order=LPWM"); - private final OkHttpClient client = new OkHttpClient(); private HttpUrl url = WORLD_URL; public WorldResult listWorlds() throws IOException, URISyntaxException @@ -50,7 +49,7 @@ public class WorldsService .url(url) .build(); - Response response = client.newCall(request).execute(); + Response response = RuneliteAPI.CLIENT.newCall(request).execute(); byte[] b; try (ResponseBody body = response.body()) diff --git a/http-service/src/main/webapp/WEB-INF/web.xml b/http-service/src/main/webapp/WEB-INF/web.xml index 47ba7366da..1abb728616 100644 --- a/http-service/src/main/webapp/WEB-INF/web.xml +++ b/http-service/src/main/webapp/WEB-INF/web.xml @@ -42,5 +42,10 @@ com.commongroundpublishing.slf4j.impl.ServletContextLoggerSCL - + + + + ServletContextLogger.LEVEL + INFO + \ No newline at end of file diff --git a/http-service/src/test/java/net/runelite/http/service/ServiceRunner.java b/http-service/src/test/java/net/runelite/http/service/ServiceRunner.java deleted file mode 100644 index cd80592b97..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/ServiceRunner.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.http.service; - -import org.junit.Test; -import spark.Spark; - -public class ServiceRunner -{ - // not a real test, runs standalone spark - //@Test - public void run() throws InterruptedException - { - Service service = new Service(); - service.init(); - - Spark.awaitInitialization(); - - for (;;) - { - Thread.sleep(1000L); - } - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/Skill.java b/runelite-api/src/main/java/net/runelite/api/Skill.java index 09ceec47b6..08425c4f3c 100644 --- a/runelite-api/src/main/java/net/runelite/api/Skill.java +++ b/runelite-api/src/main/java/net/runelite/api/Skill.java @@ -49,7 +49,8 @@ public enum Skill FARMING("Farming"), RUNECRAFT("Runecraft"), HUNTER("Hunter"), - CONSTRUCTION("Construction"); + CONSTRUCTION("Construction"), + OVERALL("Overall"); private final String name; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java index 3f34b613a2..217fb036e4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java @@ -78,6 +78,7 @@ public class HiscorePanel extends PluginPanel private final JLabel farmingLabel = new JLabel("--"); private final JLabel constructionLabel = new JLabel("--"); private final JLabel hunterLabel = new JLabel("--"); + private final JLabel overallLabel = new JLabel("--"); private GridLayout stats; @@ -135,6 +136,7 @@ public class HiscorePanel extends PluginPanel statsPanel.add(makeSkillPanel(Skill.FARMING, farmingLabel)); statsPanel.add(makeSkillPanel(Skill.CONSTRUCTION, constructionLabel)); statsPanel.add(makeSkillPanel(Skill.HUNTER, hunterLabel)); + statsPanel.add(makeSkillPanel(Skill.OVERALL, overallLabel)); } catch (IOException ex) { @@ -210,6 +212,7 @@ public class HiscorePanel extends PluginPanel setLabel(runecraftLabel, result.getRunecraft()); setLabel(hunterLabel, result.getHunter()); setLabel(constructionLabel, result.getConstruction()); + setLabel(overallLabel, result.getOverall()); } private void setLabel(JLabel label, net.runelite.http.api.hiscore.Skill skill) diff --git a/travis/build.sh b/travis/build.sh index 242f8e75f4..28eab54eaf 100755 --- a/travis/build.sh +++ b/travis/build.sh @@ -5,7 +5,7 @@ PROJECT_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${project.version} # Don't deploy pull requests (there are no secrets, anyway) # And don't deploy releases, they are already deployed by the updater before this, # and are signed. -if [[ "${TRAVIS_PULL_REQUEST}" = "false" && $PROJECT_VERSION == *"-SNAPSHOT" ]]; then +if [[ "${TRAVIS_PULL_REQUEST}" == "false" && $PROJECT_VERSION == *"-SNAPSHOT" && "$TRAVIS_BRANCH" == "master" ]]; then mvn clean deploy --settings travis/settings.xml else mvn clean verify --settings travis/settings.xml