Clean refactoring using Java 11
This commit is contained in:
parent
4a0c0b1e6a
commit
7626f48a06
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
.idea
|
||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
image: jdk11-maven3
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- sonar
|
- sonar
|
||||||
|
14
README.md
14
README.md
@ -1,11 +1,11 @@
|
|||||||
[](https://maven-badges.herokuapp.com/maven-central/de.svenkubiak/jpushover)
|
[](https://maven-badges.herokuapp.com/maven-central/de.svenkubiak/jpushover)
|
||||||
[](http://travis-ci.org/svenkubiak/JPushover)
|
|
||||||
|
|
||||||
|
|
||||||
JPushover
|
JPushover
|
||||||
================
|
================
|
||||||
|
|
||||||
Convenient class for sending messages to [Pushover][1] in Java.
|
Minimalist convenient class for sending messages to [Pushover][1] in Java.
|
||||||
|
|
||||||
|
Starting with version 3.x JPushover is build for and requires Java 11.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
------------------
|
------------------
|
||||||
@ -20,7 +20,7 @@ Usage
|
|||||||
```
|
```
|
||||||
2) Use the JPushover object with the required informations were you want
|
2) Use the JPushover object with the required informations were you want
|
||||||
```
|
```
|
||||||
JPushover.build()
|
JPushover.create()
|
||||||
.withToken("MyToken")
|
.withToken("MyToken")
|
||||||
.withUser("MyUser")
|
.withUser("MyUser")
|
||||||
.withMessage("MyMessage")
|
.withMessage("MyMessage")
|
||||||
@ -30,14 +30,14 @@ You can additionally add all available options from the official [Pushover docum
|
|||||||
|
|
||||||
You can also validate a user and token using the following method
|
You can also validate a user and token using the following method
|
||||||
|
|
||||||
boolean valid = JPushover.build()
|
boolean valid = JPushover.create()
|
||||||
.withToken("MyToken")
|
.withToken("MyToken")
|
||||||
.withUser("MyUser")
|
.withUser("MyUser")
|
||||||
.validate();
|
.validate();
|
||||||
|
|
||||||
If you want more information and/or the response from the Pushover API, use the JPushoverResponse object.
|
If you want more information and/or the response from the Pushover API, use the JPushoverResponse object.
|
||||||
|
|
||||||
JPushoverResponse jPushoverResponse = JPushover.build()
|
JPushoverResponse jPushoverResponse = JPushover.create()
|
||||||
.withToken("MyToken")
|
.withToken("MyToken")
|
||||||
.withUser("MyUser")
|
.withUser("MyUser")
|
||||||
.withMessage("MyMessage")
|
.withMessage("MyMessage")
|
||||||
@ -46,4 +46,4 @@ If you want more information and/or the response from the Pushover API, use the
|
|||||||
The JPushoverResponse will return the raw HTTP status code, along with the raw JSON response and a convenient boolean if the request was successful or not.
|
The JPushoverResponse will return the raw HTTP status code, along with the raw JSON response and a convenient boolean if the request was successful or not.
|
||||||
|
|
||||||
[1]: https://pushover.net
|
[1]: https://pushover.net
|
||||||
[2]: https://pushover.net/api
|
[2]: https://pushover.net/api
|
78
pom.xml
78
pom.xml
@ -18,9 +18,8 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<properties>
|
<properties>
|
||||||
|
<java.version>11</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<log4j.version>2.11.1</log4j.version>
|
|
||||||
<httpcomponents.version>4.5.6</httpcomponents.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:svenkubiak/JPushover.git</connection>
|
<connection>scm:git:git@github.com:svenkubiak/JPushover.git</connection>
|
||||||
@ -29,7 +28,7 @@
|
|||||||
<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>Minimalist 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>
|
||||||
<prerequisites>
|
<prerequisites>
|
||||||
<maven>3.0</maven>
|
<maven>3.0</maven>
|
||||||
@ -41,8 +40,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>${java.version}</source>
|
||||||
<target>1.8</target>
|
<target>${java.version}</target>
|
||||||
<debug>false</debug>
|
<debug>false</debug>
|
||||||
<optimize>true</optimize>
|
<optimize>true</optimize>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -63,7 +62,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.0.0-M1</version>
|
<version>3.0.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-javadocs</id>
|
<id>attach-javadocs</id>
|
||||||
@ -76,8 +75,24 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>sonar-maven-plugin</artifactId>
|
<artifactId>sonar-maven-plugin</artifactId>
|
||||||
<version>3.3.0.603</version>
|
<version>3.5.0.1254</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.owasp</groupId>
|
||||||
|
<artifactId>dependency-check-maven</artifactId>
|
||||||
|
<version>3.3.2</version>
|
||||||
|
<configuration>
|
||||||
|
<cveValidForHours>12</cveValidForHours>
|
||||||
|
<failBuildOnCVSS>4</failBuildOnCVSS>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
@ -90,80 +105,55 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>2.8.2</version>
|
<version>3.0.0-M1</version>
|
||||||
</plugin>
|
</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.4</version>
|
<version>2.7</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.1.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.20</version>
|
<version>2.22.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.1.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
<version>3.6</version>
|
<version>3.7.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
<version>2.5.2</version>
|
<version>3.0.0-M1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.1.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>com.eclipsesource.minimal-json</groupId>
|
||||||
<artifactId>httpmime</artifactId>
|
<artifactId>minimal-json</artifactId>
|
||||||
<version>${httpcomponents.version}</version>
|
<version>0.9.5</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.6</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
|
||||||
<artifactId>fluent-hc</artifactId>
|
|
||||||
<version>${httpcomponents.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.8</version>
|
<version>3.8.1</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-api</artifactId>
|
|
||||||
<version>${log4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-core</artifactId>
|
|
||||||
<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>
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
package de.svenkubiak.jpushover;
|
package de.svenkubiak.jpushover;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ProxySelector;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import com.eclipsesource.json.Json;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.Consts;
|
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
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.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import de.svenkubiak.jpushover.enums.Constants;
|
import de.svenkubiak.jpushover.enums.Constants;
|
||||||
import de.svenkubiak.jpushover.enums.Priority;
|
import de.svenkubiak.jpushover.enums.Priority;
|
||||||
@ -25,8 +23,9 @@ import de.svenkubiak.jpushover.enums.Sound;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JPushover {
|
public class JPushover {
|
||||||
private static final Logger LOG = LogManager.getLogger(JPushover.class);
|
|
||||||
private static final int HTTP_OK = 200;
|
private static final int HTTP_OK = 200;
|
||||||
|
private Priority pushoverPriority;
|
||||||
|
private Sound pushoverSound;
|
||||||
private String pushoverToken;
|
private String pushoverToken;
|
||||||
private String pushoverUser;
|
private String pushoverUser;
|
||||||
private String pushoverMessage;
|
private String pushoverMessage;
|
||||||
@ -38,9 +37,8 @@ public class JPushover {
|
|||||||
private String pushoverRetry;
|
private String pushoverRetry;
|
||||||
private String pushoverExpire;
|
private String pushoverExpire;
|
||||||
private String pushoverCallback;
|
private String pushoverCallback;
|
||||||
private Priority pushoverPriority;
|
private String proxyHost;
|
||||||
private Sound pushoverSound;
|
private int proxyPort;
|
||||||
private HttpHost proxy;
|
|
||||||
private boolean pushoverHtml;
|
private boolean pushoverHtml;
|
||||||
|
|
||||||
public JPushover() {
|
public JPushover() {
|
||||||
@ -52,7 +50,7 @@ public class JPushover {
|
|||||||
* Creates a new JPushover instance
|
* Creates a new JPushover instance
|
||||||
* @return JPushover instance
|
* @return JPushover instance
|
||||||
*/
|
*/
|
||||||
public static JPushover build() {
|
public static JPushover create() {
|
||||||
return new JPushover();
|
return new JPushover();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,11 +228,13 @@ public class JPushover {
|
|||||||
/**
|
/**
|
||||||
* Uses the given proxy for HTTP requests
|
* Uses the given proxy for HTTP requests
|
||||||
*
|
*
|
||||||
* @param proxy The host that should be used as Proxy
|
* @param proxyHost The host that should be used for the Proxy
|
||||||
|
* @param proxyPort The port that should be used for the Proxy
|
||||||
* @return JPushover instance
|
* @return JPushover instance
|
||||||
*/
|
*/
|
||||||
public final JPushover withProxy(final HttpHost proxy) {
|
public final JPushover withProxy(final String proxyHost, final int proxyPort) {
|
||||||
this.proxy = proxy;
|
this.proxyHost = proxyHost;
|
||||||
|
this.proxyPort = proxyPort;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,36 +248,23 @@ public class JPushover {
|
|||||||
*
|
*
|
||||||
* @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() throws IOException, InterruptedException {
|
||||||
Objects.requireNonNull(this.pushoverToken, "Token is required for validation");
|
Objects.requireNonNull(this.pushoverToken, "Token is required for validation");
|
||||||
Objects.requireNonNull(this.pushoverUser, "User is required for validation");
|
Objects.requireNonNull(this.pushoverUser, "User is required for validation");
|
||||||
|
|
||||||
final List<NameValuePair> params = Form.form()
|
var body = Json.object()
|
||||||
.add(Constants.TOKEN.toString(), this.pushoverToken)
|
.add(Constants.TOKEN.toString(), this.pushoverToken)
|
||||||
.add(Constants.USER.toString(), this.pushoverUser)
|
.add(Constants.USER.toString(), this.pushoverUser)
|
||||||
.add(Constants.DEVICE.toString(), this.pushoverDevice)
|
.add(Constants.DEVICE.toString(), this.pushoverDevice);
|
||||||
.build();
|
|
||||||
|
|
||||||
boolean valid = false;
|
var httpResponse = getResponse(body.toString(), Constants.VALIDATION_URL.toString());
|
||||||
try {
|
|
||||||
final Request request = Request.Post(Constants.VALIDATION_URL.toString());
|
|
||||||
if (proxy != null) {
|
|
||||||
request.viaProxy(proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
final HttpResponse httpResponse = request
|
|
||||||
.bodyForm(params, Consts.UTF_8)
|
|
||||||
.execute()
|
|
||||||
.returnResponse();
|
|
||||||
|
|
||||||
if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HTTP_OK) {
|
var valid = false;
|
||||||
final String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8);
|
if (httpResponse.statusCode() == HTTP_OK) {
|
||||||
if (StringUtils.isNotBlank(response) && response.contains("\"status\":1")) {
|
var response = httpResponse.body();
|
||||||
valid = true;
|
if (StringUtils.isNotBlank(response) && response.contains("\"status\":1")) {
|
||||||
}
|
valid = true;
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
|
||||||
LOG.error("Failed to send validation requeste to pushover", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
@ -288,7 +275,7 @@ public class JPushover {
|
|||||||
*
|
*
|
||||||
* @return JPushoverResponse instance
|
* @return JPushoverResponse instance
|
||||||
*/
|
*/
|
||||||
public final JPushoverResponse push() {
|
public final JPushoverResponse push() throws IOException, InterruptedException {
|
||||||
Objects.requireNonNull(this.pushoverToken, "Token is required for a message");
|
Objects.requireNonNull(this.pushoverToken, "Token is required for a message");
|
||||||
Objects.requireNonNull(this.pushoverUser, "User is required for a message");
|
Objects.requireNonNull(this.pushoverUser, "User is required for a message");
|
||||||
Objects.requireNonNull(this.pushoverMessage, "Message is required for a message");
|
Objects.requireNonNull(this.pushoverMessage, "Message is required for a message");
|
||||||
@ -298,7 +285,7 @@ public class JPushover {
|
|||||||
Objects.requireNonNull(this.pushoverExpire, "Expire is required on priority emergency");
|
Objects.requireNonNull(this.pushoverExpire, "Expire is required on priority emergency");
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<NameValuePair> params = Form.form()
|
var body = Json.object()
|
||||||
.add(Constants.TOKEN.toString(), this.pushoverToken)
|
.add(Constants.TOKEN.toString(), this.pushoverToken)
|
||||||
.add(Constants.USER.toString(), this.pushoverUser)
|
.add(Constants.USER.toString(), this.pushoverUser)
|
||||||
.add(Constants.MESSAGE.toString(), this.pushoverMessage)
|
.add(Constants.MESSAGE.toString(), this.pushoverMessage)
|
||||||
@ -312,88 +299,33 @@ public class JPushover {
|
|||||||
.add(Constants.PRIORITY.toString(), this.pushoverPriority.toString())
|
.add(Constants.PRIORITY.toString(), this.pushoverPriority.toString())
|
||||||
.add(Constants.TIMESTAMP.toString(), this.pushoverTimestamp)
|
.add(Constants.TIMESTAMP.toString(), this.pushoverTimestamp)
|
||||||
.add(Constants.SOUND.toString(), this.pushoverSound.toString())
|
.add(Constants.SOUND.toString(), this.pushoverSound.toString())
|
||||||
.add(Constants.HTML.toString(), this.pushoverHtml ? "1" : "0")
|
.add(Constants.HTML.toString(), this.pushoverHtml ? "1" : "0");
|
||||||
.build();
|
|
||||||
|
|
||||||
final JPushoverResponse jPushoverResponse = new JPushoverResponse().isSuccessful(false);
|
var httpResponse = getResponse(body.toString(), Constants.MESSAGES_URL.toString());
|
||||||
try {
|
|
||||||
final HttpResponse httpResponse = Request.Post(Constants.MESSAGES_URL.toString())
|
|
||||||
.bodyForm(params, Consts.UTF_8)
|
|
||||||
.execute()
|
|
||||||
.returnResponse();
|
|
||||||
|
|
||||||
if (httpResponse != null) {
|
JPushoverResponse jPushoverResponse = new JPushoverResponse().isSuccessful(false);
|
||||||
final int status = httpResponse.getStatusLine().getStatusCode();
|
jPushoverResponse
|
||||||
|
.httpStatus(httpResponse.statusCode())
|
||||||
jPushoverResponse
|
.response(httpResponse.body())
|
||||||
.httpStatus(status)
|
.isSuccessful((httpResponse.statusCode() == HTTP_OK) ? true : false);
|
||||||
.response(IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8))
|
|
||||||
.isSuccessful((status == HTTP_OK) ? true : false);
|
|
||||||
}
|
|
||||||
} catch (final IOException e) {
|
|
||||||
LOG.error("Failed to send message to pushover", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jPushoverResponse;
|
return jPushoverResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
private HttpResponse<String> getResponse(String body, String url) throws IOException, InterruptedException {
|
||||||
return pushoverToken;
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||||
}
|
.uri(URI.create(url))
|
||||||
|
.timeout(Duration.ofSeconds(5))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
|
.build();
|
||||||
|
|
||||||
public String getUser() {
|
HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
|
||||||
return pushoverUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
if (StringUtils.isNotBlank(this.proxyHost) && this.proxyPort > 0) {
|
||||||
return pushoverMessage;
|
httpClientBuilder.proxy(ProxySelector.of(new InetSocketAddress(this.proxyHost, this.proxyPort)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDevice() {
|
return httpClientBuilder.build().send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||||
return pushoverDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return pushoverTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return pushoverUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrlTitle() {
|
|
||||||
return pushoverUrlTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimestamp() {
|
|
||||||
return pushoverTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRetry() {
|
|
||||||
return pushoverRetry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExpire() {
|
|
||||||
return pushoverExpire;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCallback() {
|
|
||||||
return pushoverCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Priority getPriority() {
|
|
||||||
return pushoverPriority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sound getSound() {
|
|
||||||
return pushoverSound;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHtml() {
|
|
||||||
return pushoverHtml;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpHost getProxy() {
|
|
||||||
return proxy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
6
src/main/java/module-info.java
Normal file
6
src/main/java/module-info.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module jpushover {
|
||||||
|
requires java.net.http;
|
||||||
|
requires minimal.json;
|
||||||
|
requires org.apache.commons.lang3;
|
||||||
|
exports de.svenkubiak.jpushover;
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,78 +0,0 @@
|
|||||||
package de.svenkubiak.jpushover;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.svenkubiak.jpushover.enums.Priority;
|
|
||||||
import de.svenkubiak.jpushover.enums.Sound;
|
|
||||||
|
|
||||||
public class TestJPushover {
|
|
||||||
private static final String USER = "user";
|
|
||||||
private static final String URL_TITLE = "urlTitle";
|
|
||||||
private static final String URL = "url";
|
|
||||||
private static final String TOKEN = "token";
|
|
||||||
private static final String TITLE = "title";
|
|
||||||
private static final String TIMESTAMP = "timestamp";
|
|
||||||
private static final String RETRY = "retry";
|
|
||||||
private static final String MESSAGE = "message";
|
|
||||||
private static final String EXPIRE = "expire";
|
|
||||||
private static final String DEVICE = "device";
|
|
||||||
private static final String CALLBACK = "callback";
|
|
||||||
private static final HttpHost PROXY = new HttpHost("localhost");
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestValues(){
|
|
||||||
final JPushover push = new JPushover();
|
|
||||||
|
|
||||||
push.withCallback(CALLBACK);
|
|
||||||
assertEquals(push.getCallback(), CALLBACK);
|
|
||||||
|
|
||||||
push.withDevice(DEVICE);
|
|
||||||
assertEquals(push.getDevice(), DEVICE);
|
|
||||||
|
|
||||||
push.withExpire(EXPIRE);
|
|
||||||
assertEquals(push.getExpire(), EXPIRE);
|
|
||||||
|
|
||||||
push.withMessage(MESSAGE);
|
|
||||||
assertEquals(push.getMessage(), MESSAGE);
|
|
||||||
|
|
||||||
push.withPriority(Priority.HIGH);
|
|
||||||
assertEquals(push.getPriority(), Priority.HIGH);
|
|
||||||
|
|
||||||
push.withRetry(RETRY);
|
|
||||||
assertEquals(push.getRetry(), RETRY);
|
|
||||||
|
|
||||||
push.withSound(Sound.ALIEN);
|
|
||||||
assertEquals(push.getSound(), Sound.ALIEN);
|
|
||||||
|
|
||||||
push.withTimestamp(TIMESTAMP);
|
|
||||||
assertEquals(push.getTimestamp(), TIMESTAMP);
|
|
||||||
|
|
||||||
push.withTitle(TITLE);
|
|
||||||
assertEquals(push.getTitle(), TITLE);
|
|
||||||
|
|
||||||
push.withToken(TOKEN);
|
|
||||||
assertEquals(push.getToken(), TOKEN);
|
|
||||||
|
|
||||||
push.withUrl(URL);
|
|
||||||
assertEquals(push.getUrl(), URL);
|
|
||||||
|
|
||||||
push.withUrlTitle(URL_TITLE);
|
|
||||||
assertEquals(push.getUrlTitle(), URL_TITLE);
|
|
||||||
|
|
||||||
push.withUser(USER);
|
|
||||||
assertEquals(push.getUser(), USER);
|
|
||||||
|
|
||||||
push.enableHtml();
|
|
||||||
assertTrue(push.isHtml());
|
|
||||||
|
|
||||||
push.withProxy(PROXY);
|
|
||||||
assertEquals(push.getProxy(), PROXY);
|
|
||||||
|
|
||||||
final JPushoverResponse response = push.push();
|
|
||||||
assertTrue(response != null);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user