use of me.chanjar.weixin.common.session.WxSessionManager in project weixin-java-tools by chanjarster.
the class WxCpMessageRouterTest method testConcurrency.
public void testConcurrency() throws InterruptedException {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.rule().handler(new WxCpMessageHandler() {
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, WxSessionManager sessionManager) {
return null;
}
}).end();
final WxCpXmlMessage m = new WxCpXmlMessage();
Runnable r = new Runnable() {
@Override
public void run() {
router.route(m);
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
}
}
};
for (int i = 0; i < 10; i++) {
new Thread(r).start();
}
Thread.sleep(1000l * 2);
}
use of me.chanjar.weixin.common.session.WxSessionManager in project weixin-java-tools by chanjarster.
the class WxCpDemoServer method initWeixin.
private static void initWeixin() {
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(is1);
wxCpConfigStorage = config;
wxCpService = new WxCpServiceImpl();
wxCpService.setWxCpConfigStorage(config);
WxCpMessageHandler handler = new WxCpMessageHandler() {
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, WxSessionManager sessionManager) {
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()).build();
return m;
}
};
WxCpMessageHandler oauth2handler = new WxCpMessageHandler() {
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, WxSessionManager sessionManager) {
String href = "<a href=\"" + wxCpService.oauth2buildAuthorizationUrl(wxCpConfigStorage.getOauth2redirectUri(), null) + "\">测试oauth2</a>";
return WxCpXmlOutMessage.TEXT().content(href).fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()).build();
}
};
wxCpMessageRouter = new WxCpMessageRouter(wxCpService);
wxCpMessageRouter.rule().async(false).content(// 拦截内容为“哈哈”的消息
"哈哈").handler(handler).end().rule().async(false).content("oauth").handler(oauth2handler).end();
}
use of me.chanjar.weixin.common.session.WxSessionManager in project weixin-java-tools by chanjarster.
the class WxMpMessageRouterTest method testConcurrency.
public void testConcurrency() throws InterruptedException {
final WxMpMessageRouter router = new WxMpMessageRouter(null);
router.rule().handler(new WxMpMessageHandler() {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
return null;
}
}).end();
final WxMpXmlMessage m = new WxMpXmlMessage();
Runnable r = new Runnable() {
@Override
public void run() {
router.route(m);
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
}
}
};
for (int i = 0; i < 10; i++) {
new Thread(r).start();
}
Thread.sleep(1000l * 2);
}
Aggregations