CusHttpServletRequest问题修复

dev
wangxuanran 2023-07-18 14:46:28 +08:00
parent 24faa6c603
commit 28f6159601
3 changed files with 138 additions and 14 deletions

View File

@ -1,14 +1,12 @@
package aiyh.utils.httpUtil.cushttpclasses; package aiyh.utils.httpUtil.cushttpclasses;
import javax.servlet.RequestDispatcher; import javax.servlet.*;
import javax.servlet.ServletInputStream; import javax.servlet.http.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.Principal; import java.security.Principal;
import java.util.Collection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -95,6 +93,11 @@ public class CusHttpServletRequest implements HttpServletRequest {
return null; return null;
} }
@Override
public String changeSessionId() {
return null;
}
@Override @Override
public String getRequestedSessionId() { public String getRequestedSessionId() {
return null; return null;
@ -143,6 +146,36 @@ public class CusHttpServletRequest implements HttpServletRequest {
return false; return false;
} }
@Override
public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException {
return false;
}
@Override
public void login(String s, String s1) throws ServletException {
}
@Override
public void logout() throws ServletException {
}
@Override
public Collection<Part> getParts() throws IOException, ServletException {
return null;
}
@Override
public Part getPart(String s) throws IOException, ServletException {
return null;
}
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> aClass) throws IOException, ServletException {
return null;
}
@Override @Override
public String getProtocol() { public String getProtocol() {
return null; return null;
@ -218,6 +251,11 @@ public class CusHttpServletRequest implements HttpServletRequest {
return 0; return 0;
} }
@Override
public long getContentLengthLong() {
return 0;
}
@Override @Override
public String getContentType() { public String getContentType() {
return null; return null;
@ -271,4 +309,59 @@ public class CusHttpServletRequest implements HttpServletRequest {
public String getRealPath(String s) { public String getRealPath(String s) {
return null; return null;
} }
@Override
public int getRemotePort() {
return 0;
}
@Override
public String getLocalName() {
return null;
}
@Override
public String getLocalAddr() {
return null;
}
@Override
public int getLocalPort() {
return 0;
}
@Override
public ServletContext getServletContext() {
return null;
}
@Override
public AsyncContext startAsync() throws IllegalStateException {
return null;
}
@Override
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException {
return null;
}
@Override
public boolean isAsyncStarted() {
return false;
}
@Override
public boolean isAsyncSupported() {
return false;
}
@Override
public AsyncContext getAsyncContext() {
return null;
}
@Override
public DispatcherType getDispatcherType() {
return null;
}
} }

View File

@ -5,8 +5,10 @@ import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException; import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.api.xuanran.wang.eny.workflow.mapper.ExchangeRateMapper; import com.api.xuanran.wang.eny.workflow.mapper.ExchangeRateMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import weaver.seconddev.ey.zhangm.util.EYSeconddevUtil; import weaver.seconddev.ey.zhangm.util.EYSeconddevUtil;
@ -16,8 +18,10 @@ import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -40,9 +44,9 @@ public class GetExchangeRate {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public String exchangeRate(@Context HttpServletRequest request, public String exchangeRate(@Context HttpServletRequest request,
@Context HttpServletResponse response, @Context HttpServletResponse response){
@RequestBody Map<String, Object> params){
try { try {
Map<String, Object> params = parseBody(request);
if(eySeconddevUtil == null){ if(eySeconddevUtil == null){
eySeconddevUtil = new EYSeconddevUtil(); eySeconddevUtil = new EYSeconddevUtil();
} }
@ -101,4 +105,25 @@ public class GetExchangeRate {
} }
} }
private Map<String, Object> parseBody(HttpServletRequest request) {
try {
InputStream inputStream = request.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder requestBody = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
requestBody.append(line);
}
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> body = objectMapper.readValue(requestBody.toString(), Map.class);
if(MapUtils.isEmpty(body)){
throw new CustomerException("parse body map is empty!");
}
return body;
}catch (Exception e){
throw new CustomerException("解析请求体json error : " + e.getMessage());
}
}
} }

View File

@ -2,6 +2,8 @@ package com.api.xuanran.wang.xk_hospital.data_async.controller;
import aiyh.utils.ApiResult; import aiyh.utils.ApiResult;
import aiyh.utils.Util; import aiyh.utils.Util;
import com.api.xuanran.wang.xk_hospital.data_async.service.XkHospitalCommonDataAsyncService;
import com.api.xuanran.wang.xk_hospital.data_async.service.impl.XkHospitalCommonDataAsyncServiceImpl;
import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -23,19 +25,23 @@ public class CommonDataAsyncController {
private final Logger logger = Util.getLogger(); private final Logger logger = Util.getLogger();
private final XkHospitalCommonDataAsyncService service = new XkHospitalCommonDataAsyncServiceImpl();
@POST @POST
@Path("/{configId}}") @Path("/{type}/{configId}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public String async(@Context HttpServletRequest request, public String async(@Context HttpServletRequest request,
@Context HttpServletResponse response, @Context HttpServletResponse response,
@PathParam("configId") String configId, @PathParam("configId") String configId,
@RequestBody Map<String, Object> params){ @PathParam("type") String type,
@RequestBody Map<String, Object> params){
try { try {
return ""; service.async(configId, type, params);
return ApiResult.successNoData();
}catch (Exception e){ }catch (Exception e){
logger.error("CommonDataAsyncController error : " + e.getMessage()); logger.error("CommonDataAsyncController error : " + e.getMessage());
Util.logErrorStr(e, logger); Util.logErrorStr(e);
return ApiResult.error("数据同步失败! [ " + e.getMessage() + " ]"); return ApiResult.error("数据同步失败! [ " + e.getMessage() + " ]");
} }
} }