Commit 3fe89e14 authored by fangxinjiang's avatar fangxinjiang

init

parent 546632ad
package com.yifu.cloud.plus.v1.yifu.auth.util;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.Charsets;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/**
* @author fxj *
* @date 2022年05月27日 11:01
* @description
*/
public class MyHttpRequest extends HttpServletRequestWrapper {
private String body;
public MyHttpRequest(HttpServletRequest request) throws IOException {
super(request);
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
} else {
stringBuilder.append("");
}
} catch (IOException ex) {
throw ex;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
throw ex;
}
}
}
body = stringBuilder.toString();
}
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes("UTF-8"));
ServletInputStream servletInputStream = new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return byteArrayInputStream.read();
}
};
return servletInputStream;
}
@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(this.getInputStream(), Charsets.UTF_8));
}
public String getBody() {
return this.body;
}
@Override
public String getParameter(String name) {
return super.getParameter(name);
}
@Override
public Map<String, String[]> getParameterMap() {
return super.getParameterMap();
}
@Override
public Enumeration<String> getParameterNames() {
return super.getParameterNames();
}
@Override
public String[] getParameterValues(String name) {
return super.getParameterValues(name);
}
/**
* 设置自定义post参数 //
*
* @param paramMaps
* @return
*/
public void setParamsMaps(Map paramMaps) {
Map paramBodyMap = new HashMap();
if (!StringUtils.isEmpty(body)) {
paramBodyMap = JSONObject.parseObject(body, Map.class);
}
paramBodyMap.putAll(paramMaps);
body = JSONObject.toJSONString(paramBodyMap);
}
}
......@@ -62,7 +62,7 @@ spring:
pathmatch:
matching-strategy: ant_path_matcher
redis:
host: yifu-redis
host: 127.0.0.1
password: '@yf_2017'
cloud:
sentinel:
......@@ -102,7 +102,7 @@ spring:
pathmatch:
matching-strategy: ant_path_matcher
redis:
host: yifu-redis
host: 127.0.0.1
password: '@yf_2017'
cloud:
sentinel:
......
......@@ -69,7 +69,7 @@ spring:
activate:
on-profile: test
redis:
host: yifu-redis
host: 127.0.0.1
password: '@yf_2017'
datasource:
type: com.zaxxer.hikari.HikariDataSource
......@@ -87,7 +87,7 @@ spring:
activate:
on-profile: dev
redis:
host: yifu-redis
host: 127.0.0.1
password: '@yf_2017'
datasource:
type: com.zaxxer.hikari.HikariDataSource
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment