From 032f5f7c62ed6932386e700a74dd7e519ad4de5d Mon Sep 17 00:00:00 2001
From: Alex Bitney
Date: Sat, 6 Feb 2016 16:33:29 +0200
Subject: domain independence in few places fixed zero tags exception on user's
page
---
build.gradle | 8 ++++++++
deps/com.juick.server | 2 +-
src/main/java/com/juick/JuickApplication.java | 16 ++++++++++++----
src/main/java/com/juick/http/www/Login.java | 5 +++--
src/main/java/com/juick/http/www/Main.java | 2 ++
src/main/java/com/juick/http/www/PageTemplates.java | 9 +++++----
src/main/java/com/juick/http/www/RSS.java | 8 ++++----
src/main/java/com/juick/http/www/Settings.java | 5 +++--
src/main/java/com/juick/http/www/User.java | 5 +++--
src/main/java/com/juick/http/www/UserThread.java | 3 ++-
10 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/build.gradle b/build.gradle
index b25a8ae4..e409e380 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,6 +24,14 @@ apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'com.eriwen.gradle.js'
apply plugin: 'com.github.tkruse.groovysh'
+apply plugin: 'idea'
+
+idea {
+ project {
+ languageLevel = '1.8'
+ }
+}
+
repositories {
mavenCentral()
diff --git a/deps/com.juick.server b/deps/com.juick.server
index 94c3a302..30321534 160000
--- a/deps/com.juick.server
+++ b/deps/com.juick.server
@@ -1 +1 @@
-Subproject commit 94c3a302da985b3c98dce61d13a5d5ef3340647c
+Subproject commit 30321534978ce4352ef6516eb545eff5f33a2dc3
diff --git a/src/main/java/com/juick/JuickApplication.java b/src/main/java/com/juick/JuickApplication.java
index c4a62c6f..ce242222 100644
--- a/src/main/java/com/juick/JuickApplication.java
+++ b/src/main/java/com/juick/JuickApplication.java
@@ -55,12 +55,20 @@ public class JuickApplication {
@Override
public void failed(Throwable exc, AsynchronousSocketChannel attachment) {
- logger.log(Level.SEVERE, "www router failed", exc);
+ if (!isHttpDevMode()) {
+ logger.log(Level.SEVERE, "www router failed", exc);
+ }
}
});
- addComponent(new S2SComponent(this, conf));
- addComponent(new CrosspostComponent(sql, conf));
- addComponent(new PushComponent(sql, conf));
+ if (!isHttpDevMode()) {
+ addComponent(new S2SComponent(this, conf));
+ addComponent(new CrosspostComponent(sql, conf));
+ addComponent(new PushComponent(sql, conf));
+ }
+ }
+
+ public static boolean isHttpDevMode() {
+ return "san".equals(System.getenv("USER"));
}
public Stream getRouter() {
diff --git a/src/main/java/com/juick/http/www/Login.java b/src/main/java/com/juick/http/www/Login.java
index 00775fc1..f1f670b1 100644
--- a/src/main/java/com/juick/http/www/Login.java
+++ b/src/main/java/com/juick/http/www/Login.java
@@ -17,6 +17,7 @@
*/
package com.juick.http.www;
+import com.juick.server.Endpoints;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.servlet.ServletException;
@@ -219,7 +220,7 @@ public class Login {
response.addCookie(c);
String referer = request.getHeader("Referer");
- if (referer != null && referer.startsWith("http://juick.com/") && !referer.equals("http://juick.com/login")) {
+ if (referer != null && referer.startsWith("http://"+Endpoints.wwwJuickCom+"/") && !referer.equals("http://"+Endpoints.wwwJuickCom+"/login")) {
response.sendRedirect(referer);
} else {
response.sendRedirect("/");
@@ -235,7 +236,7 @@ public class Login {
sql.update("DELETE FROM logins WHERE user_id=?", visitor.getUID());
Cookie c = new Cookie("hash", "-");
- c.setDomain(".juick.com");
+ c.setDomain("." + Endpoints.getWwwJuickComDomain());
c.setMaxAge(0);
response.addCookie(c);
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java
index 08b92305..f37ae030 100644
--- a/src/main/java/com/juick/http/www/Main.java
+++ b/src/main/java/com/juick/http/www/Main.java
@@ -18,6 +18,7 @@
package com.juick.http.www;
import com.juick.JuickApplication;
+import com.juick.server.Endpoints;
import com.juick.server.UserQueries;
import com.juick.xmpp.Stream;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -75,6 +76,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"),
conf.getProperty("twitter_consumer_secret"));
PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600);
+ Endpoints.wwwJuickCom = conf.getProperty("www_juick_com", "juick.com");
app = new JuickApplication(conf);
sql = app.getSql();
sqlSearch = app.getSqlSearch();
diff --git a/src/main/java/com/juick/http/www/PageTemplates.java b/src/main/java/com/juick/http/www/PageTemplates.java
index 5d70e9de..3eb66877 100644
--- a/src/main/java/com/juick/http/www/PageTemplates.java
+++ b/src/main/java/com/juick/http/www/PageTemplates.java
@@ -19,6 +19,7 @@ package com.juick.http.www;
import com.juick.Message;
import com.juick.Tag;
+import com.juick.server.Endpoints;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -375,11 +376,11 @@ public class PageTemplates {
// #12345
// #12345
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1#$2$3");
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1#$2$3");
// #12345/65
// #12345/65
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1#$2/$3$4");
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1#$2/$3$4");
// *bold*
// bold
@@ -399,11 +400,11 @@ public class PageTemplates {
// @username@jabber.org
// @username@jabber.org
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3");
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3");
// @username
// @username
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3");
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3");
// (http://juick.com/last?page=2)
// (juick.com)
diff --git a/src/main/java/com/juick/http/www/RSS.java b/src/main/java/com/juick/http/www/RSS.java
index c9c9df18..070fa1d5 100644
--- a/src/main/java/com/juick/http/www/RSS.java
+++ b/src/main/java/com/juick/http/www/RSS.java
@@ -18,6 +18,7 @@
package com.juick.http.www;
import com.juick.Message;
+import com.juick.server.Endpoints;
import com.juick.server.MessagesQueries;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -33,7 +34,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- *
* @author ugnich
*/
public class RSS {
@@ -64,8 +64,8 @@ public class RSS {
for (Message msg : msgs) {
out.println("- ");
- out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
- out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
+ out.println("http://" + Endpoints.wwwJuickCom + "/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
+ out.println("http://" + Endpoints.wwwJuickCom + "/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
out.print("");
out.println("");
out.println("" + sdfRSS.format(msg.getDate()) + "");
- out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
+ out.println("http://" + Endpoints.wwwJuickCom + "/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
if (!msg.Tags.isEmpty()) {
for (int n = 0; n < msg.Tags.size(); n++) {
out.println("" + msg.Tags.get(n) + "");
diff --git a/src/main/java/com/juick/http/www/Settings.java b/src/main/java/com/juick/http/www/Settings.java
index 3713157f..6c39138f 100644
--- a/src/main/java/com/juick/http/www/Settings.java
+++ b/src/main/java/com/juick/http/www/Settings.java
@@ -17,6 +17,7 @@
*/
package com.juick.http.www;
+import com.juick.server.Endpoints;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.servlet.ServletException;
@@ -71,7 +72,7 @@ public class Settings {
if (uid > 0) {
String hash = com.juick.server.UserQueries.getHashByUID(sql, uid);
Cookie c = new Cookie("hash", hash);
- c.setDomain(".juick.com");
+ c.setDomain("." + Endpoints.getWwwJuickComDomain());
c.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(c);
@@ -81,7 +82,7 @@ public class Settings {
}
String referer = request.getHeader("Referer");
- if (referer != null && referer.startsWith("http://juick.com/") && !referer.equals("http://juick.com/login")) {
+ if (referer != null && referer.startsWith("http://"+Endpoints.wwwJuickCom+"/") && !referer.equals("http://"+Endpoints.wwwJuickCom+"/login")) {
response.sendRedirect(referer);
} else {
response.sendRedirect("/");
diff --git a/src/main/java/com/juick/http/www/User.java b/src/main/java/com/juick/http/www/User.java
index 9ccf43ac..1f2b7dc0 100644
--- a/src/main/java/com/juick/http/www/User.java
+++ b/src/main/java/com/juick/http/www/User.java
@@ -18,6 +18,7 @@
package com.juick.http.www;
import com.juick.Tag;
+import com.juick.server.Endpoints;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
@@ -271,7 +272,7 @@ public class User {
String hReferer = request.getHeader("Referer");
String ref = Utils.getCookie(request, "ref");
- if (ref == null && (hReferer == null || !(hReferer.startsWith("http://juick.com/") || hReferer.startsWith("https://juick.com/")))) {
+ if (ref == null && (hReferer == null || !(hReferer.startsWith("http://"+ Endpoints.wwwJuickCom+"/") || hReferer.startsWith("https://"+Endpoints.wwwJuickCom+"/")))) {
Cookie c = new Cookie("ref", Integer.toString(uid));
c.setMaxAge(7 * 24 * 60 * 60);
c.setPath("/");
@@ -361,7 +362,7 @@ public class User {
}), user.getUID());
}
- int maxUsageCnt = tags.stream().mapToInt(tag -> tag.UsageCnt).max().getAsInt();
+ int maxUsageCnt = tags.size() > 0 ? tags.stream().mapToInt(tag -> tag.UsageCnt).max().getAsInt() : 1;
return tags.stream().map(tag -> "" + tag.Name + "")
diff --git a/src/main/java/com/juick/http/www/UserThread.java b/src/main/java/com/juick/http/www/UserThread.java
index f54aa925..84d99788 100644
--- a/src/main/java/com/juick/http/www/UserThread.java
+++ b/src/main/java/com/juick/http/www/UserThread.java
@@ -19,6 +19,7 @@ package com.juick.http.www;
import com.juick.Message;
import com.juick.Tag;
+import com.juick.server.Endpoints;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -76,7 +77,7 @@ public class UserThread {
try (PrintWriter out = response.getWriter()) {
String headers = "";
if (paramView != null) {
- headers += "";
+ headers += "";
}
if (msg.Hidden) {
headers += "";
--
cgit v1.2.3