cp usage jodd-http
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
/**
|
||||
* 微信API的Service
|
||||
*/
|
||||
public interface WxCpService {
|
||||
public interface WxCpService<H, P> {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@@ -469,7 +469,7 @@ public interface WxCpService {
|
||||
* <pre>
|
||||
* Service没有实现某个API的时候,可以用这个,
|
||||
* 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
|
||||
* 可以参考,{@link me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor}的实现方法
|
||||
* 可以参考,{@link me.chanjar.weixin.common.util.http.jodd.MediaUploadRequestExecutor}的实现方法
|
||||
* </pre>
|
||||
*
|
||||
* @param executor 执行器
|
||||
@@ -478,7 +478,9 @@ public interface WxCpService {
|
||||
* @param <T> 请求值类型
|
||||
* @param <E> 返回值类型
|
||||
*/
|
||||
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
|
||||
<T, E> T execute(RequestExecutor<T, H, P, E> executor, String uri, E data) throws WxErrorException;
|
||||
|
||||
<T, E> T executeInternal(RequestExecutor<T, H, P, E> executor, String uri, E data) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 注入 {@link WxCpConfigStorage} 的实现
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
package me.chanjar.weixin.cp.api.impl.apache;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@@ -14,8 +14,12 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.RandomUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.fs.FileUtils;
|
||||
import me.chanjar.weixin.common.util.http.*;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.URIUtil;
|
||||
import me.chanjar.weixin.common.util.http.apache.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
@@ -37,7 +41,7 @@ import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WxCpServiceImpl implements WxCpService {
|
||||
public class WxCpServiceImpl implements WxCpService<CloseableHttpClient, HttpHost> {
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(WxCpServiceImpl.class);
|
||||
|
||||
@@ -534,7 +538,7 @@ public class WxCpServiceImpl implements WxCpService {
|
||||
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
||||
*/
|
||||
@Override
|
||||
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
public <T, E> T execute(RequestExecutor<T,CloseableHttpClient, HttpHost, E> executor, String uri, E data) throws WxErrorException {
|
||||
int retryTimes = 0;
|
||||
do {
|
||||
try {
|
||||
@@ -570,7 +574,7 @@ public class WxCpServiceImpl implements WxCpService {
|
||||
throw new RuntimeException("微信服务端异常,超出重试次数");
|
||||
}
|
||||
|
||||
protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
public synchronized <T, E> T executeInternal(RequestExecutor<T,CloseableHttpClient, HttpHost, E> executor, String uri, E data) throws WxErrorException {
|
||||
if (uri.contains("access_token=")) {
|
||||
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
|
||||
public class ApiTestModule implements Module {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.testng.Assert;
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.testng.Assert;
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
package me.chanjar.weixin.cp.api.impl.apache;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
@@ -1,8 +1,11 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
package me.chanjar.weixin.cp.api.impl.apache;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -19,8 +22,8 @@ public class WxCpBusyRetryTest {
|
||||
WxCpService service = new WxCpServiceImpl() {
|
||||
|
||||
@Override
|
||||
protected synchronized <T, E> T executeInternal(
|
||||
RequestExecutor<T, E> executor, String uri, E data)
|
||||
public synchronized <T, E> T executeInternal(
|
||||
RequestExecutor<T,CloseableHttpClient, HttpHost, E> executor, String uri, E data)
|
||||
throws WxErrorException {
|
||||
this.log.info("Executed");
|
||||
WxError error = new WxError();
|
||||
@@ -1,13 +1,12 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
package me.chanjar.weixin.cp.api.impl.apache;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/***
|
||||
* 测试发送消息
|
||||
@@ -13,7 +13,7 @@ import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageHandler;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageRouter;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<suite name="Weixin-java-tool-suite" verbose="1">
|
||||
<test name="API_Test">
|
||||
<classes>
|
||||
<class name="me.chanjar.weixin.cp.api.WxCpBusyRetryTest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.WxCpBaseAPITest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.WxCpMessageAPITest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.impl.apache.WxCpBusyRetryTest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.impl.apache.WxCpBaseAPITest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.impl.apache.WxCpMessageAPITest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.WxMenuAPITest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.WxCpDepartAPITest"/>
|
||||
<class name="me.chanjar.weixin.cp.api.WxCpMediaAPITest"/>
|
||||
|
||||
Reference in New Issue
Block a user