List of usage examples for javax.json Json createReader
public static JsonReader createReader(InputStream in)
From source file:wsserver.EKF1TimerSessionBean.java
private boolean postMultipartPrAdd(List<CbNewPrFrom1cWprops> npwps) { String charset = "UTF-8"; String requestURL = systemURL + "bitrix/ekflibraries/corpbus/manipulate_data.php"; boolean reply = true; String sreply = ""; if (npwps.isEmpty()) return reply; String logStr = "New prod cnt=" + npwps_.size() + ". "; try {// ww w . ja v a 2 s .c o m MultipartUtility multipart = new MultipartUtility(requestURL, charset); multipart.addHeaderField("User-Agent", "CodeJava"); multipart.addHeaderField("Test-Header", "Header-Value"); int index = 0; multipart.addFormField("OTYPE", "ADD"); multipart.addFormField("ENTITY", "1CPROD"); int ocnt = npwps.size(); //String logStr = ""; long allFileSize = 0; boolean uploadFiles = true; multipart.addFormField("OCNT", "50"); for (CbNewPrFrom1cWprops npwp : npwps) { long productFilesSize = 0; boolean error_file_operation = false; try { if (npwp.getFp0().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp0().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + productFilesSize + f.length()) < maxPostFilePartSize)) { productFilesSize += f.length(); } } if (npwp.getFp1().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp1().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + productFilesSize + f.length()) < maxPostFilePartSize)) { productFilesSize += f.length(); } } if (npwp.getFp2().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp2().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + productFilesSize + f.length()) < maxPostFilePartSize)) { productFilesSize += f.length(); } } if (npwp.getFp3().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp3().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + productFilesSize + f.length()) < maxPostFilePartSize)) { productFilesSize += f.length(); } } if (npwp.getFp4().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp4().replace("\\", "/")); if (f.length() <= 2000000 && ((allFileSize + productFilesSize + f.length()) < maxPostFilePartSize)) { productFilesSize += f.length(); } } } catch (Exception fle) { productFilesSize = 0; error_file_operation = true; logStr += ("NAME " + npwp.getName() + " - Error prev file operation!!! " + fle); } if ((allFileSize + productFilesSize) > maxPostFilePartSize) { logStr += ("NAME " + npwp.getName() + " - too big product files sizes summ!!!"); //continue; } else { multipart.addFormField("PIDPREV1" + index, npwp.getId()); multipart.addFormField("PIDPREV2" + index, npwp.getId()); multipart.addFormField("PID" + index, npwp.getId()); multipart.addFormField("PART" + index, npwp.getVendorCode()); multipart.addFormField("PNAME" + index, npwp.getName()); logStr += ("[" + index + "] NAME " + npwp.getId() + npwp.getName() + "," + npwp.getBasePrice() + "," + npwp.getIshopPrice() + "," + npwp.getQuant() + "," + npwp.getBxGroupExternalCode() + "," + npwp.getVendorCode());//+",[["+npwp.getJsonData()+"]]" multipart.addFormField("PSHNAME" + index, npwp.getShortName()); multipart.addFormField("PPROPS" + index, npwp.getJsonData()); multipart.addFormField("PGRPID" + index, npwp.getProductGroupId()); multipart.addFormField("PBPRICE" + index, "" + npwp.getBasePrice()); multipart.addFormField("PISPRICE" + index, "" + npwp.getIshopPrice()); multipart.addFormField("PQUANT" + index, "" + npwp.getQuant()); multipart.addFormField("PGRXMLID" + index, npwp.getBxGroupExternalCode()); if (!error_file_operation) { try { if (npwp.getFp0().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp0().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { multipart.addFilePart("DETAIL_PICTURE" + index, (f)); logStr += ",fp0" + npwp.getFp0(); allFileSize += f.length(); } else { logStr += ",fp0 " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } if (npwp.getFp1().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp1().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { multipart.addFilePart("PHOTO" + index + "_01", (f)); logStr += ",fp1=" + npwp.getFp1(); allFileSize += f.length(); } else { logStr += ",fp1 " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } if (npwp.getFp2().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp2().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { multipart.addFilePart("PHOTO" + index + "_02", (f)); logStr += ",fp2=" + npwp.getFp2(); allFileSize += f.length(); } else { logStr += ",fp2 " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } if (npwp.getFp3().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp3().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { multipart.addFilePart("PHOTO" + index + "_03", (f)); logStr += ",fp3=" + npwp.getFp3(); allFileSize += f.length(); } else { logStr += ",fp3 " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } if (npwp.getFp4().length() > 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getFp4().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { multipart.addFilePart("PHOTO" + index + "_04", (f)); logStr += ",fp4=" + npwp.getFp4(); allFileSize += f.length(); } else { logStr += ",fp4 " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } } catch (Exception fle) { //error_file_operation=true; logStr += ("NAME " + npwp.getName() + " - Error file operation!!! " + fle); } } index++; } if (allFileSize > maxPostFilePartSize) { logStr += ("End of request construction - too big prev products files sizes summ!!!"); break; } } try { if (logStr.length() > 0) cbLogsFacade.insertLog("INFO", "NEW PROD TO SEND ", "<p style=\"font-size:10px !important;\">" + index + "cnt," + logStr + "</p>" + ", allFilesSizes(bytes)=" + allFileSize); } catch (Exception lgen) { } //multipart.addFormField("OCNT",""+index); multipart.addFormField("OCNT", "50");//+50); List<String> response = multipart.finish(); for (String line : response) { sreply = sreply + line; } try { JsonReader jsonReader = Json.createReader(new StringReader(sreply)); JsonObject jobject = jsonReader.readObject(); try { cbLogsFacade.insertLog("INFO", "SUCCESS OF PARSE SERVER REPLY", "SUCCESS OF PARSE SERVER REPLY=" + jobject.toString()); } catch (Exception lge) { } try { if (jobject.getString("critical_info", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_INFO", "SERVER REPLY DETAIL", jobject.getString("critical_info", "")); } catch (Exception lge) { } try { if (jobject.getString("critical_errs", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_ERRS", "SERVER REPLY DETAIL", jobject.getString("critical_errs", "")); } catch (Exception lge) { } } catch (Exception pe) { try { cbLogsFacade.insertLog("ERROR", "ERROR OF PARSE SERVER REPLY", "ERROR OF PARSE SERVER REPLY" + sreply); } catch (Exception lge) { } } } catch (Exception ex) { try { cbLogsFacade.insertLog("ERROR", "ERROR of postMultipartPrAdd", logStr + " ERROR of postMultipartPrAdd" + ex); } catch (Exception lge) { } } return reply; }
From source file:com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject.java
/** * this method should be called after clicktracking test, in order to verify if expected events * were tracked//from w w w . j av a2 s .c om */ public void compareTrackedEventsTo(List<JsonObject> expectedEventsList) { jsActions.execute(ClickTrackingScriptsProvider.EVENTS_CAPTURE_INSTALLATION); List<JsonObject> trackedEventsArrayList = new ArrayList<JsonObject>(); List<JsonObject> trackedEventsList; JavascriptExecutor js = (JavascriptExecutor) driver; // prepare list of tracked events Object event = js.executeScript("return selenium_popEvent()"); StringReader reader = new StringReader(event.toString()); JsonReader jsonReader = Json.createReader(reader); while (!(event == null)) { reader = new StringReader(event.toString()); jsonReader = Json.createReader(reader); trackedEventsArrayList.add(jsonReader.readObject()); // take next tracked event event = js.executeScript("return selenium_popEvent()"); } trackedEventsList = trackedEventsArrayList; ClickTrackingSupport support = new ClickTrackingSupport(); support.compare(expectedEventsList, trackedEventsList); }
From source file:io.bibleget.BibleGetDB.java
public boolean renewMetaData() { if (instance.connect()) { try {/* w ww. j a va 2 s . c om*/ DatabaseMetaData dbMeta; dbMeta = instance.conn.getMetaData(); try (ResultSet rs3 = dbMeta.getTables(null, null, "METADATA", null)) { if (rs3.next()) { //System.out.println("Table METADATA exists..."); try (Statement stmt = instance.conn.createStatement()) { HTTPCaller myHTTPCaller = new HTTPCaller(); String myResponse; myResponse = myHTTPCaller.getMetaData("biblebooks"); if (myResponse != null) { JsonReader jsonReader = Json.createReader(new StringReader(myResponse)); JsonObject json = jsonReader.readObject(); JsonArray arrayJson = json.getJsonArray("results"); if (arrayJson != null) { ListIterator pIterator = arrayJson.listIterator(); while (pIterator.hasNext()) { try (Statement stmt1 = instance.conn.createStatement()) { int index = pIterator.nextIndex(); JsonArray currentJson = (JsonArray) pIterator.next(); String biblebooks_str = currentJson.toString(); //.replaceAll("\"", "\\\\\""); //System.out.println("BibleGetDB line 267: BIBLEBOOKS"+Integer.toString(index)+"='"+biblebooks_str+"'"); String stmt_str = "UPDATE METADATA SET BIBLEBOOKS" + Integer.toString(index) + "='" + biblebooks_str + "' WHERE ID=0"; //System.out.println("executing update: "+stmt_str); int update = stmt1.executeUpdate(stmt_str); //System.out.println("executeUpdate resulted in: "+Integer.toString(update)); stmt1.close(); } } } arrayJson = json.getJsonArray("languages"); if (arrayJson != null) { try (Statement stmt2 = instance.conn.createStatement()) { String languages_str = arrayJson.toString(); //.replaceAll("\"", "\\\\\""); String stmt_str = "UPDATE METADATA SET LANGUAGES='" + languages_str + "' WHERE ID=0"; int update = stmt2.executeUpdate(stmt_str); stmt2.close(); } } } myResponse = myHTTPCaller.getMetaData("bibleversions"); if (myResponse != null) { JsonReader jsonReader = Json.createReader(new StringReader(myResponse)); JsonObject json = jsonReader.readObject(); JsonObject objJson = json.getJsonObject("validversions_fullname"); if (objJson != null) { String bibleversions_str = objJson.toString(); //.replaceAll("\"", "\\\\\""); try (Statement stmt3 = instance.conn.createStatement()) { String stmt_str = "UPDATE METADATA SET VERSIONS='" + bibleversions_str + "' WHERE ID=0"; int update = stmt3.executeUpdate(stmt_str); stmt3.close(); } Set<String> versionsabbrev = objJson.keySet(); if (!versionsabbrev.isEmpty()) { String versionsabbrev_str = ""; for (String s : versionsabbrev) { versionsabbrev_str += ("".equals(versionsabbrev_str) ? "" : ",") + s; } myResponse = myHTTPCaller .getMetaData("versionindex&versions=" + versionsabbrev_str); if (myResponse != null) { jsonReader = Json.createReader(new StringReader(myResponse)); json = jsonReader.readObject(); objJson = json.getJsonObject("indexes"); if (objJson != null) { for (String name : objJson.keySet()) { JsonObjectBuilder tempBld = Json.createObjectBuilder(); JsonObject book_num = objJson.getJsonObject(name); tempBld.add("book_num", book_num.getJsonArray("book_num")); tempBld.add("chapter_limit", book_num.getJsonArray("chapter_limit")); tempBld.add("verse_limit", book_num.getJsonArray("verse_limit")); JsonObject temp = tempBld.build(); String versionindex_str = temp.toString(); //.replaceAll("\"", "\\\\\""); //add new column to METADATA table name+"IDX" VARCHAR(5000) //update METADATA table SET name+"IDX" = versionindex_str try (ResultSet rs1 = dbMeta.getColumns(null, null, "METADATA", name + "IDX")) { boolean updateFlag = false; if (rs1.next()) { //column already exists updateFlag = true; } else { try (Statement stmt4 = instance.conn .createStatement()) { String sql = "ALTER TABLE METADATA ADD COLUMN " + name + "IDX VARCHAR(5000)"; boolean colAdded = stmt4.execute(sql); if (colAdded == false) { int count = stmt4.getUpdateCount(); if (count == -1) { //System.out.println("The result is a ResultSet object or there are no more results."); } else if (count == 0) { //0 rows affected updateFlag = true; } } stmt4.close(); } } if (updateFlag) { try (Statement stmt5 = instance.conn .createStatement()) { String sql1 = "UPDATE METADATA SET " + name + "IDX='" + versionindex_str + "' WHERE ID=0"; boolean rowsUpdated = stmt5.execute(sql1); stmt5.close(); } } } } } } } } } stmt.close(); } } rs3.close(); } instance.disconnect(); } catch (SQLException ex) { Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex); return false; } return true; } return false; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public JsonValue jsonValue(String value) throws BtcException { try (JsonReader reader = Json.createReader(new StringReader(value))) { return reader.read(); } catch (Throwable t) { throw new BtcException(BtcException.BTC4J_ERROR_CODE, BtcException.BTC4J_ERROR_MESSAGE + ": " + t.getMessage(), t); }/*w w w.jav a 2s . c o m*/ }
From source file:wsserver.EKF1TimerSessionBean.java
private boolean postMultipartPrUpd(List<CbEkfgroupToUpdatedBx1c> upwps) { String charset = "UTF-8"; String requestURL = systemURL + "bitrix/ekflibraries/corpbus/manipulate_data.php"; boolean reply = true; String sreply = ""; if (upwps.isEmpty()) return reply; String logStr = "Upd prod cnt=" + upwps.size() + ". "; try {/* w ww. j ava 2 s .co m*/ MultipartUtility multipart = new MultipartUtility(requestURL, charset); multipart.addHeaderField("User-Agent", "CodeJava"); multipart.addHeaderField("Test-Header", "Header-Value"); int index = 0; multipart.addFormField("OTYPE", "UPDATE"); multipart.addFormField("ENTITY", "1CPROD"); int ocnt = upwps.size(); multipart.addFormField("OCNT", "" + ocnt); //String logStr=""; long allFileSize = 0; boolean uploadFiles = true; for (CbEkfgroupToUpdatedBx1c npwp : upwps) { try { long productFilesSize = 0; boolean error_file_operation = false; try { if (!npwp.getF1cMainPict().equals(npwp.getBxMainPict()) && npwp.getF1cMainPict().length() > 10 && uploadFiles) { File f = new File(mountImgPath + npwp.getF1cMainPict().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + productFilesSize + f.length()) < maxPostFilePartSize)) { productFilesSize += f.length(); } } /*if(npwp.getF1cAddPict1().length()>0&&uploadFiles&&false) { File f = new File(mountImgPath+npwp.getF1cAddPict1().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+productFilesSize+f.length())<maxPostFilePartSize)) { productFilesSize+=f.length(); } } if(npwp.getF1cAddPict1().length()>0&&uploadFiles&&false) { File f = new File(mountImgPath+npwp.getF1cAddPict1().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+productFilesSize+f.length())<maxPostFilePartSize)) { productFilesSize+=f.length(); } } if(npwp.getF1cAddPict1().length()>0&&uploadFiles&&false) { File f = new File(mountImgPath+npwp.getF1cAddPict1().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+productFilesSize+f.length())<maxPostFilePartSize)) { productFilesSize+=f.length(); } } if(npwp.getF1cAddPict1().length()>0&&uploadFiles&&false) { File f = new File(mountImgPath+npwp.getF1cAddPict1().replace("\\", "/")); if(f.length()<=2000000&&((allFileSize+productFilesSize+f.length())<maxPostFilePartSize)) { productFilesSize+=f.length(); } }*/ } catch (Exception fle) { productFilesSize = 0; error_file_operation = true; logStr += ("NAME " + npwp.getName() + " - Error prev file operation!!! " + fle); if (!npwp.getF1cMainPict().equals(npwp.getBxMainPict()) && npwp.getBxMainPict().length() <= 5) { multipart.addFormField("SETMAIN_PICT_ERR" + index, "1"); multipart.addFormField("MAIN_PICT" + index, StringEscapeUtils.escapeJava( (npwp.getBxMainPict() == null || (npwp.getBxMainPict().length() > 10) ? "a" : npwp.getBxMainPict() + "a"))); } } if ((allFileSize + productFilesSize) > maxPostFilePartSize) { logStr += ("NAME " + npwp.getName() + " - too big product files sizes summ!!!"); //continue; } else { if (!error_file_operation) { try { if (!npwp.getF1cMainPict().equals(npwp.getBxMainPict()) && npwp.getF1cMainPict().length() > 10 && uploadFiles) { File f = new File(mountImgPath + npwp.getF1cMainPict().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { multipart.addFilePart("DETAIL_PICTURE" + index, (f)); multipart.addFormField("SETDETAIL_PICTURE" + index, "1"); multipart.addFormField("SETMAIN_PICT" + index, "1"); multipart.addFormField("MAIN_PICT" + index, StringEscapeUtils.escapeJava(npwp.getF1cMainPict())); logStr += ",fp0" + npwp.getF1cMainPict(); allFileSize += f.length(); } else { logStr += ",fp0 " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } /*if(npwp.getFp1().length()>0&&uploadFiles) { File f = new File(mountImgPath+npwp.getFp1().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+f.length())<maxPostFilePartSize)) { multipart.addFilePart("PHOTO"+index+"_01", (f) ); logStr+=",fp1="+npwp.getFp1(); allFileSize+=f.length(); } else { logStr+=",fp1 "+f.length()+" more "+maxPostedFileSize/1000000+"Mbytes or too big allFileSize"; } } if(npwp.getFp2().length()>0&&uploadFiles) { File f = new File(mountImgPath+npwp.getFp2().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+f.length())<maxPostFilePartSize)) { multipart.addFilePart("PHOTO"+index+"_02", (f) ); logStr+=",fp2="+npwp.getFp2(); allFileSize+=f.length(); } else { logStr+=",fp2 "+f.length()+" more "+maxPostedFileSize/1000000+"Mbytes or too big allFileSize"; } } if(npwp.getFp3().length()>0&&uploadFiles) { File f = new File(mountImgPath+npwp.getFp3().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+f.length())<maxPostFilePartSize)) { multipart.addFilePart("PHOTO"+index+"_03", (f) ); logStr+=",fp3="+npwp.getFp3(); allFileSize+=f.length(); } else { logStr+=",fp3 "+f.length()+" more "+maxPostedFileSize/1000000+"Mbytes or too big allFileSize"; } } if(npwp.getFp4().length()>0&&uploadFiles) { File f = new File(mountImgPath+npwp.getFp4().replace("\\", "/")); if(f.length()<=maxPostedFileSize&&((allFileSize+f.length())<maxPostFilePartSize)) { multipart.addFilePart("PHOTO"+index+"_04", (f) ); logStr+=",fp4="+npwp.getFp4(); allFileSize+=f.length(); } else { logStr+=",fp4 "+f.length()+" more "+maxPostedFileSize/1000000+"Mbytes or too big allFileSize"; } }*/ } catch (Exception fle) { error_file_operation = true; logStr += ("NAME " + npwp.getName() + " - Error file operation!!! " + fle); if (!npwp.getF1cMainPict().equals(npwp.getBxMainPict()) && npwp.getBxMainPict().length() <= 5) { multipart.addFormField("SETMAIN_PICT_ERR" + index, "1"); multipart.addFormField("MAIN_PICT" + index, StringEscapeUtils.escapeJava((npwp.getBxMainPict() == null || (npwp.getBxMainPict().length() > 10) ? "a" : npwp.getBxMainPict() + "a"))); } } } } updProdsIds.add(npwp.getF1cId()); multipart.addFormField("PIDPREV1" + index, "" + npwp.getId()); multipart.addFormField("PIDPREV2" + index, "" + npwp.getId()); if (!npwp.getF1cMainPict().equals(npwp.getBxMainPict()) && (npwp.getF1cMainPict().length() <= 10 || (npwp.getBxMainPict().length() >= 5 && npwp.getBxMainPict().length() <= 15))) { multipart.addFormField("SETMAIN_PICT_DIR" + index, "1"); multipart.addFormField("MAIN_PICT" + index, StringEscapeUtils.escapeJava(npwp.getF1cMainPict())); } multipart.addFormField("PID" + index, "" + npwp.getId()); multipart.addFormField("PXMLID" + index, npwp.getF1cId()); multipart.addFormField("PART" + index, npwp.getArtikul()); multipart.addFormField("PNAME" + index, npwp.getName()); if (npwp.getToUpdate() == 1 || (Math.abs(npwp.getBxPropCnt() - npwp.getF1cPropCnt()) > 1)) multipart.addFormField("PPROPS" + index, npwp.getJsonData()); logStr += "[" + index + "] NAME " + npwp.getName() + "," + npwp.getBasePrice() + "," + npwp.getIshopPrice() + "," + npwp.getQuant() + "," + npwp.getBxGroupExternalCode() + npwp.getArtikul() + "[" + npwp.getToUpdate() + "[" + npwp.getJsonData() + "]]bxpcnt=" + npwp.getBxPropCnt() + ",1fpcnt=" + npwp.getF1cPropCnt();// if (npwp.getBasePrice() != npwp.getBbsprice()) multipart.addFormField("SETPBPRICE" + index, "1"); else multipart.addFormField("SETPBPRICE" + index, "0"); if (npwp.getIshopPrice() != npwp.getBisprice()) multipart.addFormField("SETPISPRICE" + index, "1"); else multipart.addFormField("SETPISPRICE" + index, "0"); if (npwp.getQuant() != npwp.getBamount()) multipart.addFormField("SETPQUANT" + index, "1"); else multipart.addFormField("SETPQUANT" + index, "0"); multipart.addFormField("PBPRICE" + index, "" + npwp.getBasePrice()); multipart.addFormField("PISPRICE" + index, "" + npwp.getIshopPrice()); multipart.addFormField("PQUANT" + index, "" + npwp.getQuant()); if (!npwp.getBxGroupExternalCode().equals(npwp.getParent1cId())) multipart.addFormField("SETPGRXMLID" + index, "1"); else multipart.addFormField("SETPGRXMLID" + index, "0"); multipart.addFormField("PGRXMLID" + index, npwp.getBxGroupExternalCode()); if (!npwp.getBxName().equals(npwp.getName()) && npwp.getName().length() > 0) multipart.addFormField("SETPNAME" + index, "1"); else multipart.addFormField("SETPNAME" + index, "0"); if (npwp.getBxSortOrder() != npwp.getF1cSortOrder()) multipart.addFormField("SETSORT_ORDER" + index, "1"); else multipart.addFormField("SETSORT_ORDER" + index, "0"); multipart.addFormField("SORT_ORDER" + index, "" + npwp.getF1cSortOrder()); } catch (Exception ex) { try { cbLogsFacade.insertLog("ERROR", "ERROR of postMultipartPrUpd set data", "ERROR of postMultipartPrUpd set data " + ex); return false; } catch (Exception lge) { } } index++; } try { if (logStr.length() > 0) cbLogsFacade.insertLog("INFO", "UPD PROD TO SEND ", "<p style=\"font-size:10px !important;\">" + logStr + "</p>"); } catch (Exception lgen) { } List<String> response = multipart.finish(); for (String line : response) { sreply = sreply + line; } try { JsonReader jsonReader = Json.createReader(new StringReader(sreply)); JsonObject jobject = jsonReader.readObject(); try { cbLogsFacade.insertLog("INFO", "SUCCESS OF PARSE SERVER REPLY", "SUCCESS OF PARSE SERVER REPLY=" + jobject.toString()); } catch (Exception lge) { } try { if (jobject.getString("critical_info", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_INFO", "SERVER REPLY DETAIL", jobject.getString("critical_info", "")); } catch (Exception lge) { } try { if (jobject.getString("critical_errs", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_ERRS", "SERVER REPLY DETAIL", jobject.getString("critical_errs", "")); } catch (Exception lge) { } } catch (Exception pe) { try { cbLogsFacade.insertLog("ERROR", "ERROR OF PARSE SERVER REPLY", "ERROR OF PARSE SERVER REPLY" + sreply); } catch (Exception lge) { } } } catch (Exception ex) { try { cbLogsFacade.insertLog("ERROR", "ERROR of postMultipartPrUpd", logStr + " ERROR of postMultipartPrUpd " + ex.getMessage()); } catch (Exception lge) { } } return reply; }
From source file:wsserver.EKF1TimerSessionBean.java
private boolean postMultipartPrDel(List<CbEkfroupDelFromBxView> dpwps) { String charset = "UTF-8"; String requestURL = systemURL + "bitrix/ekflibraries/corpbus/manipulate_data.php"; boolean reply = true; String sreply = ""; if (dpwps.isEmpty()) return reply; String logStr = "Del prod cnt=" + dpwps.size() + ". "; try {//from www. ja v a 2s .com MultipartUtility multipart = new MultipartUtility(requestURL, charset); multipart.addHeaderField("User-Agent", "CodeJava"); multipart.addHeaderField("Test-Header", "Header-Value"); int index = 0; multipart.addFormField("OTYPE", "DELETE"); multipart.addFormField("ENTITY", "1CPROD"); int ocnt = dpwps.size(); multipart.addFormField("OCNT", "" + ocnt); //String logStr=""; for (CbEkfroupDelFromBxView npwp : dpwps) { multipart.addFormField("PID" + index, npwp.getId()); logStr += "[" + index + "] PID " + npwp.getId(); index++; } try { if (logStr.length() > 0) cbLogsFacade.insertLog("INFO", "DEL PROD TO SEND ", logStr); } catch (Exception lgen) { } List<String> response = multipart.finish(); for (String line : response) { sreply = sreply + line; } try { JsonReader jsonReader = Json.createReader(new StringReader(sreply)); JsonObject jobject = jsonReader.readObject(); try { cbLogsFacade.insertLog("INFO", "SUCCESS OF PARSE SERVER REPLY", "SUCCESS OF PARSE SERVER REPLY=" + jobject.toString()); } catch (Exception lge) { } try { if (jobject.getString("critical_info", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_INFO", "SERVER REPLY DETAIL", jobject.getString("critical_info", "")); } catch (Exception lge) { } try { if (jobject.getString("critical_errs", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_ERRS", "SERVER REPLY DETAIL", jobject.getString("critical_errs", "")); } catch (Exception lge) { } } catch (Exception pe) { try { cbLogsFacade.insertLog("ERROR", "ERROR OF PARSE SERVER REPLY", "ERROR OF PARSE SERVER REPLY" + sreply); } catch (Exception lge) { } } } catch (Exception ex) { try { cbLogsFacade.insertLog("ERROR", "ERROR of postMultipartPrDel", logStr + " ERROR of postMultipartPrDel" + ex); } catch (Exception lge) { } } return reply; }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) private void builtPublicationMap(String key, Map<String, Map<String, List<String>>> map, Map<String, List<String>> current, Map<String, String> params) throws KeyNotFoundException, CoreServiceException, OrtolangException { Object object = readObject(key); if (object instanceof MetadataSource) { MetadataElement mde = ((MetadataSource) object).findMetadataByName(MetadataFormat.ACL); if (mde != null) { LOGGER.log(Level.FINE, "ACL metadata found, load json, find policy template and render it..."); MetadataObject md = (MetadataObject) readObject(mde.getKey()); try { JsonReader reader = Json.createReader(binarystore.get(md.getStream())); JsonObject json = reader.readObject(); String template = json.getString("template"); reader.close();/*from w w w . jav a2s.c o m*/ AuthorisationPolicyTemplate policy = authorisation.getPolicyTemplate(template); Map<String, List<String>> rules = authorisation.getPolicyRules(policy.getTemplate()); Map<String, List<String>> filtered = new HashMap<String, List<String>>(); for (Entry<String, List<String>> entry : rules.entrySet()) { if (params.containsKey(entry.getKey())) { filtered.put(params.get(entry.getKey()), entry.getValue()); } else { filtered.put(entry.getKey(), entry.getValue()); } } current = filtered; } catch (AuthorisationServiceException | BinaryStoreServiceException | DataNotFoundException e) { LOGGER.log(Level.SEVERE, "unable to read acl metadata", e); } } } map.put(key, current); if (object instanceof MetadataSource) { for (MetadataElement element : ((MetadataSource) object).getMetadatas()) { map.put(element.getKey(), current); } } if (object instanceof Collection) { for (CollectionElement element : ((Collection) object).getElements()) { builtPublicationMap(element.getKey(), map, current, params); } } }
From source file:wsserver.EKF1TimerSessionBean.java
private boolean postMultipartSectAdd(List<CbEkfgroupAdd1csectToBx> nswps) { String charset = "UTF-8"; String requestURL = systemURL + "bitrix/ekflibraries/corpbus/manipulate_data.php"; boolean reply = true; String sreply = ""; if (nswps.isEmpty()) return reply; String logStr = "New sect cnt=" + nswps.size() + ". "; try {/* w w w . ja v a2s .c o m*/ MultipartUtility multipart = new MultipartUtility(requestURL, charset); multipart.addHeaderField("User-Agent", "CodeJava"); multipart.addHeaderField("Test-Header", "Header-Value"); int index = 0; multipart.addFormField("OTYPE", "ADD"); multipart.addFormField("ENTITY", "1CSECT"); int ocnt = nswps.size(); multipart.addFormField("OCNT", "" + ocnt); //String logStr=""; for (CbEkfgroupAdd1csectToBx npwp : nswps) { multipart.addFormField("SID" + index, npwp.getId()); multipart.addFormField("SNAME" + index, npwp.getName()); multipart.addFormField("SGRXMLID" + index, npwp.getParentId()); logStr += "[" + index + "] NAME " + npwp.getName() + "," + npwp.getId() + "," + npwp.getParentId(); index++; } try { if (logStr.length() > 0) cbLogsFacade.insertLog("INFO", "NEW SECT TO SEND ", logStr); } catch (Exception lgen) { } List<String> response = multipart.finish(); for (String line : response) { sreply = sreply + line; } try { JsonReader jsonReader = Json.createReader(new StringReader(sreply)); JsonObject jobject = jsonReader.readObject(); try { cbLogsFacade.insertLog("INFO", "SUCCESS OF PARSE SERVER REPLY", "SUCCESS OF PARSE SERVER REPLY=" + jobject.toString()); } catch (Exception lge) { } try { if (jobject.getString("critical_info", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_INFO", "SERVER REPLY DETAIL", jobject.getString("critical_info", "")); } catch (Exception lge) { } try { if (jobject.getString("critical_errs", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_ERRS", "SERVER REPLY DETAIL", jobject.getString("critical_errs", "")); } catch (Exception lge) { } try { if (Tools.parseInt(jobject.getString("errcnt", "0"), 1) > 0) { reply = false; try { cbLogsFacade.insertLog("ERROR", "EXCHANGE STOPPED", "UNSUCCESS EXECUTE SECT ADD SCRIPT"); } catch (Exception lge) { } } } catch (Exception lge) { reply = false; } } catch (Exception pe) { try { cbLogsFacade.insertLog("ERROR", "ERROR OF PARSE SERVER REPLY", "ERROR OF PARSE SERVER REPLY" + sreply); } catch (Exception lge) { } } } catch (Exception ex) { try { cbLogsFacade.insertLog("ERROR", "ERROR of postMultipartSectAdd", logStr + " ERROR of postMultipartSectAdd" + ex); } catch (Exception lge) { } } return reply; }
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
JsonObject getResult(HttpResponse response, String body, String type) throws HTTPException, ParseException, IOException { int respStatusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); logger.trace(format("response status %d, HttpEntity %s ", respStatusCode, "" + entity)); String responseBody = entity != null ? EntityUtils.toString(entity) : null; logger.trace(format("responseBody: %s ", responseBody)); // If the status code in the response is greater or equal to the status code set in the client object then an exception will // be thrown, otherwise, we continue to read the response and return any error code that is less than 'statusCode' if (respStatusCode >= statusCode) { HTTPException e = new HTTPException( format("%s request to %s failed request body %s. Response: %s", type, url, body, responseBody), respStatusCode);//from w w w . j ava 2 s. co m logger.error(e.getMessage()); throw e; } if (responseBody == null) { HTTPException e = new HTTPException( format("%s request to %s failed request body %s with null response body returned.", type, url, body), respStatusCode); logger.error(e.getMessage()); throw e; } logger.debug("Status: " + respStatusCode); JsonReader reader = Json.createReader(new StringReader(responseBody)); JsonObject jobj = (JsonObject) reader.read(); JsonObjectBuilder job = Json.createObjectBuilder(); job.add("statusCode", respStatusCode); JsonArray errors = jobj.getJsonArray("errors"); // If the status code is greater than or equal to 400 but less than or equal to the client status code setting, // then encountered an error and we return back the status code, and log the error rather than throwing an exception. if (respStatusCode < statusCode && respStatusCode >= 400) { if (errors != null && !errors.isEmpty()) { JsonObject jo = errors.getJsonObject(0); String errorMsg = format( "[HTTP Status Code: %d] - %s request to %s failed request body %s error message: [Error Code %d] - %s", respStatusCode, type, url, body, jo.getInt("code"), jo.getString("message")); logger.error(errorMsg); } return job.build(); } if (errors != null && !errors.isEmpty()) { JsonObject jo = errors.getJsonObject(0); HTTPException e = new HTTPException( format("%s request to %s failed request body %s error message: [Error Code %d] - %s", type, url, body, jo.getInt("code"), jo.getString("message")), respStatusCode); throw e; } boolean success = jobj.getBoolean("success"); if (!success) { HTTPException e = new HTTPException( format("%s request to %s failed request body %s Body of response did not contain success", type, url, body), respStatusCode); logger.error(e.getMessage()); throw e; } JsonObject result = jobj.getJsonObject("result"); if (result == null) { HTTPException e = new HTTPException( format("%s request to %s failed request body %s " + "Body of response did not contain result", type, url, body), respStatusCode); logger.error(e.getMessage()); throw e; } JsonArray messages = jobj.getJsonArray("messages"); if (messages != null && !messages.isEmpty()) { JsonObject jo = messages.getJsonObject(0); String message = format( "%s request to %s failed request body %s response message: [Error Code %d] - %s", type, url, body, jo.getInt("code"), jo.getString("message")); logger.info(message); } // Construct JSON object that contains the result and HTTP status code for (Entry<String, JsonValue> entry : result.entrySet()) { job.add(entry.getKey(), entry.getValue()); } job.add("statusCode", respStatusCode); result = job.build(); logger.debug(format("%s %s, body:%s result: %s", type, url, body, "" + result)); return result; }