Search in sources :

Example 6 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class Statics method concurrentMap.

/**
 * @param key
 * @return
 */
public static ConcurrentMap concurrentMap(String key) {
    if (statics.containsKey(key)) {
        return (ConcurrentMap) statics.get(key);
    } else {
        ConcurrentMap _static = new ConcurrentMap();
        statics.put(key, _static);
        return _static;
    }
}
Also used : ConcurrentMap(j.util.ConcurrentMap)

Example 7 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class DateUtil method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    JHttp http = JHttp.getInstance();
    HttpClient client = http.createClient();
    JHttpContext context = new JHttpContext();
    final String keyOfThisShop = "0000-0000-0000-0000";
    String url = "http://www.gugumall.cn/I.handler";
    url += "?request=call";
    url += "&cmd=get-products";
    url += "&seller=systemseller";
    url += "&update=2016-06-06 00:00:00";
    url += "&catalog=";
    url += "&rpp=5";
    url += "&pn=1";
    ConcurrentMap params = new ConcurrentMap();
    params.put("request", "call");
    params.put("cmd", "get-products");
    params.put("seller", "systemseller");
    params.put("update", "2016-06-06 00:00:00");
    params.put("catalog", "");
    params.put("rpp", "5");
    params.put("pn", "1");
    String sign = createSign(keyOfThisShop, params);
    url += "&v=" + sign;
    String response = http.getResponse(context, client, url);
    System.out.println(response);
    int start = response.lastIndexOf("<v>");
    if (start < 0) {
        System.out.println("未成功识别出商户信息,无检验码,具体错误请将整个response作为xml解析");
        return;
    }
    int end = response.indexOf("</v>", start);
    String v = response.substring(start + 3, end);
    System.out.println(v);
    // xml部分
    response = response.substring(0, start);
    String responseSign = response + keyOfThisShop;
    responseSign = JUtilMD5.MD5EncodeToHex(responseSign);
    System.out.println(responseSign);
    if (v.equalsIgnoreCase(responseSign)) {
        System.out.println("校验通过");
    } else {
        System.out.println("校验未通过");
    }
}
Also used : HttpClient(org.apache.http.client.HttpClient) ConcurrentMap(j.util.ConcurrentMap) JUtilString(j.util.JUtilString)

Example 8 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class SSOConfig method tellServerToLoginSameProtocalAsBackUrl.

/**
 * @param clientId
 * @param ssoUserId
 * @param ssoBackUrl
 * @param ssoLoginPage
 * @param infos
 * @return
 * @throws Exception
 */
public static String tellServerToLoginSameProtocalAsBackUrl(String clientIdOrUrl, String ssoUserId, String ssoBackUrl, String ssoLoginPage, ConcurrentMap infos) throws Exception {
    try {
        String loginUrl = SSOConfig.getSsoServer() + "ssoserver" + Handlers.getActionPathPattern();
        loginUrl += "?" + Handlers.getHandler("/ssoserver").getRequestBy() + "=ssologinauto";
        if (JUtilString.getProtocal(ssoBackUrl).equals("http")) {
            loginUrl = JUtilString.replaceAll(loginUrl, "https://", "http://");
        }
        Map paras = new HashMap();
        paras.put(Constants.SSO_CLIENT, clientIdOrUrl);
        paras.put(Constants.SSO_USER_ID, ssoUserId);
        paras.put(Constants.SSO_LOGIN_INFO, JObject.serializable2String(infos, false));
        paras.put(Constants.SSO_PASSPORT, Permission.getSSOPassport());
        int loop = 0;
        String _response = "";
        while ((_response == null || !_response.startsWith(Constants.RESPONSE_OK + ":")) && loop < 3) {
            JHttpContext context = new JHttpContext();
            context.setAllowedErrorCodes(new String[] { "301" });
            context = http.post(context, hclient, loginUrl, paras);
            _response = context.getStatus() == 200 ? context.getResponseText() : null;
            context.finalize();
            context = null;
            loop++;
            if (_response == null || !_response.startsWith(Constants.RESPONSE_OK + ":")) {
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                }
            }
        }
        log.log("tellServerToLogin - " + _response, Logger.LEVEL_DEBUG);
        if (_response == null || !_response.startsWith(Constants.RESPONSE_OK + ":")) {
            return null;
        } else {
            String globalSessionId = _response.substring(Constants.RESPONSE_OK.length() + 1, _response.lastIndexOf(":"));
            String token = _response.substring(_response.lastIndexOf(":") + 1);
            if (clientIdOrUrl.matches(JUtilString.RegExpHttpUrl)) {
                loginUrl = SSOConfig.getSsoServer(SSOConfig.getSsoClientByIdOrUrl(clientIdOrUrl), clientIdOrUrl) + "ssoserver" + Handlers.getActionPathPattern();
            } else if (ssoBackUrl.matches(JUtilString.RegExpHttpUrl)) {
                loginUrl = SSOConfig.getSsoServer(SSOConfig.getSsoClientByIdOrUrl(clientIdOrUrl), ssoBackUrl) + "ssoserver" + Handlers.getActionPathPattern();
            } else {
                loginUrl = SSOConfig.getSsoServer() + "ssoserver" + Handlers.getActionPathPattern();
            }
            loginUrl += "?" + Handlers.getHandler("/ssoserver").getRequestBy() + "=jump";
            loginUrl += "&" + Constants.SSO_CLIENT + "=" + clientIdOrUrl;
            if (ssoBackUrl != null) {
                loginUrl += "&" + Constants.SSO_BACK_URL + "=" + JUtilString.encodeURI(ssoBackUrl, SysConfig.sysEncoding);
            }
            if (ssoLoginPage != null) {
                loginUrl += "&" + Constants.SSO_LOGIN_PAGE + "=" + JUtilString.encodeURI(ssoLoginPage, SysConfig.sysEncoding);
            }
            loginUrl += "&" + Constants.SSO_GLOBAL_SESSION_ID + "=" + globalSessionId;
            loginUrl += "&" + Constants.SSO_TOKEN + "=" + token;
            log.log("sso jump url - " + loginUrl, Logger.LEVEL_DEBUG);
            return loginUrl;
        }
    } catch (Exception ex) {
        log.log(ex, Logger.LEVEL_ERROR);
        return null;
    }
}
Also used : JHttpContext(j.http.JHttpContext) HashMap(java.util.HashMap) JUtilString(j.util.JUtilString) HashMap(java.util.HashMap) ConcurrentMap(j.util.ConcurrentMap) Map(java.util.Map)

Example 9 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class SSOConfig method tellServerToLogin.

/**
 * @param clientId
 * @param ssoUserId
 * @param ssoBackUrl
 * @param ssoLoginPage
 * @param infos
 * @return
 * @throws Exception
 */
public static String tellServerToLogin(String clientIdOrUrl, String ssoUserId, String ssoBackUrl, String ssoLoginPage, ConcurrentMap infos) throws Exception {
    try {
        String loginUrl = SSOConfig.getSsoServer() + "ssoserver" + Handlers.getActionPathPattern();
        loginUrl += "?" + Handlers.getHandler("/ssoserver").getRequestBy() + "=ssologinauto";
        Map paras = new HashMap();
        paras.put(Constants.SSO_CLIENT, clientIdOrUrl);
        paras.put(Constants.SSO_USER_ID, ssoUserId);
        paras.put(Constants.SSO_LOGIN_INFO, JObject.serializable2String(infos, false));
        paras.put(Constants.SSO_PASSPORT, Permission.getSSOPassport());
        int loop = 0;
        String _response = "";
        while ((_response == null || !_response.startsWith(Constants.RESPONSE_OK + ":")) && loop < 3) {
            JHttpContext context = new JHttpContext();
            context.setAllowedErrorCodes(new String[] { "301" });
            context = http.post(context, hclient, loginUrl, paras);
            _response = context.getStatus() == 200 ? context.getResponseText() : null;
            context.finalize();
            context = null;
            loop++;
            if (_response == null || !_response.startsWith(Constants.RESPONSE_OK + ":")) {
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                }
            }
        }
        if (_response == null || !_response.startsWith(Constants.RESPONSE_OK + ":")) {
            return null;
        } else {
            String globalSessionId = _response.substring(Constants.RESPONSE_OK.length() + 1, _response.lastIndexOf(":"));
            String token = _response.substring(_response.lastIndexOf(":") + 1);
            if (clientIdOrUrl.matches(JUtilString.RegExpHttpUrl)) {
                loginUrl = SSOConfig.getSsoServer(SSOConfig.getSsoClientByIdOrUrl(clientIdOrUrl), clientIdOrUrl) + "ssoserver" + Handlers.getActionPathPattern();
            } else if (ssoBackUrl.matches(JUtilString.RegExpHttpUrl)) {
                loginUrl = SSOConfig.getSsoServer(SSOConfig.getSsoClientByIdOrUrl(clientIdOrUrl), ssoBackUrl) + "ssoserver" + Handlers.getActionPathPattern();
            } else {
                loginUrl = SSOConfig.getSsoServer() + "ssoserver" + Handlers.getActionPathPattern();
            }
            loginUrl += "?" + Handlers.getHandler("/ssoserver").getRequestBy() + "=jump";
            loginUrl += "&" + Constants.SSO_CLIENT + "=" + clientIdOrUrl;
            if (ssoBackUrl != null) {
                loginUrl += "&" + Constants.SSO_BACK_URL + "=" + JUtilString.encodeURI(ssoBackUrl, SysConfig.sysEncoding);
            }
            if (ssoLoginPage != null) {
                loginUrl += "&" + Constants.SSO_LOGIN_PAGE + "=" + JUtilString.encodeURI(ssoLoginPage, SysConfig.sysEncoding);
            }
            loginUrl += "&" + Constants.SSO_GLOBAL_SESSION_ID + "=" + globalSessionId;
            loginUrl += "&" + Constants.SSO_TOKEN + "=" + token;
            log.log("sso jump url - " + loginUrl, Logger.LEVEL_DEBUG);
            return loginUrl;
        }
    } catch (Exception ex) {
        log.log(ex, Logger.LEVEL_ERROR);
        return null;
    }
}
Also used : JHttpContext(j.http.JHttpContext) HashMap(java.util.HashMap) JUtilString(j.util.JUtilString) HashMap(java.util.HashMap) ConcurrentMap(j.util.ConcurrentMap) Map(java.util.Map)

Example 10 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class Sample method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    JHttp http = JHttp.getInstance();
    HttpClient client = http.createClient();
    JHttpContext context = new JHttpContext();
    final String keyOfThisShop = "0000-0000-0000-0000";
    String url = "http://www.gugumall.cn/I.handler";
    url += "?request=call";
    url += "&cmd=get-products";
    url += "&seller=systemseller";
    url += "&update=2016-06-06 00:00:00";
    url += "&catalog=";
    url += "&rpp=5";
    url += "&pn=1";
    ConcurrentMap params = new ConcurrentMap();
    params.put("request", "call");
    params.put("cmd", "get-products");
    params.put("seller", "systemseller");
    params.put("update", "2016-06-06 00:00:00");
    params.put("catalog", "");
    params.put("rpp", "5");
    params.put("pn", "1");
    String sign = createSign(keyOfThisShop, params);
    url += "&v=" + sign;
    String response = http.getResponse(context, client, url, "UTF-8");
    int start = response.lastIndexOf("<v>");
    if (start < 0) {
        System.out.println("未成功识别出商户信息,无检验码,具体错误请将整个response作为xml解析");
        return;
    }
    int end = response.indexOf("</v>", start);
    String v = response.substring(start + 3, end);
    System.out.println(v);
    // xml部分
    response = response.substring(0, start);
    String responseSign = response + keyOfThisShop;
    responseSign = JUtilMD5.MD5EncodeToHex(responseSign);
    if (v.equalsIgnoreCase(responseSign)) {
        System.out.println("校验通过");
    } else {
        System.out.println("校验未通过");
    }
}
Also used : HttpClient(org.apache.http.client.HttpClient) ConcurrentMap(j.util.ConcurrentMap) JUtilString(j.util.JUtilString)

Aggregations

ConcurrentMap (j.util.ConcurrentMap)16 ConcurrentList (j.util.ConcurrentList)8 List (java.util.List)7 HttpClient (org.apache.http.client.HttpClient)7 Client (j.service.Client)5 JUtilString (j.util.JUtilString)5 RemoteException (java.rmi.RemoteException)4 JHttpContext (j.http.JHttpContext)3 ServiceBase (j.service.server.ServiceBase)3 JUtilList (j.util.JUtilList)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 CachedMap (j.cache.CachedMap)1 JObject (j.common.JObject)1 JUtilSorter (j.util.JUtilSorter)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1