I have vaadin spring-boot project with vaadin 21, java 16, spring-boot 2.5.4. I added push notifications mixed from this guide and this guide Since i added MessageEndPoint with Vaadin @Endpoint annotation, i have this mistake
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
with 405 mistake in browser console and my icons and images from /resourses folder do not load
MessageEndpoint class code:
@Endpoint
@AnonymousAllowed
@RestController
@RequestMapping("connect/MessageEndpoint")
public class MessageEndpoint {
@PostMapping(value = "/getPublicKey")
public @Nonnull String getPublicKey() {
return PushNotificationService.INSTANCE.getPublicKey();
}
@PostMapping(value = "/subscribe", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void subscribe( @RequestBody Object subscription, String userGuid) {
ObjectMapper om = new ObjectMapper();
try {
String value = om.writeValueAsString(((LinkedHashMap) subscription).get("subscription"));
String guid = om.writeValueAsString(((LinkedHashMap) subscription).get("userGuid"));
MSubscription subscription1 = om.readValue(value, MSubscription.class);
PushNotificationService.INSTANCE.subscribe(subscription1, guid.substring(1, guid.length() - 1));
} catch (Exception exception) {
exception.printStackTrace();
}
}
@PostMapping(value = "/unsubscribe", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void unsubscribe( @RequestBody Object subscription, String userGuid) {
ObjectMapper om = new ObjectMapper();
try {
String value = om.writeValueAsString(((LinkedHashMap) subscription).get("subscription"));
String guid = om.writeValueAsString(((LinkedHashMap) subscription).get("userGuid"));
MSubscription subscription1 = om.readValue(value, MSubscription.class);
PushNotificationService.INSTANCE.unsubscribe(subscription1, guid.substring(1, guid.length() - 1));
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
- I tried to remove @Endpoint annotation but without it push notifications do not work
- I tried to do some magic with spring security config. I thought it could help fix 405 mistake