Example usage for javax.json JsonObject getString

List of usage examples for javax.json JsonObject getString

Introduction

In this page you can find the example usage for javax.json JsonObject getString.

Prototype

String getString(String name, String defaultValue);

Source Link

Document

Returns the string value of the associated JsonString mapping for the specified name.

Usage

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcBlockTemplate jsonBlockTemplate(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }//from   w w w .j a  v a2s .  c  om
    BtcBlockTemplate block = new BtcBlockTemplate();
    block.setVersion(jsonLong(object, BTCOBJ_BLOCK_VERSION));
    block.setPreviousBlockHash(object.getString(BTCOBJ_BLOCK_PREVIOUS_BLOCK_HASH, ""));
    List<BtcTransactionTemplate> transactions = new ArrayList<BtcTransactionTemplate>();
    JsonValue txs = object.get(BTCOBJ_BLOCK_TEMPLATE_TRANSACTIONS);
    if ((txs != null) && (txs.getValueType() == JsonValue.ValueType.ARRAY) && (txs instanceof JsonArray)) {
        JsonArray txsArray = (JsonArray) txs;
        for (JsonValue tx : txsArray.getValuesAs(JsonValue.class)) {
            transactions.add(jsonTransactionTemplate(tx));
        }
    }
    block.setTransactions(transactions);
    block.setCoinbase(jsonCoinbase(value));
    block.setTarget(object.getString(BTCOBJ_BLOCK_TEMPLATE_TARGET, ""));
    block.setMinimumTime(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_MIN_TIME));
    List<String> mutable = new ArrayList<String>();
    JsonValue mutableIds = object.get(BTCOBJ_BLOCK_TEMPLATE_MUTABLE);
    if ((mutableIds != null) && (mutableIds.getValueType() == JsonValue.ValueType.ARRAY)
            && (mutableIds instanceof JsonArray)) {
        JsonArray mutableIdsArray = (JsonArray) mutableIds;
        for (JsonValue mutableId : mutableIdsArray.getValuesAs(JsonValue.class)) {
            mutable.add(jsonString(mutableId));
        }
    }
    block.setMutable(mutable);
    block.setNonceRange(object.getString(BTCOBJ_BLOCK_TEMPLATE_NONCE_RANGE, ""));
    block.setSignatureOperations(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_SIGNATURE_OPERATIONS));
    block.setSize(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_SIZE));
    block.setTime(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_TIME));
    block.setBits(object.getString(BTCOBJ_BLOCK_BITS, ""));
    block.setHeight(jsonLong(object, BTCOBJ_BLOCK_HEIGHT));
    return block;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcMiningInfo jsonMiningInfo(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }/* ww  w . j a va 2s. c o  m*/
    BtcMiningInfo info = new BtcMiningInfo();
    info.setBlocks(jsonLong(object, BTCOBJ_INFO_BLOCKS));
    info.setCurrentBlockSize(jsonLong(object, BTCOBJ_INFO_CURRENT_BLOCK_SIZE));
    info.setCurrentBlockTransactions(jsonLong(object, BTCOBJ_INFO_CURRENT_BLOCK_TRANSACTIONS));
    info.setDifficulty(jsonDouble(object, BTCOBJ_INFO_DIFFICULTY));
    info.setErrors(object.getString(BTCOBJ_INFO_ERRORS, ""));
    info.setGenerate(object.getBoolean(BTCOBJ_INFO_GENERATE, false));
    info.setGenProcessorLimit(jsonLong(object, BTCOBJ_INFO_PROCESSOR_LIMIT, -1));
    info.setHashesPerSecond(jsonLong(object, BTCOBJ_INFO_HASHES_PER_SECOND));
    info.setPooledTransactions(jsonLong(object, BTCOBJ_INFO_POOLED_TRANSACTIONS));
    info.setTestnet(object.getBoolean(BTCOBJ_INFO_TESTNET, false));
    return info;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcInfo jsonInfo(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }// www . j a va2  s . co  m
    BtcInfo info = new BtcInfo();
    info.setVersion(jsonLong(object, BTCOBJ_INFO_VERSION));
    info.setProtocolVersion(jsonLong(object, BTCOBJ_INFO_PROTOCOL_VERSION));
    info.setWalletVersion(jsonLong(object, BTCOBJ_INFO_WALLET_VERSION));
    info.setBalance(jsonDouble(object, BTCOBJ_INFO_BALANCE));
    info.setBlocks(jsonLong(object, BTCOBJ_INFO_BLOCKS));
    info.setTimeOffset(jsonLong(object, BTCOBJ_INFO_TIME_OFFSET));
    info.setConnections(jsonLong(object, BTCOBJ_INFO_CONNECTIONS));
    info.setProxy(object.getString(BTCOBJ_INFO_PROXY, ""));
    info.setDifficulty(jsonDouble(object, BTCOBJ_INFO_DIFFICULTY));
    info.setTestnet(object.getBoolean(BTCOBJ_INFO_TESTNET, false));
    info.setKeyPoolOldest(jsonLong(object, BTCOBJ_INFO_KEYPOOL_OLDEST));
    info.setKeyPoolSize(jsonLong(object, BTCOBJ_INFO_KEYPOOL_SIZE));
    info.setTransactionFee(jsonDouble(object, BTCOBJ_INFO_TRANSACTION_FEE));
    info.setErrors(object.getString(BTCOBJ_INFO_ERRORS, ""));
    return info;
}

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

private Node createNode(String nodeName, JsonObject jsonNode, String urlPropName)
        throws NetworkConfigurationException {

    //        jsonNode.
    //        if (jsonNode.isNull(urlPropName)) {
    //            return  null;
    //        }//from  www.  j  a  v  a2 s  . c o m

    String url = jsonNode.getString(urlPropName, null);
    if (url == null) {
        return null;
    }

    Properties props = extractProperties(jsonNode, "grpcOptions");

    if (null != props) {
        String value = props.getProperty("grpc.keepalive_time_ms");
        if (null != value) {
            props.remove("grpc.keepalive_time_ms");
            props.put("grpc.NettyChannelBuilderOption.keepAliveTime",
                    new Object[] { new Long(value), TimeUnit.MILLISECONDS });
        }

        value = props.getProperty("grpc.keepalive_timeout_ms");
        if (null != value) {
            props.remove("grpc.keepalive_timeout_ms");
            props.put("grpc.NettyChannelBuilderOption.keepAliveTimeout",
                    new Object[] { new Long(value), TimeUnit.MILLISECONDS });
        }
    }

    // Extract the pem details
    getTLSCerts(nodeName, jsonNode, props);

    return new Node(nodeName, url, props);
}

From source file:wsserver.EKF1TimerSessionBean.java

private void callT1() {
    Runnable r = new Runnable() {

        public void run() {
            try {
                try {
                    cbLogsFacade.insertLog("INFO", "Start load bx_bsect",
                            "Start load bx_bsect url=" + systemURL);
                } catch (Exception lge) {

                }//w ww  .  j  a v  a2  s .c  om
                String url = systemURL + "bitrix/ekflibraries/corpbus/get_json_data.php?ENTITY=BSECT";

                URL obj = new URL(url);
                HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                // optional default is GET
                con.setRequestMethod("GET");
                con.setConnectTimeout(180000);

                //add request header
                con.setRequestProperty("User-Agent", "Mozilla-Firefox");

                int responseCode = con.getResponseCode();
                System.out.println("\nSending 'GET' request to URL : " + url);
                System.out.println("Response Code : " + responseCode);

                BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();

                try {
                    cbLogsFacade.insertLog("INFO", "Complete load bx_bsect urldata",
                            "Complete load bx_bsect urldata");
                } catch (Exception lge) {

                }
                JsonReader jsonReader = Json.createReader(new StringReader(response.toString()));

                bxBsectFacade.clearBxBsect();

                int crcnt = 0;
                int badCnt = 0;
                JsonArray jarray = jsonReader.readArray();
                //JsonParser parser = Json.createParser(in);
                boolean hasCrashes = false;
                for (int i = 0; i < jarray.size(); i++) {
                    JsonObject jobject = jarray.getJsonObject(i);
                    BxBsect bsectObj = new BxBsect();
                    bsectObj.setId(-1);
                    try {
                        bsectObj.setBxId(Tools.parseInt(jobject.getString("ID", "-1"), -1));
                    } catch (Exception e) {
                        bsectObj.setBxId(-1);
                    }

                    try {
                        String f1cId = jobject.getString("1C_ID", "");
                        if (f1cId.length() == 36)
                            bsectObj.setF1cId(f1cId);
                        else
                            bsectObj.setF1cId("NULL");
                    } catch (Exception e) {
                        bsectObj.setF1cId("NULL");
                    }
                    try {
                        bsectObj.setParentBxId(Tools.parseInt(jobject.getString("PARENT_ID", "-1"), -1));
                    } catch (Exception e) {
                        bsectObj.setParentBxId(-1);
                    }
                    try {
                        bsectObj.setName(jobject.getString("NAME", "NULL"));
                    } catch (Exception e) {
                        bsectObj.setName("NULL");
                    }
                    int try_cnt = 0;
                    boolean notSucc = true;
                    String err = "";
                    while (try_cnt < 10 && notSucc) {
                        try {
                            bxBsectFacade.create(bsectObj);
                            crcnt++;
                            notSucc = false;
                        } catch (Exception e) {
                            notSucc = true;
                            badCnt++;
                            try_cnt++;
                            err += "[[" + Tools.parseInt(jobject.getString("ID", "-1"), -1)
                                    + "]]<<==!!||||||!!==>>Error of bxBsectFacade.create " + e;
                        }
                    }

                    try {
                        if (try_cnt > 0)
                            cbLogsFacade.insertLog("ERROR", "Error of bxBSectFacade", err);
                    } catch (Exception lge) {

                    }
                    hasCrashes = hasCrashes | notSucc;
                }

                try {
                    cbLogsFacade.insertLog("INFO", "Complete load bx_bsect", "Complete load bx_bsect "
                            + ", all=" + jarray.size() + ",succ=" + crcnt + ",errcnt=" + badCnt);
                } catch (Exception lge) {

                }

                BxBsect bsectObjCompl = new BxBsect();
                bsectObjCompl.setId(-1);
                bsectObjCompl.setBxId(jarray.size());
                if (hasCrashes)
                    bsectObjCompl.setF1cId("00000000-0000-0000-0000-00nocomplete");
                else
                    bsectObjCompl.setF1cId("00000000-0000-0000-0000-0000complete");
                //bsectObjCompl.setF1cId("00000000-0000-0000-0000-0bxinprocess");
                //bsectObjCompl.setF1cId("00000000-0000-0000-0000-01?inprocess");
                //bsectObjCompl.setF1cId("00000000-0000-0000-0000-bxancomplete");
                //bsectObjCompl.setF1cId("00000000-0000-0000-0000-1cancomplete");
                bsectObjCompl.setParentBxId(badCnt);
                bsectObjCompl.setName("jasz=" + jarray.size() + ",crcnt=" + crcnt);
                int try_cnt22 = 0;
                boolean notSucc22 = true;
                while (try_cnt22 < 10 && notSucc22) {
                    try {
                        //bxBsectFacade.create(bsectObjCompl);
                        notSucc22 = false;
                    } catch (Exception e) {
                        notSucc22 = true;
                        //badCnt22++;
                        try_cnt22++;
                    }
                }

            } catch (Exception e) {
                System.out.println("<<==!!||||||!!==>>Error of get-parse json " + e);
                try {
                    cbLogsFacade.insertLog("ERROR", "Error of get-parse json bx_bsect",
                            "<<==!!||||||!!==>>Error of get-parse json " + e);
                } catch (Exception lge) {

                }
            } finally {
                callT2();
            }
        }

    };

    Thread t = new Thread(r);
    t.start();
}

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 {/* w ww  .j  a  v a 2s  . 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", "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:wsserver.EKF1TimerSessionBean.java

private boolean postMultipartSectDel(List<CbEkfgroupDel1csectFromBx> dswps) {
    String charset = "UTF-8";
    String requestURL = systemURL + "bitrix/ekflibraries/corpbus/manipulate_data.php";
    boolean reply = true;
    String sreply = "";

    if (dswps.isEmpty())
        return reply;

    String logStr = "Del sect cnt=" + dswps.size() + ". ";

    try {/*ww  w. j a  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", "DELETE");
        multipart.addFormField("ENTITY", "1CSECT");
        int ocnt = dswps.size();
        multipart.addFormField("OCNT", "" + ocnt);
        //String logStr="";
        for (CbEkfgroupDel1csectFromBx npwp : dswps) {
            multipart.addFormField("SID" + index, npwp.getId());
            multipart.addFormField("SNAME" + index, npwp.getName());
            multipart.addFormField("SBXID" + index, "" + npwp.getBxId());
            //npwp.
            logStr += "[" + index + "] id=" + npwp.getId() + "," + npwp.getName() + ",BXID=" + npwp.getBxId();
            index++;
        }

        try {
            if (logStr.length() > 0)
                cbLogsFacade.insertLog("INFO", "DEL 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) {

            }

        } 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 postMultipartSectDel",
                    logStr + " ERROR of postMultipartSectDel" + ex);
        } catch (Exception lge) {

        }
    }

    return reply;
}

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 {//from  ww w .  j a v  a 2  s  .  c  om
        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: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 {// w  ww .ja va2  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", "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: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 {/*from   ww  w .  j  ava  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", "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;
}