You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.4 KiB
38 lines
1.4 KiB
package com.ruoyi.system.forest.interceptor; |
|
|
|
|
|
import com.dtflys.forest.exceptions.ForestRuntimeException; |
|
import com.dtflys.forest.http.ForestRequest; |
|
import com.dtflys.forest.http.ForestResponse; |
|
import com.dtflys.forest.interceptor.Interceptor; |
|
|
|
|
|
import com.ruoyi.common.utils.BytesUtil; |
|
import com.ruoyi.system.config.WxConfig; |
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@Slf4j |
|
public class UnlimitedInterceptor implements Interceptor<Object> { |
|
|
|
@Override |
|
public void onError(ForestRuntimeException e, ForestRequest forestRequest, ForestResponse forestResponse) { |
|
log.error("---> UnlimitedInterceptor error: ",e); |
|
int type= WxConfig.UNLIMITED_TYPE_FAIL; |
|
byte[] bytes= BytesUtil.typeAndPayloadMerger(BytesUtil.int2Bytes(type),new byte[0]); |
|
forestResponse.setResult(bytes); |
|
} |
|
|
|
|
|
@Override |
|
public void onSuccess(Object s, ForestRequest forestRequest, ForestResponse forestResponse) { |
|
int type= WxConfig.UNLIMITED_TYPE_FAIL; |
|
if (forestResponse.getContentType().isApplication()&&forestResponse.getContentType().isJson()){ |
|
type=WxConfig.UNLIMITED_TYPE_JSON; |
|
}else if (forestResponse.getContentType().isImage()){ |
|
type=WxConfig.UNLIMITED_TYPE_IMAGE; |
|
} |
|
byte[] bytes=BytesUtil.typeAndPayloadMerger(BytesUtil.int2Bytes(type),(byte[])s);//设定前4(含)位是返回内容格式,后4位是内容 |
|
forestResponse.setResult(bytes); |
|
|
|
} |
|
}
|
|
|