aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-08 15:54:33 +0300
committerGravatar Vitaly Takmazov2016-11-08 15:54:33 +0300
commit4314d834724bbb5c671e7300b7de865fe53c51fb (patch)
treeadf95198a7db90a8cb6d2cdab90935af1e612ddc
parent397179619fdfa0b4b15f62437a91bd17924e7678 (diff)
reorganize structure again
-rw-r--r--juick-core/src/main/java/com/juick/server/helpers/Status.java (renamed from juick-notifications/src/main/java/com/juick/notifications/api/Status.java)2
-rw-r--r--juick-crosspost/build.gradle33
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/Crosspost.java (renamed from juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java)9
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java105
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java33
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/controllers/StatusController.java27
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java (renamed from juick-notifications/src/main/java/com/juick/notifications/CloudNotifications.java)8
-rw-r--r--juick-notifications/src/main/java/com/juick/components/configuration/NotificationsConfiguration.java (renamed from juick-notifications/src/main/java/com/juick/notifications/configuration/NotificationsConfiguration.java)8
-rw-r--r--juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java (renamed from juick-notifications/src/main/java/com/juick/notifications/configuration/NotificationsInitializer.java)2
-rw-r--r--juick-notifications/src/main/java/com/juick/components/controllers/StatusController.java (renamed from juick-notifications/src/main/java/com/juick/notifications/controllers/StatusController.java)8
-rw-r--r--juick-ws/src/main/java/com/juick/ws/ApiController.java6
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java1
-rw-r--r--juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java19
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java10
-rw-r--r--juick-xmpp/build.gradle33
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java (renamed from juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java)11
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java107
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XMPPInitializer.java33
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/CacheEntry.java)2
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/CleaningUp.java)8
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/Connection.java)8
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/ConnectionIn.java)6
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/ConnectionOut.java)8
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/DNSQueries.java)2
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java (renamed from juick-ws/src/main/java/com/juick/ws/s2s/JuickBot.java)8
-rw-r--r--settings.gradle2
26 files changed, 419 insertions, 80 deletions
diff --git a/juick-notifications/src/main/java/com/juick/notifications/api/Status.java b/juick-core/src/main/java/com/juick/server/helpers/Status.java
index dcdc0ccd..f68baae5 100644
--- a/juick-notifications/src/main/java/com/juick/notifications/api/Status.java
+++ b/juick-core/src/main/java/com/juick/server/helpers/Status.java
@@ -1,4 +1,4 @@
-package com.juick.notifications.api;
+package com.juick.server.helpers;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/juick-crosspost/build.gradle b/juick-crosspost/build.gradle
new file mode 100644
index 00000000..2cb9ef9a
--- /dev/null
+++ b/juick-crosspost/build.gradle
@@ -0,0 +1,33 @@
+apply plugin: 'java'
+apply plugin: 'war'
+apply plugin: 'org.akhikhl.gretty'
+apply plugin: 'com.github.ben-manes.versions'
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile project(':juick-core')
+ compile 'org.slf4j:slf4j-jdk14:1.7.21'
+ def springFrameworkVersion = '4.3.3.RELEASE'
+ compile "org.springframework:spring-webmvc:${springFrameworkVersion}"
+ def jacksonVersion = '2.8.4'
+ compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
+ compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
+ compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${jacksonVersion}"
+ compile 'javax.inject:javax.inject:1'
+ compile 'org.apache.httpcomponents:httpclient:4.5.2'
+ compile 'org.apache.commons:commons-dbcp2:2.1.1'
+ compile 'com.mitchellbosecke:pebble-spring4:2.2.3'
+ providedRuntime 'mysql:mysql-connector-java:5.1.39'
+}
+
+compileJava.options.encoding = 'UTF-8'
+
+gretty {
+ httpPort = 8080
+ contextPath = ''
+ servletContainer = 'tomcat8'
+}
+
diff --git a/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
index dcb4a709..493fa5e4 100644
--- a/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java
+++ b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.ws.components;
+package com.juick.components;
import com.juick.server.CrosspostQueries;
import com.juick.xmpp.JID;
@@ -29,7 +29,6 @@ import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.stereotype.Component;
import javax.crypto.Mac;
@@ -51,9 +50,9 @@ import java.util.logging.Logger;
* @author Ugnich Anton
*/
@Component
-public class CrosspostComponent implements DisposableBean, Stream.StreamListener, Message.MessageListener {
+public class Crosspost implements DisposableBean, Stream.StreamListener, Message.MessageListener {
- private static Logger logger = Logger.getLogger(CrosspostComponent.class.getName());
+ private static Logger logger = Logger.getLogger(Crosspost.class.getName());
public final static String TWITTERURL = "https://api.twitter.com/1.1/statuses/update.json";
public final static String FBURL = "https://graph.facebook.com/me/feed";
@@ -66,7 +65,7 @@ public class CrosspostComponent implements DisposableBean, Stream.StreamListener
ExecutorService service;
@Inject
- public CrosspostComponent(Environment env, ExecutorService service) {
+ public Crosspost(Environment env, ExecutorService service) {
this.service = service;
logger.info("component initialized");
try {
diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
new file mode 100644
index 00000000..7ed9fcee
--- /dev/null
+++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
@@ -0,0 +1,105 @@
+package com.juick.components.configuration;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.juick.components.Crosspost;
+import com.mitchellbosecke.pebble.PebbleEngine;
+import com.mitchellbosecke.pebble.loader.Loader;
+import com.mitchellbosecke.pebble.loader.ServletLoader;
+import com.mitchellbosecke.pebble.spring4.PebbleViewResolver;
+import com.mitchellbosecke.pebble.spring4.extension.SpringExtension;
+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;
+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.ViewResolver;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Created by vitalyster on 28.06.2016.
+ */
+@Configuration
+@ComponentScan(basePackages = {"com.juick"})
+@PropertySource("classpath:juick.conf")
+public class CrosspostConfiguration extends WebMvcConfigurationSupport {
+ @Inject
+ Environment env;
+ @Inject
+ ExecutorService service;
+
+ @Inject
+ private ServletContext servletContext;
+
+ @Bean
+ public Loader templateLoader(){
+ return new ServletLoader(servletContext);
+ }
+
+ @Bean
+ public SpringExtension springExtension() {
+ return new SpringExtension();
+ }
+
+ @Bean
+ public PebbleEngine pebbleEngine() {
+ return new PebbleEngine.Builder()
+ .loader(this.templateLoader())
+ .extension(springExtension())
+ .build();
+ }
+
+ @Bean
+ public ViewResolver viewResolver() {
+ PebbleViewResolver viewResolver = new PebbleViewResolver();
+ viewResolver.setPrefix("/WEB-INF/templates/");
+ viewResolver.setSuffix(".html");
+ viewResolver.setPebbleEngine(pebbleEngine());
+ return viewResolver;
+ }
+ @Bean
+ public Crosspost crosspost() {
+ return new Crosspost(env, service);
+ }
+ @Bean
+ public ExecutorService service() {
+ return Executors.newCachedThreadPool();
+ }
+
+ @Override
+ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
+ RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
+ mapping.setUseSuffixPatternMatch(false);
+ return mapping;
+ }
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.setOrder(0);
+ registry.addResourceHandler("/scripts.js").addResourceLocations("/");
+ registry.addResourceHandler("/style.css").addResourceLocations("/");
+ }
+
+ @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-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
new file mode 100644
index 00000000..e85d7a2a
--- /dev/null
+++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
@@ -0,0 +1,33 @@
+package com.juick.components.configuration;
+import org.springframework.web.filter.CharacterEncodingFilter;
+import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
+
+import javax.servlet.Filter;
+
+/**
+ * Created by vt on 09/02/16.
+ */
+public class CrosspostInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
+ @Override
+ protected Class<?>[] getRootConfigClasses() {
+ return new Class[] {CrosspostConfiguration.class};
+ }
+
+ @Override
+ protected Class<?>[] getServletConfigClasses() {
+ return null;
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[] {
+ "/"
+ };
+ }
+ @Override
+ protected Filter[] getServletFilters() {
+ CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
+ characterEncodingFilter.setEncoding("UTF-8");
+ return new Filter[] { characterEncodingFilter};
+ }
+}
diff --git a/juick-crosspost/src/main/java/com/juick/components/controllers/StatusController.java b/juick-crosspost/src/main/java/com/juick/components/controllers/StatusController.java
new file mode 100644
index 00000000..348cfed1
--- /dev/null
+++ b/juick-crosspost/src/main/java/com/juick/components/controllers/StatusController.java
@@ -0,0 +1,27 @@
+package com.juick.components.controllers;
+
+import com.juick.components.Crosspost;
+import com.juick.server.helpers.Status;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.inject.Inject;
+
+/**
+ * Created by vitalyster on 24.10.2016.
+ */
+@Controller
+@ResponseBody
+public class StatusController {
+ @Inject
+ Crosspost crosspost;
+
+ @RequestMapping(method = RequestMethod.GET, value = "/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+ public Status status() {
+ String status = crosspost != null ? "OK" : "Fail";
+ return new Status(status);
+ }
+}
diff --git a/juick-notifications/src/main/java/com/juick/notifications/CloudNotifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index e108ec03..8cf5d5da 100644
--- a/juick-notifications/src/main/java/com/juick/notifications/CloudNotifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.notifications;
+package com.juick.components;
import com.google.android.gcm.server.*;
import com.juick.json.MessageSerializer;
@@ -63,9 +63,9 @@ import java.util.logging.Logger;
* @author Ugnich Anton
*/
@Component
-public class CloudNotifications implements DisposableBean, Stream.StreamListener, MessageListener {
+public class Notifications implements DisposableBean, Stream.StreamListener, MessageListener {
- private static Logger logger = Logger.getLogger(CloudNotifications.class.getName());
+ private static Logger logger = Logger.getLogger(Notifications.class.getName());
String wns_application_sip;
String wns_client_secret;
@@ -77,7 +77,7 @@ public class CloudNotifications implements DisposableBean, Stream.StreamListener
ExecutorService service;
@Inject
- public CloudNotifications(Environment env, ExecutorService service) {
+ public Notifications(Environment env, ExecutorService service) {
this.service = service;
logger.info("component initialized");
wns_application_sip = env.getProperty("wns_application_sip", "");
diff --git a/juick-notifications/src/main/java/com/juick/notifications/configuration/NotificationsConfiguration.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsConfiguration.java
index fd122724..64d01a36 100644
--- a/juick-notifications/src/main/java/com/juick/notifications/configuration/NotificationsConfiguration.java
+++ b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsConfiguration.java
@@ -1,8 +1,8 @@
-package com.juick.notifications.configuration;
+package com.juick.components.configuration;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import com.juick.notifications.CloudNotifications;
+import com.juick.components.Notifications;
import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.loader.Loader;
import com.mitchellbosecke.pebble.loader.ServletLoader;
@@ -74,8 +74,8 @@ public class NotificationsConfiguration extends WebMvcConfigurationSupport {
return viewResolver;
}
@Bean
- public CloudNotifications push() {
- return new CloudNotifications(env, service);
+ public Notifications push() {
+ return new Notifications(env, service);
}
@Bean
public ExecutorService service() {
diff --git a/juick-notifications/src/main/java/com/juick/notifications/configuration/NotificationsInitializer.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
index cd547138..1449a4f8 100644
--- a/juick-notifications/src/main/java/com/juick/notifications/configuration/NotificationsInitializer.java
+++ b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
@@ -1,4 +1,4 @@
-package com.juick.notifications.configuration;
+package com.juick.components.configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
diff --git a/juick-notifications/src/main/java/com/juick/notifications/controllers/StatusController.java b/juick-notifications/src/main/java/com/juick/components/controllers/StatusController.java
index 41f44a35..50d73de6 100644
--- a/juick-notifications/src/main/java/com/juick/notifications/controllers/StatusController.java
+++ b/juick-notifications/src/main/java/com/juick/components/controllers/StatusController.java
@@ -1,7 +1,7 @@
-package com.juick.notifications.controllers;
+package com.juick.components.controllers;
-import com.juick.notifications.CloudNotifications;
-import com.juick.notifications.api.Status;
+import com.juick.components.Notifications;
+import com.juick.server.helpers.Status;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -17,7 +17,7 @@ import javax.inject.Inject;
@ResponseBody
public class StatusController {
@Inject
- CloudNotifications push;
+ Notifications push;
@RequestMapping(method = RequestMethod.GET, value = "/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status status() {
diff --git a/juick-ws/src/main/java/com/juick/ws/ApiController.java b/juick-ws/src/main/java/com/juick/ws/ApiController.java
index 9adda912..5203de57 100644
--- a/juick-ws/src/main/java/com/juick/ws/ApiController.java
+++ b/juick-ws/src/main/java/com/juick/ws/ApiController.java
@@ -1,6 +1,6 @@
package com.juick.ws;
-import com.juick.ws.api.WebSocketStatus;
+import com.juick.server.helpers.Status;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -18,7 +18,7 @@ public class ApiController {
@RequestMapping(value = "/api/status", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public WebSocketStatus status() {
- return new WebSocketStatus(wsHandler.clients.size());
+ public Status status() {
+ return new Status(String.valueOf(wsHandler.clients.size()));
}
}
diff --git a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
index ea02db76..caeb5b21 100644
--- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
@@ -11,7 +11,6 @@ import com.juick.xmpp.extensions.JuickMessage;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
diff --git a/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java b/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
deleted file mode 100644
index 82e15765..00000000
--- a/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.juick.ws.api;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-/**
- * Created by vitalyster on 25.07.2016.
- */
-public class WebSocketStatus {
- private int clientsCount;
-
- public WebSocketStatus(int count) {
- clientsCount = count;
- }
-
- @JsonProperty("status")
- public int getClientsCount() {
- return clientsCount;
- }
-}
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
index 783865ed..c4395e29 100644
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
+++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
@@ -4,8 +4,6 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.juick.ws.WebsocketComponent;
import com.juick.ws.XMPPConnection;
-import com.juick.ws.components.CrosspostComponent;
-import com.juick.ws.components.XMPPComponent;
import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.loader.Loader;
import com.mitchellbosecke.pebble.loader.ServletLoader;
@@ -94,14 +92,6 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
return new XMPPConnection(env, service);
}
@Bean
- public XMPPComponent xmpp() {
- return new XMPPComponent(env, service);
- }
- @Bean
- public CrosspostComponent crosspost() {
- return new CrosspostComponent(env, service);
- }
- @Bean
public ExecutorService service() {
return Executors.newCachedThreadPool();
}
diff --git a/juick-xmpp/build.gradle b/juick-xmpp/build.gradle
new file mode 100644
index 00000000..2cb9ef9a
--- /dev/null
+++ b/juick-xmpp/build.gradle
@@ -0,0 +1,33 @@
+apply plugin: 'java'
+apply plugin: 'war'
+apply plugin: 'org.akhikhl.gretty'
+apply plugin: 'com.github.ben-manes.versions'
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile project(':juick-core')
+ compile 'org.slf4j:slf4j-jdk14:1.7.21'
+ def springFrameworkVersion = '4.3.3.RELEASE'
+ compile "org.springframework:spring-webmvc:${springFrameworkVersion}"
+ def jacksonVersion = '2.8.4'
+ compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
+ compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
+ compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${jacksonVersion}"
+ compile 'javax.inject:javax.inject:1'
+ compile 'org.apache.httpcomponents:httpclient:4.5.2'
+ compile 'org.apache.commons:commons-dbcp2:2.1.1'
+ compile 'com.mitchellbosecke:pebble-spring4:2.2.3'
+ providedRuntime 'mysql:mysql-connector-java:5.1.39'
+}
+
+compileJava.options.encoding = 'UTF-8'
+
+gretty {
+ httpPort = 8080
+ contextPath = ''
+ servletContainer = 'tomcat8'
+}
+
diff --git a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
index 2cc898ec..b892f207 100644
--- a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
+++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
@@ -1,15 +1,14 @@
-package com.juick.ws.components;
+package com.juick.components;
import com.juick.User;
import com.juick.server.MessagesQueries;
import com.juick.server.SubscriptionsQueries;
import com.juick.server.UserQueries;
-import com.juick.ws.s2s.*;
+import com.juick.components.s2s.*;
import com.juick.xmpp.*;
import com.juick.xmpp.extensions.JuickMessage;
import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
-import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.env.Environment;
@@ -36,10 +35,10 @@ import java.util.logging.Logger;
* @author ugnich
*/
@Component
-public class XMPPComponent implements DisposableBean, Stream.StreamListener,
+public class XMPPServer implements DisposableBean, Stream.StreamListener,
Message.MessageListener, Iq.IqListener, Presence.PresenceListener {
- private static final Logger logger = Logger.getLogger(XMPPComponent.class.getName());
+ private static final Logger logger = Logger.getLogger(XMPPServer.class.getName());
public ExecutorService service;
private StreamComponent router;
@@ -59,7 +58,7 @@ public class XMPPComponent implements DisposableBean, Stream.StreamListener,
final public HashMap<String, StanzaChild> childParsers = new HashMap<>();
@Inject
- public XMPPComponent(Environment env, ExecutorService service) {
+ public XMPPServer(Environment env, ExecutorService service) {
this.service = service;
logger.info("component initialized");
try {
diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java
new file mode 100644
index 00000000..1695de6a
--- /dev/null
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java
@@ -0,0 +1,107 @@
+package com.juick.components.configuration;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.juick.components.XMPPServer;
+import com.mitchellbosecke.pebble.PebbleEngine;
+import com.mitchellbosecke.pebble.loader.Loader;
+import com.mitchellbosecke.pebble.loader.ServletLoader;
+import com.mitchellbosecke.pebble.spring4.PebbleViewResolver;
+import com.mitchellbosecke.pebble.spring4.extension.SpringExtension;
+import org.apache.commons.dbcp2.BasicDataSource;
+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;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Created by vitalyster on 28.06.2016.
+ */
+@Configuration
+@ComponentScan(basePackages = {"com.juick"})
+@PropertySource("classpath:juick.conf")
+public class XMPPConfiguration extends WebMvcConfigurationSupport {
+ @Inject
+ Environment env;
+ @Inject
+ ExecutorService service;
+
+ @Bean
+ JdbcTemplate jdbc() {
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
+ dataSource.setUrl(env.getProperty("datasource_url"));
+ return new JdbcTemplate(dataSource);
+ }
+ @Inject
+ private ServletContext servletContext;
+
+ @Bean
+ public Loader templateLoader(){
+ return new ServletLoader(servletContext);
+ }
+
+ @Bean
+ public SpringExtension springExtension() {
+ return new SpringExtension();
+ }
+
+ @Bean
+ public PebbleEngine pebbleEngine() {
+ return new PebbleEngine.Builder()
+ .loader(this.templateLoader())
+ .extension(springExtension())
+ .build();
+ }
+
+ @Bean
+ public ViewResolver viewResolver() {
+ PebbleViewResolver viewResolver = new PebbleViewResolver();
+ viewResolver.setPrefix("/WEB-INF/templates/");
+ viewResolver.setSuffix(".html");
+ viewResolver.setPebbleEngine(pebbleEngine());
+ return viewResolver;
+ }
+ @Bean
+ public XMPPServer xmpp() {
+ return new XMPPServer(env, service);
+ }
+ @Bean
+ public ExecutorService service() {
+ return Executors.newCachedThreadPool();
+ }
+
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.setOrder(0);
+ registry.addResourceHandler("/scripts.js").addResourceLocations("/");
+ registry.addResourceHandler("/style.css").addResourceLocations("/");
+ }
+
+ @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/src/main/java/com/juick/components/configuration/XMPPInitializer.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPInitializer.java
new file mode 100644
index 00000000..604516c4
--- /dev/null
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPInitializer.java
@@ -0,0 +1,33 @@
+package com.juick.components.configuration;
+import org.springframework.web.filter.CharacterEncodingFilter;
+import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
+
+import javax.servlet.Filter;
+
+/**
+ * Created by vt on 09/02/16.
+ */
+public class XMPPInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
+ @Override
+ protected Class<?>[] getRootConfigClasses() {
+ return new Class[] {XMPPConfiguration.class};
+ }
+
+ @Override
+ protected Class<?>[] getServletConfigClasses() {
+ return null;
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[] {
+ "/"
+ };
+ }
+ @Override
+ protected Filter[] getServletFilters() {
+ CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
+ characterEncodingFilter.setEncoding("UTF-8");
+ return new Filter[] { characterEncodingFilter};
+ }
+}
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/CacheEntry.java b/juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java
index e870e0d8..8a10182c 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/CacheEntry.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java
@@ -1,4 +1,4 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
/**
*
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/CleaningUp.java b/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
index 8140c829..031a7b34 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/CleaningUp.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
@@ -1,6 +1,6 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
-import com.juick.ws.components.XMPPComponent;
+import com.juick.components.XMPPServer;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
@@ -12,9 +12,9 @@ import java.util.Iterator;
* @author ugnich
*/
public class CleaningUp implements Runnable {
- XMPPComponent xmpp;
+ XMPPServer xmpp;
- public CleaningUp(XMPPComponent xmpp) {
+ public CleaningUp(XMPPServer xmpp) {
this.xmpp = xmpp;
}
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/Connection.java b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java
index 83cc18ac..0c1f3d4d 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/Connection.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java
@@ -1,6 +1,6 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
-import com.juick.ws.components.XMPPComponent;
+import com.juick.components.XMPPServer;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -32,7 +32,7 @@ public class Connection {
public long tsLocalData = 0;
public long bytesLocal = 0;
public long packetsLocal = 0;
- XMPPComponent xmpp;
+ XMPPServer xmpp;
Socket socket;
public static final String NS_DB = "jabber:server:dialback";
public static final String NS_TLS = "urn:ietf:params:xml:ns:xmpp-tls";
@@ -55,7 +55,7 @@ public class Connection {
};
- public Connection(XMPPComponent xmpp) throws XmlPullParserException, KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, KeyManagementException {
+ public Connection(XMPPServer xmpp) throws XmlPullParserException, KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, KeyManagementException {
this.xmpp = xmpp;
tsCreated = System.currentTimeMillis();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java
index 5ac21fb6..41336582 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/ConnectionIn.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java
@@ -1,6 +1,6 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
-import com.juick.ws.components.XMPPComponent;
+import com.juick.components.XMPPServer;
import com.juick.xmpp.Iq;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
@@ -33,7 +33,7 @@ public class ConnectionIn extends Connection implements Runnable {
public long packetsRemote = 0;
JuickBot bot;
- public ConnectionIn(XMPPComponent xmpp, JuickBot bot, Socket socket) throws Exception {
+ public ConnectionIn(XMPPServer xmpp, JuickBot bot, Socket socket) throws Exception {
super(xmpp);
this.bot = bot;
this.socket = socket;
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/ConnectionOut.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java
index 6a0fe33b..cedb3745 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/ConnectionOut.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java
@@ -1,6 +1,6 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
-import com.juick.ws.components.XMPPComponent;
+import com.juick.components.XMPPServer;
import com.juick.xmpp.extensions.StreamFeatures;
import com.juick.xmpp.utils.XmlUtils;
import org.xmlpull.v1.XmlPullParser;
@@ -30,12 +30,12 @@ public class ConnectionOut extends Connection implements Runnable {
String checkSID = null;
String dbKey = null;
- public ConnectionOut(XMPPComponent xmpp, String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException {
+ public ConnectionOut(XMPPServer xmpp, String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException {
super(xmpp);
to = hostname;
}
- public ConnectionOut(XMPPComponent xmpp, String hostname, String checkSID, String dbKey) throws Exception {
+ public ConnectionOut(XMPPServer xmpp, String hostname, String checkSID, String dbKey) throws Exception {
super(xmpp);
to = hostname;
this.checkSID = checkSID;
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/DNSQueries.java b/juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java
index 35e72c2b..6de9e15d 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/DNSQueries.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java
@@ -1,4 +1,4 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
diff --git a/juick-ws/src/main/java/com/juick/ws/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
index 659b7ecd..737fbdc2 100644
--- a/juick-ws/src/main/java/com/juick/ws/s2s/JuickBot.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
@@ -1,7 +1,7 @@
-package com.juick.ws.s2s;
+package com.juick.components.s2s;
import com.juick.User;
-import com.juick.ws.components.XMPPComponent;
+import com.juick.components.XMPPServer;
import com.juick.server.PMQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
@@ -20,8 +20,8 @@ import java.util.regex.Pattern;
* @author ugnich
*/
public class JuickBot {
- XMPPComponent xmpp;
- public JuickBot(XMPPComponent xmpp, JID JuickJID) {
+ XMPPServer xmpp;
+ public JuickBot(XMPPServer xmpp, JID JuickJID) {
this.xmpp = xmpp;
this.JuickJID = JuickJID;
}
diff --git a/settings.gradle b/settings.gradle
index e85c92a1..8c4b604f 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':deps:com.juick.xmpp', ':juick-core', ':juick-api', ':juick-www', ':juick-rss', ':juick-ws', ':juick-demo', ':juick-notifications'
+include ':deps:com.juick.xmpp', ':juick-core', ':juick-api', ':juick-www', ':juick-rss', ':juick-ws', ':juick-demo', ':juick-notifications', ':juick-crosspost', ':juick-xmpp'