Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
17e38fb717 | |
|
|
6717eda5cc | |
|
|
85a8c09b24 | |
|
|
cf9207aaae |
37
pom.xml
37
pom.xml
|
|
@ -7,8 +7,13 @@
|
||||||
<groupId>cn.cloudowr</groupId>
|
<groupId>cn.cloudowr</groupId>
|
||||||
<artifactId>dict</artifactId>
|
<artifactId>dict</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>jar</packaging>
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/src/main/webapp</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|
@ -53,6 +58,19 @@
|
||||||
<mainClass>cn.cloudowr.dict.Main</mainClass>
|
<mainClass>cn.cloudowr.dict.Main</mainClass>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>cn.cloudowr.dict.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -62,10 +80,21 @@
|
||||||
<version>3.0</version>
|
<version>3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jfinal</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-server</artifactId>
|
<artifactId>jetty-server</artifactId>
|
||||||
<version>8.1.8</version>
|
<version>9.4.1.v20170120</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-servlet</artifactId>
|
||||||
|
<version>9.4.1.v20170120</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-webapp</artifactId>
|
||||||
|
<version>9.4.1.v20170120</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--<dependency>-->
|
<!--<dependency>-->
|
||||||
<!--<groupId>mysql</groupId>-->
|
<!--<groupId>mysql</groupId>-->
|
||||||
<!--<artifactId>mysql-connector-java</artifactId>-->
|
<!--<artifactId>mysql-connector-java</artifactId>-->
|
||||||
|
|
@ -85,8 +114,6 @@
|
||||||
<groupId>cn.cloudowr</groupId>
|
<groupId>cn.cloudowr</groupId>
|
||||||
<artifactId>sdk</artifactId>
|
<artifactId>sdk</artifactId>
|
||||||
<version>1.4.16</version>
|
<version>1.4.16</version>
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${basedir}/lib/sdk-1.4.16.jar</systemPath>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -11,21 +11,20 @@ import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static cn.cloudowr.dict.Main.*;
|
||||||
|
import static java.lang.System.exit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyf66 on 2017/2/16.
|
* Created by lyf66 on 2017/2/16.
|
||||||
*/
|
*/
|
||||||
public class Config extends com.jfinal.config.JFinalConfig{
|
public class Config extends com.jfinal.config.JFinalConfig{
|
||||||
|
|
||||||
private static MongoDatabase mongoDatabase;
|
private static MongoDatabase mongoDatabase;
|
||||||
private static String username;
|
|
||||||
private static String database;
|
|
||||||
private static String password;
|
|
||||||
private static String host;
|
|
||||||
private static int port;
|
|
||||||
private static String dabaseName;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configConstant(Constants me) {
|
public void configConstant(Constants me) {
|
||||||
|
|
@ -59,28 +58,21 @@ public class Config extends com.jfinal.config.JFinalConfig{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterJFinalStart() {
|
public void afterJFinalStart() {
|
||||||
read();
|
Properties p = new Properties();
|
||||||
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
try {
|
||||||
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
p.load(new FileInputStream(new File(configFilename)));
|
||||||
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
MongoCredential mongoCredential = MongoCredential.createCredential(p.getProperty("mongoUser"), "admin", p.getProperty("mongoPasswd").toCharArray());
|
||||||
|
MongoClient mongoClient = new MongoClient(new ServerAddress(p.getProperty("mongoUrl"), toIntOrNull(p.getProperty("mongoPort"))), Arrays.asList(mongoCredential));
|
||||||
|
mongoDatabase = mongoClient.getDatabase(p.getProperty("mongoDatabase"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MongoDatabase getMongoDataBase() {
|
public static MongoDatabase getMongoDataBase() {
|
||||||
return mongoDatabase;
|
return mongoDatabase;
|
||||||
}
|
}
|
||||||
public static void read(){
|
|
||||||
try{
|
|
||||||
Properties pro = new Properties();
|
|
||||||
pro.load(Config.class.getResourceAsStream("/config.properties"));
|
|
||||||
username = pro.getProperty("username");
|
|
||||||
database = pro.getProperty("database");
|
|
||||||
password = pro.getProperty("password");
|
|
||||||
host = pro.getProperty("host");
|
|
||||||
port = Integer.parseInt(pro.getProperty("port"));
|
|
||||||
dabaseName = pro.getProperty("dabaseName");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,121 @@
|
||||||
package cn.cloudowr.dict;
|
package cn.cloudowr.dict;
|
||||||
|
|
||||||
import com.jfinal.core.JFinal;
|
import com.jfinal.core.JFinalFilter;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.servlet.FilterHolder;
|
||||||
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
|
|
||||||
|
import javax.servlet.DispatcherType;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static java.lang.System.exit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyf66 on 2017/2/16.
|
* Created by lyf66 on 2017/2/16.
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static String configFilename = "usercenter-config.properties";
|
||||||
JFinal.start("src/main/webapp", 4200, "/");
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Properties p = null;
|
||||||
|
try {
|
||||||
|
File configFile = new File(configFilename);
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
configFile.createNewFile();
|
||||||
|
p = createDefaultProperties();
|
||||||
|
p.store(new FileOutputStream(configFile), "");
|
||||||
|
System.out.println("已生成配置文件,请进行正确配置后重启应用");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = new Properties();
|
||||||
|
p.load(new FileInputStream(configFile));
|
||||||
|
|
||||||
|
if (!checkProperties(p)) {
|
||||||
|
System.out.println("配置文件不正确");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("配置文件不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// JFinal.start("", toIntOrNull(p.getProperty("port")), "/");
|
||||||
|
EnumSet<DispatcherType> all = EnumSet.of(DispatcherType.ASYNC, DispatcherType.ERROR,
|
||||||
|
DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST);
|
||||||
|
final Server server = new Server(toIntOrNull(p.getProperty("port")));
|
||||||
|
WebAppContext context = new WebAppContext("/", "/");
|
||||||
|
FilterHolder filter = new FilterHolder(new JFinalFilter());
|
||||||
|
filter.setInitParameter("configClass", "cn.cloudowr.usercenter.Config");
|
||||||
|
context.addFilter(filter, "/*", all);
|
||||||
|
server.setHandler(context);
|
||||||
|
server.start();
|
||||||
|
server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Properties createDefaultProperties() {
|
||||||
|
Properties p = new Properties();
|
||||||
|
p.setProperty("port", "");
|
||||||
|
p.setProperty("mysqlUrl", "");
|
||||||
|
p.setProperty("mysqlUser", "");
|
||||||
|
p.setProperty("mysqlPasswd", "");
|
||||||
|
p.setProperty("mongoPort", "");
|
||||||
|
p.setProperty("mongoUrl", "");
|
||||||
|
p.setProperty("mongoUser", "");
|
||||||
|
p.setProperty("mongoPasswd", "");
|
||||||
|
p.setProperty("mongoDatabase", "");
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean checkProperties(Properties p) {
|
||||||
|
if (p.getProperty("port") == null ||
|
||||||
|
p.getProperty("mysqlUrl") == null ||
|
||||||
|
p.getProperty("mysqlUser") == null ||
|
||||||
|
p.getProperty("mysqlPasswd") == null ||
|
||||||
|
p.getProperty("mongoPort") == null ||
|
||||||
|
p.getProperty("mongoUrl") == null ||
|
||||||
|
p.getProperty("mongoUser") == null ||
|
||||||
|
p.getProperty("mongoPasswd") == null ||
|
||||||
|
p.getProperty("mongoDatabase") == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer port = toIntOrNull(p.getProperty("port"));
|
||||||
|
if (port == null) return false;
|
||||||
|
if (port <= 1024) return false;
|
||||||
|
|
||||||
|
String mysqlUrl = p.getProperty("mysqlUrl");
|
||||||
|
if (mysqlUrl.isEmpty()) return false;
|
||||||
|
|
||||||
|
String mysqlUser = p.getProperty("mysqlUser");
|
||||||
|
if (mysqlUser.isEmpty()) return false;
|
||||||
|
|
||||||
|
String mysqlPasswd = p.getProperty("mysqlPasswd");
|
||||||
|
if (mysqlPasswd.isEmpty()) return false;
|
||||||
|
|
||||||
|
String mongoUrl = p.getProperty("mongoUrl");
|
||||||
|
if (mongoUrl.isEmpty()) return false;
|
||||||
|
String mongoUser = p.getProperty("mongoUser");
|
||||||
|
if (mongoUser.isEmpty()) return false;
|
||||||
|
String mongoPasswd = p.getProperty("mongoPasswd");
|
||||||
|
if (mongoPasswd.isEmpty()) return false;
|
||||||
|
String mongoDatabase = p.getProperty("mongoDatabase");
|
||||||
|
if (mongoDatabase.isEmpty()) return false;
|
||||||
|
Integer mongoPort = toIntOrNull(p.getProperty("mongoPort"));
|
||||||
|
if (mongoPort == null) return false;
|
||||||
|
if (mongoPort <= 1024) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer toIntOrNull(String str) {
|
||||||
|
String trim = str.trim();
|
||||||
|
if (trim.matches("^-?[0-9]+$")) {
|
||||||
|
return Integer.valueOf(trim);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
username=root
|
|
||||||
database=admin
|
|
||||||
password=CoWR1111
|
|
||||||
host=120.24.5.249
|
|
||||||
port=3717
|
|
||||||
dabaseName=dict
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||||
|
version="3.1">
|
||||||
|
<filter>
|
||||||
|
<filter-name>cn.cloudowr.dict</filter-name>
|
||||||
|
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>configClass</param-name>
|
||||||
|
<param-value>cn.cloudowr.dict.Config</param-value>
|
||||||
|
</init-param>
|
||||||
|
</filter>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>cn.cloudowr.dict</filter-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
</web-app>
|
||||||
Loading…
Reference in New Issue