11package com .cym .config ;
22
3- import java .io .BufferedInputStream ;
4- import java .io .ByteArrayInputStream ;
53import java .io .File ;
6- import java .io .OutputStream ;
74import java .io .UnsupportedEncodingException ;
85import java .net .URLEncoder ;
9- import java .nio .charset .StandardCharsets ;
106import java .util .ArrayList ;
11- import java .util .Date ;
127import java .util .HashMap ;
138import java .util .HashSet ;
14- import java .util .Iterator ;
159import java .util .List ;
1610import java .util .Map ;
1711import java .util .Properties ;
1812import java .util .Set ;
1913
2014import org .noear .solon .annotation .Component ;
2115import org .noear .solon .annotation .Inject ;
16+ import org .noear .solon .core .exception .StatusException ;
2217import org .noear .solon .core .handle .Context ;
2318import org .noear .solon .core .handle .Filter ;
2419import org .noear .solon .core .handle .FilterChain ;
2520import org .noear .solon .core .handle .UploadedFile ;
21+ import org .noear .solon .core .util .KeyValues ;
22+ import org .noear .solon .core .util .MultiMap ;
2623import org .slf4j .Logger ;
2724import org .slf4j .LoggerFactory ;
2825
3835import com .cym .utils .PropertiesUtils ;
3936
4037import cn .hutool .core .codec .Base64 ;
41- import cn .hutool .core .date .DateUtil ;
4238import cn .hutool .core .io .FileUtil ;
4339import cn .hutool .core .util .StrUtil ;
4440import cn .hutool .http .HttpRequest ;
4541import cn .hutool .http .HttpResponse ;
46- import cn .hutool .http .HttpUtil ;
4742import cn .hutool .json .JSONUtil ;
4843
4944@ Component
@@ -68,7 +63,22 @@ public class AppFilter implements Filter {
6863
6964 @ Override
7065 public void doFilter (Context ctx , FilterChain chain ) throws Throwable {
66+ //todo: 原异常处理改为正常的上抛了
67+ try {
68+ doFilterDo (ctx , chain );
69+ } catch (StatusException e ) {
70+ //4xx 相关状态异常
71+ ctx .status (e .getCode ());
72+
73+ if (404 != e .getCode ()) {
74+ logger .error (e .getMessage (), e );
75+ }
76+ } catch (Throwable e ) {
77+ logger .error (e .getMessage (), e );
78+ }
79+ }
7180
81+ private void doFilterDo (Context ctx , FilterChain chain ) throws Throwable {
7282 String path = ctx .path ().toLowerCase ();
7383
7484 // 全局过滤器
@@ -174,7 +184,8 @@ private boolean adminInterceptor(Context ctx) {
174184 } else {
175185 // 普通请求
176186 Admin admin = new BaseController ().getAdmin ();
177- String body = buldBody (ctx .paramsMap (), remote , admin );
187+ //todo: ctx.paramsMap() 已取消,复用 ctx.paramMap()
188+ String body = buldBody (ctx .paramMap (), remote , admin );
178189
179190 httpResponse = HttpRequest .post (url ).body (body ).execute ();
180191 }
@@ -277,18 +288,16 @@ private void frontInterceptor(Context ctx) {
277288
278289 }
279290
280- private String buldBody (Map <String , List < String > > parameterMap , Remote remote , Admin admin ) throws UnsupportedEncodingException {
291+ private String buldBody (MultiMap <String > parameterMap , Remote remote , Admin admin ) throws UnsupportedEncodingException {
281292 List <String > body = new ArrayList <>();
282293 body .add ("creditKey=" + remote .getCreditKey ());
283294 if (admin != null ) {
284295 body .add ("adminName=" + admin .getName ());
285296 }
286297
287- for (Iterator itr = parameterMap .entrySet ().iterator (); itr .hasNext ();) {
288- Map .Entry me = (Map .Entry ) itr .next ();
289-
290- for (String value : (List <String >) me .getValue ()) {
291- body .add (me .getKey () + "=" + URLEncoder .encode (value , "UTF-8" ));
298+ for (KeyValues <String > kv : parameterMap ) {
299+ for (String value : kv .getValues ()) {
300+ body .add (kv .getKey () + "=" + URLEncoder .encode (value , "UTF-8" ));
292301 }
293302
294303 }
0 commit comments