本文整理汇总了Java中net.ymate.framework.commons.HttpClientHelper类的典型用法代码示例。如果您正苦于以下问题:Java HttpClientHelper类的具体用法?Java HttpClientHelper怎么用?Java HttpClientHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpClientHelper类属于net.ymate.framework.commons包,在下文中一共展示了HttpClientHelper类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
/**
* @return 提交请求并返回回应结果
* @throws Exception 可能产生的任何异常
*/
public RESPONSE execute() throws Exception {
Map<String, Object> _params = buildSignatureParams();
_params.put(IWxPay.Const.SIGN, __doCreateSignature(_params, __accountMeta.getMchKey()));
// 处理沙箱URL地址
String _requestURL = __doGetRequestURL();
if (!StringUtils.startsWithIgnoreCase(_requestURL, "http")) {
_requestURL = "https://api.mch.weixin.qq.com/" + __accountMeta.getSandboxPrefix() + _requestURL;
}
IHttpResponse _response = HttpClientHelper.create()
.customSSL(__accountMeta.getConnectionSocketFactory())
.post(_requestURL, __doBuildXML(_params));
if (_response != null) {
if (_response.getStatusCode() == 200) {
return __doParseResponse(_response);
} else if (_LOG.isDebugEnabled()) {
_LOG.debug("ResponseBody: " + _response.toString());
}
}
return null;
}
示例2: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL, true);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken())) {
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL.concat(_connectUser.getAccessToken()), __doGetRequestHeaders());
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setOpenId(_result.getString("id"))
.setNickName(_result.getString("login"))
.setPhotoUrl(_result.getString("avatar_url"));
}
}
}
return _connectUser;
}
示例3: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken())) {
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL.concat(_connectUser.getAccessToken()), __doGetRequestHeaders());
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setOpenId(_result.getString("id"))
.setNickName(_result.getString("login"))
.setPhotoUrl(_result.getString("avatar_url"));
}
}
}
return _connectUser;
}
示例4: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken())) {
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL.concat(_connectUser.getAccessToken()), __doGetRequestHeaders());
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setOpenId(_result.getString("id"))
.setNickName(_result.getString("name"))
.setPhotoUrl(_result.getString("avatar"));
String _gender = _result.getString("gender");
if (StringUtils.isNotBlank(_gender)) {
_connectUser.setGender(OAuthConnectUser.Gender.valueOf(_gender.toUpperCase()));
} else {
_connectUser.setGender(OAuthConnectUser.Gender.UNKNOW);
}
}
}
}
return _connectUser;
}
示例5: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken())) {
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL.concat(_connectUser.getAccessToken()), __doGetRequestHeaders());
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setOpenId(_result.getString("uid"))
.setNickName(_result.getString("uname"))
.setPhotoUrl(_result.getString("portrait"));
String _photoUrl = _result.getString("portrait");
if (StringUtils.isNotBlank(_photoUrl)) {
_connectUser.setPhotoUrl("http://tb.himg.baidu.com/sys/portrait/item/" + _photoUrl);
}
_connectUser.setGender(OAuthConnectUser.Gender.UNKNOW);
}
}
}
return _connectUser;
}
示例6: execute
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
public RESPONSE execute() throws Exception {
IHttpResponse _response = HttpClientHelper.create().post(this.gatewayUrl, this.requestParameters);
if (_response != null) {
if (_response.getStatusCode() == 200) {
return this.responseParser.parserResponse(_response.getContent());
} else if (_LOG.isDebugEnabled()) {
_LOG.debug("ResponseBody: " + _response.toString());
}
}
return null;
}
示例7: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken()) && StringUtils.isNotBlank(_connectUser.getOpenId())) {
Map<String, String> _params = new HashMap<String, String>();
_params.put("access_token", _connectUser.getAccessToken());
_params.put("openid", _connectUser.getOpenId());
//
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL, _params);
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setNickName(_result.getString("nickname"))
.setPhotoUrl(_result.getString("headimgurl"))
.setUnionId(_result.getString("unionid"));
switch (_result.getIntValue("sex")) {
case 1:
_connectUser.setGender(OAuthConnectUser.Gender.MALE);
break;
case 2:
_connectUser.setGender(OAuthConnectUser.Gender.FEMALE);
break;
default:
_connectUser.setGender(OAuthConnectUser.Gender.UNKNOW);
}
//
_connectUser.putAttribute("country", _result.getString("country"));
_connectUser.putAttribute("province", _result.getString("province"));
_connectUser.putAttribute("city", _result.getString("city"));
}
}
}
return _connectUser;
}
示例8: __doGetAccessToken
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
protected OAuthConnectUser __doGetAccessToken(String code, String tokenUrl) throws Exception {
OAuthConnectUser _connectUser = super.__doGetAccessToken(code, tokenUrl);
if (_connectUser != null) {
IHttpResponse _response = HttpClientHelper.create().get(__OPEN_ID_URL.concat(_connectUser.getAccessToken()), __doGetRequestHeaders());
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setOpenId(_result.getString("openid"));
}
}
return _connectUser;
}
示例9: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken()) && StringUtils.isNotBlank(_connectUser.getOpenId())) {
Map<String, String> _params = new HashMap<String, String>();
_params.put("access_token", _connectUser.getAccessToken());
_params.put("oauth_consumer_key", __initCfg.getClientId());
_params.put("openid", _connectUser.getOpenId());
//
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL, _params);
JSONObject _result = super.__doParseConnectResponseBody(_response);
if (_result != null) {
int _ret = _result.getIntValue("ret");
if (_ret == 0) {
_connectUser.setNickName(_result.getString("nickname"))
.setPhotoUrl(_result.getString("figureurl_qq_2"));
if (StringUtils.isBlank(_connectUser.getPhotoUrl())) {
_connectUser.setPhotoUrl(_result.getString("figureurl_qq_1"));
}
String _gender = _result.getString("gender");
if (StringUtils.equals(_gender, "女")) {
_connectUser.setGender(OAuthConnectUser.Gender.FEMALE);
} else if (StringUtils.equals(_gender, "男")) {
_connectUser.setGender(OAuthConnectUser.Gender.MALE);
} else {
_connectUser.setGender(OAuthConnectUser.Gender.UNKNOW);
}
} else {
throw new RuntimeException(_result.toJSONString());
}
}
}
}
return _connectUser;
}
示例10: getConnectUser
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
@Override
public OAuthConnectUser getConnectUser(String code) throws Exception {
OAuthConnectUser _connectUser = __doGetAccessToken(code, __TOKEN_URL, true);
if (_connectUser != null) {
if (StringUtils.isNotBlank(_connectUser.getAccessToken())) {
Map<String, String> _params = new HashMap<String, String>();
_params.put("access_token", _connectUser.getAccessToken());
_params.put("uid", _connectUser.getOpenId());
//
IHttpResponse _response = HttpClientHelper.create().get(__USERINFO_URL, _params, __doGetRequestHeaders());
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
_connectUser.setNickName(_result.getString("screen_name"))
.setPhotoUrl(_result.getString("avatar_large"));
String _gender = _result.getString("gender");
if (StringUtils.equals(_gender, "f")) {
_connectUser.setGender(OAuthConnectUser.Gender.FEMALE);
} else if (StringUtils.equals(_gender, "m")) {
_connectUser.setGender(OAuthConnectUser.Gender.MALE);
} else {
_connectUser.setGender(OAuthConnectUser.Gender.UNKNOW);
}
//
_connectUser.putAttribute("province", _result.getString("province"));
_connectUser.putAttribute("city", _result.getString("city"));
//
return _connectUser;
}
}
}
return null;
}
示例11: __doGetAccessToken
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
protected OAuthConnectUser __doGetAccessToken(String code, String tokenUrl, boolean usePost) throws Exception {
Map<String, String> _params = new HashMap<String, String>();
_params.put(__clientParamName, __initCfg.getClientId());
_params.put(__secretParamName, __initCfg.getClientSecret());
if (__needRedirectUri) {
_params.put("redirect_uri", __initCfg.getRedirectUri());
}
_params.put("code", code);
_params.put("grant_type", "authorization_code");
//
IHttpResponse _response = null;
if (usePost) {
_response = HttpClientHelper.create().post(tokenUrl, _params, __doGetRequestHeaders());
} else {
_response = HttpClientHelper.create().get(tokenUrl, _params, __doGetRequestHeaders());
}
JSONObject _result = __doParseConnectResponseBody(_response);
if (_result != null) {
return new OAuthConnectUser()
.setAccessToken(_result.getString("access_token"))
.setRefreshToken(_result.getString("refresh_token"))
.setExpiresIn(_result.getIntValue("expires_in"))
.setOpenId(StringUtils.isBlank(__openIdParamName) ? null : _result.getString(__openIdParamName))
.setScope(_result.getString("scope"));
}
return null;
}
开发者ID:suninformation,项目名称:ymate-module-oauth-connector,代码行数:28,代码来源:AbstractOAuthConnectProcessor.java
示例12: __doValidateToken
import net.ymate.framework.commons.HttpClientHelper; //导入依赖的package包/类
private boolean __doValidateToken(ISSOToken token) {
try {
if (SSO.get().getModuleCfg().isClientMode()) {
Map<String, String> _params = new HashMap<String, String>();
_params.put("token_id", token.getId());
_params.put("uid", token.getUid());
_params.put("remote_addr", token.getRemoteAddr());
_params.put("sign", ParamUtils.createSignature(_params, false, SSO.get().getModuleCfg().getServiceAuthKey()));
IHttpResponse _result = HttpClientHelper.create().post(SSO.get().getModuleCfg().getServiceBaseUrl().concat("sso/authorize"), _params, new Header[]{new BasicHeader("User-Agent", WebContext.getRequest().getHeader("User-Agent"))});
if (_result != null && _result.getStatusCode() == 200) {
JSONObject _resultObj = JSON.parseObject(_result.getContent());
if (_resultObj.getIntValue("ret") == ErrorCode.SUCCESSED) {
// 令牌验证通过,则进行本地Cookie存储
SSO.get().getModuleCfg().getTokenAdapter().setToken(token);
// 尝试从响应报文中提取并追加token属性数据
JSONObject _dataObj = _resultObj.getJSONObject("data");
if (_dataObj != null && !_dataObj.isEmpty()) {
for (Map.Entry<String, Object> _attr : _dataObj.entrySet()) {
token.getAttributes().put(_attr.getKey(), BlurObject.bind(_attr.getValue()).toStringValue());
}
}
//
return true;
}
}
} else {
ISSOTokenStorageAdapter _storageAdapter = SSO.get().getModuleCfg().getTokenStorageAdapter();
// 尝试从存储中加载原始令牌数据并进行有效性验证
ISSOToken _originalToken = _storageAdapter.load(token.getUid(), token.getId());
if (_originalToken != null) {
boolean _ipCheck = (SSO.get().getModuleCfg().isIpCheckEnabled() && !StringUtils.equals(token.getRemoteAddr(), _originalToken.getRemoteAddr()));
if (_originalToken.timeout() || !_originalToken.verified() || _ipCheck) {
_storageAdapter.remove(_originalToken.getUid(), _originalToken.getId());
} else {
// 尝试加载令牌自定义属性
ISSOTokenAttributeAdapter _attributeAdapter = SSO.get().getModuleCfg().getTokenAttributeAdapter();
if (_attributeAdapter != null) {
_attributeAdapter.loadAttributes(token);
}
return true;
}
}
}
} catch (Exception e) {
_LOG.warn("An exception occurred while validate token '" + token.getId() + "' for user '" + token.getUid() + "'", RuntimeUtils.unwrapThrow(e));
}
return false;
}