Search in sources :

Example 1 with TomcatInfoModel

use of io.jpom.model.data.TomcatInfoModel in project Jpom by dromara.

the class TomcatManageService method getTomcatProjectList.

/**
 * 查询tomcat的项目列表
 *
 * @param id tomcat的id
 * @return tomcat的项目列表
 */
public JSONArray getTomcatProjectList(String id) {
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    String body = tomcatCmd(tomcatInfoModel, "text/list");
    String[] result = body.replace(StrUtil.CRLF, "$").replace("\n", "$").split("\\$");
    JSONArray jsonArray = new JSONArray();
    for (int i = 1; i < result.length; i++) {
        String str = result[i];
        JSONObject jsonObject = new JSONObject();
        String[] strs = str.split(StrUtil.COLON);
        if (strs[0].endsWith("jpomAgent")) {
            continue;
        }
        jsonObject.put("path", StrUtil.SLASH.equals(strs[0]) ? "/ROOT" : strs[0]);
        jsonObject.put("status", strs[1]);
        jsonObject.put("session", strs[2]);
        jsonArray.add(jsonObject);
    }
    return jsonArray;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) JSONArray(com.alibaba.fastjson.JSONArray)

Example 2 with TomcatInfoModel

use of io.jpom.model.data.TomcatInfoModel in project Jpom by dromara.

the class TomcatManageService method getTomcatStatus.

/**
 * 查询tomcat状态
 *
 * @param id tomcat的id
 * @return tomcat状态0表示未运行,1表示运行中
 */
public int getTomcatStatus(String id) {
    int result = 0;
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    String url = String.format("http://127.0.0.1:%d/", tomcatInfoModel.getPort());
    HttpRequest httpRequest = new HttpRequest(url);
    // 设置超时时间为3秒
    httpRequest.setConnectionTimeout(3000);
    try {
        HttpResponse httpResponse = httpRequest.execute();
        result = 1;
    } catch (Exception ignored) {
    }
    return result;
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) HttpResponse(cn.hutool.http.HttpResponse) JpomRuntimeException(io.jpom.system.JpomRuntimeException)

Example 3 with TomcatInfoModel

use of io.jpom.model.data.TomcatInfoModel in project Jpom by dromara.

the class TomcatEditController method update.

/**
 * 修改Tomcat信息
 *
 * @param tomcatInfoModel Tomcat信息
 * @return 操作结果
 */
@RequestMapping(value = "update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String update(TomcatInfoModel tomcatInfoModel) {
    // 根据Tomcat名称查询tomcat是否已经存在
    String name = tomcatInfoModel.getName();
    TomcatInfoModel tomcatInfoModelTemp = tomcatEditService.getItemByName(name);
    if (tomcatInfoModelTemp != null && !tomcatInfoModelTemp.getId().equals(tomcatInfoModel.getId())) {
        return JsonMessage.getString(401, "名称已经存在,请使用其他名称!");
    }
    tomcatInfoModel.setModifyUser(getUserName());
    // 设置tomcat路径,去除多余的符号
    tomcatInfoModel.setPath(FileUtil.normalize(tomcatInfoModel.getPath()));
    Objects.requireNonNull(tomcatInfoModel.pathAndCheck());
    tomcatEditService.updateItem(tomcatInfoModel);
    tomcatInfoModel.initTomcat();
    return JsonMessage.getString(200, "修改成功");
}
Also used : TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with TomcatInfoModel

use of io.jpom.model.data.TomcatInfoModel in project Jpom by dromara.

the class TomcatManageController method uploadWar.

/**
 * 上传war文件
 *
 * @param id tomcat id
 * @return 操作结果
 */
@RequestMapping(value = "uploadWar", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String uploadWar(String id) {
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file");
    File dir = new File(tomcatInfoModel.getAppBase());
    multipartFileBuilder.setSavePath(dir.getAbsolutePath()).setUseOriginalFilename(true);
    // 保存
    try {
        multipartFileBuilder.save();
    } catch (IOException e) {
        return JsonMessage.getString(500, "上传异常");
    }
    return JsonMessage.getString(200, "上传成功");
}
Also used : TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) IOException(java.io.IOException) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with TomcatInfoModel

use of io.jpom.model.data.TomcatInfoModel in project Jpom by dromara.

the class TomcatManageController method start.

/**
 * 启动tomcat
 *
 * @param id tomcat id
 * @return 操作结果
 */
@RequestMapping(value = "start", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String start(String id) {
    // 查询tomcat信息
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    String result = AbstractTomcatCommander.getInstance().execCmd(tomcatInfoModel, "start");
    String msg = "启动成功";
    if ("stopped".equals(result)) {
        msg = "启动失败";
    }
    return JsonMessage.getString(200, msg, result);
}
Also used : TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TomcatInfoModel (io.jpom.model.data.TomcatInfoModel)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 File (java.io.File)5 IOException (java.io.IOException)4 JSONArray (com.alibaba.fastjson.JSONArray)3 JSONObject (com.alibaba.fastjson.JSONObject)3 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)2 HttpRequest (cn.hutool.http.HttpRequest)1 HttpResponse (cn.hutool.http.HttpResponse)1 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 TomcatEditService (io.jpom.service.manage.TomcatEditService)1 JpomRuntimeException (io.jpom.system.JpomRuntimeException)1