aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-08 16:36:52 +0300
committerGravatar Vitaly Takmazov2016-11-08 17:45:40 +0300
commit7270411d55c154e42c942caeaf4d4b942d72dea2 (patch)
treec102da1c5265d8eed69c3441ccdbb4c953a983ba
parent40c1a196d019fbaf3dd8f0d8f6d1bdc8225bb7a0 (diff)
ws: fix injection
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/Crosspost.java4
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java14
-rw-r--r--juick-ws/src/main/java/com/juick/ws/StatusController.java2
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java1
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java4
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java4
6 files changed, 23 insertions, 6 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
index 493fa5e4..55d1370d 100644
--- a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
+++ b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
@@ -57,7 +57,6 @@ public class Crosspost implements DisposableBean, Stream.StreamListener, Message
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";
public final static String VKURL = "https://api.vk.com/method/wall.post";
- @Inject
JdbcTemplate jdbc;
Stream xmpp;
String twitter_consumer_key;
@@ -65,8 +64,9 @@ public class Crosspost implements DisposableBean, Stream.StreamListener, Message
ExecutorService service;
@Inject
- public Crosspost(Environment env, ExecutorService service) {
+ public Crosspost(Environment env, ExecutorService service, JdbcTemplate jdbc) {
this.service = service;
+ this.jdbc = jdbc;
logger.info("component initialized");
try {
twitter_consumer_key = env.getProperty("twitter_consumer_key", "");
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
index 7ed9fcee..99555a1b 100644
--- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
+++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
@@ -8,6 +8,7 @@ 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;
@@ -16,6 +17,7 @@ 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;
@@ -38,6 +40,16 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport {
Environment env;
@Inject
ExecutorService service;
+ @Inject
+ JdbcTemplate jdbc;
+
+ @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;
@@ -70,7 +82,7 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport {
}
@Bean
public Crosspost crosspost() {
- return new Crosspost(env, service);
+ return new Crosspost(env, service, jdbc);
}
@Bean
public ExecutorService service() {
diff --git a/juick-ws/src/main/java/com/juick/ws/StatusController.java b/juick-ws/src/main/java/com/juick/ws/StatusController.java
index 216089b4..f7e80106 100644
--- a/juick-ws/src/main/java/com/juick/ws/StatusController.java
+++ b/juick-ws/src/main/java/com/juick/ws/StatusController.java
@@ -16,6 +16,8 @@ import javax.inject.Inject;
public class StatusController {
@Inject
WebsocketComponent wsHandler;
+ @Inject
+ XMPPConnection ws;
@RequestMapping(method = RequestMethod.GET, headers = "Connection!=upgrade", value = "/")
public ModelAndView status() {
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 caeb5b21..0f2f75f6 100644
--- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
@@ -36,6 +36,7 @@ public class XMPPConnection implements Stream.StreamListener, Message.MessageLis
Stream xmpp;
String xmppPassword;
MessageSerializer ms;
+ @Inject
WebsocketComponent wsHandler;
@Inject
diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
index 31aa0bc7..a091d477 100644
--- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
+++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
@@ -52,13 +52,13 @@ public class XMPPServer implements DisposableBean, Stream.StreamListener,
private final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>());
private final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
private final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>());
- @Inject
public JdbcTemplate jdbc;
final public HashMap<String, StanzaChild> childParsers = new HashMap<>();
@Inject
- public XMPPServer(Environment env, ExecutorService service) {
+ public XMPPServer(Environment env, ExecutorService service, JdbcTemplate jdbc) {
this.service = service;
+ this.jdbc = jdbc;
logger.info("component initialized");
try {
HOSTNAME = env.getProperty("hostname");
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
index 1695de6a..7cada270 100644
--- a/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java
+++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XMPPConfiguration.java
@@ -39,6 +39,8 @@ public class XMPPConfiguration extends WebMvcConfigurationSupport {
Environment env;
@Inject
ExecutorService service;
+ @Inject
+ JdbcTemplate jdbc;
@Bean
JdbcTemplate jdbc() {
@@ -78,7 +80,7 @@ public class XMPPConfiguration extends WebMvcConfigurationSupport {
}
@Bean
public XMPPServer xmpp() {
- return new XMPPServer(env, service);
+ return new XMPPServer(env, service, jdbc);
}
@Bean
public ExecutorService service() {