List of usage examples for org.apache.commons.httpclient HttpStatus SC_REQUEST_TIMEOUT
int SC_REQUEST_TIMEOUT
To view the source code for org.apache.commons.httpclient HttpStatus SC_REQUEST_TIMEOUT.
Click Source Link
From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
/** * /*from ww w . j a v a2s .com*/ * * @param dataIdPattern * @param groupNamePattern * @param contentPattern * @param serverId * @param currentPage * @param sizeOfPerPage * @return */ @SuppressWarnings("unchecked") private PageContextResult<ConfigInfo> processQuery(String dataIdPattern, String groupNamePattern, String contentPattern, String serverId, long currentPage, long sizeOfPerPage) { PageContextResult<ConfigInfo> response = new PageContextResult<ConfigInfo>(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg(",serverId"); return response; } if (log.isDebugEnabled()) log.debug("processQuery(" + dataIdPattern + "," + groupNamePattern + "," + contentPattern + "," + serverId + ")"); boolean hasPattern = PatternUtils.hasCharPattern(dataIdPattern) || PatternUtils.hasCharPattern(groupNamePattern) || PatternUtils.hasCharPattern(contentPattern); String url = null; if (hasPattern) { if (!StringUtils.isBlank(contentPattern)) { log.warn(", , dataIdPattern=" + dataIdPattern + ",groupNamePattern=" + groupNamePattern + ",contentPattern=" + contentPattern); // url = String.format(LIST_LIKE_FORMAT_URL, groupNamePattern, dataIdPattern, 1, Integer.MAX_VALUE); } else url = String.format(LIST_LIKE_FORMAT_URL, groupNamePattern, dataIdPattern, currentPage, sizeOfPerPage); } else { url = String.format(LIST_FORMAT_URL, groupNamePattern, dataIdPattern, currentPage, sizeOfPerPage); } GetMethod method = new GetMethod(url); configureGetMethod(method); try { int status = client.executeMethod(method); response.setStatusCode(status); switch (status) { case HttpStatus.SC_OK: String json = ""; try { json = getContent(method).trim(); Page<ConfigInfo> page = null; if (!json.equals("null")) { page = (Page<ConfigInfo>) JSONUtils.deserializeObject(json, new TypeReference<Page<ConfigInfo>>() { }); } if (page != null) { List<ConfigInfo> diamondData = page.getPageItems(); if (!StringUtils.isBlank(contentPattern)) { Pattern pattern = Pattern.compile(contentPattern.replaceAll("\\*", ".*")); List<ConfigInfo> newList = new ArrayList<ConfigInfo>(); // Collections.sort(diamondData); int totalCount = 0; long begin = sizeOfPerPage * (currentPage - 1); long end = sizeOfPerPage * currentPage; for (ConfigInfo configInfo : diamondData) { if (configInfo.getContent() != null) { Matcher m = pattern.matcher(configInfo.getContent()); if (m.find()) { // sizeOfPerPage if (totalCount >= begin && totalCount < end) { newList.add(configInfo); } totalCount++; } } } page.setPageItems(newList); page.setTotalCount(totalCount); } response.setOriginalDataSize(diamondData.size()); response.setTotalCounts(page.getTotalCount()); response.setCurrentPage(currentPage); response.setSizeOfPerPage(sizeOfPerPage); } else { response.setOriginalDataSize(0); response.setTotalCounts(0); response.setCurrentPage(currentPage); response.setSizeOfPerPage(sizeOfPerPage); } response.operation(); List<ConfigInfo> pageItems = new ArrayList<ConfigInfo>(); if (page != null) { pageItems = page.getPageItems(); } response.setDiamondData(pageItems); response.setSuccess(true); response.setStatusMsg("diamond"); log.info("diamond, url=" + url); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("," + e.getLocalizedMessage()); log.error("page, dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId + ",json=" + json, e); } break; case HttpStatus.SC_REQUEST_TIMEOUT: response.setSuccess(false); response.setStatusMsg("" + require_timeout + ""); log.error(":" + require_timeout + ", dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId); break; default: response.setSuccess(false); response.setStatusMsg("" + status); log.error("" + status + ",dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId); break; } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("," + e.getMessage()); log.error(", dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("," + e.getMessage()); log.error(", dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId, e); } finally { // method.releaseConnection(); } return response; }
From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
/** * ?//from ww w . j a va 2 s . com * * @param dataIdPattern * @param groupNamePattern * @param contentPattern * @param serverId * @param currentPage * @param sizeOfPerPage * @return */ @SuppressWarnings("unchecked") private PageContextResult<ConfigInfo> processQuery(String dataIdPattern, String groupNamePattern, String contentPattern, String serverId, long currentPage, long sizeOfPerPage) { PageContextResult<ConfigInfo> response = new PageContextResult<ConfigInfo>(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg(",??serverId?"); return response; } if (log.isDebugEnabled()) log.debug("processQuery(" + dataIdPattern + "," + groupNamePattern + "," + contentPattern + "," + serverId + ")"); boolean hasPattern = PatternUtils.hasCharPattern(dataIdPattern) || PatternUtils.hasCharPattern(groupNamePattern) || PatternUtils.hasCharPattern(contentPattern); String url = null; if (hasPattern) { if (!StringUtils.isBlank(contentPattern)) { log.warn("?, ??, dataIdPattern=" + dataIdPattern + ",groupNamePattern=" + groupNamePattern + ",contentPattern=" + contentPattern); // ? url = String.format(LIST_LIKE_FORMAT_URL, groupNamePattern, dataIdPattern, 1, Integer.MAX_VALUE); } else url = String.format(LIST_LIKE_FORMAT_URL, groupNamePattern, dataIdPattern, currentPage, sizeOfPerPage); } else { url = String.format(LIST_FORMAT_URL, groupNamePattern, dataIdPattern, currentPage, sizeOfPerPage); } GetMethod method = new GetMethod(url); configureGetMethod(method); try { int status = client.executeMethod(method); response.setStatusCode(status); switch (status) { case HttpStatus.SC_OK: String json = ""; try { json = getContent(method).trim(); Page<ConfigInfo> page = null; if (!json.equals("null")) { page = (Page<ConfigInfo>) JSONUtils.deserializeObject(json, new TypeReference<Page<ConfigInfo>>() { }); } if (page != null) { List<ConfigInfo> diamondData = page.getPageItems(); if (!StringUtils.isBlank(contentPattern)) { Pattern pattern = Pattern.compile(contentPattern.replaceAll("\\*", ".*")); List<ConfigInfo> newList = new ArrayList<ConfigInfo>(); // ? Collections.sort(diamondData); int totalCount = 0; long begin = sizeOfPerPage * (currentPage - 1); long end = sizeOfPerPage * currentPage; for (ConfigInfo configInfo : diamondData) { if (configInfo.getContent() != null) { Matcher m = pattern.matcher(configInfo.getContent()); if (m.find()) { // ?sizeOfPerPage if (totalCount >= begin && totalCount < end) { newList.add(configInfo); } totalCount++; } } } page.setPageItems(newList); page.setTotalCount(totalCount); } response.setOriginalDataSize(diamondData.size()); response.setTotalCounts(page.getTotalCount()); response.setCurrentPage(currentPage); response.setSizeOfPerPage(sizeOfPerPage); } else { response.setOriginalDataSize(0); response.setTotalCounts(0); response.setCurrentPage(currentPage); response.setSizeOfPerPage(sizeOfPerPage); } response.operation(); List<ConfigInfo> pageItems = new ArrayList<ConfigInfo>(); if (page != null) { pageItems = page.getPageItems(); } response.setDiamondData(pageItems); response.setSuccess(true); response.setStatusMsg("diamond?"); log.info("diamond?, url=" + url); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("???,?" + e.getLocalizedMessage()); log.error("???page, dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId + ",json=" + json, e); } break; case HttpStatus.SC_REQUEST_TIMEOUT: response.setSuccess(false); response.setStatusMsg("?" + require_timeout + ""); log.error("?:" + require_timeout + ", dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId); break; default: response.setSuccess(false); response.setStatusMsg("????" + status); log.error("???" + status + ",dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId); break; } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("?,?" + e.getMessage()); log.error("?, dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("?,?" + e.getMessage()); log.error("?, dataId=" + dataIdPattern + ",group=" + groupNamePattern + ",serverId=" + serverId, e); } finally { // ? method.releaseConnection(); } return response; }
From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
/** * //from w w w . j av a 2s. c om * * @param serverId * @param id * @return */ private ContextResult processDelete(String serverId, long id) { ContextResult response = new ContextResult(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg(",serverId"); return response; } log.info("processDelete(" + serverId + "," + id); String url = "/diamond-server/admin.do?method=deleteConfig&id=" + id; GetMethod method = new GetMethod(url); configureGetMethod(method); try { int status = client.executeMethod(method); response.setStatusCode(status); switch (status) { case HttpStatus.SC_OK: response.setSuccess(true); response.setReceiveResult(getContent(method)); response.setStatusMsg(", url=" + url); log.warn(", url=" + url); break; case HttpStatus.SC_REQUEST_TIMEOUT: response.setSuccess(false); response.setStatusMsg("" + require_timeout + ""); log.error(":" + require_timeout + ", id=" + id + ",serverId=" + serverId); break; default: response.setSuccess(false); response.setStatusMsg("" + status); log.error("" + status + ", id=" + id + ",serverId=" + serverId); break; } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("," + e.getMessage()); log.error(", id=" + id + ",serverId=" + serverId, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("," + e.getMessage()); log.error(", id=" + id + ",serverId=" + serverId, e); } finally { // method.releaseConnection(); } return response; }
From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
/** * ?/*from w w w . j a v a 2 s. c o m*/ * * @param serverId * @param id * @return */ private ContextResult processDelete(String serverId, long id) { ContextResult response = new ContextResult(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg(",??serverId?"); return response; } log.info("processDelete(" + serverId + "," + id); String url = "/diamond-server/admin.do?method=deleteConfig&id=" + id; GetMethod method = new GetMethod(url); configureGetMethod(method); try { int status = client.executeMethod(method); response.setStatusCode(status); switch (status) { case HttpStatus.SC_OK: response.setSuccess(true); response.setReceiveResult(getContent(method)); response.setStatusMsg("?, url=" + url); log.warn("???, url=" + url); break; case HttpStatus.SC_REQUEST_TIMEOUT: response.setSuccess(false); response.setStatusMsg("?" + require_timeout + ""); log.error("?:" + require_timeout + ", id=" + id + ",serverId=" + serverId); break; default: response.setSuccess(false); response.setStatusMsg("????" + status); log.error("???" + status + ", id=" + id + ",serverId=" + serverId); break; } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("?,?" + e.getMessage()); log.error("?, id=" + id + ",serverId=" + serverId, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("?,?" + e.getMessage()); log.error("?, id=" + id + ",serverId=" + serverId, e); } finally { // ? method.releaseConnection(); } return response; }
From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
@Override public BatchContextResult<ConfigInfoEx> batchQuery(String serverId, String groupName, List<String> dataIds) { // // w w w . ja v a 2 s. co m BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // listnull if (dataIds == null) { log.error("dataId list cannot be null, serverId=" + serverId + ",group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId list cannot be null"); return response; } // dataIdlist StringBuilder dataIdBuilder = new StringBuilder(); for (String dataId : dataIds) { dataIdBuilder.append(dataId).append(Constants.LINE_SEPARATOR); } String dataIdStr = dataIdBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchQuery"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // NameValuePair dataId_value = new NameValuePair("dataIds", dataIdStr); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // json, BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch query deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // , response.setSuccess(true); response.setStatusMsg("batch query success"); log.info("batch query success, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch query deserialize error"); log.error("batch query deserialize error, serverId=" + serverId + ",dataIdStr=" + dataIdStr + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch query timeout, socket timeout(ms):" + require_timeout); log.error("batch query timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch query fail, status:" + status); log.error("batch query fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch query http exception" + e.getMessage()); log.error("batch query http exception, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch query io exception" + e.getMessage()); log.error("batch query io exception, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName, e); } finally { // post.releaseConnection(); } return response; }
From source file:com.mengka.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
public BatchContextResult<ConfigInfoEx> batchQuery(String serverId, String groupName, List<String> dataIds) { // //w w w . j a va2s.c om BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // list?null if (dataIds == null) { log.error("dataId list cannot be null, serverId=" + serverId + ",group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId list cannot be null"); return response; } // dataIdlist???? StringBuilder dataIdBuilder = new StringBuilder(); for (String dataId : dataIds) { dataIdBuilder.append(dataId).append(Constants.LINE_SEPARATOR); } String dataIdStr = dataIdBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchQuery"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // ? NameValuePair dataId_value = new NameValuePair("dataIds", dataIdStr); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http?? int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // ???json, ??BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch query deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // ????, ?? response.setSuccess(true); response.setStatusMsg("batch query success"); log.info("batch query success, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch query deserialize error"); log.error("batch query deserialize error, serverId=" + serverId + ",dataIdStr=" + dataIdStr + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch query timeout, socket timeout(ms):" + require_timeout); log.error("batch query timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch query fail, status:" + status); log.error("batch query fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch query http exception" + e.getMessage()); log.error("batch query http exception, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch query io exception" + e.getMessage()); log.error("batch query io exception, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName, e); } finally { // ? post.releaseConnection(); } return response; }
From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
@Override public BatchContextResult<ConfigInfoEx> batchQuery(String serverId, String groupName, List<String> dataIds) { // /* w w w. ja v a 2s. com*/ BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // list?null if (dataIds == null) { log.error("dataId list cannot be null, serverId=" + serverId + ",group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId list cannot be null"); return response; } // dataIdlist???? StringBuilder dataIdBuilder = new StringBuilder(); for (String dataId : dataIds) { dataIdBuilder.append(dataId).append(Constants.LINE_SEPARATOR); } String dataIdStr = dataIdBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchQuery"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // ? NameValuePair dataId_value = new NameValuePair("dataIds", dataIdStr); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http?? int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // ???json, ??BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch query deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // ????, ?? response.setSuccess(true); response.setStatusMsg("batch query success"); log.info("batch query success, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch query deserialize error"); log.error("batch query deserialize error, serverId=" + serverId + ",dataIdStr=" + dataIdStr + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch query timeout, socket timeout(ms):" + require_timeout); log.error("batch query timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch query fail, status:" + status); log.error("batch query fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch query http exception" + e.getMessage()); log.error("batch query http exception, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch query io exception" + e.getMessage()); log.error("batch query io exception, serverId=" + serverId + ",dataIds=" + dataIdStr + ",group=" + groupName, e); } finally { // ? post.releaseConnection(); } return response; }
From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
@Override public BatchContextResult<ConfigInfoEx> batchAddOrUpdate(String serverId, String groupName, Map<String, String> dataId2ContentMap) { // //from w w w.j a v a 2 s .c o m BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // mapnull if (dataId2ContentMap == null) { log.error("dataId2ContentMap cannot be null, serverId=" + serverId + " ,group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId2ContentMap cannot be null"); return response; } // dataIdcontentmap StringBuilder allDataIdAndContentBuilder = new StringBuilder(); for (String dataId : dataId2ContentMap.keySet()) { String content = dataId2ContentMap.get(dataId); allDataIdAndContentBuilder.append(dataId + Constants.WORD_SEPARATOR + content) .append(Constants.LINE_SEPARATOR); } String allDataIdAndContent = allDataIdAndContentBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchAddOrUpdate"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // NameValuePair dataId_value = new NameValuePair("allDataIdAndContent", allDataIdAndContent); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // json, BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch write deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // , response.setStatusMsg("batch write success"); log.info("batch write success,serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch write deserialize error"); log.error("batch write deserialize error, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch write timeout, socket timeout(ms):" + require_timeout); log.error("batch write timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch write fail, status:" + status); log.error("batch write fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch write http exception" + e.getMessage()); log.error("batch write http exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch write io exception" + e.getMessage()); log.error("batch write io exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } finally { // post.releaseConnection(); } return response; }
From source file:com.mengka.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
public BatchContextResult<ConfigInfoEx> batchAddOrUpdate(String serverId, String groupName, Map<String, String> dataId2ContentMap) { // // w ww .j av a 2 s .c o m BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // map?null if (dataId2ContentMap == null) { log.error("dataId2ContentMap cannot be null, serverId=" + serverId + " ,group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId2ContentMap cannot be null"); return response; } // dataIdcontentmap???? StringBuilder allDataIdAndContentBuilder = new StringBuilder(); for (String dataId : dataId2ContentMap.keySet()) { String content = dataId2ContentMap.get(dataId); allDataIdAndContentBuilder.append(dataId + Constants.WORD_SEPARATOR + content) .append(Constants.LINE_SEPARATOR); } String allDataIdAndContent = allDataIdAndContentBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchAddOrUpdate"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // ? NameValuePair dataId_value = new NameValuePair("allDataIdAndContent", allDataIdAndContent); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http?? int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // ???json, ??BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch write deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // ????, ??? response.setStatusMsg("batch write success"); log.info("batch write success,serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch write deserialize error"); log.error("batch write deserialize error, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch write timeout, socket timeout(ms):" + require_timeout); log.error("batch write timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch write fail, status:" + status); log.error("batch write fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch write http exception" + e.getMessage()); log.error("batch write http exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch write io exception" + e.getMessage()); log.error("batch write io exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } finally { // ? post.releaseConnection(); } return response; }
From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
@Override public BatchContextResult<ConfigInfoEx> batchAddOrUpdate(String serverId, String groupName, Map<String, String> dataId2ContentMap) { // /* w ww. j a v a 2s. c o m*/ BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // map?null if (dataId2ContentMap == null) { log.error("dataId2ContentMap cannot be null, serverId=" + serverId + " ,group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId2ContentMap cannot be null"); return response; } // dataIdcontentmap???? StringBuilder allDataIdAndContentBuilder = new StringBuilder(); for (String dataId : dataId2ContentMap.keySet()) { String content = dataId2ContentMap.get(dataId); allDataIdAndContentBuilder.append(dataId + Constants.WORD_SEPARATOR + content) .append(Constants.LINE_SEPARATOR); } String allDataIdAndContent = allDataIdAndContentBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchAddOrUpdate"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // ? NameValuePair dataId_value = new NameValuePair("allDataIdAndContent", allDataIdAndContent); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http?? int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // ???json, ??BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch write deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // ????, ??? response.setStatusMsg("batch write success"); log.info("batch write success,serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch write deserialize error"); log.error("batch write deserialize error, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch write timeout, socket timeout(ms):" + require_timeout); log.error("batch write timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch write fail, status:" + status); log.error("batch write fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch write http exception" + e.getMessage()); log.error("batch write http exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch write io exception" + e.getMessage()); log.error("batch write io exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } finally { // ? post.releaseConnection(); } return response; }