diff options
7 files changed, 29 insertions, 163 deletions
diff --git a/juick-console/build.gradle b/juick-console/build.gradle deleted file mode 100644 index 0c20d04b..00000000 --- a/juick-console/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } -} - -apply plugin: 'java' -apply plugin: 'application' -apply plugin: 'com.github.ben-manes.versions' - -mainClassName = "com.juick.console.Console" - -dependencies { - compile project(':juick-server') - compile 'mysql:mysql-connector-java:5.1.40' - compile 'org.jline:jline:3.1.2' -} - -compileJava.options.encoding = 'UTF-8' - -configurations { - all*.exclude module: 'commons-logging' -}
\ No newline at end of file diff --git a/juick-console/src/main/java/com/juick/console/Console.java b/juick-console/src/main/java/com/juick/console/Console.java deleted file mode 100644 index ad858c56..00000000 --- a/juick-console/src/main/java/com/juick/console/Console.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.juick.console; - -import com.juick.console.configuration.ConsoleAppConfiguration; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.core.env.SimpleCommandLinePropertySource; - -import java.io.IOException; - -/** - * Created by vitalyster on 30.08.2016. - */ -public class Console { - - public static void main(String ...args) throws IOException { - final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - - // setup configuration - applicationContext.register(ConsoleAppConfiguration.class); - // add CLI property source - applicationContext.getEnvironment().getPropertySources() - .addLast(new SimpleCommandLinePropertySource(args)); - - // setup all the dependencies (refresh) and make them run (start) - applicationContext.refresh(); - applicationContext.start(); - applicationContext.getBean(ConsoleApp.class).start(); - } -} diff --git a/juick-console/src/main/java/com/juick/console/ConsoleApp.java b/juick-console/src/main/java/com/juick/console/ConsoleApp.java deleted file mode 100644 index bfa3eae3..00000000 --- a/juick-console/src/main/java/com/juick/console/ConsoleApp.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.juick.console; - -import com.juick.User; -import com.juick.server.protocol.JuickProtocol; -import com.juick.server.protocol.ProtocolReply; -import com.juick.service.UserService; -import org.jline.reader.EndOfFileException; -import org.jline.reader.LineReader; -import org.jline.reader.LineReaderBuilder; -import org.jline.reader.UserInterruptException; -import org.jline.terminal.Terminal; -import org.jline.terminal.TerminalBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.core.env.Environment; - -import javax.inject.Inject; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; - -/** - * Created by vitalyster on 19.12.2016. - */ -public class ConsoleApp { - - private static final Logger logger = LoggerFactory.getLogger(ConsoleApp.class); - - @Inject - JuickProtocol juickProtocol; - @Inject - Environment env; - @Inject - UserService userService; - - public ConsoleApp(ApplicationContext context) { - juickProtocol = context.getBean(JuickProtocol.class); - } - public void start() throws IOException { - Terminal terminal = TerminalBuilder.builder() - .system(true) - .nativeSignals(true) - .jna(true) - .build(); - LineReader reader = LineReaderBuilder.builder() - .terminal(terminal) - .build(); - PrintWriter out = terminal.writer(); - String uname = env.getProperty("uname", "ugnich"); - User user = userService.getUserByName(uname); - if (user != null) { - String prompt = String.format("@%s>", user.getName()); - while (true) { - try { - String input = reader.readLine(prompt, null, null); - if (input == null) { - logger.error("invalid terminal"); - break; - } - ProtocolReply reply = juickProtocol.getReply(user, input); - out.println(reply.getResult()); - out.flush(); - } catch (UserInterruptException e) { - logger.debug("user interrupt"); - } catch (EndOfFileException e) { - logger.debug("app exit"); - break; - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - logger.warn("protocol exception", e); - } - } - } else { - out.println("uname missing or invalid"); - } - } -} diff --git a/juick-console/src/main/java/com/juick/console/configuration/ConsoleAppConfiguration.java b/juick-console/src/main/java/com/juick/console/configuration/ConsoleAppConfiguration.java deleted file mode 100644 index 11e2609e..00000000 --- a/juick-console/src/main/java/com/juick/console/configuration/ConsoleAppConfiguration.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.juick.console.configuration; - -import com.juick.configuration.DataConfiguration; -import com.juick.console.ConsoleApp; -import com.juick.server.protocol.JuickProtocol; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Created by vitalyster on 19.12.2016. - */ -@Configuration -@ComponentScan(basePackages = {"com.juick.console", "com.juick.service", "com.juick.server.protocol"}) -@Import(DataConfiguration.class) -public class ConsoleAppConfiguration implements ApplicationContextAware { - private ApplicationContext applicationContext; - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } - @Bean - public JuickProtocol juickProtocol() { - return new JuickProtocol("https://juick.com/"); - } - @Bean - public ConsoleApp app() { - return new ConsoleApp(applicationContext); - } -} diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java index 81f636a7..2f998298 100644 --- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java @@ -1,9 +1,11 @@ package com.juick.ws; import com.juick.User; +import com.juick.server.protocol.JuickProtocol; import com.juick.service.MessagesService; import com.juick.service.UserService; import org.apache.commons.lang3.CharEncoding; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; @@ -13,11 +15,13 @@ import org.springframework.http.HttpHeaders; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.PingMessage; +import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; import javax.inject.Inject; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.ArrayList; import java.util.Collections; @@ -35,6 +39,8 @@ public class WebsocketComponent extends TextWebSocketHandler { UserService userService; @Inject MessagesService messagesService; + @Inject + JuickProtocol protocol; @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { @@ -130,6 +136,21 @@ public class WebsocketComponent extends TextWebSocketHandler { }); } + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + getClients().stream().filter(s -> !s.legacy && s.session.equals(session)).forEach(s -> { + User user = s.visitor; + String input = message.getPayload(); + if (StringUtils.isNotBlank(input)) { + try { + s.session.sendMessage(new TextMessage(protocol.getReply(user, input).getResult())); + } catch (IOException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { + logger.error("protocol exception", e); + } + } + }); + } + public List<SocketSubscribed> getClients() { return clients; } 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 e0a31b13..b7e0e658 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 @@ -1,8 +1,10 @@ package com.juick.ws.configuration; +import com.juick.server.protocol.JuickProtocol; import com.juick.ws.WebsocketComponent; import com.juick.ws.XMPPConnection; 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; @@ -19,6 +21,7 @@ import javax.inject.Inject; * Created by aalexeev on 11/24/16. */ @Configuration +@ComponentScan(basePackages = {"com.juick.server.protocol"}) @EnableScheduling @EnableWebSocket @PropertySource("classpath:juick.conf") @@ -35,6 +38,10 @@ class WebsocketConfiguration implements WebSocketConfigurer { public XMPPConnection ws() { return new XMPPConnection(env, wsHandler()); } + @Bean + public JuickProtocol protocol() { + return new JuickProtocol("https://juick.com/"); + } @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { diff --git a/settings.gradle b/settings.gradle index 5b96cb5d..af94a9e0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = "Juick" -include ':juick-core', 'juick-server', ':juick-api', ':juick-www', ':juick-rss', ':juick-ws', ':juick-console', ':juick-notifications', ':juick-crosspost', ':juick-xmpp', ':juick-xmpp-ft', ':juick-xmpp-bot', ':juick-spring-www' +include ':juick-core', 'juick-server', ':juick-api', ':juick-www', ':juick-rss', ':juick-ws', ':juick-notifications', ':juick-crosspost', ':juick-xmpp', ':juick-xmpp-ft', ':juick-xmpp-bot', ':juick-spring-www' |