mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
新增restful模式
This commit is contained in:
@@ -6,6 +6,8 @@ import com.sop.example.rest.examplerest.rest.GoodsController;
|
|||||||
import com.sop.example.rest.examplerest.rest.vo.GoodsVO;
|
import com.sop.example.rest.examplerest.rest.vo.GoodsVO;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@@ -16,13 +18,26 @@ import java.util.Map;
|
|||||||
public class GoodsControllerImpl implements GoodsController {
|
public class GoodsControllerImpl implements GoodsController {
|
||||||
@Override
|
@Override
|
||||||
public GoodsVO getById(Integer id) {
|
public GoodsVO getById(Integer id) {
|
||||||
|
WebContext webContext = WebContext.current();
|
||||||
GoodsVO goodsVO = new GoodsVO();
|
GoodsVO goodsVO = new GoodsVO();
|
||||||
goodsVO.setId(id);
|
goodsVO.setId(id);
|
||||||
goodsVO.setName("冰箱");
|
goodsVO.setName("冰箱");
|
||||||
|
|
||||||
Map<String, String> headers = WebContext.current().getHeaders();
|
List<String> list = new ArrayList<>();
|
||||||
|
|
||||||
|
list.add("realIp:" + webContext.getRealIp());
|
||||||
|
|
||||||
|
Map<String, String> headers = webContext.getHeaders();
|
||||||
String token = headers.get("token");
|
String token = headers.get("token");
|
||||||
System.out.println(token);
|
list.add("token:" + token);
|
||||||
|
|
||||||
|
String remoteAddr = webContext.getRemoteAddr();
|
||||||
|
list.add("remoteAddr:" + remoteAddr);
|
||||||
|
|
||||||
|
String idValue = webContext.getParameter("id");
|
||||||
|
list.add("id:" + idValue);
|
||||||
|
|
||||||
|
goodsVO.setRemark(list.toString());
|
||||||
return goodsVO;
|
return goodsVO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,4 +12,6 @@ public class GoodsVO {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private String remark;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -119,6 +119,7 @@ public class ParamExecutorImpl implements ParamExecutor<HttpServletRequest, Http
|
|||||||
defaultWebContext.setLocale(request.getLocale());
|
defaultWebContext.setLocale(request.getLocale());
|
||||||
defaultWebContext.setHeaders(RequestUtil.getHeaders(request));
|
defaultWebContext.setHeaders(RequestUtil.getHeaders(request));
|
||||||
defaultWebContext.setParamtreMap(new LinkedHashMap<>(request.getParameterMap()));
|
defaultWebContext.setParamtreMap(new LinkedHashMap<>(request.getParameterMap()));
|
||||||
|
defaultWebContext.setRealIp(RequestUtil.getIP(request));
|
||||||
return defaultWebContext;
|
return defaultWebContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@ public class DefaultWebContext extends WebContext implements Serializable {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private Map<String, String> headers;
|
private Map<String, String> headers;
|
||||||
private Map<String, String[]> paramtreMap;
|
private Map<String, String[]> paramtreMap;
|
||||||
|
private String realIp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParameter(String name) {
|
public String getParameter(String name) {
|
||||||
|
@@ -58,6 +58,11 @@ public abstract class WebContext {
|
|||||||
*/
|
*/
|
||||||
public abstract Map<String, String> getHeaders();
|
public abstract Map<String, String> getHeaders();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取真实ip地址
|
||||||
|
*/
|
||||||
|
public abstract String getRealIp();
|
||||||
|
|
||||||
protected void setContext(WebContext openContext) {
|
protected void setContext(WebContext openContext) {
|
||||||
THREAD_LOCAL.set(openContext);
|
THREAD_LOCAL.set(openContext);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user