aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-08-01 13:43:30 +0300
committerGravatar Vitaly Takmazov2016-08-01 13:43:30 +0300
commit1c3d94825fdf7f899dcad372ab7bc538a79df971 (patch)
tree7cf2b9173e8050e9425e12be2c16941e044a019a
parenta85973603a137a2866bb434e4276844425d3cb77 (diff)
Utils.parseInt -> apache-lang3's NumberUtils
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/NewMessage.java7
-rw-r--r--juick-www/src/main/java/com/juick/www/Utils.java11
3 files changed, 7 insertions, 15 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java b/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
index 4e2f6d57..b737b5d9 100644
--- a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
+++ b/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
@@ -10,6 +10,7 @@ import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
import com.juick.ws.s2s.*;
import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.xmlpull.v1.XmlPullParserException;
@@ -179,6 +180,7 @@ public class XMPPComponent implements ServletContextListener, Stream.StreamListe
conf.load(sce.getServletContext().getResourceAsStream("/WEB-INF/juick.conf"));
HOSTNAME = conf.getProperty("hostname");
componentName = conf.getProperty("componentname");
+ int componentPort = NumberUtils.toInt(conf.getProperty("component_port"), 5347);
JID Jid = new JID(conf.getProperty("xmppbot_jid"));
STATSFILE = conf.getProperty("statsfile");
keystore = conf.getProperty("keystore");
@@ -196,7 +198,7 @@ public class XMPPComponent implements ServletContextListener, Stream.StreamListe
executorService.submit(() -> {
Socket routerSocket = null;
try {
- routerSocket = new Socket("localhost", 5347);
+ routerSocket = new Socket("localhost", componentPort);
setRouter(new StreamComponent(new JID("s2s"), routerSocket.getInputStream(), routerSocket.getOutputStream(), conf.getProperty("xmpp_password")));
getRouter().addChildParser(new JuickMessage());
getRouter().addListener((Stream.StreamListener) this);
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java
index d4867999..82de4782 100644
--- a/juick-www/src/main/java/com/juick/www/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/NewMessage.java
@@ -27,6 +27,7 @@ import com.juick.xmpp.extensions.JuickUser;
import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
import net.coobird.thumbnailator.Thumbnails;
+import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.servlet.ServletException;
@@ -306,7 +307,7 @@ public class NewMessage {
}
public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
return;
@@ -317,7 +318,7 @@ public class NewMessage {
return;
}
- int rid = Utils.parseInt(request.getParameter("rid"), 0);
+ int rid = NumberUtils.toInt(request.getParameter("rid"), 0);
com.juick.Message reply = null;
if (rid > 0) {
reply = MessagesQueries.getReply(sql, mid, rid);
@@ -419,7 +420,7 @@ public class NewMessage {
}
public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
return;
diff --git a/juick-www/src/main/java/com/juick/www/Utils.java b/juick-www/src/main/java/com/juick/www/Utils.java
index 240b6be4..24f78a1c 100644
--- a/juick-www/src/main/java/com/juick/www/Utils.java
+++ b/juick-www/src/main/java/com/juick/www/Utils.java
@@ -138,17 +138,6 @@ public class Utils {
return str.replaceAll("@", "\\\\@");
}
- public static int parseInt(String str, int def) {
- int ret = def;
- if (str != null) {
- try {
- ret = Integer.parseInt(str);
- } catch (Exception e) {
- }
- }
- return ret;
- }
-
public static String fetchURL(String url) {
try {
URLConnection c = new URL(url).openConnection();