version bumps and update to log4j2

This commit is contained in:
Sven Kubiak 2015-11-29 10:35:32 +01:00
parent 02ba6c5f3f
commit 62c4286c3f
4 changed files with 111 additions and 72 deletions

View File

@ -1,10 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{dd.MM.yyyy;HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

70
pom.xml
View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.svenkubiak</groupId> <groupId>de.svenkubiak</groupId>
<artifactId>jpushover</artifactId> <artifactId>jpushover</artifactId>
@ -19,17 +20,17 @@
</developers> </developers>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<logback.version>1.1.3</logback.version> <log4j.version>2.4.1</log4j.version>
</properties> </properties>
<prerequisites> <prerequisites>
<maven>3.1.0</maven> <maven>3.3.0</maven>
</prerequisites> </prerequisites>
<scm> <scm>
<connection>scm:git:git@github.com:svenkubiak/JPushover.git</connection> <connection>scm:git:git@github.com:svenkubiak/JPushover.git</connection>
<developerConnection>scm:git:git@github.com:svenkubiak/JPushover.git</developerConnection> <developerConnection>scm:git:git@github.com:svenkubiak/JPushover.git</developerConnection>
<url>git@github.com:svenkubiak/JPushover.git</url> <url>git@github.com:svenkubiak/JPushover.git</url>
<tag>HEAD</tag> <tag>HEAD</tag>
</scm> </scm>
<name>JPushover</name> <name>JPushover</name>
<description>Convenient class for sending messages to Pushover in Java project</description> <description>Convenient class for sending messages to Pushover in Java project</description>
<url>https://github.com/svenkubiak/JPushover</url> <url>https://github.com/svenkubiak/JPushover</url>
@ -86,11 +87,46 @@
<goals>deploy</goals> <goals>deploy</goals>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId> <artifactId>versions-maven-plugin</artifactId>
<version>2.2</version> <version>2.2</version>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins> </plugins>
</build> </build>
<dependencies> <dependencies>
@ -102,7 +138,7 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId> <artifactId>fluent-hc</artifactId>
<version>4.4.1</version> <version>4.5.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
@ -110,14 +146,19 @@
<version>3.4</version> <version>3.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>logback-classic</artifactId> <artifactId>log4j-api</artifactId>
<version>${logback.version}</version> <version>${log4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>logback-core</artifactId> <artifactId>log4j-core</artifactId>
<version>${logback.version}</version> <version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@ -125,11 +166,6 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>

View File

@ -10,8 +10,8 @@ import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.fluent.Form; import org.apache.http.client.fluent.Form;
import org.apache.http.client.fluent.Request; import org.apache.http.client.fluent.Request;
import org.slf4j.Logger; import org.apache.logging.log4j.LogManager;
import org.slf4j.LoggerFactory; import org.apache.logging.log4j.Logger;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
@ -20,14 +20,14 @@ import de.svenkubiak.jpushover.enums.Priority;
import de.svenkubiak.jpushover.enums.Sound; import de.svenkubiak.jpushover.enums.Sound;
/** /**
* *
* @author svenkubiak * @author svenkubiak
* *
*/ */
public class JPushover { 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 static final int HTTP_OK = 200;
private String pushoverToken; private String pushoverToken;
private String pushoverUser; private String pushoverUser;
private String pushoverMessage; private String pushoverMessage;
@ -49,8 +49,8 @@ public class JPushover {
/** /**
* Your application's API token * Your application's API token
* (required) * (required)
* *
* @param token The pushover API token * @param token The pushover API token
* @return JPushover instance * @return JPushover instance
*/ */
@ -62,8 +62,8 @@ public class JPushover {
/** /**
* The user/group key (not e-mail address) of your user (or you), * The user/group key (not e-mail address) of your user (or you),
* viewable when logged into the @see <a href="https://pushover.net/login">pushover dashboard</a> * viewable when logged into the @see <a href="https://pushover.net/login">pushover dashboard</a>
* (required) * (required)
* *
* @param user The username * @param user The username
* @return JPushover instance * @return JPushover instance
*/ */
@ -71,11 +71,11 @@ public class JPushover {
this.pushoverUser = user; this.pushoverUser = user;
return this; return this;
} }
/** /**
* Specifies how often (in seconds) the Pushover servers will send the same notification to the user. * Specifies how often (in seconds) the Pushover servers will send the same notification to the user.
* Only required if priority is set to emergency. * Only required if priority is set to emergency.
* *
* @param retry Number of seconds * @param retry Number of seconds
* @return JPushover instance * @return JPushover instance
*/ */
@ -83,11 +83,11 @@ public class JPushover {
this.pushoverRetry = retry; this.pushoverRetry = retry;
return this; return this;
} }
/** /**
* Specifies how many seconds your notification will continue to be retried for (every retry seconds). * Specifies how many seconds your notification will continue to be retried for (every retry seconds).
* Only required if priority is set to emergency. * Only required if priority is set to emergency.
* *
* @param expire Number of seconds * @param expire Number of seconds
* @return JPushover instance * @return JPushover instance
*/ */
@ -97,9 +97,9 @@ public class JPushover {
} }
/** /**
* Your message * Your message
* (required) * (required)
* *
* @param message The message to sent * @param message The message to sent
* @return JPushover instance * @return JPushover instance
*/ */
@ -112,7 +112,7 @@ public class JPushover {
* Your user's device name to send the message directly to that device, * Your user's device name to send the message directly to that device,
* rather than all of the user's devices * rather than all of the user's devices
* (optional) * (optional)
* *
* @param device The device name * @param device The device name
* @return JPushover instance * @return JPushover instance
*/ */
@ -124,7 +124,7 @@ public class JPushover {
/** /**
* Your message's title, otherwise your app's name is used * Your message's title, otherwise your app's name is used
* (optional) * (optional)
* *
* @param title The title * @param title The title
* @return JPushover instance * @return JPushover instance
*/ */
@ -136,7 +136,7 @@ public class JPushover {
/** /**
* A supplementary URL to show with your message * A supplementary URL to show with your message
* (optional) * (optional)
* *
* @param url The url * @param url The url
* @return JPushover instance * @return JPushover instance
*/ */
@ -147,7 +147,7 @@ public class JPushover {
/** /**
* A title for your supplementary URL, otherwise just the URL is shown * A title for your supplementary URL, otherwise just the URL is shown
* *
* @param urlTitle The url title * @param urlTitle The url title
* @return JPushover instance * @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, * 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 * rather than the time your message is received by our API
* *
* @param timestamp The Unix timestamp * @param timestamp The Unix timestamp
* @return JPushover instance * @return JPushover instance
*/ */
@ -171,7 +171,7 @@ public class JPushover {
/** /**
* Priority of the message based on the @see <a href="https://pushover.net/api#priority">documentation</a> * Priority of the message based on the @see <a href="https://pushover.net/api#priority">documentation</a>
* (optional) * (optional)
* *
* @param priority The priority enum * @param priority The priority enum
* @return JPushover instance * @return JPushover instance
*/ */
@ -184,7 +184,7 @@ public class JPushover {
* The name of one of the sounds supported by device clients to override * The name of one of the sounds supported by device clients to override
* the user's default sound choice * the user's default sound choice
* (optional) * (optional)
* *
* @param sound THe sound enum * @param sound THe sound enum
* @return JPushover instance * @return JPushover instance
*/ */
@ -192,13 +192,13 @@ public class JPushover {
this.pushoverSound = sound; this.pushoverSound = sound;
return this; return this;
} }
/** /**
* Callback parameter may be supplied with a publicly-accessible URL that the * 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 * Pushover servers will send a request to when the user has acknowledged your
* notification. * notification.
* Only required if priority is set to emergency. * Only required if priority is set to emergency.
* *
* @param callback * @param callback
* @return * @return
*/ */
@ -206,61 +206,61 @@ public class JPushover {
this.pushoverCallback = callback; this.pushoverCallback = callback;
return this; return this;
} }
/** /**
* Sends a validation request to pushover ensuring that the token and user * 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. * is correct, that there is at least one active device on the account.
* *
* Requires token parameter * Requires token parameter
* Requires user parameter * Requires user parameter
* Optional device parameter to check specific device * 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 * @return true if token and user are valid and at least on device is on the account, false otherwise
*/ */
public boolean validate() { public boolean validate() {
Preconditions.checkNotNull(this.pushoverToken, "Token is required for validation"); Preconditions.checkNotNull(this.pushoverToken, "Token is required for validation");
Preconditions.checkNotNull(this.pushoverUser, "User is required for validation"); Preconditions.checkNotNull(this.pushoverUser, "User is required for validation");
List<NameValuePair> params = Form.form() final List<NameValuePair> params = Form.form()
.add(Constants.TOKEN.get(), this.pushoverToken) .add(Constants.TOKEN.get(), this.pushoverToken)
.add(Constants.USER.get(), this.pushoverUser) .add(Constants.USER.get(), this.pushoverUser)
.add(Constants.DEVICE.get(), this.pushoverDevice) .add(Constants.DEVICE.get(), this.pushoverDevice)
.build(); .build();
HttpResponse httpResponse = null; HttpResponse httpResponse = null;
boolean valid = false; boolean valid = false;
try { try {
httpResponse = Request.Post(Constants.VALIDATION_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse(); httpResponse = Request.Post(Constants.VALIDATION_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse();
if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HTTP_OK) { 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")) { if (StringUtils.isNotBlank(response) && response.contains("\"status\":1")) {
valid = true; valid = true;
} }
} }
} catch (IOException e) { } catch (final IOException e) {
LOG.error("Failed to send validation requeste to pushover", e); LOG.error("Failed to send validation requeste to pushover", e);
} }
return valid; return valid;
} }
/** /**
* Sends a message to pushover * Sends a message to pushover
* *
* @return JPushoverResponse instance * @return JPushoverResponse instance
*/ */
public JPushoverResponse push() { public JPushoverResponse push() {
Preconditions.checkNotNull(this.pushoverToken, "Token is required for a message"); Preconditions.checkNotNull(this.pushoverToken, "Token is required for a message");
Preconditions.checkNotNull(this.pushoverUser, "User 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"); Preconditions.checkNotNull(this.pushoverMessage, "Message is required for a message");
if (Priority.EMERGENCY.equals(this.pushoverPriority)) { if (Priority.EMERGENCY.equals(this.pushoverPriority)) {
Preconditions.checkNotNull(this.pushoverRetry, "Retry is required on priority emergency"); Preconditions.checkNotNull(this.pushoverRetry, "Retry is required on priority emergency");
Preconditions.checkNotNull(this.pushoverExpire, "Expire is required on priority emergency"); Preconditions.checkNotNull(this.pushoverExpire, "Expire is required on priority emergency");
} }
List<NameValuePair> params = Form.form() final List<NameValuePair> params = Form.form()
.add(Constants.TOKEN.get(), this.pushoverToken) .add(Constants.TOKEN.get(), this.pushoverToken)
.add(Constants.USER.get(), this.pushoverUser) .add(Constants.USER.get(), this.pushoverUser)
.add(Constants.MESSAGE.get(), this.pushoverMessage) .add(Constants.MESSAGE.get(), this.pushoverMessage)
@ -275,24 +275,24 @@ public class JPushover {
.add(Constants.TIMESTAMP.get(), this.pushoverTimestamp) .add(Constants.TIMESTAMP.get(), this.pushoverTimestamp)
.add(Constants.SOUND.get(), this.pushoverSound.get()) .add(Constants.SOUND.get(), this.pushoverSound.get())
.build(); .build();
HttpResponse httpResponse = null; HttpResponse httpResponse = null;
JPushoverResponse jPushoverResponse = null; JPushoverResponse jPushoverResponse = null;
try { try {
httpResponse = Request.Post(Constants.MESSAGES_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse(); httpResponse = Request.Post(Constants.MESSAGES_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse();
if (httpResponse != null) { if (httpResponse != null) {
int status = httpResponse.getStatusLine().getStatusCode(); final int status = httpResponse.getStatusLine().getStatusCode();
jPushoverResponse = new JPushoverResponse() jPushoverResponse = new JPushoverResponse()
.httpStatus(status) .httpStatus(status)
.response(IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8)) .response(IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8))
.isSuccessful((status == HTTP_OK) ? true : false); .isSuccessful((status == HTTP_OK) ? true : false);
} }
} catch (IOException e) { } catch (final IOException e) {
LOG.error("Failed to send message to pushover", e); LOG.error("Failed to send message to pushover", e);
} }
return (jPushoverResponse == null) ? new JPushoverResponse().isSuccessful(false) : jPushoverResponse; return (jPushoverResponse == null) ? new JPushoverResponse().isSuccessful(false) : jPushoverResponse;
} }

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{dd.MM.yyyy HH:mm:ss,SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>