Enable VAPID
This commit is contained in:
@@ -6,11 +6,12 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
public class SubscriptionController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionController.class);
|
||||
|
||||
@@ -23,4 +24,9 @@ public class SubscriptionController {
|
||||
|
||||
return this.subscriptionService.subscribe(subscriptionDto).toResponseEntity();
|
||||
}
|
||||
|
||||
@GetMapping("subscription/vapidPublicKey")
|
||||
public String getVapidPublicKey() {
|
||||
return this.subscriptionService.getVapidPublicKey();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.pushservice.client.dto;
|
||||
|
||||
import de.pushservice.client.model.Urgency;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
|
||||
public class MessageDto {
|
||||
private String payload;
|
||||
@@ -36,4 +37,9 @@ public class MessageDto {
|
||||
public void setUrgency(Urgency urgency) {
|
||||
this.urgency = urgency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.pushservice.client.dto;
|
||||
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
|
||||
public class NotificationRequestDto {
|
||||
private String scope;
|
||||
private MessageDto messageDto;
|
||||
@@ -24,4 +26,9 @@ public class NotificationRequestDto {
|
||||
public void setMessageDto(MessageDto messageDto) {
|
||||
this.messageDto = messageDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.pushservice.client.dto;
|
||||
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Payload for a notification. Gets sent to the third party push service which forwards it to the user agent.
|
||||
@@ -60,4 +62,9 @@ public class PayloadDto {
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.pushservice.client.dto;
|
||||
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
|
||||
public class SubscriptionDto {
|
||||
private String auth;
|
||||
private String endpoint;
|
||||
@@ -37,4 +39,9 @@ public class SubscriptionDto {
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,4 +68,11 @@ public class SubscriptionService {
|
||||
LOGGER.error(String.format("Could not send notification! %s", responseReason));
|
||||
}
|
||||
}
|
||||
|
||||
public String getVapidPublicKey() {
|
||||
final ResponseEntity<String> responseEntity = new RestTemplate()
|
||||
.exchange(this.config.getServerUrl() + "vapidPublicKey", HttpMethod.GET, HttpEntity.EMPTY, String.class);
|
||||
|
||||
return responseEntity.getBody();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user