提交 678ba7d0 编写于 作者: O o2null

Merge branch 'o2cloud_0813' into 'wrdp'

服务器启动时添加保存urlmapping至o2云unit的服务

See merge request o2oa/o2oa!4896
......@@ -12,6 +12,9 @@ import java.util.Objects;
import java.util.Random;
import java.util.concurrent.ConcurrentSkipListMap;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.connection.ConnectionAction;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
......@@ -176,7 +179,17 @@ public class WebServers extends ConcurrentSkipListMap<String, WebServer> {
map.put("indexPage", Config.portal().getIndexPage());
map.put("webSocketEnable", Config.communicate().wsEnable());
map.put("urlMapping", Config.portal().getUrlMapping());
if(!(Config.portal().getUrlMapping().isEmpty())){
try {
String urlMapping = XGsonBuilder.toJson(Config.portal().getUrlMapping());
Map<String, String> urlmap = new HashMap<>();
urlmap.put("urlMapping", urlMapping);
CipherConnectionAction.put(true,Config.url_x_program_center_jaxrs("collect","urlMapping"),urlmap);
} catch (Exception e) {
e.printStackTrace();
}
}
/* 密码规则 */
map.put("passwordRegex", Config.person().getPasswordRegex());
map.put("passwordRegexHint", Config.person().getPasswordRegexHint());
......@@ -201,5 +214,4 @@ public class WebServers extends ConcurrentSkipListMap<String, WebServer> {
}
FileUtils.writeStringToFile(file, gson.toJson(map), DefaultCharset.charset);
}
}
......@@ -102,6 +102,20 @@ public class Business {
}
}
public String getUnitName() throws Exception {
String url = Config.collect().url(Collect.ADDRESS_COLLECT_LOGIN);
Map<String, String> map = new HashMap<>();
map.put("credential", Config.collect().getName());
map.put("password", Config.collect().getPassword());
ActionResponse resp = ConnectionAction.post(url, null, map);
LoginWo loginWo = resp.getData(LoginWo.class);
if(loginWo!=null) {
return loginWo.getName();
}else{
return null;
}
}
public static class ValidateReq extends GsonPropertyObject {
private String name;
......
package com.x.program.center.jaxrs.collect;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.program.center.Business;
import org.apache.commons.lang3.StringUtils;
class ActionUpdateUnitUrlMapping extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, WrapInUrlMapping wrapIn) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Boolean rFlag = false;
String urlMapping = wrapIn.getUrlMapping();
/*if (BooleanUtils.isNotTrue(Config.nodes().centerServers().first().getValue().getConfigApiEnable())) {
throw new ExceptionModifyConfig();
}*/
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
String unitName = business.getUnitName();
if (StringUtils.isNotEmpty(unitName)) {
rFlag = updateUnitMapping(unitName,urlMapping);
}
}
Wo wo = new Wo();
wo.setValue(rFlag);
result.setData(wo);
return result;
}
public static class Wo extends WrapBoolean {
}
}
......@@ -22,7 +22,9 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.program.center.Business;
import com.x.program.center.ThisApplication;
import org.apache.commons.lang3.StringUtils;
class BaseAction extends StandardJaxrsAction {
......@@ -117,6 +119,15 @@ class BaseAction extends StandardJaxrsAction {
return resp.getData(ReturnWoBoolean.class).getValue();
}
Boolean updateUnitMapping(String name, String urlMapping) throws Exception {
String url = Config.collect().url("/o2_collect_assemble/jaxrs/unit/urlMapping/");
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("name", name);
parameters.put("urlMapping", urlMapping);
ActionResponse resp = ConnectionAction.put(url, null,parameters);
return resp.getData(ReturnWoBoolean.class).getValue();
}
Boolean delete(String name, String mobile, String codeAnswer) throws Exception {
String url = Config.collect().url("/o2_collect_assemble/jaxrs/unit/name/"+ URLEncoder.encode(name, DefaultCharset.name)
+ "/mobile/" + URLEncoder.encode(mobile, DefaultCharset.name) + "/code/" + URLEncoder.encode(codeAnswer, DefaultCharset.name));
......
......@@ -377,4 +377,22 @@ public class CollectAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "更新urlMapping.", action = ActionUpdateUnitUrlMapping.class)
@PUT
@Path("urlMapping")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void updateUrlMapping(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
WrapInUrlMapping wrapIn) {
ActionResult<ActionUpdateUnitUrlMapping.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionUpdateUnitUrlMapping().execute(effectivePerson,wrapIn);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.program.center.jaxrs.collect;
import com.x.base.core.project.config.Collect;
import java.util.ArrayList;
import java.util.List;
public class WrapInUrlMapping extends Collect {
public static List<String> Excludes = new ArrayList<>();
private String urlMapping;
public String getUrlMapping() {
return urlMapping;
}
public void setUrlMapping(String urlMapping) {
this.urlMapping = urlMapping;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册