diff --git a/logback.xml b/logback.xml deleted file mode 100644 index 8473ed0..0000000 --- a/logback.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - %d{dd.MM.yyyy;HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 69e566b..6cd7db2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 de.svenkubiak jpushover @@ -19,17 +20,17 @@ UTF-8 - 1.1.3 + 2.4.1 - 3.1.0 + 3.3.0 scm:git:git@github.com:svenkubiak/JPushover.git scm:git:git@github.com:svenkubiak/JPushover.git git@github.com:svenkubiak/JPushover.git - HEAD - + HEAD + JPushover Convenient class for sending messages to Pushover in Java project https://github.com/svenkubiak/JPushover @@ -86,11 +87,46 @@ deploy + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + org.codehaus.mojo versions-maven-plugin 2.2 + + org.apache.maven.plugins + maven-clean-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19 + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + org.apache.maven.plugins + maven-site-plugin + 3.4 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + @@ -102,7 +138,7 @@ org.apache.httpcomponents fluent-hc - 4.4.1 + 4.5.1 org.apache.commons @@ -110,14 +146,19 @@ 3.4 - ch.qos.logback - logback-classic - ${logback.version} + org.apache.logging.log4j + log4j-api + ${log4j.version} - ch.qos.logback - logback-core - ${logback.version} + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} junit @@ -125,11 +166,6 @@ 4.12 test - - org.slf4j - slf4j-api - 1.7.12 - com.google.guava guava diff --git a/src/main/java/de/svenkubiak/jpushover/JPushover.java b/src/main/java/de/svenkubiak/jpushover/JPushover.java index 20cfaf2..4c9ddf5 100644 --- a/src/main/java/de/svenkubiak/jpushover/JPushover.java +++ b/src/main/java/de/svenkubiak/jpushover/JPushover.java @@ -10,8 +10,8 @@ import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.fluent.Form; import org.apache.http.client.fluent.Request; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.google.common.base.Preconditions; @@ -20,14 +20,14 @@ import de.svenkubiak.jpushover.enums.Priority; import de.svenkubiak.jpushover.enums.Sound; /** - * + * * @author svenkubiak * */ public class JPushover { - private static final Logger LOG = LoggerFactory.getLogger(JPushover.class); + private static final Logger LOG = LogManager.getLogger(JPushover.class); private static final int HTTP_OK = 200; - + private String pushoverToken; private String pushoverUser; private String pushoverMessage; @@ -49,8 +49,8 @@ public class JPushover { /** * Your application's API token - * (required) - * + * (required) + * * @param token The pushover API token * @return JPushover instance */ @@ -62,8 +62,8 @@ public class JPushover { /** * The user/group key (not e-mail address) of your user (or you), * viewable when logged into the @see pushover dashboard - * (required) - * + * (required) + * * @param user The username * @return JPushover instance */ @@ -71,11 +71,11 @@ public class JPushover { this.pushoverUser = user; return this; } - + /** * Specifies how often (in seconds) the Pushover servers will send the same notification to the user. * Only required if priority is set to emergency. - * + * * @param retry Number of seconds * @return JPushover instance */ @@ -83,11 +83,11 @@ public class JPushover { this.pushoverRetry = retry; return this; } - + /** * Specifies how many seconds your notification will continue to be retried for (every retry seconds). * Only required if priority is set to emergency. - * + * * @param expire Number of seconds * @return JPushover instance */ @@ -97,9 +97,9 @@ public class JPushover { } /** - * Your message - * (required) - * + * Your message + * (required) + * * @param message The message to sent * @return JPushover instance */ @@ -112,7 +112,7 @@ public class JPushover { * Your user's device name to send the message directly to that device, * rather than all of the user's devices * (optional) - * + * * @param device The device name * @return JPushover instance */ @@ -124,7 +124,7 @@ public class JPushover { /** * Your message's title, otherwise your app's name is used * (optional) - * + * * @param title The title * @return JPushover instance */ @@ -136,7 +136,7 @@ public class JPushover { /** * A supplementary URL to show with your message * (optional) - * + * * @param url The url * @return JPushover instance */ @@ -147,7 +147,7 @@ public class JPushover { /** * A title for your supplementary URL, otherwise just the URL is shown - * + * * @param urlTitle The url title * @return JPushover instance */ @@ -159,7 +159,7 @@ public class JPushover { /** * A Unix timestamp of your message's date and time to display to the user, * rather than the time your message is received by our API - * + * * @param timestamp The Unix timestamp * @return JPushover instance */ @@ -171,7 +171,7 @@ public class JPushover { /** * Priority of the message based on the @see documentation * (optional) - * + * * @param priority The priority enum * @return JPushover instance */ @@ -184,7 +184,7 @@ public class JPushover { * The name of one of the sounds supported by device clients to override * the user's default sound choice * (optional) - * + * * @param sound THe sound enum * @return JPushover instance */ @@ -192,13 +192,13 @@ public class JPushover { this.pushoverSound = sound; return this; } - + /** * Callback parameter may be supplied with a publicly-accessible URL that the * Pushover servers will send a request to when the user has acknowledged your * notification. * Only required if priority is set to emergency. - * + * * @param callback * @return */ @@ -206,61 +206,61 @@ public class JPushover { this.pushoverCallback = callback; return this; } - + /** * Sends a validation request to pushover ensuring that the token and user * is correct, that there is at least one active device on the account. - * + * * Requires token parameter * Requires user parameter * Optional device parameter to check specific device - * + * * @return true if token and user are valid and at least on device is on the account, false otherwise */ public boolean validate() { Preconditions.checkNotNull(this.pushoverToken, "Token is required for validation"); Preconditions.checkNotNull(this.pushoverUser, "User is required for validation"); - - List params = Form.form() + + final List params = Form.form() .add(Constants.TOKEN.get(), this.pushoverToken) .add(Constants.USER.get(), this.pushoverUser) .add(Constants.DEVICE.get(), this.pushoverDevice) .build(); - + HttpResponse httpResponse = null; boolean valid = false; try { httpResponse = Request.Post(Constants.VALIDATION_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse(); - + if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HTTP_OK) { - String response = IOUtils.toString(httpResponse.getEntity().getContent()); + final String response = IOUtils.toString(httpResponse.getEntity().getContent()); if (StringUtils.isNotBlank(response) && response.contains("\"status\":1")) { valid = true; } } - } catch (IOException e) { + } catch (final IOException e) { LOG.error("Failed to send validation requeste to pushover", e); } - + return valid; } /** * Sends a message to pushover - * + * * @return JPushoverResponse instance */ public JPushoverResponse push() { Preconditions.checkNotNull(this.pushoverToken, "Token is required for a message"); Preconditions.checkNotNull(this.pushoverUser, "User is required for a message"); Preconditions.checkNotNull(this.pushoverMessage, "Message is required for a message"); - + if (Priority.EMERGENCY.equals(this.pushoverPriority)) { Preconditions.checkNotNull(this.pushoverRetry, "Retry is required on priority emergency"); Preconditions.checkNotNull(this.pushoverExpire, "Expire is required on priority emergency"); } - - List params = Form.form() + + final List params = Form.form() .add(Constants.TOKEN.get(), this.pushoverToken) .add(Constants.USER.get(), this.pushoverUser) .add(Constants.MESSAGE.get(), this.pushoverMessage) @@ -275,24 +275,24 @@ public class JPushover { .add(Constants.TIMESTAMP.get(), this.pushoverTimestamp) .add(Constants.SOUND.get(), this.pushoverSound.get()) .build(); - + HttpResponse httpResponse = null; JPushoverResponse jPushoverResponse = null; try { httpResponse = Request.Post(Constants.MESSAGES_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse(); - + if (httpResponse != null) { - int status = httpResponse.getStatusLine().getStatusCode(); - + final int status = httpResponse.getStatusLine().getStatusCode(); + jPushoverResponse = new JPushoverResponse() .httpStatus(status) .response(IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8)) .isSuccessful((status == HTTP_OK) ? true : false); } - } catch (IOException e) { + } catch (final IOException e) { LOG.error("Failed to send message to pushover", e); } - + return (jPushoverResponse == null) ? new JPushoverResponse().isSuccessful(false) : jPushoverResponse; } diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..c8ea537 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file