aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle4
-rw-r--r--gradle/wrapper/gradle-wrapper.jarbin54227 -> 54333 bytes
-rw-r--r--gradle/wrapper/gradle-wrapper.properties3
-rwxr-xr-xgradlew6
-rw-r--r--juick-api/src/main/java/com/juick/api/ApiServer.java108
-rw-r--r--juick-server-web/src/main/java/com/juick/server/configuration/JuickServerWebsocketConfiguration.java2
-rw-r--r--juick-server/build.gradle (renamed from juick-api/build.gradle)4
-rw-r--r--juick-server/src/main/java/com/juick/api/ApiServer.java (renamed from juick-ws/src/main/java/com/juick/ws/XMPPConnection.java)91
-rw-r--r--juick-server/src/main/java/com/juick/api/CrosspostManager.java (renamed from juick-api/src/main/java/com/juick/api/CrosspostManager.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/EmailManager.java (renamed from juick-api/src/main/java/com/juick/api/EmailManager.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/FacebookPageManager.java (renamed from juick-api/src/main/java/com/juick/api/FacebookPageManager.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/MessengerManager.java (renamed from juick-api/src/main/java/com/juick/api/MessengerManager.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/TelegramBotManager.java (renamed from juick-api/src/main/java/com/juick/api/TelegramBotManager.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/TopManager.java (renamed from juick-api/src/main/java/com/juick/api/TopManager.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/WebsocketManager.java (renamed from juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java)30
-rw-r--r--juick-server/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java (renamed from juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java)38
-rw-r--r--juick-server/src/main/java/com/juick/api/configuration/ApiInitializer.java (renamed from juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java (renamed from juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java)3
-rw-r--r--juick-server/src/main/java/com/juick/api/configuration/ApiSecurityInitializer.java (renamed from juick-api/src/main/java/com/juick/api/configuration/ApiSecurityInitializer.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/ApiController.java (renamed from juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java)18
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Messages.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Messages.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/MessengerWebhook.java (renamed from juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Notifications.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Notifications.java)4
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Others.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Others.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/PM.java (renamed from juick-api/src/main/java/com/juick/api/controllers/PM.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Post.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Post.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Service.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Service.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/SkypeEndpoint.java (renamed from juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Tags.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Tags.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/TelegramWebhook.java (renamed from juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/Users.java (renamed from juick-api/src/main/java/com/juick/api/controllers/Users.java)0
-rw-r--r--juick-server/src/main/java/com/juick/api/controllers/util/JsonpAdvice.java (renamed from juick-api/src/main/java/com/juick/api/controllers/util/JsonpAdvice.java)0
-rw-r--r--juick-server/src/main/resources/juick.conf.sample (renamed from juick-api/src/main/resources/juick.conf.sample)0
-rw-r--r--juick-server/src/main/webapp/WEB-INF/juick.conf.example (renamed from juick-api/src/main/webapp/WEB-INF/juick.conf.example)0
-rw-r--r--juick-server/src/main/webapp/WEB-INF/web.xml (renamed from juick-api/src/main/webapp/WEB-INF/web.xml)0
-rw-r--r--juick-server/src/test/java/com/juick/api/tests/MessagesTests.java (renamed from juick-api/src/test/java/com/juick/api/tests/MessagesTests.java)0
-rw-r--r--juick-server/src/test/resources/juick.conf.example (renamed from juick-api/src/test/resources/juick.conf.example)0
-rw-r--r--juick-ws/build.gradle21
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java75
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java57
-rw-r--r--juick-ws/src/main/webapp/WEB-INF/web.xml7
-rw-r--r--settings.gradle2
42 files changed, 144 insertions, 329 deletions
diff --git a/build.gradle b/build.gradle
index f18d7056..5b3155b8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -45,11 +45,9 @@ apply plugin: 'java'
apply plugin: 'org.akhikhl.gretty'
farm {
- webapp ':juick-xmpp-wip'
- webapp ':juick-ws'
webapp ':juick-www'
webapp ':juick-xmpp'
- webapp ':juick-api'
+ webapp ':juick-server'
servletContainer = 'tomcat8'
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 51288f9c..c44b679a 100644
--- a/gradle/wrapper/gradle-wrapper.jar
+++ b/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 46ac96b0..568c50bf 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Fri Sep 22 11:47:52 MSK 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
diff --git a/gradlew b/gradlew
index 4453ccea..cccdd3d5 100755
--- a/gradlew
+++ b/gradlew
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
-warn ( ) {
+warn () {
echo "$*"
}
-die ( ) {
+die () {
echo
echo "$*"
echo
@@ -155,7 +155,7 @@ if $cygwin ; then
fi
# Escape application args
-save ( ) {
+save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
diff --git a/juick-api/src/main/java/com/juick/api/ApiServer.java b/juick-api/src/main/java/com/juick/api/ApiServer.java
deleted file mode 100644
index 3643e974..00000000
--- a/juick-api/src/main/java/com/juick/api/ApiServer.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * 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.api;
-
-import com.juick.User;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import rocks.xmpp.addr.Jid;
-import rocks.xmpp.core.XmppException;
-import rocks.xmpp.core.session.Extension;
-import rocks.xmpp.core.session.XmppSessionConfiguration;
-import rocks.xmpp.core.session.debug.LogbackDebugger;
-import rocks.xmpp.core.stanza.model.Message;
-import rocks.xmpp.extensions.component.accept.ExternalComponent;
-import rocks.xmpp.extensions.oob.model.x.OobX;
-
-import javax.annotation.PostConstruct;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-/**
- * @author Ugnich Anton
- */
-public class ApiServer implements AutoCloseable {
- private static Logger logger = LoggerFactory.getLogger(ApiServer.class);
-
- private ExternalComponent xmpp;
-
- @Value("${xmpp_host:localhost}")
- private String xmppHost;
- @Value("${xmpp_password:secret}")
- private String xmppPassword;
- @Value("${xmpp_jid:api.localhost}")
- private String xmppJid;
- @Value("${xmpp_port:5347}")
- private int xmppPort;
- @Value("${xmpp_disabled:false}")
- private boolean isXmppDisabled;
-
- @PostConstruct
- public void init() {
- if (!isXmppDisabled) {
- setupXmppComponent(xmppHost, xmppPort, xmppJid, xmppPassword);
- }
- }
-
- @Override
- public void close() {
- try {
- if (xmpp != null)
- xmpp.close();
-
- logger.info("ExternalComponent on juick-api destroyed");
- } catch (Exception e) {
- logger.warn("Exception occurs on juick-api destroy", e);
- }
- }
-
- public void setupXmppComponent(final String host, final int port, final String jid, final String password) {
- XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
- .extensions(Extension.of(com.juick.Message.class))
- .build();
- xmpp = ExternalComponent.create(jid, password, configuration, host, port);
- try {
- xmpp.connect();
- } catch (XmppException e) {
- logger.warn("xmpp extension", e);
- }
- }
-
- public void sendMessage(Message message) {
- if (!isXmppDisabled) {
- xmpp.sendMessage(message);
- }
- }
-
- public void processMessage(User visitor, String body, String attachmentName) {
- Message xmsg = new Message();
- xmsg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "perl"));
- xmsg.setTo(Jid.of("juick@juick.com/Juick"));
- xmsg.setBody(body);
- try {
- if (StringUtils.isNotEmpty(attachmentName)) {
- String attachmentUrl = String.format("juick://%s", attachmentName);
- xmsg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!"));
- }
- sendMessage(xmsg);
- } catch (URISyntaxException e1) {
- logger.warn("attachment error", e1);
- }
- }
-}
diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerWebsocketConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerWebsocketConfiguration.java
index 6790a7c9..18501eaf 100644
--- a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerWebsocketConfiguration.java
+++ b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerWebsocketConfiguration.java
@@ -31,7 +31,7 @@ import java.util.List;
@EnableScheduling
public class JuickServerWebsocketConfiguration {
private static final Logger logger = LoggerFactory.getLogger(JuickServerWebsocketConfiguration.class);
- @Value("${websocket_url:ws://localhost:8080/}")
+ @Value("${websocket_url:ws://localhost:8080/ws/}")
private String baseUri;
@Value("${api_user:juick}")
private String serviceUser;
diff --git a/juick-api/build.gradle b/juick-server/build.gradle
index 8fde37ed..438025a1 100644
--- a/juick-api/build.gradle
+++ b/juick-server/build.gradle
@@ -25,7 +25,7 @@ dependencies {
testCompile project(path: ':juick-server-web', configuration: 'testArtifacts')
testCompile project(path: ':juick-server-jdbc', configuration: 'testArtifacts')
- testRuntime 'org.apache.tomcat:tomcat-websocket:9.0.4'
+ testRuntime 'org.apache.tomcat.embed:tomcat-embed-websocket:9.0.4'
testRuntime 'com.jayway.jsonpath:json-path:2.4.0'
}
@@ -33,7 +33,7 @@ compileJava.options.encoding = 'UTF-8'
gretty {
httpPort = 8080
- contextPath = '/api'
+ contextPath = '/'
servletContainer = 'tomcat8'
}
diff --git a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java b/juick-server/src/main/java/com/juick/api/ApiServer.java
index e338bf66..51097440 100644
--- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/juick-server/src/main/java/com/juick/api/ApiServer.java
@@ -14,28 +14,27 @@
* 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;
+package com.juick.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.User;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-import org.springframework.util.Assert;
import org.springframework.web.socket.TextMessage;
+import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.XmppException;
import rocks.xmpp.core.session.Extension;
-import rocks.xmpp.core.session.XmppSession;
import rocks.xmpp.core.session.XmppSessionConfiguration;
import rocks.xmpp.core.session.debug.LogbackDebugger;
import rocks.xmpp.core.stanza.model.Message;
import rocks.xmpp.extensions.component.accept.ExternalComponent;
+import rocks.xmpp.extensions.oob.model.x.OobX;
import rocks.xmpp.util.XmppUtils;
import javax.annotation.PostConstruct;
@@ -45,46 +44,66 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.List;
import java.util.stream.Collectors;
/**
- * @author ugnich
+ * @author Ugnich Anton
*/
-@Component
-public class XMPPConnection implements AutoCloseable {
- private static final Logger logger = LoggerFactory.getLogger(XMPPConnection.class);
+public class ApiServer implements AutoCloseable {
+ private static Logger logger = LoggerFactory.getLogger(ApiServer.class);
- @Inject
- private WebsocketComponent wsHandler;
+ private ExternalComponent xmpp;
+
+ @Value("${xmpp_host:localhost}")
+ private String xmppHost;
@Value("${xmpp_password:secret}")
private String xmppPassword;
- @Inject
- private ObjectMapper jsonMapper;
+ @Value("${ws_jid:ws.localhost}")
+ private String xmppJid;
@Value("${xmpp_port:5347}")
private int xmppPort;
- @Value("${ws_jid:ws.juick.local}")
- private String wsJid;
- @Value("${service_user:juick}")
- private String serviceUser;
-
- private XmppSession xmpp;
-
+ @Value("${xmpp_disabled:false}")
+ private boolean isXmppDisabled;
+ @Inject
+ private ObjectMapper jsonMapper;
@Inject
private MessagesService messagesService;
@Inject
private SubscriptionService subscriptionService;
-
+ @Inject
+ private WebsocketManager wsHandler;
+ @Value("${service_user:juick}")
+ private String serviceUser;
@PostConstruct
public void init() {
- Assert.notNull(wsHandler, "WebsocketComponent must be initialized");
+ if (!isXmppDisabled) {
+ setupXmppComponent(xmppHost, xmppPort, xmppJid, xmppPassword);
+ } else {
+ logger.warn("XMPP is not enabled");
+ }
+ }
+
+ @Override
+ public void close() {
+ try {
+ if (xmpp != null)
+ xmpp.close();
+
+ logger.info("ExternalComponent on juick-api destroyed");
+ } catch (Exception e) {
+ logger.warn("Exception occurs on juick-api destroy", e);
+ }
+ }
+ public void setupXmppComponent(final String host, final int port, final String jid, final String password) {
XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
.extensions(Extension.of(com.juick.Message.class))
- .debugger(LogbackDebugger.class)
.build();
- xmpp = ExternalComponent.create(wsJid, xmppPassword, configuration, "localhost", xmppPort);
+ xmpp = ExternalComponent.create(jid, password, configuration, host, port);
xmpp.addInboundMessageListener(e -> {
try {
Message msg = e.getMessage();
@@ -131,12 +150,26 @@ public class XMPPConnection implements AutoCloseable {
}
}
- @Override
- public void close() throws Exception {
- if (xmpp != null)
- xmpp.close();
+ public void sendMessage(Message message) {
+ if (!isXmppDisabled) {
+ xmpp.sendMessage(message);
+ }
+ }
- logger.info("XmppSession on WS destroyed");
+ public void processMessage(User visitor, String body, String attachmentName) {
+ Message xmsg = new Message();
+ xmsg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "perl"));
+ xmsg.setTo(Jid.of("juick@juick.com/Juick"));
+ xmsg.setBody(body);
+ try {
+ if (StringUtils.isNotEmpty(attachmentName)) {
+ String attachmentUrl = String.format("juick://%s", attachmentName);
+ xmsg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!"));
+ }
+ sendMessage(xmsg);
+ } catch (URISyntaxException e1) {
+ logger.warn("attachment error", e1);
+ }
}
private void onJuickPM(final int uid_to, final com.juick.Message jmsg) throws JsonProcessingException {
diff --git a/juick-api/src/main/java/com/juick/api/CrosspostManager.java b/juick-server/src/main/java/com/juick/api/CrosspostManager.java
index a601d7b7..a601d7b7 100644
--- a/juick-api/src/main/java/com/juick/api/CrosspostManager.java
+++ b/juick-server/src/main/java/com/juick/api/CrosspostManager.java
diff --git a/juick-api/src/main/java/com/juick/api/EmailManager.java b/juick-server/src/main/java/com/juick/api/EmailManager.java
index fa86b406..fa86b406 100644
--- a/juick-api/src/main/java/com/juick/api/EmailManager.java
+++ b/juick-server/src/main/java/com/juick/api/EmailManager.java
diff --git a/juick-api/src/main/java/com/juick/api/FacebookPageManager.java b/juick-server/src/main/java/com/juick/api/FacebookPageManager.java
index e9ed0e59..e9ed0e59 100644
--- a/juick-api/src/main/java/com/juick/api/FacebookPageManager.java
+++ b/juick-server/src/main/java/com/juick/api/FacebookPageManager.java
diff --git a/juick-api/src/main/java/com/juick/api/MessengerManager.java b/juick-server/src/main/java/com/juick/api/MessengerManager.java
index 7341b946..7341b946 100644
--- a/juick-api/src/main/java/com/juick/api/MessengerManager.java
+++ b/juick-server/src/main/java/com/juick/api/MessengerManager.java
diff --git a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java b/juick-server/src/main/java/com/juick/api/TelegramBotManager.java
index 6f2e50d1..6f2e50d1 100644
--- a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/api/TelegramBotManager.java
diff --git a/juick-api/src/main/java/com/juick/api/TopManager.java b/juick-server/src/main/java/com/juick/api/TopManager.java
index b8123639..b8123639 100644
--- a/juick-api/src/main/java/com/juick/api/TopManager.java
+++ b/juick-server/src/main/java/com/juick/api/TopManager.java
diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-server/src/main/java/com/juick/api/WebsocketManager.java
index 45814ecb..40747e5a 100644
--- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
+++ b/juick-server/src/main/java/com/juick/api/WebsocketManager.java
@@ -15,10 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.ws;
+package com.juick.api;
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.server.util.HttpNotFoundException;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import com.juick.service.UserService;
@@ -44,8 +47,8 @@ import java.util.List;
/**
* Created by vitalyster on 28.06.2016.
*/
-public class WebsocketComponent extends TextWebSocketHandler {
- private static final Logger logger = LoggerFactory.getLogger(WebsocketComponent.class);
+public class WebsocketManager extends TextWebSocketHandler {
+ private static final Logger logger = LoggerFactory.getLogger(WebsocketManager.class);
private final List<SocketSubscribed> clients = Collections.synchronizedList(new LinkedList<>());
@@ -76,42 +79,41 @@ public class WebsocketComponent extends TextWebSocketHandler {
} else {
logger.info("wrong hash for {} from {}", visitor.getUid(), hXRealIP);
}
- logger.info("user {} connected to {} from {}", visitor.getUid(), hLocation.getPath(), hXRealIP);
int MID = 0;
SocketSubscribed sockSubscr = null;
- if (hLocation.getPath().equals("/")) {
+ if (hLocation.getPath().equals("/ws/")) {
logger.info("user {} connected", visitor.getUid());
sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, false);
- } else if (hLocation.getPath().equals("/_all")) {
+ } else if (hLocation.getPath().equals("/ws/_all")) {
logger.info("user {} connected to legacy _all ({})", visitor.getUid(), hLocation.getPath());
sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true);
sockSubscr.allMessages = true;
- } else if (hLocation.getPath().equals("/_replies")) {
+ } else if (hLocation.getPath().equals("/ws/_replies")) {
logger.info("user {} connected to legacy _replies ({})", visitor.getUid(), hLocation.getPath());
sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true);
sockSubscr.allReplies = true;
- } else if (hLocation.getPath().matches("/\\d+$")) {
- MID = NumberUtils.toInt(hLocation.getPath().substring(1), 0);
+ } else if (hLocation.getPath().matches("^/ws/(\\d)+$")) {
+ MID = NumberUtils.toInt(hLocation.getPath().substring(4), 0);
if (MID > 0) {
if (messagesService.canViewThread(MID, visitor.getUid())) {
logger.info("user {} connected to legacy thread ({}) from {}", visitor.getUid(), MID, hXRealIP);
sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true);
sockSubscr.MID = MID;
} else {
- try {
- session.close(new CloseStatus(403, "Forbidden"));
- } catch (IOException e) {
- logger.warn("ws error", e);
- }
+ throw new HttpForbiddenException();
}
}
+ } else {
+ throw new HttpNotFoundException();
}
if (sockSubscr != null) {
synchronized (clients) {
clients.add(sockSubscr);
logger.info("{} clients connected", clients.size());
}
+ } else {
+ throw new HttpBadRequestException();
}
}
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-server/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
index a475ca6f..ea59ac52 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
+++ b/juick-server/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
@@ -18,17 +18,26 @@
package com.juick.api.configuration;
import com.juick.api.ApiServer;
+import com.juick.api.WebsocketManager;
import com.juick.server.component.JuickServerComponent;
import com.juick.server.component.JuickServerReconnectManager;
import com.juick.server.configuration.BaseWebConfiguration;
import com.juick.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
+import org.springframework.core.Ordered;
import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry;
+import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
+import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
+import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
import org.springframework.web.util.UriComponentsBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -37,6 +46,7 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
+import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Collections;
@@ -47,14 +57,16 @@ import java.util.Collections;
@EnableAsync
@EnableWebMvc
@EnableSwagger2
+@EnableScheduling
+@EnableWebSocket
@PropertySource("classpath:juick.conf")
@ComponentScan(basePackages = "com.juick")
-public class ApiAppConfiguration extends BaseWebConfiguration {
+public class ApiAppConfiguration extends BaseWebConfiguration implements WebSocketConfigurer {
@Inject
UserService userService;
@Value("${api_user:juick}")
private String serviceUser;
- @Value("${websocket_url:ws://localhost:8080/}")
+ @Value("${websocket_url:ws://localhost:8080/ws/}")
private String baseUri;
@Lazy
@Bean
@@ -97,5 +109,27 @@ public class ApiAppConfiguration extends BaseWebConfiguration {
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
+ @Bean
+ public WebsocketManager wsHandler() {
+ return new WebsocketManager();
+ }
+
+ @Override
+ public void registerWebSocketHandlers(@Nonnull WebSocketHandlerRegistry registry) {
+ //((ServletWebSocketHandlerRegistry) registry).setOrder(Ordered.LOWEST_PRECEDENCE);
+ registry.addHandler(wsHandler(), "/ws/**").setAllowedOrigins("*");
+ }
+
+ @Bean
+ public ServletServerContainerFactoryBean createWebSocketContainer() {
+ ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
+ container.setMaxTextMessageBufferSize(8192);
+ container.setMaxBinaryMessageBufferSize(8192);
+ return container;
+ }
+ @Override
+ public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
+ configurer.enable();
+ }
}
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-server/src/main/java/com/juick/api/configuration/ApiInitializer.java
index 8f35e3f7..8f35e3f7 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
+++ b/juick-server/src/main/java/com/juick/api/configuration/ApiInitializer.java
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java b/juick-server/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java
index 7e3f3345..2ae1d9e5 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java
+++ b/juick-server/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java
@@ -122,6 +122,7 @@ public class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
}
@Override
public void configure(WebSecurity web) throws Exception {
- web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources/**", "/configuration/**", "/swagger-ui.html", "/webjars/**");
+ web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources/**",
+ "/configuration/**", "/swagger-ui.html", "/webjars/**", "/ws/**");
}
}
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityInitializer.java b/juick-server/src/main/java/com/juick/api/configuration/ApiSecurityInitializer.java
index 259315fb..259315fb 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityInitializer.java
+++ b/juick-server/src/main/java/com/juick/api/configuration/ApiSecurityInitializer.java
diff --git a/juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java b/juick-server/src/main/java/com/juick/api/controllers/ApiController.java
index dc59193b..0929d1ea 100644
--- a/juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/ApiController.java
@@ -15,24 +15,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.ws.controllers;
+package com.juick.api.controllers;
import com.juick.Status;
-import com.juick.ws.WebsocketComponent;
+import com.juick.api.WebsocketManager;
+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
+import java.net.URI;
/**
* Created by vitalyster on 25.07.2016.
*/
+@ApiIgnore
@RestController
public class ApiController {
@Inject
- private WebsocketComponent wsHandler;
+ private WebsocketManager wsHandler;
+
+ @RequestMapping(value = "/", method = RequestMethod.GET, headers = "Connection!=Upgrade")
+ public ResponseEntity<Void> description() {
+ URI redirectUri = ServletUriComponentsBuilder.fromCurrentRequestUri().path("/swagger-ui.html").build().toUri();
+ return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).location(redirectUri).build();
+ }
@RequestMapping(value = "/api/status", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE, headers = "Connection!=Upgrade")
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-server/src/main/java/com/juick/api/controllers/Messages.java
index e16e46d5..e16e46d5 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Messages.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java b/juick-server/src/main/java/com/juick/api/controllers/MessengerWebhook.java
index 835165ba..835165ba 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/MessengerWebhook.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java b/juick-server/src/main/java/com/juick/api/controllers/Notifications.java
index 2a55844c..e4474e6e 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Notifications.java
@@ -32,6 +32,7 @@ import com.juick.service.UserService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
import java.io.IOException;
@@ -64,6 +65,7 @@ public class Notifications {
return user;
}
+ @ApiIgnore
@RequestMapping(value = "/notifications", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<List<User>> doGet(
@RequestParam(required = false, defaultValue = "0") int uid,
@@ -96,6 +98,7 @@ public class Notifications {
throw new HttpBadRequestException();
}
+ @ApiIgnore
@RequestMapping(value = "/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status doDelete(
@RequestBody List<ExternalToken> list) throws IOException {
@@ -123,6 +126,7 @@ public class Notifications {
return Status.OK;
}
+ @ApiIgnore
@RequestMapping(value = "/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status doPut(
@RequestBody List<ExternalToken> list) throws IOException {
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Others.java b/juick-server/src/main/java/com/juick/api/controllers/Others.java
index 4245de81..4245de81 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Others.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Others.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/PM.java b/juick-server/src/main/java/com/juick/api/controllers/PM.java
index 87858e8c..87858e8c 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/PM.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/PM.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-server/src/main/java/com/juick/api/controllers/Post.java
index a89786b1..a89786b1 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Post.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Post.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Service.java b/juick-server/src/main/java/com/juick/api/controllers/Service.java
index 9e7f3333..9e7f3333 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Service.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Service.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java b/juick-server/src/main/java/com/juick/api/controllers/SkypeEndpoint.java
index 91a617b4..91a617b4 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/SkypeEndpoint.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/SkypeEndpoint.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Tags.java b/juick-server/src/main/java/com/juick/api/controllers/Tags.java
index 85bb1ba4..85bb1ba4 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Tags.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Tags.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-server/src/main/java/com/juick/api/controllers/TelegramWebhook.java
index 31e7b4ea..31e7b4ea 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/TelegramWebhook.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Users.java b/juick-server/src/main/java/com/juick/api/controllers/Users.java
index b221d9fe..b221d9fe 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Users.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/Users.java
diff --git a/juick-api/src/main/java/com/juick/api/controllers/util/JsonpAdvice.java b/juick-server/src/main/java/com/juick/api/controllers/util/JsonpAdvice.java
index 90a01da0..90a01da0 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/util/JsonpAdvice.java
+++ b/juick-server/src/main/java/com/juick/api/controllers/util/JsonpAdvice.java
diff --git a/juick-api/src/main/resources/juick.conf.sample b/juick-server/src/main/resources/juick.conf.sample
index 12500325..12500325 100644
--- a/juick-api/src/main/resources/juick.conf.sample
+++ b/juick-server/src/main/resources/juick.conf.sample
diff --git a/juick-api/src/main/webapp/WEB-INF/juick.conf.example b/juick-server/src/main/webapp/WEB-INF/juick.conf.example
index 61ebbc29..61ebbc29 100644
--- a/juick-api/src/main/webapp/WEB-INF/juick.conf.example
+++ b/juick-server/src/main/webapp/WEB-INF/juick.conf.example
diff --git a/juick-api/src/main/webapp/WEB-INF/web.xml b/juick-server/src/main/webapp/WEB-INF/web.xml
index 7e1c30d0..7e1c30d0 100644
--- a/juick-api/src/main/webapp/WEB-INF/web.xml
+++ b/juick-server/src/main/webapp/WEB-INF/web.xml
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-server/src/test/java/com/juick/api/tests/MessagesTests.java
index fff7e02c..fff7e02c 100644
--- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
+++ b/juick-server/src/test/java/com/juick/api/tests/MessagesTests.java
diff --git a/juick-api/src/test/resources/juick.conf.example b/juick-server/src/test/resources/juick.conf.example
index cca3c182..cca3c182 100644
--- a/juick-api/src/test/resources/juick.conf.example
+++ b/juick-server/src/test/resources/juick.conf.example
diff --git a/juick-ws/build.gradle b/juick-ws/build.gradle
deleted file mode 100644
index 4683f3f9..00000000
--- a/juick-ws/build.gradle
+++ /dev/null
@@ -1,21 +0,0 @@
-apply plugin: 'java'
-apply plugin: 'war'
-apply plugin: 'org.akhikhl.gretty'
-
-dependencies {
- compile project(':juick-server-jdbc')
- compile project(':juick-server-web')
- compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}"
-}
-
-compileJava.options.encoding = 'UTF-8'
-
-gretty {
- httpPort = 8080
- contextPath = '/ws'
- servletContainer = 'tomcat8'
-}
-
-configurations {
- all*.exclude module: 'commons-logging'
-} \ No newline at end of file
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
deleted file mode 100644
index 194a75a5..00000000
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * 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.configuration;
-
-import com.juick.server.configuration.BaseWebConfiguration;
-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.Ordered;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.springframework.web.socket.config.annotation.EnableWebSocket;
-import org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry;
-import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
-import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
-import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
-
-import javax.annotation.Nonnull;
-
-/**
- * Created by aalexeev on 11/24/16.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.ws.controllers"})
-@EnableScheduling
-@EnableWebSocket
-@EnableWebMvc
-@PropertySource("classpath:juick.conf")
-public class WebsocketConfiguration extends BaseWebConfiguration implements WebSocketConfigurer {
- @Bean
- public XMPPConnection xmpp() {
- return new XMPPConnection();
- }
- @Bean
- public WebsocketComponent wsHandler() {
- return new WebsocketComponent();
- }
-
- @Override
- public void registerWebSocketHandlers(@Nonnull WebSocketHandlerRegistry registry) {
- ((ServletWebSocketHandlerRegistry) registry).setOrder(Ordered.LOWEST_PRECEDENCE);
- registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*");
- }
-
- @Bean
- public ServletServerContainerFactoryBean createWebSocketContainer() {
- ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
- container.setMaxTextMessageBufferSize(8192);
- container.setMaxBinaryMessageBufferSize(8192);
- return container;
- }
- @Override
- public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
- configurer.enable();
- }
-}
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
deleted file mode 100644
index 42f0fac2..00000000
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * 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.configuration;
-
-import com.juick.configuration.DataConfiguration;
-import com.juick.server.configuration.StorageConfiguration;
-import org.apache.commons.codec.CharEncoding;
-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 WebsocketInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
-
- @Override
- protected Class<?>[] getRootConfigClasses() {
- return new Class<?>[]{ WebsocketConfiguration.class, DataConfiguration.class, StorageConfiguration.class};
- }
-
- @Override
- protected Class<?>[] getServletConfigClasses() {
- return null;
- }
-
- @Override
- protected String[] getServletMappings() {
- return new String[]{"/"};
- }
-
- @Override
- protected Filter[] getServletFilters() {
- return new Filter[]{new CharacterEncodingFilter(CharEncoding.UTF_8)};
- }
-
- @Override
- protected String getServletName() {
- return "Web socket dispatcher servlet";
- }
-}
diff --git a/juick-ws/src/main/webapp/WEB-INF/web.xml b/juick-ws/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index a57cceb9..00000000
--- a/juick-ws/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
-
-</web-app> \ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 3b78e42e..07848f53 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,4 +1,4 @@
rootProject.name = "Juick"
-include ':juick-core', ':juick-server-core', ':juick-server-jdbc', ':juick-server-web', ':juick-api', ':juick-www', ':juick-rss', ':juick-ws', ':juick-notifications', ':juick-xmpp', ':juick-xmpp-wip'
+include ':juick-core', ':juick-server-core', ':juick-server-jdbc', ':juick-server-web', ':juick-server', ':juick-www', ':juick-rss', ':juick-notifications', ':juick-xmpp', ':juick-xmpp-wip'