开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 130

huifeng/cppweb

forked from 寻根/cppweb
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
cppweb
/
library
/
java
/
webx
/
Startup.java
cppweb
/
library
/
java
/
webx
/
Startup.java
Startup.java 5.79 KB
一键复制 编辑 原始数据 按行查看 历史
寻根 提交于 2020年09月05日 12:22 +08:00 . cppweb.1.0.0版本
package webx;
import stdx.Utils;
import stdx.ConfigFile;
import java.util.ArrayList;
import dbx.DBConnect;
import dbx.RedisConnect;
import webx.http.HttpRequest;
import webx.http.HttpResponse;
public class Startup extends WebApp{
public static class DBConfig{
int port;
String id;
String host;
String type;
String name;
String user;
String passwd;
}
private static int dbconnmaxlen = 8;
private static int dbconntimeout = 60;
@SuppressWarnings("unchecked")
public byte[] getCgiPath(byte[] path){
try{
String tmp = new String(path);
tmp = tmp.replace('/', '.');
tmp = tmp.replace('\\', '.');
Class clazz = Class.forName(tmp);
Path cgipath = (Path)clazz.getAnnotation(Path.class);
Document document = (Document)clazz.getAnnotation(Document.class);
TimerTask timertask = (TimerTask)clazz.getAnnotation(TimerTask.class);
DailyTask dailytask = (DailyTask)clazz.getAnnotation(DailyTask.class);
if (cgipath == null) return null;
tmp = cgipath.value();
String name = clazz.getName();
int pos = name.lastIndexOf('.');
if (pos > 0) name = name.substring(pos + 1);
while (tmp.indexOf("$classname") >= 0) tmp = tmp.replace("$classname", name);
while (tmp.indexOf("$(classname)") >= 0) tmp = tmp.replace("$(classname)", name);
while (tmp.indexOf("${classname}") >= 0) tmp = tmp.replace("${classname}", name);
while (tmp.indexOf("$filename") >= 0) tmp = tmp.replace("$filename", name);
while (tmp.indexOf("$(filename)") >= 0) tmp = tmp.replace("$(filename)", name);
while (tmp.indexOf("${filename}") >= 0) tmp = tmp.replace("${filename}", name);
SetCgiAccess(tmp, cgipath.access());
if (document != null){
SetCgiDoc(tmp, GetDocString(document.request()), GetDocString(document.response()), document.remark());
}
if (timertask != null){
SetCgiExtdata(tmp, "timertask=" + timertask.value());
SetCgiAccess(tmp, "protect");
}
if (dailytask != null){
SetCgiExtdata(tmp, "dailytask=" + dailytask.value());
SetCgiAccess(tmp, "protect");
}
return tmp.getBytes();
}
catch (Exception e){
e.printStackTrace();
return null;
}
}
public void process(HttpRequest request, HttpResponse response) throws Exception{
String path = request.get("path");
ConfigFile dbcfg = new ConfigFile();
try {
System.load(path + "etc/plugin/bin/InitSystem.so");
}
catch (UnsatisfiedLinkError e){
System.load(path + "etc/plugin/bin/InitSystem.dll");
}
String cfgpath = WebApp.GetConfig("DATABASE_CONFIGFILE_PATH");
if (cfgpath.isEmpty()) cfgpath = path + "etc/dbconfig.lua";
if (dbcfg.open(cfgpath)){
int port = dbcfg.getInt("PORT");
String host = dbcfg.get("HOST");
String name = dbcfg.get("NAME");
String user = dbcfg.get("USER");
String passwd = dbcfg.get("PASSWORD");
String dllpath = dbcfg.get("DLLPATH");
try {
dbconnmaxlen = Integer.parseInt(dbcfg.get("MAXSIZE"));
}
catch (Exception e){
}
try {
dbconntimeout = Integer.parseInt(dbcfg.get("TIMEOUT"));
}
catch (Exception e){
}
if (Utils.IsNotEmpty(name) && initdb(null, dllpath, host, port, name, user, passwd)){
DBConnect dbconn = DBConnect.Connect();
try{
String sql = "SELECT ID,TYPE,HOST,PORT,NAME,USER,PASSWD FROM T_XG_DBETC WHERE ENABLED>0";
ArrayList<DBConfig> vec = dbconn.selectList(DBConfig.class, sql);
for (DBConfig item : vec) initdb(item.id, item.type, item.host, item.port, item.name, item.user, item.passwd);
}
catch(Exception e){
e.printStackTrace();
}
finally{
Utils.Close(dbconn);
}
}
host = dbcfg.get("REDIS_HOST");
port = dbcfg.getInt("REDIS_PORT");
passwd = dbcfg.get("REDIS_PASSWORD");
if (Utils.IsNotEmpty(host)){
try {
RedisConnect.GetPool().init(host, port, passwd, false).get();
LogFile.Trace(LogFile.IMP, "initialize redis[%s:%d] success", host, port);
}
catch(Exception e){
LogFile.Trace(LogFile.ERR, "initialize redis[%s:%d] failed", host, port);
}
}
}
}
public boolean initdb(String dbid, String type, String host, int port, String name, String user, String passwd){
DBConnect.Config db = new DBConnect.Config();
db.user = user;
db.passwd = passwd;
name = Utils.Translate(name);
type = type.toLowerCase();
if (type.indexOf("mysql") >= 0){
db.url = String.format("jdbc:mysql://%s:%d/%s", host, port, name);
}
else if (type.indexOf("oracle") >= 0){
db.url = String.format("jdbc:oracle:thin:@%s:%d/%s", host, port, name);
}
else if (type.indexOf("postgres") >= 0){
db.url = String.format("jdbc:postgresql://%s:%d/%s", host, port, name);
}
else if (type.indexOf("sqlite") >= 0){
db.url = String.format("jdbc:sqlite:%s", name);
}
if (db.url.isEmpty()) return false;
try{
DBConnect dbconn = null;
if (dbid == null){
dbconn = DBConnect.GetPool().init(db, dbconnmaxlen, dbconntimeout).get();
}
else{
dbconn = DBConnect.GetPool(dbid).init(db, dbconnmaxlen, dbconntimeout).get();
}
LogFile.Trace(LogFile.IMP, "initialize database[%s] success", db.url);
Utils.Close(dbconn);
return true;
}
catch(Exception e){
LogFile.Trace(LogFile.ERR, "initialize database[%s] failed[%s]", db.url, e.getMessage());
e.printStackTrace();
return false;
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

基于C++开发的WEB服务器,支持C/C++、Python、Java等多语言混合开发WEB应用。
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/huifeng_github/cppweb.git
git@gitee.com:huifeng_github/cppweb.git
huifeng_github
cppweb
cppweb
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /