All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.logicbus.backend.DefaultNormalizer Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.logicbus.backend;

import javax.servlet.http.HttpServletRequest;

import com.anysoft.util.Configurable;
import com.anysoft.util.Properties;
import com.logicbus.models.catalog.Path;


/**
 * 缺省实现的Normalizer
 * 
 * @author duanyy
 * 
 * @version 1.2.7.2 [20140910 duanyy] 
* - 增加基于Properties的构造函数 * * @version 1.6.4.4 [20150910 duanyy]
* - ServiceDetailQuery的快捷方式改为detail
* * @version 1.6.14.12 [20210617 duanyy]
* - 继承Configurable接口,便于动态创建
* - 支持路径模版
*/ public class DefaultNormalizer implements Normalizer,PathPatternSupport, Configurable { protected ServicePathTrie pathTrie = new ServicePathTrie(); public DefaultNormalizer(Properties settings) { } public DefaultNormalizer(){ } @Override public void configure(Properties p){ } @Override public Path normalize(Context ctx, HttpServletRequest request) { String path = request.getPathInfo(); String queryString = request.getQueryString(); String id; if (path == null || path.equals("/")){ //查询所有服务信息 id = "/core/ServiceQuery"; } else { int start = path.indexOf("/"); id = path.substring(start); if (queryString != null && queryString.equals("detail")){ ctx.SetValue("service", id); id = "/core/ServiceDetailQuery"; }else{ if (queryString != null && queryString.equals("reload")){ ctx.SetValue("service", id); id = "/core/ServiceReload"; }else{ if (queryString != null && queryString.equals("resume")){ ctx.SetValue("service", id); id = "/core/ServiceResume"; }else{ if (queryString != null && queryString.equals("pause")){ ctx.SetValue("service", id); id = "/core/ServicePause"; } } } } } return createPath(id,ctx,request); } /** * 根据预生成的ID来生成路径 * *
* 可在子类实现中更改所生成的路径,例如将某个目录的服务都重定向到某个服务,在将原路径设置为参数。
* * {@code * protected Path createPath(String id,Context ctx,HttpServletRequest request){ * if (id.startsWith("/project")){ * ctx.setValue("path",id); * return new Path(""); * }else{ * return new Path(id); * } * } * } * * @param id 服务ID * @param ctx 上下文 * @param request Http请求 * @return 转换后的路径 */ protected Path createPath(String id,Context ctx, HttpServletRequest request){ String path = pathTrie.match(id,ctx); if (path == null){ path = id; } return new Path(path); } @Override public void apply(String path, String pattern) { pathTrie.insert(pattern,path); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy