diff --git a/src/main/java/ru/maximkulikov/goodgame/api/GoodChat.java b/src/main/java/ru/maximkulikov/goodgame/api/GoodChat.java index 7fc1d03..84be1e3 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/GoodChat.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/GoodChat.java @@ -3,8 +3,10 @@ import java.io.IOException; import java.net.URI; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.jetty.websocket.api.Session; @@ -60,7 +62,6 @@ public void run() { } catch (Exception e) { logger.error("Connecting exeption: {}", e.getLocalizedMessage()); - e.printStackTrace(); } finally { try { GoodChat.this.client.stop(); @@ -116,7 +117,6 @@ public final void sendMessage(final ReqChatObject chatObject) { Thread.sleep(700); } catch (InterruptedException e) { - e.printStackTrace(); logger.error("Send message Exeption. Closing thread: {}", e.getLocalizedMessage()); Thread.currentThread().interrupt(); } @@ -153,7 +153,6 @@ public final void stop() { GoodChat.this.client.stop(); } catch (Exception e) { logger.error("GoddChat dit not stop in proper way! {}", e.getLocalizedMessage()); - e.printStackTrace(); } } } @@ -361,7 +360,7 @@ public final void onMessage(final String msg) { break; default: answer = new Response(ChatResponses.UNKNOWN, null); - System.out.println(msg); + logger.info(msg); break; } @@ -369,7 +368,6 @@ public final void onMessage(final String msg) { } catch (IOException e) { logger.error("On message receive exception: {}", e.getLocalizedMessage()); - e.printStackTrace(); } } @@ -385,9 +383,8 @@ protected final void sendMessage(final String s) { fut = this.session.getRemote().sendStringByFuture(s); fut.get(2, TimeUnit.SECONDS); - } catch (Throwable t) { - logger.error("send Message exception: {}", t.getLocalizedMessage()); - t.printStackTrace(); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + logger.error("send Message exception: {}", e.getLocalizedMessage()); } } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/auth/Authenticator.java b/src/main/java/ru/maximkulikov/goodgame/api/auth/Authenticator.java index a0c0cce..d35f591 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/auth/Authenticator.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/auth/Authenticator.java @@ -157,7 +157,8 @@ public final void setRefreshToken(final String refreshToken) { * @return */ public String setHost(final String host) { - return this.host = host; + this.host = host; + return this.host; } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackRequest.java b/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackRequest.java index 31cd742..a0d28df 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackRequest.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackRequest.java @@ -98,12 +98,12 @@ private void processRequest() { ) { String requestLine = br.readLine(); - String rawRequest = "\n" + requestLine; - - String headerLine = null; - while ((headerLine = br.readLine()).length() != 0) { - rawRequest += headerLine + "\n"; - } +// String rawRequest = "\n" + requestLine; +// +// String headerLine = null; +// while ((headerLine = br.readLine()).length() != 0) { +// rawRequest += headerLine + "\n"; +// } StringTokenizer tokens = new StringTokenizer(requestLine); @@ -165,9 +165,6 @@ private void processRequest() { os.writeBytes(entityBody); } - os.close(); - br.close(); - this.socket.close(); if (this.authenticationListener != null) { diff --git a/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackServer.java b/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackServer.java index 977ca24..327c791 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackServer.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/auth/grants/implicit/AuthenticationCallbackServer.java @@ -34,7 +34,7 @@ public class AuthenticationCallbackServer implements AuthenticationListener { private final URL failurePage; private final URL successPage; private int port; - private String host = "127.0.0.1"; + private String host; private ServerSocket serverSocket; private String accessToken; private AuthenticationError authenticationError; @@ -44,6 +44,7 @@ public class AuthenticationCallbackServer implements AuthenticationListener { public AuthenticationCallbackServer(final int port) { this.port = port; + host = "127.0.0.1"; // Load default pages this.authPage = getClass().getResource(DEFAULT_AUTH_PAGE); this.failurePage = getClass().getResource(DEFAULT_FAILURE_PAGE); diff --git a/src/main/java/ru/maximkulikov/goodgame/api/chatmodels/ReqIgnoreListContainer.java b/src/main/java/ru/maximkulikov/goodgame/api/chatmodels/ReqIgnoreListContainer.java index b7cbc23..6215fbf 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/chatmodels/ReqIgnoreListContainer.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/chatmodels/ReqIgnoreListContainer.java @@ -19,18 +19,16 @@ public final Empty getData() { return this.data; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; + public final void setData(final Empty data) { + this.data = data; + } - ReqIgnoreListContainer that = (ReqIgnoreListContainer) o; + public final String getType() { + return this.type; + } - return new EqualsBuilder() - .append(type, that.type) - .append(data, that.data) - .isEquals(); + public final void setType(final String type) { + this.type = type; } @Override @@ -41,23 +39,18 @@ public int hashCode() { .toHashCode(); } - /** - * - */ - - public ReqIgnoreListContainer() { - } + @Override + public boolean equals(Object o) { + if (this == o) return true; - public final void setData(final Empty data) { - this.data = data; - } + if (o == null || getClass() != o.getClass()) return false; - public final String getType() { - return this.type; - } + ReqIgnoreListContainer that = (ReqIgnoreListContainer) o; - public final void setType(final String type) { - this.type = type; + return new EqualsBuilder() + .append(type, that.type) + .append(data, that.data) + .isEquals(); } @Override diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/AbstractResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/AbstractResource.java index 00a1fce..9ee2df1 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/AbstractResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/AbstractResource.java @@ -44,8 +44,6 @@ protected AbstractResource(final String baseUrl) { } - ; - protected void configureHeaders() { http.removeHeader(ACCEPT); diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/AjaxResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/AjaxResource.java index 36beb5f..2339b48 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/AjaxResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/AjaxResource.java @@ -26,6 +26,7 @@ public class AjaxResource extends AbstractResource { private static final String CONTENT_TYPE = "Content-Type"; private static final String FORM_URL_ENCODED = "application/x-www-form-urlencoded; charset=UTF-8"; private static final String COOKIE = "Cookie"; + private static final String PARAMETERS_NULL = "{} parameters are null"; private GoodGame gg; /** @@ -46,6 +47,10 @@ public AjaxResource(final String ajaxBaseUrl, final GoodGame gg) { * @param handler */ public final boolean games(final String searchGame, final AjaxGamesHandler handler) { + if (searchGame == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/games/all/", getBaseUrl()); RequestParams params = new RequestParams(); @@ -83,8 +88,12 @@ public void onSuccess(int statusCode, Map> headers, String * @param handler */ public final boolean games(final String searchGame, final RequestParams params, final AjaxGamesHandler handler) { - String url = String.format("%s/games/all/", getBaseUrl()); + if (searchGame == null || params == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } + String url = String.format("%s/games/all/", getBaseUrl()); params.put("q", searchGame); http.get(url, params, new GoodGameHttpResponseHandler(handler) { @@ -119,6 +128,10 @@ public void onSuccess(int statusCode, Map> headers, String * @see GoodGame#setPhpSessId(String) */ public final boolean login(final String login, final String password, final AjaxLoginResponseHandler handler) { + if (login == null || password == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/login/", getBaseUrl()); RequestParams params = new RequestParams(); @@ -152,6 +165,7 @@ public void onSuccess(int statusCode, Map> headers, String } handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -169,6 +183,11 @@ public void onSuccess(int statusCode, Map> headers, String * @see #games(String, AjaxGamesHandler) */ public final boolean updateTitle(final String channelId, final String title, final String gameId, final UpdateTitleResponseHandler handler) { + if (channelId == null || title == null || gameId == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } + String url = String.format("%s/channel/update-title/", getBaseUrl()); RequestParams params = new RequestParams(); @@ -177,7 +196,6 @@ public final boolean updateTitle(final String channelId, final String title, fin params.put("title", title); params.put("gameId", gameId); - http.removeHeader(CONTENT_TYPE); http.removeHeader(COOKIE); http.setHeader(CONTENT_TYPE, FORM_URL_ENCODED); @@ -190,6 +208,7 @@ public void onSuccess(int statusCode, Map> headers, String UpdateTitle value = objectMapper.readValue(content, UpdateTitle.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/ChannelsResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/ChannelsResource.java index 93517dc..cdc0f6a 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/ChannelsResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/ChannelsResource.java @@ -21,6 +21,7 @@ */ public class ChannelsResource extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(ChannelsResource.class); + private static final String PARAMETERS_NULL = "{} parameters are null"; /** * @param baseUrl Базовая ссылка для доступа к ресурсу @@ -39,6 +40,10 @@ public ChannelsResource(final String baseUrl, final int apiVersion) { * @param handler */ public final boolean getDonations(final String channel, final DonationsResponseHandler handler) { + if (channel == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/channel/%s/donations", getBaseUrl(), channel); this.configureHeaders(); http.get(url, new GoodGameHttpResponseHandler(handler) { @@ -48,6 +53,7 @@ public void onSuccess(final int statusCode, final Map> head DonationsContainer value = objectMapper.readValue(content, DonationsContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -67,6 +73,10 @@ public void onSuccess(final int statusCode, final Map> head */ public final boolean getDonations(final String channel, final RequestParams params, final DonationsResponseHandler handler) { + if (channel == null || params == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/channel/%s/donations", getBaseUrl(), channel); this.configureHeaders(); http.get(url, params, new GoodGameHttpResponseHandler(handler) { @@ -76,6 +86,7 @@ public void onSuccess(final int statusCode, final Map> head DonationsContainer value = objectMapper.readValue(content, DonationsContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -92,6 +103,10 @@ public void onSuccess(final int statusCode, final Map> head * @param handler */ public final boolean getPremiums(final String channel, final PremiumsResponseHandler handler) { + if (channel == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/channel/%s/premiums", getBaseUrl(), channel); this.configureHeaders(); @@ -121,6 +136,10 @@ public void onSuccess(final int statusCode, final Map> head */ public final boolean getPremiums(final String channel, final RequestParams params, final PremiumsResponseHandler handler) { + if (channel == null || params == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/channel/%s/premiums", getBaseUrl(), channel); this.configureHeaders(); @@ -147,6 +166,10 @@ public void onSuccess(final int statusCode, final Map> head * @param handler */ public final boolean getSubscribers(final String channel, final SubscriberResponseHandler handler) { + if (channel == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/channel/%s/subscribers", getBaseUrl(), channel); this.configureHeaders(); @@ -176,6 +199,10 @@ public void onSuccess(final int statusCode, final Map> head */ public final boolean getSubscribers(final String channel, final RequestParams params, final SubscriberResponseHandler handler) { + if (channel == null || params == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/channel/%s/subscribers", getBaseUrl(), channel); this.configureHeaders(); diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/ChatResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/ChatResource.java index cb6e05d..8d215cc 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/ChatResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/ChatResource.java @@ -38,6 +38,7 @@ public void onSuccess(final int statusCode, final Map> head ChatToken value = objectMapper.readValue(content, ChatToken.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/GamesResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/GamesResource.java index ae17875..b278987 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/GamesResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/GamesResource.java @@ -19,6 +19,7 @@ */ public class GamesResource extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(GamesResource.class); + private static final String PARAMETERS_NULL = "{} parameters are null"; public GamesResource(final String baseUrl, final int apiVersion) { super(baseUrl, apiVersion); @@ -31,6 +32,10 @@ public GamesResource(final String baseUrl, final int apiVersion) { * @param handler */ public final boolean getGame(final String gameUrl, final GameResponseHandler handler) { + if (gameUrl == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/games/%s", getBaseUrl(), gameUrl); this.configureHeaders(); @@ -41,6 +46,7 @@ public void onSuccess(final int statusCode, final Map> head Game value = objectMapper.readValue(content, Game.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -56,6 +62,10 @@ public void onSuccess(final int statusCode, final Map> head * @param handler */ public final boolean getGames(final RequestParams params, final GamesResponseHandler handler) { + if (params == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/games", getBaseUrl()); this.configureHeaders(); @@ -66,6 +76,7 @@ public void onSuccess(final int statusCode, final Map> head GamesContainer value = objectMapper.readValue(content, GamesContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -89,6 +100,7 @@ public void onSuccess(final int statusCode, final Map> head GamesContainer value = objectMapper.readValue(content, GamesContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/GithubResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/GithubResource.java index d454282..d313f0f 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/GithubResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/GithubResource.java @@ -19,10 +19,9 @@ */ public class GithubResource extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(GithubResource.class); + private static final String PARAMETERS_NULL = "{} parameters are null"; private static final String ID = "id"; - private static final String FMT = "fmt"; - private static final String JSON = "json"; private final GoodGame gg; @@ -33,6 +32,10 @@ public GithubResource(final String baseUrl, GoodGame goodGame) { } public final boolean getChannelStatus(final String channelId, final GitHubSharedHandler handler) { + if (channelId == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/getchannelstatus", getBaseUrl()); RequestParams params = new RequestParams(); @@ -45,7 +48,6 @@ public final boolean getChannelStatus(final String channelId, final GitHubShared public void onSuccess(final int statusCode, final Map> headers, final String content) { handler.onSuccess(content); - } }); return true; @@ -74,6 +76,7 @@ public void onSuccess(final int statusCode, final Map> head GitHubSubscribers value = objectMapper.readValue(content, GitHubSubscribers.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -83,6 +86,10 @@ public void onSuccess(final int statusCode, final Map> head } public final boolean getChannelsByGame(final String gameUrl, final GitHubSharedHandler handler) { + if (gameUrl == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/getchannelsbygame", getBaseUrl()); RequestParams params = new RequestParams(); @@ -95,13 +102,16 @@ public final boolean getChannelsByGame(final String gameUrl, final GitHubSharedH public void onSuccess(final int statusCode, final Map> headers, final String content) { handler.onSuccess(content); - } }); return true; } public final boolean getGgChannelStatus(final String id, final GitHubSharedHandler handler) { + if (id == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/getggchannelstatus", getBaseUrl()); RequestParams params = new RequestParams(); @@ -114,13 +124,16 @@ public final boolean getGgChannelStatus(final String id, final GitHubSharedHandl public void onSuccess(final int statusCode, final Map> headers, final String content) { handler.onSuccess(content); - } }); return true; } public final boolean getToken(final String username, final String password, final GitHubTokenHandler handler) { + if (username == null || password == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/token", getBaseUrl()); RequestParams params = new RequestParams(); @@ -139,6 +152,7 @@ public void onSuccess(final int statusCode, final Map> head gg.auth().setRefreshToken(value.getRefreshToken()); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } @@ -148,6 +162,10 @@ public void onSuccess(final int statusCode, final Map> head } public final boolean getUpcomingBroadcast(final String id, final GitHubSharedHandler handler) { + if (id == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/getupcomingbroadcast", getBaseUrl()); RequestParams params = new RequestParams(); @@ -158,9 +176,7 @@ public final boolean getUpcomingBroadcast(final String id, final GitHubSharedHan http.post(url, params, new GoodGameHttpResponseHandler(handler) { @Override public void onSuccess(final int statusCode, final Map> headers, final String content) { - handler.onSuccess(content); - } }); return true; diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/InfoResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/InfoResource.java index 8e14e98..194c012 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/InfoResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/InfoResource.java @@ -37,6 +37,7 @@ public void onSuccess(final int statusCode, final Map> head Info value = objectMapper.readValue(content, Info.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/OauthResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/OauthResource.java index dab86d0..f6daa68 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/OauthResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/OauthResource.java @@ -20,6 +20,7 @@ */ public class OauthResource extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(OauthResource.class); + private static final String PARAMETERS_NULL = "{} parameters are null"; private static final String CODE = "code"; private static final String OAUTH = "%s/oauth"; @@ -57,6 +58,7 @@ public OauthResource(final String defaultBaseUrl, final int defaultApiVersion, f public final boolean getAccessToken(final boolean useAutorizationCode, final OauthResponseHandler handler) { if (this.gg.auth().getRedirectURI() == null || this.gg.getClientId() == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); return false; } @@ -70,6 +72,7 @@ public final boolean getAccessToken(final boolean useAutorizationCode, final Oau if (useAutorizationCode) { if (this.gg.auth().getAuthorizationCode() == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); return false; } params.put(REDIRECT_URI, this.gg.auth().getRedirectURI().toString()); @@ -80,6 +83,7 @@ public final boolean getAccessToken(final boolean useAutorizationCode, final Oau } else { if (this.gg.auth().getRefreshToken() == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); return false; } params.put(GRANT_TYPE, REFRESH_TOKEN); @@ -98,6 +102,7 @@ public void onSuccess(final int statusCode, final Map> head handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -122,6 +127,7 @@ public void onSuccess(final int statusCode, final Map> head handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/PlayerResourses.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/PlayerResourses.java index deb6979..d70f829 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/PlayerResourses.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/PlayerResourses.java @@ -16,6 +16,7 @@ */ public class PlayerResourses extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(PlayerResourses.class); + private static final String PARAMETERS_NULL = "{} parameters are null"; public PlayerResourses(final String defaultBaseUrl, final int defaultApiVersion) { super(defaultBaseUrl, defaultApiVersion); @@ -28,6 +29,10 @@ public PlayerResourses(final String defaultBaseUrl, final int defaultApiVersion) * @param handler */ public final boolean getPlayer(final String channelId, final PlayerResponseHandler handler) { + if (channelId == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/player/%s", getBaseUrl(), channelId); this.configureHeaders(); @@ -38,6 +43,7 @@ public void onSuccess(final int statusCode, final Map> head Player value = objectMapper.readValue(content, Player.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/SmilesResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/SmilesResource.java index 20892a7..d004c5f 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/SmilesResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/SmilesResource.java @@ -17,6 +17,7 @@ */ public class SmilesResource extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(SmilesResource.class); + private static final String PARAMETERS_NULL = "{} parameters should be > 0"; private static final String PAGE = "page"; public SmilesResource(final String baseUrl, final int apiVersion) { @@ -35,6 +36,10 @@ protected SmilesResource(final String baseUrl) { * @param handler */ public final boolean getChannelSmiles(final long channelID, final SmilesResponseHandler handler) { + if (channelID < 0) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/smiles/%s", getBaseUrl(), channelID); this.configureHeaders(); @@ -45,6 +50,7 @@ public void onSuccess(final int statusCode, final Map> head SmilesContainer value = objectMapper.readValue(content, SmilesContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -62,6 +68,11 @@ public void onSuccess(final int statusCode, final Map> head */ public final boolean getChannelSmiles(final long channelId, final int page, final SmilesResponseHandler handler) { + if (channelId < 0 || page < 0) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } + String url = String.format("%s/smiles/%s", getBaseUrl(), channelId); RequestParams params = new RequestParams(); @@ -75,6 +86,7 @@ public void onSuccess(final int statusCode, final Map> head SmilesContainer value = objectMapper.readValue(content, SmilesContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -99,6 +111,7 @@ public void onSuccess(final int statusCode, final Map> head SmilesContainer value = objectMapper.readValue(content, SmilesContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -114,6 +127,10 @@ public void onSuccess(final int statusCode, final Map> head * @param handler */ public final boolean getSmiles(final int page, final SmilesResponseHandler handler) { + if (page < 0) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/smiles", getBaseUrl()); RequestParams params = new RequestParams(); params.put(PAGE, page); @@ -126,6 +143,7 @@ public void onSuccess(final int statusCode, final Map> head SmilesContainer value = objectMapper.readValue(content, SmilesContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/java/ru/maximkulikov/goodgame/api/resources/StreamsResource.java b/src/main/java/ru/maximkulikov/goodgame/api/resources/StreamsResource.java index b0fb35e..63f9900 100644 --- a/src/main/java/ru/maximkulikov/goodgame/api/resources/StreamsResource.java +++ b/src/main/java/ru/maximkulikov/goodgame/api/resources/StreamsResource.java @@ -18,6 +18,7 @@ */ public class StreamsResource extends AbstractResource { private static final Logger logger = LoggerFactory.getLogger(StreamsResource.class); + private static final String PARAMETERS_NULL = "{} parameters are null"; public StreamsResource(final String baseUrl, final int apiVersion) { super(baseUrl, apiVersion); @@ -32,6 +33,10 @@ public StreamsResource(final String baseUrl, final int apiVersion) { * @param handler */ public final boolean getChannel(final String channel, final StreamChannelResponseHandler handler) { + if (channel == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/streams/%s", getBaseUrl(), channel); this.configureHeaders(); @@ -42,6 +47,7 @@ public void onSuccess(final int statusCode, final Map> head ChannelContainer value = objectMapper.readValue(content, ChannelContainer.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -66,6 +72,7 @@ public void onSuccess(final int statusCode, final Map> head EmbededChannels value = objectMapper.readValue(content, EmbededChannels.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } @@ -81,6 +88,10 @@ public void onSuccess(final int statusCode, final Map> head * @param handler */ public final boolean getStreams(final RequestParams params, final StreamsResponseHandler handler) { + if (params == null) { + logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName()); + return false; + } String url = String.format("%s/streams", getBaseUrl()); @@ -92,6 +103,7 @@ public void onSuccess(final int statusCode, final Map> head EmbededChannels value = objectMapper.readValue(content, EmbededChannels.class); handler.onSuccess(value); } catch (IOException e) { + logger.error("IOException {}", e.getLocalizedMessage()); handler.onFailure(e); } } diff --git a/src/main/test/ru/maximkulikov/goodgame/api/package-info.java b/src/main/test/ru/maximkulikov/goodgame/api/package-info.java deleted file mode 100644 index 7506113..0000000 --- a/src/main/test/ru/maximkulikov/goodgame/api/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package ru.maximkulikov.goodgame.api;