private String createSecret() { byte[] nonce = new byte[16]; for (int i = 0; i < 16; i++) { nonce[i] = (byte) (Math.random() * 256); } return Base64.encodeToString(nonce, Base64.DEFAULT).trim(); }
public void request2(String uri, int reqNum, int reqTerm) throws Exception { HttpClientContext context = HttpClientContext.create(); HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(); HttpRoute route = new HttpRoute(new HttpHost(uri, 80)); // Request new connection. This can be a long process if (reqNum == 0) { System.out.println( String.format("request to %s infinite times with term '%d' ms", uri, reqTerm)); } else { System.out.println( String.format("request to %s '%d' times with term '%d' ms", uri, reqNum, reqTerm)); } int i = 0, tick = 0; while (true) { usleep(reqTerm); tick = (int) (Math.random() * 10) % 2; if (tick == 0) { continue; } System.out.println("111111111"); ConnectionRequest connRequest = connManager.requestConnection(route, null); // Wait for connection up to 10 sec HttpClientConnection conn = connRequest.get(10, TimeUnit.SECONDS); System.out.println("222222222"); try { if (!conn.isOpen()) // If not open { System.out.println("333333333"); // establish connection based on its route info connManager.connect(conn, route, 1000, context); // and mark it as route complete connManager.routeComplete(conn, route, context); } // Do useful things with the connection. System.out.println("request " + uri); System.out.println( "--> response status = " + conn.receiveResponseHeader().getStatusLine()); } finally { connManager.releaseConnection(conn, null, 1, TimeUnit.MINUTES); } System.out.println("----------------------------------------"); if (reqNum != 0 && reqNum < ++i) { break; } } }
public boolean initialize() { try { initParams = new RemoteWrapperParamParser(getActiveAddressBean(), true); uid = Math.random(); postParameters = new ArrayList<NameValuePair>(); postParameters.add( new BasicNameValuePair(PushDelivery.NOTIFICATION_ID_KEY, Double.toString(uid))); postParameters.add( new BasicNameValuePair( PushDelivery.LOCAL_CONTACT_POINT, initParams.getLocalContactPoint())); // Init the http client if (initParams.isSSLRequired()) { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load( new FileInputStream(new File("conf/servertestkeystore")), Main.getContainerConfig().getSSLKeyStorePassword().toCharArray()); SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); int sslPort = Main.getContainerConfig().getSSLPort() > 0 ? Main.getContainerConfig().getSSLPort() : ContainerConfig.DEFAULT_SSL_PORT; Scheme sch = new Scheme("https", socketFactory, sslPort); httpclient.getConnectionManager().getSchemeRegistry().register(sch); } Scheme plainsch = new Scheme( "http", PlainSocketFactory.getSocketFactory(), Main.getContainerConfig().getContainerPort()); httpclient.getConnectionManager().getSchemeRegistry().register(plainsch); // lastReceivedTimestamp = initParams.getStartTime(); structure = registerAndGetStructure(); } catch (Exception e) { logger.error(e.getMessage(), e); NotificationRegistry.getInstance().removeNotification(uid); return false; } return true; }
public void request1(String uri, int reqNum, int reqTerm) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); if (reqNum == 0) { System.out.println( String.format("request to %s infinite times with term '%d' ms", uri, reqTerm)); } else { System.out.println( String.format("request to %s '%d' times with term '%d' ms", uri, reqNum, reqTerm)); } int i = 0, tick = 0; HttpGet httpGet = new HttpGet(uri); CloseableHttpResponse response; HttpEntity entity; while (true) { usleep(reqTerm); tick = (int) (Math.random() * 10) % 2; if (tick == 0) { continue; } System.out.println("request " + httpGet.getURI()); response = httpclient.execute(httpGet); System.out.println("--> response status = " + response.getStatusLine()); // response handler try { entity = response.getEntity(); EntityUtils.consume(entity); } catch (Exception e) { System.out.println(" --> http fail:" + e.getMessage()); } finally { // Thread.sleep(5000); //테스트에만 썼다. close 지연시키려고. response.close(); } System.out.println("----------------------------------------"); if (reqNum != 0 && reqNum < ++i) { break; } } }
// public List getUserStoryList(String sessionId,String iterationId,ServletOutputStream out) { public List getUserStoryList(String sessionId, String iterationId, PrintWriter out) { List<Map> list = new ArrayList<Map>(); statusMap.put(sessionId, "0"); try { String apiURL = rallyApiHost + "/hierarchicalrequirement?" + "query=(Iteration%20=%20" + rallyApiHost + "/iteration/" + iterationId + ")&fetch=true&start=1&pagesize=100"; log.info("getUserStoryList apiURL=" + apiURL); String responseXML = getRallyXML(apiURL); org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder(); org.jdom.Document doc = bSAX.build(new StringReader(responseXML)); Element root = doc.getRootElement(); XPath xpath = XPath.newInstance("//Object"); List xlist = xpath.selectNodes(root); int totalSteps = xlist.size() + 1; int currentStep = 0; List taskRefLink = new ArrayList(); Iterator iter = xlist.iterator(); while (iter.hasNext()) { double totalTimeSpent = 0.0D; Map map = new HashMap(); Element item = (Element) iter.next(); String objId = item.getChildText("ObjectID"); String name = item.getChildText("Name"); String planEstimate = item.getChildText("PlanEstimate"); String formattedId = item.getChildText("FormattedID"); String taskActualTotal = item.getChildText("TaskActualTotal"); String taskEstimateTotal = item.getChildText("TaskEstimateTotal"); String taskRemainingTotal = item.getChildText("TaskRemainingTotal"); String scheduleState = item.getChildText("ScheduleState"); Element ownerElement = item.getChild("Owner"); String owner = ""; String ownerRef = ""; if (ownerElement != null) { owner = ownerElement.getAttributeValue("refObjectName"); } Element taskElements = item.getChild("Tasks"); // List taskElementList=taskElements.getContent(); List taskElementList = taskElements.getChildren(); List taskList = new ArrayList(); log.info("taskElements.getChildren=" + taskElements); log.info("taskList=" + taskElementList); for (int i = 0; i < taskElementList.size(); i++) { Element taskElement = (Element) taskElementList.get(i); String taskRef = taskElement.getAttributeValue("ref"); String[] objectIdArr = taskRef.split("/"); String objectId = objectIdArr[objectIdArr.length - 1]; log.info("objectId=" + objectId); // Map taskMap=getTaskMap(taskRef); Map taskMap = getTaskMapBatch(objectId); double taskTimeSpentTotal = Double.parseDouble((String) taskMap.get("taskTimeSpentTotal")); totalTimeSpent += taskTimeSpentTotal; taskList.add(taskMap); } map.put("type", "userstory"); map.put("formattedId", formattedId); map.put("name", name); map.put("taskStatus", scheduleState); map.put("owner", owner); map.put("planEstimate", planEstimate); map.put("taskEstimateTotal", taskEstimateTotal); map.put("taskRemainingTotal", taskRemainingTotal); map.put("taskTimeSpentTotal", "" + totalTimeSpent); list.add(map); list.addAll(taskList); ++currentStep; double percentage = 100.0D * currentStep / totalSteps; String status = "" + Math.round(percentage); statusMap.put(sessionId, status); out.println("<script>parent.updateProcessStatus('" + status + "%')</script>" + status); out.flush(); log.info("out.flush..." + status); // log.info("status="+status+" sessionId="+sessionId); // log.info("L1 statusMap="+statusMap+" "+statusMap.hashCode()); } double planEstimate = 0.0D; double taskEstimateTotal = 0.0D; double taskRemainingTotal = 0.0D; double taskTimeSpentTotal = 0.0D; Map iterationMap = new HashMap(); for (Map map : list) { String type = (String) map.get("type"); String planEstimateStr = (String) map.get("planEstimate"); log.info("planEstimateStr=" + planEstimateStr); if ("userstory".equals(type)) { if (planEstimateStr != null) { planEstimate += Double.parseDouble(planEstimateStr); } taskEstimateTotal += Double.parseDouble((String) map.get("taskEstimateTotal")); taskRemainingTotal += Double.parseDouble((String) map.get("taskRemainingTotal")); taskTimeSpentTotal += Double.parseDouble((String) map.get("taskTimeSpentTotal")); } } apiURL = rallyApiHost + "/iteration/" + iterationId + "?fetch=true"; log.info("iteration apiURL=" + apiURL); responseXML = getRallyXML(apiURL); bSAX = new org.jdom.input.SAXBuilder(); doc = bSAX.build(new StringReader(responseXML)); root = doc.getRootElement(); xpath = XPath.newInstance("//Iteration"); xlist = xpath.selectNodes(root); String projName = ""; String iterName = ""; String iterState = ""; iter = xlist.iterator(); while (iter.hasNext()) { Element item = (Element) iter.next(); iterName = item.getChildText("Name"); iterState = item.getChildText("State"); Element projElement = item.getChild("Project"); projName = projElement.getAttributeValue("refObjectName"); } iterationMap.put("type", "iteration"); iterationMap.put("formattedId", ""); iterationMap.put("name", projName + " - " + iterName); iterationMap.put("taskStatus", iterState); iterationMap.put("owner", ""); iterationMap.put("planEstimate", "" + planEstimate); iterationMap.put("taskEstimateTotal", "" + taskEstimateTotal); iterationMap.put("taskRemainingTotal", "" + taskRemainingTotal); iterationMap.put("taskTimeSpentTotal", "" + taskTimeSpentTotal); list.add(0, iterationMap); statusMap.put(sessionId, "100"); log.info("L2 statusMap=" + statusMap); log.info("L2 verify=" + getProcessStatus(sessionId)); log.info("-----------"); // String jsonData=JsonUtil.encodeObj(list); String jsonData = JSONValue.toJSONString(list); out.println("<script>parent.tableResult=" + jsonData + "</script>"); out.println("<script>parent.showTableResult()</script>"); } catch (Exception ex) { log.error("ERROR: ", ex); } return list; }