Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
b3f9b9ddbb |
36
pom.xml
36
pom.xml
|
|
@ -19,6 +19,40 @@
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.mortbay.jetty</groupId>
|
||||||
|
<artifactId>jetty-maven-plugin</artifactId>
|
||||||
|
<version>8.1.8.v20121106</version>
|
||||||
|
<configuration>
|
||||||
|
<stopKey>stop</stopKey>
|
||||||
|
<stopPort>5202</stopPort>
|
||||||
|
<webAppConfig>
|
||||||
|
<contextPath>/</contextPath>
|
||||||
|
</webAppConfig>
|
||||||
|
<scanIntervalSeconds>5</scanIntervalSeconds>
|
||||||
|
<connectors>
|
||||||
|
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
|
||||||
|
<port>4202</port>
|
||||||
|
<maxIdleTime>60000</maxIdleTime>
|
||||||
|
</connector>
|
||||||
|
</connectors>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>java</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>cn.cloudowr.dict.Main</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -61,6 +95,8 @@
|
||||||
<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>
|
||||||
|
|
@ -39,7 +39,7 @@ public class ACon extends AbsController{
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = UUID.randomUUID().toString().replace("-", "");
|
String key = UUID.randomUUID().toString().replace("-", "");
|
||||||
UploadFileRequest uploadFileRequest = new UploadFileRequest(Config.BukketName, key);
|
UploadFileRequest uploadFileRequest = new UploadFileRequest(Main.BukketName, key);
|
||||||
uploadFileRequest.setUploadFile(file.getUploadPath() + File.separator + file.getFileName());
|
uploadFileRequest.setUploadFile(file.getUploadPath() + File.separator + file.getFileName());
|
||||||
uploadFileRequest.setTaskNum(5);
|
uploadFileRequest.setTaskNum(5);
|
||||||
uploadFileRequest.setPartSize(1 * 1024 * 1024);
|
uploadFileRequest.setPartSize(1 * 1024 * 1024);
|
||||||
|
|
@ -48,7 +48,7 @@ public class ACon extends AbsController{
|
||||||
uploadFileResult.getMultipartUploadResult();
|
uploadFileResult.getMultipartUploadResult();
|
||||||
|
|
||||||
MongoCollection<Document> collection = getCollection();
|
MongoCollection<Document> collection = getCollection();
|
||||||
doc.put("ossurl", Config.OssUrl + key);
|
doc.put("ossurl", Main.OssUrl + key);
|
||||||
doc.put("filename", file.getFileName());
|
doc.put("filename", file.getFileName());
|
||||||
collection.insertOne(doc);
|
collection.insertOne(doc);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,25 @@
|
||||||
package cn.cloudowr.attach;
|
package cn.cloudowr.attach;
|
||||||
|
|
||||||
|
|
||||||
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
||||||
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
||||||
import com.aliyun.oss.OSSClient;
|
import com.aliyun.oss.OSSClient;
|
||||||
import com.jfinal.config.*;
|
import com.jfinal.config.*;
|
||||||
import com.jfinal.template.Engine;
|
import com.jfinal.template.Engine;
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.MongoClientURI;
|
|
||||||
import com.mongodb.MongoCredential;
|
import com.mongodb.MongoCredential;
|
||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static cn.cloudowr.attach.Main.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyf66 on 2017/2/17.
|
* Created by lyf66 on 2017/2/17.
|
||||||
*/
|
*/
|
||||||
public class Config extends JFinalConfig{
|
public class Config extends JFinalConfig{
|
||||||
|
|
||||||
public static final String AccessKey = "LTAI7tcTTMuROink";
|
|
||||||
public static final String BukketName = "cowr-attach";
|
|
||||||
public static final String OssUrl = "http://cowr-attach.oss-cn-shenzhen.aliyuncs.com/";
|
|
||||||
private static MongoDatabase mongoDatabase;
|
private static MongoDatabase mongoDatabase;
|
||||||
private static OSSClient ossClient;
|
private static OSSClient ossClient;
|
||||||
|
|
||||||
|
|
@ -63,13 +62,9 @@ public class Config extends JFinalConfig{
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void afterJFinalStart() {
|
public void afterJFinalStart() {
|
||||||
MongoClientURI connectionString = new MongoClientURI("mongodb://root:CoWR1111@dds-wz9ceed1f19591041217-pub.mongodb.rds.aliyuncs.com:3717,dds-wz9ceed1f19591042677-pub.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-5320915");
|
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
||||||
MongoClient mongoClient = new MongoClient(connectionString);
|
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
||||||
mongoDatabase = mongoClient.getDatabase("dict");
|
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
||||||
|
|
||||||
String endpoint = "oss-cn-shenzhen.aliyuncs.com";
|
|
||||||
String accessKeyId = "LTAI7tcTTMuROink";
|
|
||||||
String accessKeySecret = "qZj94FrKmJF946eHCpNjYtEXKUS0i6";
|
|
||||||
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,4 +72,6 @@ public class Config extends JFinalConfig{
|
||||||
public void beforeJFinalStop() {
|
public void beforeJFinalStop() {
|
||||||
ossClient.shutdown();
|
ossClient.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package cn.cloudowr.attach;
|
package cn.cloudowr.attach;
|
||||||
|
|
||||||
import cn.cloudowr.sdk.FastJSONUtil;
|
import cn.cloudowr.sdk.FastJSONUtil;
|
||||||
import cn.cloudowr.sdk.IdInterceptor;
|
import cn.cloudowr.sdk.jfinal.IdInterceptor;
|
||||||
import com.aliyun.oss.model.UploadFileRequest;
|
import com.aliyun.oss.model.UploadFileRequest;
|
||||||
import com.aliyun.oss.model.UploadFileResult;
|
import com.aliyun.oss.model.UploadFileResult;
|
||||||
import com.jfinal.aop.Before;
|
import com.jfinal.aop.Before;
|
||||||
|
|
@ -48,7 +48,7 @@ public class Controller extends com.jfinal.core.Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = UUID.randomUUID().toString().replace("-", "");
|
String key = UUID.randomUUID().toString().replace("-", "");
|
||||||
UploadFileRequest uploadFileRequest = new UploadFileRequest(Config.BukketName, key);
|
UploadFileRequest uploadFileRequest = new UploadFileRequest(Main.BukketName, key);
|
||||||
uploadFileRequest.setUploadFile(file.getUploadPath() + File.separator + file.getFileName());
|
uploadFileRequest.setUploadFile(file.getUploadPath() + File.separator + file.getFileName());
|
||||||
uploadFileRequest.setTaskNum(5);
|
uploadFileRequest.setTaskNum(5);
|
||||||
uploadFileRequest.setPartSize(1 * 1024 * 1024);
|
uploadFileRequest.setPartSize(1 * 1024 * 1024);
|
||||||
|
|
@ -57,7 +57,7 @@ public class Controller extends com.jfinal.core.Controller {
|
||||||
uploadFileResult.getMultipartUploadResult();
|
uploadFileResult.getMultipartUploadResult();
|
||||||
|
|
||||||
MongoCollection<Document> collection = Config.getMongoDatabase().getCollection("attach");
|
MongoCollection<Document> collection = Config.getMongoDatabase().getCollection("attach");
|
||||||
doc.put("ossurl", Config.OssUrl + key);
|
doc.put("ossurl", Main.OssUrl + key);
|
||||||
doc.put("filename", file.getFileName());
|
doc.put("filename", file.getFileName());
|
||||||
collection.insertOne(doc);
|
collection.insertOne(doc);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,49 @@ package cn.cloudowr.attach;
|
||||||
|
|
||||||
import com.jfinal.core.JFinal;
|
import com.jfinal.core.JFinal;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyf66 on 2017/2/16.
|
* Created by lyf66 on 2017/2/16.
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
public static String username;
|
||||||
|
public static String database;
|
||||||
|
public static String password;
|
||||||
|
public static String host;
|
||||||
|
public static int port;
|
||||||
|
public static String dabaseName;
|
||||||
|
public static String endpoint ;
|
||||||
|
public static String accessKeyId ;
|
||||||
|
public static String accessKeySecret ;
|
||||||
|
public static String BukketName ;
|
||||||
|
public static String OssUrl ;
|
||||||
|
private static int AppPort;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFinal.start("src/main/webapp", 4202, "/");
|
read();
|
||||||
|
JFinal.start("src/main/webapp", AppPort, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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");
|
||||||
|
endpoint = pro.getProperty("endpoint");
|
||||||
|
accessKeyId = pro.getProperty("accessKeyId");
|
||||||
|
accessKeySecret = pro.getProperty("accessKeySecret");
|
||||||
|
BukketName = pro.getProperty("BukketName");
|
||||||
|
OssUrl = pro.getProperty("OssUrl");
|
||||||
|
AppPort = Integer.parseInt(pro.getProperty("AppPort"));
|
||||||
|
}catch ( Exception e ){
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
username=root
|
||||||
|
database=admin
|
||||||
|
password=CoWR1111
|
||||||
|
host=120.24.5.249
|
||||||
|
port=3717
|
||||||
|
dabaseName=dict
|
||||||
|
accessKeyId=LTAI7tcTTMuROink
|
||||||
|
BukketName=cowr-attach
|
||||||
|
OssUrl=http://cowr-attach.oss-cn-shenzhen.aliyuncs.com/
|
||||||
|
accessKeySecret=qZj94FrKmJF946eHCpNjYtEXKUS0i6
|
||||||
|
endpoint=oss-cn-shenzhen.aliyuncs.com
|
||||||
|
AppPort=4202
|
||||||
Loading…
Reference in New Issue