-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
提供扩展httpclientbuilder的能力 #3128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
提供扩展httpclientbuilder的能力 #3128
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c007437
fix: 企业付款给员工签名错误
ifcute 5735565
Merge branch 'Wechat-Group:develop' into develop
ifcute 6cba1fa
fix: 1、修复资金账单只能导出基本户账单的问题 2、修改账户类型枚举值
ifcute 2b1c210
Merge branch 'Wechat-Group:develop' into develop
ifcute 6af77c2
feat: 提供扩展httpClientBuilder的能力
ifcute 4ac2400
feat: 修改author
ifcute b168e23
feat: 提供扩展httpClientBuilder的能力
ifcute 198a7b1
feat: 修改author
ifcute 4ea7c1f
Merge remote-tracking branch 'origin/develop' into develop
ifcute File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: 提供扩展httpClientBuilder的能力
- Loading branch information
commit b168e23bd0850cd456641e7b5150e4b386b631c8
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...ava-pay/src/main/java/com/github/binarywang/wxpay/config/HttpClientBuilderCustomizer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.binarywang.wxpay.config; | ||
|
||
import org.apache.http.impl.client.HttpClientBuilder; | ||
|
||
/** | ||
* @author wangn <15124178@qq.com> 2023/9/8 | ||
*/ | ||
@FunctionalInterface | ||
public interface HttpClientBuilderCustomizer { | ||
void customize(HttpClientBuilder var1); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...-java-pay/src/test/java/com/github/binarywang/wxpay/config/CustomizedWxPayConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.binarywang.wxpay.config; | ||
|
||
import com.github.binarywang.wxpay.exception.WxPayException; | ||
import com.github.binarywang.wxpay.service.WxPayService; | ||
import com.github.binarywang.wxpay.testbase.CustomizedApiTestModule; | ||
import com.google.inject.Inject; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.testng.annotations.Guice; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* <pre> | ||
* Created by BinaryWang on 2017/6/18. | ||
* </pre> | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
binarywang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
@Slf4j | ||
@Test | ||
@Guice(modules = CustomizedApiTestModule.class) | ||
public class CustomizedWxPayConfigTest { | ||
|
||
@Inject | ||
private WxPayService wxPayService; | ||
|
||
public void testCustomizerHttpClient() { | ||
try { | ||
wxPayService.queryOrder("a", null); | ||
} catch (WxPayException e) { | ||
// ignore | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void testCustomizerV3HttpClient() { | ||
try { | ||
wxPayService.queryOrderV3("a", null); | ||
} catch (WxPayException e) { | ||
// ignore | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/CustomizedApiTestModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.github.binarywang.wxpay.testbase; | ||
|
||
import com.github.binarywang.wxpay.config.WxPayConfig; | ||
import com.github.binarywang.wxpay.service.WxPayService; | ||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; | ||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
import com.thoughtworks.xstream.XStream; | ||
import me.chanjar.weixin.common.error.WxRuntimeException; | ||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | ||
import org.apache.http.HttpRequestInterceptor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* The type Api test module. | ||
*/ | ||
public class CustomizedApiTestModule implements Module { | ||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
private static final String TEST_CONFIG_XML = "test-config.xml"; | ||
|
||
@Override | ||
public void configure(Binder binder) { | ||
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { | ||
if (inputStream == null) { | ||
throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); | ||
} | ||
|
||
XmlWxPayConfig config = this.fromXml(XmlWxPayConfig.class, inputStream); | ||
config.setIfSaveApiData(true); | ||
|
||
config.setApiV3HttpClientBuilderCustomizer((builder) -> { | ||
builder.addInterceptorLast((HttpRequestInterceptor) (r, c) -> System.out.println("--------> V3 HttpRequestInterceptor ...")); | ||
}); | ||
|
||
config.setHttpClientBuilderCustomizer((builder) -> { | ||
builder.addInterceptorLast((HttpRequestInterceptor) (r, c) -> System.out.println("--------> HttpRequestInterceptor ...")); | ||
}); | ||
|
||
WxPayService wxService = new WxPayServiceImpl(); | ||
wxService.setConfig(config); | ||
|
||
binder.bind(WxPayService.class).toInstance(wxService); | ||
binder.bind(WxPayConfig.class).toInstance(config); | ||
} catch (IOException e) { | ||
this.log.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private <T> T fromXml(Class<T> clazz, InputStream is) { | ||
XStream xstream = XStreamInitializer.getInstance(); | ||
xstream.alias("xml", clazz); | ||
xstream.processAnnotations(clazz); | ||
return (T) xstream.fromXML(is); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.