Search in sources :

Example 1 with NutMap

use of org.nutz.lang.util.NutMap in project nutz by nutzam.

the class Xmls method asMap.

/**
     * 根据一个 XML 节点,将其变成一个 Map。
     * <p/>
     * <b>注意: 不支持混合节点</b>
     * 
     * @param ele
     *            元素
     * @param lowFirst
     *            是否把所有key的首字母都小写
     * 
     * @return 一个 Map 对象
     */
public static NutMap asMap(Element ele, final boolean lowFirst) {
    final NutMap map = new NutMap();
    eachChildren(ele, new Each<Element>() {

        public void invoke(int index, Element _ele, int length) throws ExitLoop, ContinueLoop, LoopException {
            String key = _ele.getNodeName();
            if (lowFirst)
                key = Strings.lowerFirst(key);
            Map<String, Object> tmp = asMap(_ele, lowFirst);
            if (!tmp.isEmpty()) {
                map.setv(key, tmp);
                return;
            }
            String val = getText(_ele);
            if (!Strings.isBlank(val)) {
                map.setv(key, val);
            }
        }
    });
    return map;
}
Also used : Element(org.w3c.dom.Element) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) NutMap(org.nutz.lang.util.NutMap) NutMap(org.nutz.lang.util.NutMap)

Example 2 with NutMap

use of org.nutz.lang.util.NutMap in project nutzboot by nutzam.

the class MainLauncher method make.

@AdaptBy(type = JsonAdaptor.class)
@At("/maker/make")
@Ok("json:full")
public NutMap make(@Param("..") NutMap params) throws IOException {
    NutMap re = new NutMap();
    String key = R.UU32();
    File tmpRoot = Files.createDirIfNoExists(tmpDir + "/" + key);
    build(tmpRoot, params);
    re.put("key", key);
    re.put("ok", true);
    return re;
}
Also used : File(java.io.File) NutMap(org.nutz.lang.util.NutMap) At(org.nutz.mvc.annotation.At) AdaptBy(org.nutz.mvc.annotation.AdaptBy) Ok(org.nutz.mvc.annotation.Ok)

Example 3 with NutMap

use of org.nutz.lang.util.NutMap in project nutzboot by nutzam.

the class EthModule method remoteAccounts.

@At("/remote/accounts")
public NutMap remoteAccounts() {
    Map<String, Web3jAccount> accounts = new HashMap<>();
    try {
        List<String> accountAddrs = web3j.ethAccounts().send().getAccounts();
        for (String address : accountAddrs) {
            Web3jAccount account = new Web3jAccount();
            account.setBanlance(web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST).send().getBalance());
            account.setAddress(address);
            account.setName(address.substring(0, 8));
            accounts.put(account.getName(), account);
        }
        return new NutMap("ok", true).setv("data", accounts);
    } catch (IOException e) {
        log.info("something happen", e);
        return new NutMap("msg", e.getMessage());
    }
}
Also used : Web3jAccount(org.nutz.boot.starter.web3.Web3jAccount) HashMap(java.util.HashMap) IOException(java.io.IOException) NutMap(org.nutz.lang.util.NutMap) At(org.nutz.mvc.annotation.At)

Example 4 with NutMap

use of org.nutz.lang.util.NutMap in project nutzcloud by nutzam.

the class LiteRpcLoachUpdater method onUpdate.

@SuppressWarnings("unchecked")
public void onUpdate(Map<String, List<NutMap>> services) {
    if (services == null || services.isEmpty()) {
        // fuck
        return;
    }
    Map<String, List<NutMap>> rpcMap = new HashMap<>();
    for (List<NutMap> _se : services.values()) {
        for (NutMap server : _se) {
            Map<String, List<String>> rpcKeys = (Map<String, List<String>>) server.get(LiteRpc.RPC_REG_KEY);
            if (rpcKeys == null || rpcKeys.isEmpty())
                continue;
            for (Map.Entry<String, List<String>> en : rpcKeys.entrySet()) {
                String klassName = en.getKey();
                for (String methodSign : en.getValue()) {
                    methodSign = klassName + ":" + methodSign;
                    List<NutMap> servers = rpcMap.get(methodSign);
                    if (servers == null) {
                        servers = new ArrayList<>();
                        rpcMap.put(methodSign, servers);
                    }
                    servers.add(server);
                }
            }
        }
    }
    liteRpc.setServices(rpcMap);
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) NutMap(org.nutz.lang.util.NutMap) NutMap(org.nutz.lang.util.NutMap)

Example 5 with NutMap

use of org.nutz.lang.util.NutMap in project nutzcloud by nutzam.

the class LoachClient method _ping.

protected boolean _ping() {
    try {
        String pingURL = url + "/ping/" + getServiceName() + "/" + id;
        if (isDebug())
            log.debug("Ping URL=" + pingURL);
        Request req = Request.create(pingURL, METHOD.GET);
        req.getHeader().clear();
        req.getHeader().set("If-Not-Match", lastPingETag);
        Response resp = Sender.create(req, conf.getInt("loach.client.ping.timeout", 1000)).setConnTimeout(1000).send();
        String cnt = resp.getContent();
        if (isDebug())
            log.debug("Ping result : " + cnt);
        if (resp.isOK()) {
            lastPingETag = Strings.sBlank(resp.getHeader().get("ETag"), "ABC");
            NutMap re = Json.fromJson(NutMap.class, cnt);
            if (re != null && re.getBoolean("ok", false))
                return true;
        } else if (resp.getStatus() == 304) {
            return true;
        }
    } catch (Throwable e) {
        log.debugf("bad url? %s %s", url, e.getMessage());
    }
    return false;
}
Also used : Response(org.nutz.http.Response) Request(org.nutz.http.Request) NutMap(org.nutz.lang.util.NutMap)

Aggregations

NutMap (org.nutz.lang.util.NutMap)78 Test (org.junit.Test)32 IOException (java.io.IOException)13 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 LinkedHashMap (java.util.LinkedHashMap)7 At (org.nutz.mvc.annotation.At)7 Date (java.util.Date)6 List (java.util.List)6 Response (org.nutz.http.Response)5 File (java.io.File)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 Request (org.nutz.http.Request)4 AmazonInfo (com.netflix.appinfo.AmazonInfo)3 BigDecimal (java.math.BigDecimal)3 ServletException (javax.servlet.ServletException)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)2