aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-06-29 17:09:49 +0300
committerGravatar Vitaly Takmazov2017-06-29 17:13:29 +0300
commitb75b5a3d1a3bf001923d49923dcebee95ba2327e (patch)
tree5080eacdf348c9598885ad5d3b5c567632db3717
parent02723131139806c761539a42a5fa80b68ecadee8 (diff)
notifications and configurations refactoring
-rw-r--r--juick-api/build.gradle2
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java2
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java3
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Notifications.java112
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java6
-rw-r--r--juick-core/src/main/java/com/juick/DeviceRegistration.java30
-rw-r--r--juick-core/src/main/java/com/juick/TokensList.java35
-rw-r--r--juick-core/src/main/java/com/juick/User.java16
-rw-r--r--juick-crosspost/build.gradle2
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java3
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostMvcConfiguration.java43
-rw-r--r--juick-notifications/build.gradle16
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java29
-rw-r--r--juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java3
-rw-r--r--juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java28
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java8
-rw-r--r--juick-rss/build.gradle1
-rw-r--r--juick-server-core/build.gradle25
-rw-r--r--juick-server-jdbc/build.gradle1
-rw-r--r--juick-server-web/build.gradle9
-rw-r--r--juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java (renamed from juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java)26
-rw-r--r--juick-ws/build.gradle3
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java3
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java34
-rw-r--r--juick-www/build.gradle4
-rw-r--r--juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java14
-rw-r--r--juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java9
-rw-r--r--juick-www/src/test/java/com/juick/www/WebAppTests.java3
-rw-r--r--juick-xmpp-bot/build.gradle3
-rw-r--r--juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotAppConfiguration.java2
-rw-r--r--juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java3
-rw-r--r--juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotMvcConfiguration.java33
-rw-r--r--juick-xmpp/build.gradle7
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java6
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java3
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XmppMvcConfiguration.java35
37 files changed, 166 insertions, 398 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
index b85bb4fc..e978a161 100644
--- a/juick-api/build.gradle
+++ b/juick-api/build.gradle
@@ -12,13 +12,11 @@ dependencies {
compile project(':juick-server-jdbc')
compile project(':juick-server-web')
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}"
compile 'com.github.pengrad:java-telegram-bot-api:3.0.1'
compile 'org.apache.commons:commons-email:1.4'
compile 'org.imgscalr:imgscalr-lib:4.2'
- providedRuntime 'mysql:mysql-connector-java:5.1.40'
testCompile project(path: ':juick-server-jdbc', configuration: 'testArtifacts')
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
index cbf7d05c..7ef1cf45 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
@@ -3,6 +3,7 @@ package com.juick.api.configuration;
import com.juick.api.ApiServer;
import com.juick.api.TGBot;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
@@ -19,6 +20,7 @@ import javax.inject.Inject;
@EnableScheduling
@EnableAsync
@PropertySource("classpath:juick.conf")
+@ComponentScan(basePackages = "com.juick.api.controllers")
public class ApiAppConfiguration {
@Inject
TGBot tgBot;
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
index 965fd32b..d01df787 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
@@ -1,6 +1,7 @@
package com.juick.api.configuration;
import com.juick.configuration.DataConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -22,7 +23,7 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{ApiMvcConfiguration.class};
+ return new Class<?>[]{BaseWebConfiguration.class};
}
@Override
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java b/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
index c121efb6..96edde51 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
@@ -2,14 +2,16 @@ package com.juick.api.controllers;
import com.juick.Message;
import com.juick.Status;
-import com.juick.TokensList;
+import com.juick.DeviceRegistration;
import com.juick.User;
+import com.juick.server.helpers.AnonymousUser;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.service.MessagesService;
import com.juick.service.PushQueriesService;
import com.juick.service.SubscriptionService;
import com.juick.server.util.UserUtils;
+import com.juick.service.UserService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -17,7 +19,7 @@ import org.springframework.web.bind.annotation.*;
import javax.inject.Inject;
import java.io.IOException;
import java.security.Principal;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -33,9 +35,20 @@ public class Notifications {
MessagesService messagesService;
@Inject
SubscriptionService subscriptionService;
+ @Inject
+ UserService userService;
+
+
+ private User collectTokens(Integer uid) {
+ User user = userService.getUserByUID(uid).orElse(AnonymousUser.INSTANCE);
+ pushQueriesService.getGCMRegID(uid).forEach(t -> user.getDevices().add(new DeviceRegistration("gcm", t)));
+ pushQueriesService.getAPNSToken(uid).forEach(t -> user.getDevices().add(new DeviceRegistration("apns", t)));
+ pushQueriesService.getMPNSURL(uid).forEach(t -> user.getDevices().add(new DeviceRegistration("mpns", t)));
+ return user;
+ }
@RequestMapping(value = "/notifications", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public ResponseEntity<List<TokensList>> doGet(
+ public ResponseEntity<List<User>> doGet(
@RequestParam(required = false, defaultValue = "0") int uid,
@RequestParam(required = false, defaultValue = "0") int mid,
@RequestParam(required = false, defaultValue = "0") int rid) {
@@ -43,23 +56,9 @@ public class Notifications {
if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
throw new HttpForbiddenException();
}
- List<TokensList> tokensLists = new ArrayList<>();
if (uid > 0 && mid == 0) {
// PM
- TokensList gcmTokens = new TokensList();
- gcmTokens.setType("gcm");
- gcmTokens.setTokens(pushQueriesService.getGCMRegID(uid));
- tokensLists.add(gcmTokens);
- TokensList apnsTokens = new TokensList();
- apnsTokens.setType("apns");
- apnsTokens.setTokens(pushQueriesService.getAPNSToken(uid));
- tokensLists.add(apnsTokens);
- TokensList mpnsTokens = new TokensList();
- mpnsTokens.setType("mpns");
- mpnsTokens.setTokens(pushQueriesService.getMPNSURL(uid));
- tokensLists.add(mpnsTokens);
- return ResponseEntity.ok(tokensLists);
-
+ return ResponseEntity.ok(Collections.singletonList(collectTokens(uid)));
} else {
if (mid > 0) {
Message msg = messagesService.getMessage(mid);
@@ -72,21 +71,8 @@ public class Notifications {
users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), mid);
}
- List<Integer> uids = users.stream().map(User::getUid).collect(Collectors.toList());
-
- TokensList gcmTokens = new TokensList();
- gcmTokens.setType("gcm");
- gcmTokens.setTokens(pushQueriesService.getGCMTokens(uids));
- tokensLists.add(gcmTokens);
- TokensList apnsTokens = new TokensList();
- apnsTokens.setType("apns");
- apnsTokens.setTokens(pushQueriesService.getAPNSTokens(uids));
- tokensLists.add(apnsTokens);
- TokensList mpnsTokens = new TokensList();
- mpnsTokens.setType("mpns");
- mpnsTokens.setTokens(pushQueriesService.getMPNSTokens(uids));
- tokensLists.add(mpnsTokens);
- return ResponseEntity.ok(tokensLists);
+ return ResponseEntity.ok(users.stream().map(User::getUid)
+ .map(this::collectTokens).collect(Collectors.toList()));
}
}
}
@@ -95,49 +81,53 @@ public class Notifications {
@RequestMapping(value = "/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status doDelete(
- @RequestBody TokensList list) throws IOException {
+ @RequestBody List<DeviceRegistration> list) throws IOException {
User visitor = UserUtils.getCurrentUser();
// FIXME: it is possible to delete other user's tokens
if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
throw new HttpForbiddenException();
}
- switch (list.getType()) {
- case "gcm":
- list.getTokens().forEach(t -> pushQueriesService.deleteGCMToken(t));
- break;
- case "apns":
- list.getTokens().forEach(t -> pushQueriesService.deleteAPNSToken(t));
- break;
- case "mpns":
- list.getTokens().forEach(t -> pushQueriesService.deleteMPNSToken(t));
- break;
- default:
- throw new HttpBadRequestException();
- }
+ list.forEach(t -> {
+ switch (t.getType()) {
+ case "gcm":
+ pushQueriesService.deleteGCMToken(t.getToken());
+ break;
+ case "apns":
+ pushQueriesService.deleteAPNSToken(t.getToken());
+ break;
+ case "mpns":
+ pushQueriesService.deleteMPNSToken(t.getToken());
+ break;
+ default:
+ throw new HttpBadRequestException();
+ }
+ });
return Status.OK;
}
@RequestMapping(value = "/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status doPut(
- @RequestBody TokensList list) throws IOException {
+ @RequestBody List<DeviceRegistration> list) throws IOException {
User visitor = UserUtils.getCurrentUser();
if (visitor.getUid() == 0) {
throw new HttpForbiddenException();
}
- switch (list.getType()) {
- case "gcm":
- list.getTokens().forEach(t -> pushQueriesService.addGCMToken(visitor.getUid(), t));
- break;
- case "apns":
- list.getTokens().forEach(t -> pushQueriesService.addAPNSToken(visitor.getUid(), t));
- break;
- case "mpns":
- list.getTokens().forEach(t -> pushQueriesService.addMPNSToken(visitor.getUid(), t));
- break;
- default:
- throw new HttpBadRequestException();
- }
+ list.forEach(t -> {
+ switch (t.getType()) {
+ case "gcm":
+ pushQueriesService.addGCMToken(visitor.getUid(), t.getToken());
+ break;
+ case "apns":
+ pushQueriesService.addAPNSToken(visitor.getUid(), t.getToken());
+ break;
+ case "mpns":
+ pushQueriesService.addMPNSToken(visitor.getUid(), t.getToken());
+ break;
+ default:
+ throw new HttpBadRequestException();
+ }
+ });
return Status.OK;
}
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
index a9705aee..e8fcc86f 100644
--- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
+++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
@@ -5,7 +5,7 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.api.ApiServer;
import com.juick.api.TGBot;
-import com.juick.api.configuration.ApiMvcConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import com.juick.api.configuration.ApiSecurityConfig;
import com.juick.api.configuration.MessengerConfiguration;
import com.juick.api.configuration.TelegramConfiguration;
@@ -20,6 +20,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
@@ -50,7 +51,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebAppConfiguration
public class MessagesTests {
@Configuration
- @Import(value = {ApiMvcConfiguration.class, ApiSecurityConfig.class,
+ @ComponentScan(basePackages = "com.juick.api.controllers")
+ @Import(value = {BaseWebConfiguration.class, ApiSecurityConfig.class,
MockDataConfiguration.class, MessengerConfiguration.class, TelegramConfiguration.class})
static class Config {
@Bean
diff --git a/juick-core/src/main/java/com/juick/DeviceRegistration.java b/juick-core/src/main/java/com/juick/DeviceRegistration.java
new file mode 100644
index 00000000..9b6f1d4b
--- /dev/null
+++ b/juick-core/src/main/java/com/juick/DeviceRegistration.java
@@ -0,0 +1,30 @@
+package com.juick;
+
+/**
+ * Created by vitalyster on 22.11.2016.
+ */
+public class DeviceRegistration {
+ private String type;
+ private String token;
+
+ public DeviceRegistration(String type, String token) {
+ this.type = type;
+ this.token = token;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+}
diff --git a/juick-core/src/main/java/com/juick/TokensList.java b/juick-core/src/main/java/com/juick/TokensList.java
deleted file mode 100644
index 0da95951..00000000
--- a/juick-core/src/main/java/com/juick/TokensList.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.juick;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by vitalyster on 22.11.2016.
- */
-public class TokensList {
- private String type;
- private List<String> tokens;
-
- public TokensList() {
- tokens = new ArrayList<>();
- }
-
- @JsonProperty("type")
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public List<String> getTokens() {
- return tokens;
- }
-
- public void setTokens(List<String> tokens) {
- this.tokens = tokens;
- }
-}
diff --git a/juick-core/src/main/java/com/juick/User.java b/juick-core/src/main/java/com/juick/User.java
index 9a3d619c..d0b37c1b 100644
--- a/juick-core/src/main/java/com/juick/User.java
+++ b/juick-core/src/main/java/com/juick/User.java
@@ -23,6 +23,9 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* @author Ugnich Anton
@@ -40,6 +43,11 @@ public class User {
private boolean banned;
private String credentials;
private String lang;
+ private List<DeviceRegistration> devices;
+
+ public User() {
+ devices = new ArrayList<>();
+ }
@Override
public boolean equals(Object obj) {
@@ -175,4 +183,12 @@ public class User {
public boolean isAnonymous() {
return false;
}
+
+ public List<DeviceRegistration> getDevices() {
+ return devices;
+ }
+
+ public void setDevices(List<DeviceRegistration> devices) {
+ this.devices = devices;
+ }
}
diff --git a/juick-crosspost/build.gradle b/juick-crosspost/build.gradle
index c704cbdb..8e2ecbbf 100644
--- a/juick-crosspost/build.gradle
+++ b/juick-crosspost/build.gradle
@@ -4,7 +4,7 @@ apply plugin: 'org.akhikhl.gretty'
dependencies {
compile project(':juick-server-jdbc')
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
+ compile project(':juick-server-web')
compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}"
providedRuntime 'mysql:mysql-connector-java:5.1.40'
}
diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
index 442bd1c8..8eaab803 100644
--- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
+++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
@@ -1,6 +1,7 @@
package com.juick.components.configuration;
import com.juick.configuration.DataConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -19,7 +20,7 @@ public class CrosspostInitializer extends AbstractAnnotationConfigDispatcherServ
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{CrosspostMvcConfiguration.class};
+ return new Class<?>[]{BaseWebConfiguration.class};
}
@Override
diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostMvcConfiguration.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostMvcConfiguration.java
deleted file mode 100644
index 619c3d78..00000000
--- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostMvcConfiguration.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.juick.components.configuration;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-
-import java.util.List;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.components.controllers"})
-public class CrosspostMvcConfiguration extends WebMvcConfigurationSupport {
-
- @Override
- public RequestMappingHandlerMapping requestMappingHandlerMapping() {
- RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
- mapping.setUseSuffixPatternMatch(false);
- return mapping;
- }
-
- @Override
- protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
- .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
- .serializationInclusion(JsonInclude.Include.NON_NULL)
- .serializationInclusion(JsonInclude.Include.NON_ABSENT)
- .serializationInclusion(JsonInclude.Include.NON_EMPTY);
-
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
- converter.getObjectMapper().registerModule(new Jdk8Module());
- converters.add(converter);
-
- super.configureMessageConverters(converters);
- }
-}
diff --git a/juick-notifications/build.gradle b/juick-notifications/build.gradle
index 9c99557d..3e641c93 100644
--- a/juick-notifications/build.gradle
+++ b/juick-notifications/build.gradle
@@ -6,23 +6,7 @@ dependencies {
compile project(':juick-server-web')
compile 'com.ganyo:gcm-server:1.1.0'
compile 'com.notnoop.apns:apns:1.0.0.Beta6'
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
- compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}"
- compile "javax.inject:javax.inject:1"
-
- compile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}"
- compile "ch.qos.logback:logback-core:${rootProject.logbackVersion}"
- compile "ch.qos.logback:logback-access:${rootProject.logbackVersion}"
-
- compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}"
- compile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}"
- compile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}"
- compile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}"
-
- compile "org.apache.httpcomponents:httpclient:4.5.3"
- compile "org.apache.commons:commons-lang3:3.6"
- compile "org.apache.commons:commons-text:1.1"
compile "rocks.xmpp:xmpp-core-client:0.7.4"
compile "rocks.xmpp:xmpp-extensions-client:0.7.4"
diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index 0a315f76..f0ab3b81 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -19,7 +19,8 @@ package com.juick.components;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.gcm.server.*;
-import com.juick.TokensList;
+import com.juick.DeviceRegistration;
+import com.juick.User;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.apache.commons.lang3.math.NumberUtils;
@@ -72,29 +73,29 @@ public class Notifications implements NotificationClientListener, AutoCloseable
boolean isReply = jmsg.getRid() > 0;
int pmTo = NumberUtils.toInt(msg.getTo().getLocal(), 0);
- final List<TokensList> tokensList = new ArrayList<>();
+ final List<User> users = new ArrayList<>();
if (isPM) {
- tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d",
+ users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%d",
pmTo),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
} else {
if (isReply) {
- tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d&mid=%d&rid=%d",
+ users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%d&mid=%d&rid=%d",
jmsg.getUser().getUid(), jmsg.getMid(), jmsg.getRid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
} else {
- tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%s&mid=%s",
+ users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%s&mid=%s",
jmsg.getUser().getUid(), jmsg.getMid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
}
}
// GCM
- List<String> regids = tokensList.stream().filter(t -> t.getType().equals("gcm"))
- .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
+ List<String> regids = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("gcm"))
+ .map(DeviceRegistration::getToken).collect(Collectors.toList());
if (!regids.isEmpty()) {
try {
String json = jsonMapper.writeValueAsString(jmsg);
@@ -124,8 +125,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable
}
/*** WinPhone ***/
- List<String> urls = tokensList.stream().filter(t -> t.getType().equals("mpns"))
- .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
+ List<String> urls = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("mpns"))
+ .map(DeviceRegistration::getToken).collect(Collectors.toList());
if (urls.isEmpty()) {
logger.info("WNS: no recipients");
@@ -160,8 +161,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable
}
/*** iOS ***/
- List<String> tokens = tokensList.stream().filter(t -> t.getType().equals("apns"))
- .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
+ List<String> tokens = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("apns"))
+ .map(DeviceRegistration::getToken).collect(Collectors.toList());
if (!tokens.isEmpty()) {
for (String token : tokens) {
String payload = APNS.newPayload().alertTitle("@" + jmsg.getUser().getName()).alertBody(jmsg.getText()).build();
diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
index 4249d988..8ecf72ea 100644
--- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
+++ b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
@@ -1,5 +1,6 @@
package com.juick.components.configuration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -21,7 +22,7 @@ public class NotificationsInitializer extends AbstractAnnotationConfigDispatcher
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{NotificationsMvcConfiguration.class};
+ return new Class<?>[]{ BaseWebConfiguration.class };
}
@Override
diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java
deleted file mode 100644
index 3d828832..00000000
--- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.juick.components.configuration;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
-import javax.inject.Inject;
-import java.util.List;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.components.controllers"})
-public class NotificationsMvcConfiguration extends WebMvcConfigurationSupport {
- @Inject
- ObjectMapper jsonMapper;
-
- @Override
- protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(jsonMapper);
- converters.add(converter);
- super.configureMessageConverters(converters);
- }
-}
diff --git a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
index 4dd949c3..7b9a88a3 100644
--- a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
+++ b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
@@ -1,6 +1,6 @@
package com.juick.components.service;
-import com.juick.TokensList;
+import com.juick.DeviceRegistration;
import com.juick.service.BaseRestService;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
@@ -12,6 +12,7 @@ import org.springframework.web.client.RestTemplate;
import javax.inject.Inject;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Created by vitalyster on 15.12.2016.
@@ -27,9 +28,8 @@ public class NotificationsTokenService extends BaseRestService implements TokenS
@Override
public void deleteTokens(String type, List<String> devices) {
if (devices.size() > 0) {
- TokensList list = new TokensList();
- list.setType(type);
- list.setTokens(devices);
+ List<DeviceRegistration> list = devices.stream()
+ .map(d -> new DeviceRegistration(type, d)).collect(Collectors.toList());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
getRest().exchange("http://api.juick.com/notifications",
diff --git a/juick-rss/build.gradle b/juick-rss/build.gradle
index 3a1b82ab..5da16641 100644
--- a/juick-rss/build.gradle
+++ b/juick-rss/build.gradle
@@ -5,7 +5,6 @@ apply plugin: 'org.akhikhl.gretty'
dependencies {
compile project(':juick-server-jdbc')
compile project(':juick-server-web')
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
compile 'com.rometools:rome:1.7.3'
compile 'com.rometools:rome-modules:1.7.3'
providedRuntime 'mysql:mysql-connector-java:5.1.40'
diff --git a/juick-server-core/build.gradle b/juick-server-core/build.gradle
index b93fb533..081bfd75 100644
--- a/juick-server-core/build.gradle
+++ b/juick-server-core/build.gradle
@@ -11,36 +11,11 @@ dependencies {
compile "com.fasterxml.jackson.core:jackson-annotations:${rootProject.jacksonVersion}"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}"
- providedCompile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}"
- providedCompile "ch.qos.logback:logback-core:${rootProject.logbackVersion}"
- providedCompile "ch.qos.logback:logback-access:${rootProject.logbackVersion}"
-
- providedCompile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}"
- providedCompile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}"
- providedCompile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}"
- providedCompile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}"
-
- compile "org.apache.httpcomponents:httpclient:4.5.3"
- providedCompile "org.apache.commons:commons-lang3:3.6"
- providedCompile "org.apache.commons:commons-collections4:4.1"
- providedCompile "org.apache.commons:commons-text:1.1"
- providedCompile "commons-io:commons-io:2.5"
- providedCompile "commons-codec:commons-codec:1.10"
-
- compile 'org.imgscalr:imgscalr-lib:4.2'
-
compile "javax.inject:javax.inject:1"
- providedCompile "javax.servlet:javax.servlet-api:3.1.0"
-
- providedRuntime "commons-fileupload:commons-fileupload:1.3.3"
-
- testCompile "ch.vorburger.mariaDB4j:mariaDB4j:2.2.3"
testCompile "junit:junit:${rootProject.junitVersion}"
testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}"
testCompile "org.mockito:mockito-core:${rootProject.mockitoVersion}"
-
- testRuntime "mysql:mysql-connector-java:5.1.40"
}
compileJava.options.encoding = 'UTF-8'
diff --git a/juick-server-jdbc/build.gradle b/juick-server-jdbc/build.gradle
index fde15afe..184a7bfe 100644
--- a/juick-server-jdbc/build.gradle
+++ b/juick-server-jdbc/build.gradle
@@ -45,6 +45,7 @@ dependencies {
compile 'org.imgscalr:imgscalr-lib:4.2'
providedCompile "javax.servlet:javax.servlet-api:3.1.0"
+ providedRuntime 'mysql:mysql-connector-java:5.1.40'
providedRuntime "commons-fileupload:commons-fileupload:1.3.3"
diff --git a/juick-server-web/build.gradle b/juick-server-web/build.gradle
index fde15afe..92f017e4 100644
--- a/juick-server-web/build.gradle
+++ b/juick-server-web/build.gradle
@@ -29,14 +29,12 @@ dependencies {
compile 'com.github.ben-manes.caffeine:caffeine:2.5.2'
- compile "org.springframework:spring-context:${rootProject.springFrameworkVersion}"
- compile "org.springframework:spring-jdbc:${rootProject.springFrameworkVersion}"
+ compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
+ compile "org.springframework:spring-context-support:${rootProject.springFrameworkVersion}"
compile "org.springframework.security:spring-security-web:${rootProject.springSecurityVersion}"
compile "org.springframework.security:spring-security-config:${rootProject.springSecurityVersion}"
- providedCompile "org.apache.commons:commons-dbcp2:2.1.1"
- compile "com.googlecode.log4jdbc:log4jdbc:1.2"
compile "javax.inject:javax.inject:1"
compile "rocks.xmpp:xmpp-core-client:0.7.4"
@@ -48,14 +46,11 @@ dependencies {
providedRuntime "commons-fileupload:commons-fileupload:1.3.3"
- testCompile "ch.vorburger.mariaDB4j:mariaDB4j:2.2.3"
testCompile "junit:junit:${rootProject.junitVersion}"
testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}"
testCompile "org.mockito:mockito-core:${rootProject.mockitoVersion}"
testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}"
testCompile "org.springframework.security:spring-security-test:${rootProject.springSecurityVersion}"
-
- testRuntime "mysql:mysql-connector-java:5.1.40"
}
compileJava.options.encoding = 'UTF-8'
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java
index 37c07434..34f97ed2 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
+++ b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java
@@ -1,12 +1,11 @@
-package com.juick.api.configuration;
+package com.juick.server.configuration;
import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
@@ -19,8 +18,7 @@ import java.util.List;
* Created by vitalyster on 28.06.2016.
*/
@Configuration
-@ComponentScan(basePackages = {"com.juick.api.controllers"})
-public class ApiMvcConfiguration extends WebMvcConfigurationSupport {
+public class BaseWebConfiguration extends WebMvcConfigurationSupport {
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
@@ -31,18 +29,22 @@ public class ApiMvcConfiguration extends WebMvcConfigurationSupport {
@Override
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
- .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
- .serializationInclusion(JsonInclude.Include.NON_NULL)
- .serializationInclusion(JsonInclude.Include.NON_ABSENT)
- .serializationInclusion(JsonInclude.Include.NON_EMPTY);
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
- converter.getObjectMapper().registerModule(new Jdk8Module());
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(jsonMapper());
converters.add(converter);
super.configureMessageConverters(converters);
}
@Bean
+ public ObjectMapper jsonMapper() {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
+ mapper.registerModule(new Jdk8Module());
+ return mapper;
+ }
+
+ @Bean
public MultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setMaxUploadSize(10000000);
diff --git a/juick-ws/build.gradle b/juick-ws/build.gradle
index c704cbdb..253c2dcc 100644
--- a/juick-ws/build.gradle
+++ b/juick-ws/build.gradle
@@ -4,9 +4,8 @@ apply plugin: 'org.akhikhl.gretty'
dependencies {
compile project(':juick-server-jdbc')
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
+ compile project(':juick-server-web')
compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}"
- providedRuntime 'mysql:mysql-connector-java:5.1.40'
}
compileJava.options.encoding = 'UTF-8'
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
index bb3d3087..21f51fcf 100644
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
+++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
@@ -1,6 +1,7 @@
package com.juick.ws.configuration;
import com.juick.configuration.DataConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -19,7 +20,7 @@ public class WebsocketInitializer extends AbstractAnnotationConfigDispatcherServ
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{WebsocketMvcConfiguration.class};
+ return new Class<?>[]{ BaseWebConfiguration.class };
}
@Override
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java
deleted file mode 100644
index a6a988d7..00000000
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.juick.ws.configuration;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
-import java.util.List;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.ws.controllers"})
-@PropertySource("classpath:juick.conf")
-public class WebsocketMvcConfiguration extends WebMvcConfigurationSupport {
- @Override
- protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
- .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
- .serializationInclusion(JsonInclude.Include.NON_NULL)
- .serializationInclusion(JsonInclude.Include.NON_ABSENT)
- .serializationInclusion(JsonInclude.Include.NON_EMPTY);
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
- converter.getObjectMapper().registerModule(new Jdk8Module());
- converters.add(converter);
- super.configureMessageConverters(converters);
- }
-}
diff --git a/juick-www/build.gradle b/juick-www/build.gradle
index 4c26f754..3a2508a2 100644
--- a/juick-www/build.gradle
+++ b/juick-www/build.gradle
@@ -23,11 +23,7 @@ dependencies {
compile 'com.github.scribejava:scribejava-apis:4.1.1'
compile 'com.github.ooxi:serialized-php-parser:0.5.0'
compile 'com.sun.mail:javax.mail:1.5.6'
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
- compile "org.springframework:spring-context-support:${rootProject.springFrameworkVersion}"
compile 'com.mitchellbosecke:pebble-spring4:2.3.0'
- providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
- providedRuntime 'mysql:mysql-connector-java:5.1.40'
testCompile project(path: ':juick-server-jdbc', configuration: 'testArtifacts')
// htmlunit 2.25 isn't compatible with spring-test 4.3.6
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java
index 2e5a4f89..8dc8093e 100644
--- a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java
+++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java
@@ -33,12 +33,14 @@ public class WwwAppConfiguration {
private UserService userService;
@Inject
private TagService tagService;
+ @Inject
+ private ObjectMapper jsonMapper;
@Bean
public WebApp webApp() throws IOException {
WebApp app = new WebApp();
String manifestString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("manifest.json"), StandardCharsets.UTF_8);
- HashMap<String, String> manifest = jsonMapper().readValue(manifestString,
+ HashMap<String, String> manifest = jsonMapper.readValue(manifestString,
new TypeReference<HashMap<String, String>>() {});
app.setScriptsUrl(manifest.get("scripts.js"));
app.setStyleUrl(manifest.get("style.css"));
@@ -58,14 +60,4 @@ public class WwwAppConfiguration {
return new HelpService("help");
}
- @Bean
- public ObjectMapper jsonMapper() {
- ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
- mapper.registerModule(new Jdk8Module());
- return mapper;
- }
-
}
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java
index 199fbf85..bc5851db 100644
--- a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java
+++ b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java
@@ -2,6 +2,7 @@ package com.juick.www.configuration;
import com.juick.configuration.DataConfiguration;
import com.juick.configuration.SearchConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -18,6 +19,7 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{
+ BaseWebConfiguration.class,
WwwAppConfiguration.class,
DataConfiguration.class,
SearchConfiguration.class,
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
index ae51f1cd..d7e5c72e 100644
--- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
+++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
@@ -31,8 +31,6 @@ import java.util.concurrent.TimeUnit;
@ComponentScan(basePackages = {"com.juick.www.controllers"})
@PropertySource("classpath:juick.conf")
public class WwwServletConfiguration extends WebMvcConfigurationSupport {
- @Inject
- private Environment env;
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
@@ -61,13 +59,6 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport {
return result;
}
- @Bean
- public MultipartResolver multipartResolver() {
- CommonsMultipartResolver resolver = new CommonsMultipartResolver();
- resolver.setMaxUploadSize(10000000);
- return resolver;
- }
-
@Inject
private ServletContext servletContext;
diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java
index 773a6d9a..fb9db34c 100644
--- a/juick-www/src/test/java/com/juick/www/WebAppTests.java
+++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java
@@ -6,6 +6,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.juick.Message;
import com.juick.User;
import com.juick.configuration.MockDataConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
import com.juick.tests.util.MockUtils;
@@ -41,7 +42,7 @@ import static org.mockito.Mockito.when;
public class WebAppTests {
@Configuration
@Import(value = {
- WwwServletConfiguration.class, WwwAppConfiguration.class, SapeConfiguration.class,
+ BaseWebConfiguration.class, WwwServletConfiguration.class, WwwAppConfiguration.class, SapeConfiguration.class,
MockDataConfiguration.class
})
static class Config {}
diff --git a/juick-xmpp-bot/build.gradle b/juick-xmpp-bot/build.gradle
index 25199b05..b42f6977 100644
--- a/juick-xmpp-bot/build.gradle
+++ b/juick-xmpp-bot/build.gradle
@@ -4,8 +4,7 @@ apply plugin: 'org.akhikhl.gretty'
dependencies {
compile project(':juick-server-jdbc')
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
- providedRuntime 'mysql:mysql-connector-java:5.1.40'
+ compile project(':juick-server-web')
}
compileJava.options.encoding = 'UTF-8'
diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotAppConfiguration.java b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotAppConfiguration.java
index d6905c1b..09b366b6 100644
--- a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotAppConfiguration.java
+++ b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotAppConfiguration.java
@@ -3,6 +3,7 @@ package com.juick.components.configuration;
import com.juick.components.XMPPBot;
import com.juick.server.protocol.JuickProtocol;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
@@ -13,6 +14,7 @@ import javax.inject.Inject;
* Created by aalexeev on 11/12/16.
*/
@Configuration
+@ComponentScan(basePackages = {"com.juick.components.controllers"})
@PropertySource("classpath:juick.conf")
public class BotAppConfiguration {
@Inject
diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java
index 1803aedf..9e8745af 100644
--- a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java
+++ b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java
@@ -1,6 +1,7 @@
package com.juick.components.configuration;
import com.juick.configuration.DataConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -19,7 +20,7 @@ public class BotInitializer extends AbstractAnnotationConfigDispatcherServletIni
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{BotMvcConfiguration.class};
+ return new Class<?>[]{ BaseWebConfiguration.class };
}
@Override
diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotMvcConfiguration.java b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotMvcConfiguration.java
deleted file mode 100644
index 2c55c0ce..00000000
--- a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotMvcConfiguration.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.juick.components.configuration;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
-import java.util.List;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.components.controllers"})
-public class BotMvcConfiguration extends WebMvcConfigurationSupport {
-
- @Override
- protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
- .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
- .serializationInclusion(JsonInclude.Include.NON_NULL)
- .serializationInclusion(JsonInclude.Include.NON_ABSENT)
- .serializationInclusion(JsonInclude.Include.NON_EMPTY);
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
- converter.getObjectMapper().registerModule(new Jdk8Module());
- converters.add(converter);
- super.configureMessageConverters(converters);
- }
-}
diff --git a/juick-xmpp/build.gradle b/juick-xmpp/build.gradle
index cd0e6ec2..e74f1e9b 100644
--- a/juick-xmpp/build.gradle
+++ b/juick-xmpp/build.gradle
@@ -4,13 +4,8 @@ apply plugin: 'org.akhikhl.gretty'
dependencies {
compile project(':juick-server-jdbc')
+ compile project(':juick-server-web')
compile 'com.github.juick:com.juick.xmpp:483936e0bd'
- compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}"
- compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
- compile 'javax.inject:javax.inject:1'
- compile 'org.apache.httpcomponents:httpclient:4.5.3'
- compile 'org.apache.commons:commons-dbcp2:2.1.1'
- providedRuntime 'mysql:mysql-connector-java:5.1.40'
}
compileJava.options.encoding = 'UTF-8'
diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java
index 35de10f6..956b5bce 100644
--- a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppAppConfiguration.java
@@ -10,10 +10,7 @@ import com.juick.components.s2s.CleaningUp;
import com.juick.components.s2s.JuickBot;
import com.juick.configuration.DataConfiguration;
import org.apache.commons.lang3.BooleanUtils;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -22,6 +19,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Configuration
+@ComponentScan(basePackages = {"com.juick.components.controllers"})
@PropertySource("classpath:juick.conf")
@Import(DataConfiguration.class)
@EnableScheduling
diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java
index ac33acc5..b7c096db 100644
--- a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java
@@ -1,5 +1,6 @@
package com.juick.components.configuration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -18,7 +19,7 @@ public class XmppInitializer extends AbstractAnnotationConfigDispatcherServletIn
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{XmppMvcConfiguration.class};
+ return new Class<?>[]{ BaseWebConfiguration.class};
}
@Override
diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppMvcConfiguration.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppMvcConfiguration.java
deleted file mode 100644
index 977496b8..00000000
--- a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppMvcConfiguration.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.juick.components.configuration;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
-import java.util.List;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.components.controllers"})
-@PropertySource("classpath:juick.conf")
-public class XmppMvcConfiguration extends WebMvcConfigurationSupport {
-
- @Override
- protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
- .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
- .serializationInclusion(JsonInclude.Include.NON_NULL)
- .serializationInclusion(JsonInclude.Include.NON_ABSENT)
- .serializationInclusion(JsonInclude.Include.NON_EMPTY);
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
- converter.getObjectMapper().registerModule(new Jdk8Module());
- converters.add(converter);
- super.configureMessageConverters(converters);
- }
-}