Example usage for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider

List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider

Introduction

In this page you can find the example usage for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider.

Prototype

public BouncyCastleProvider() 

Source Link

Document

Construct a new provider.

Usage

From source file:OCSPClient.java

License:Open Source License

public static void main(String args[]) {

    boolean signed = false;
    X509Certificate signer = null;
    X509Certificate[] certificates = new X509Certificate[1];
    PrivateKey signerPK = null;//from   ww  w .  ja  v  a  2  s .c  o  m
    X509Certificate issuer = null;
    X509Certificate responder = null;
    try {

        Security.addProvider(new BouncyCastleProvider());
        Hashtable hOCSPParams = readOCSPParameters();
        if (hOCSPParams != null) {

            // Debug
            if ((hOCSPParams.get("debug") != null) && (hOCSPParams.get("debug").equals("true"))) {
                debug = true;
                System.out.println("debug: ON\n");
            } else {
                System.out.println("debug: OFF\n");
            }

            // Inicializacin para el uso de certificados X509
            CertificateFactory cf = CertificateFactory.getInstance("X509");

            // Obtener la clave privada del firmante de la peticin OCSP
            String signerKeystoreType = (String) hOCSPParams.get("OCSPSigner.KS.type");
            String signerKeystoreFile = (String) hOCSPParams.get("OCSPSigner.KS.filename");
            String signerKeystorePassWD = (String) hOCSPParams.get("OCSPSigner.KS.password");
            String signerPKAlias = (String) hOCSPParams.get("OCSPSigner.KS.privkey.alias");
            String signerPKPassPW = (String) hOCSPParams.get("OCSPSigner.KS.privkey.password");
            if (signerKeystoreType != null && signerKeystoreFile != null && signerKeystorePassWD != null
                    && signerPKAlias != null && signerPKPassPW != null) {
                signed = true;
                // Extraer informacin para firmar la peticin OCSP
                KeyStore ks = KeyStore.getInstance(signerKeystoreType);
                ks.load(new FileInputStream(signerKeystoreFile), signerKeystorePassWD.toCharArray());
                signerPK = (PrivateKey) ks.getKey(signerPKAlias, signerPKPassPW.toCharArray());
                signer = (X509Certificate) ks.getCertificate(signerPKAlias);
                if (signer == null || signerPK == null) {
                    System.out.println("ERROR: el alias " + signerPKAlias + " no existe!");
                    System.exit(1);
                }
                debuglog("Certificado firmante peticin OCSP: " + signer.getSubjectDN());

            } else {
                debuglog(
                        "No se encuentran todos los parmetros necesarios para firmar la peticin OCSP. La peticin NO se firmar.\n");
            }

            // Extraer informacin del certificado a firmar
            String certificateFile = (String) hOCSPParams.get("OCSPRequest.certificate.file");
            if (certificateFile != null) {
                FileInputStream certfile = new FileInputStream(certificateFile);
                Collection certs = cf.generateCertificates(certfile);
                if (certs.size() == 0) {
                    System.out.println(
                            "ERROR: no se han encontrado certificados en el fichero: " + certificateFile);
                    System.exit(1);
                }
                certificates = (X509Certificate[]) certs.toArray(new X509Certificate[0]);
                debuglog("Certificado a consultar:            " + certificates[0].getSubjectDN());
            }

            // Extraer informacin del certificado emisor
            String issuerFile = (String) hOCSPParams.get("OCSPRequest.issuer.file");
            if (issuerFile != null) {
                FileInputStream masterfile = new FileInputStream(issuerFile);
                issuer = (X509Certificate) cf.generateCertificate(masterfile);
                if (issuer == null) {
                    System.out.println("ERROR: no se ha encontrado el certificado emisor!!");
                    System.exit(1);
                }
                debuglog("Certificado emisor:                 " + issuer.getSubjectDN());
            }

            // Extraer informacin del certificado responder
            String responderFile = (String) hOCSPParams.get("OCSPRequest.responder.certificate.file");
            if (responderFile != null) {
                FileInputStream respfile = new FileInputStream(responderFile);
                responder = (X509Certificate) cf.generateCertificate(respfile);
                if (responder == null) {
                    System.out.println("ERROR: no se ha encontrado el certificado responder!");
                    System.exit(1);
                }
                debuglog("Certificado Responder:              " + responder.getSubjectDN());
            }

            debuglog("\nPETICION");
            if (signed)
                debuglog("La peticin ser firmada usando " + signer);
            else
                debuglog("La peticin NO va firmada.");

            // Incluir ID de aplicacin para auditar
            String requestorName = (String) hOCSPParams.get("OCSPRequest.userToAudit");
            if (requestorName != null) {
                debuglog("La peticin incluye el ID [" + requestorName
                        + "] como RequestorName para auditar la peticin en @firma.");
            } else {
                debuglog("La peticin NO incluir el ID para auditar la peticin en @firma.");
            }

            // Construyendo la peticin 
            ClientOCSPDriver driv = new ClientOCSPDriver(signer, signerPK, certificates, issuer, responder);
            debuglog("Objeto ClientOCSPDriver construido.");
            byte[] ocspdata = driv.getRequest(requestorName);
            debuglog("Peticin OCSP completada.");

            String saveRequest = (String) hOCSPParams.get("OCSPRequest.saveToFile");
            if (saveRequest != null) {
                debuglog("Guardando la peticin OCSP en: " + saveRequest);
                writeToFile(saveRequest, ocspdata);
            }

            // Realizando la llamada al OCSPResponder
            debuglog("\nRESPUESTA");
            String urlOCSP = (String) hOCSPParams.get("OCSPResponder.URL");
            if (urlOCSP != null) {

                URL url = new URL(urlOCSP);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                con.setAllowUserInteraction(false);
                con.setDoInput(true);
                con.setDoOutput(true);
                con.setUseCaches(false);
                con.setFollowRedirects(false);
                con.setRequestMethod("POST");
                con.setRequestProperty("Content-Length", Integer.toString(ocspdata.length));
                con.setRequestProperty("Content-Type", "application/ocsp-request");
                OutputStream os = con.getOutputStream();
                os.write(ocspdata);
                con.connect();
                os.close();

                if (con.getResponseCode() != HttpURLConnection.HTTP_OK) {
                    System.out.println("ERROR: la peticin no ha sido aceptada! (cdigo devuelto: "
                            + con.getResponseCode() + ")");
                    System.exit(1);
                }
                if (con.getContentType() == null || !con.getContentType().equals("application/ocsp-response")) {
                    System.out.println("ERROR: la respuesta no es de tipo OCSPResponse!");
                    System.exit(1);
                }
                int len = con.getContentLength();
                if (len < 1) {
                    System.out.println("ERROR: no hay respuesta en el OCSPResponse!");
                    System.exit(1);
                }
                InputStream reader = con.getInputStream();
                byte[] ocsprespdata = new byte[len];
                int offset = 0;
                int bytes_read;
                while ((bytes_read = reader.read(ocsprespdata, offset, len - offset)) != -1) {
                    offset += bytes_read;
                    if (offset == len)
                        break;
                }
                if (offset != len) {
                    System.out.println("ERROR: no es posible leer el OCSPResponse!");
                    System.exit(1);
                }
                reader.close();
                con.disconnect();

                debuglog("El servidor OCSPResponder [" + urlOCSP + "] ha contestado satisfactoriamente.");

                String saveResponse = (String) hOCSPParams.get("OCSPResponse.saveToFile");
                if (saveResponse != null) {
                    debuglog("Guardando la respuesta OCSP en: " + saveResponse);
                    writeToFile(saveResponse, ocsprespdata);
                }

                HashMap certstat = driv.processResponse(ocsprespdata);
                System.out.println("---------------------------------");
                System.out.println("RESULTADO:");
                System.out.println();
                for (int i = 0; i < certificates.length; ++i) {
                    System.out.println(
                            "Certificado " + (i + 1) + ": " + certificates[i].getSubjectX500Principal());
                    CertificateStatus stat = (CertificateStatus) certstat.get(certificates[i]);
                    if (stat == null)
                        System.out.println("Estado: CORRECTO (good)");
                    else if (stat instanceof UnknownStatus)
                        System.out.println("Estado: DESCONOCIDO (unknown)");
                    else if (stat instanceof RevokedStatus) {
                        RevokedStatus rstat = (RevokedStatus) stat;
                        System.out.println("Estado: REVOCADO (" + rstat.getRevocationTime() + ")");
                        try {
                            System.out.println("Causa: " + (rstat.hasRevocationReason()
                                    ? Integer.toString(rstat.getRevocationReason())
                                    : "Unknown"));
                        } catch (IllegalStateException e) {
                            System.out.println("Causa: Unknown");

                        }
                    } else
                        System.out.println("Estado no reconocido!");
                    System.out.println("---------------------------------");
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:NaverShopnImage.java

public String run() {
    String response_type = "FALSE";
    try {/*from  ww w.j av a  2  s . co  m*/
        SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
        Security.addProvider(new BouncyCastleProvider());

        String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
        String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

        String serviceName = "ImageService"; // 
        String id = "eugink";
        String password = "asdf0101";
        String timestamp = null;
        String signature = null;
        String data = null;

        byte[] encryptKey = null;

        String encryptedData = null;
        String decryptedData = null;
        String hashedData = null;

        String operationName = "UploadImage";
        //String orderID = "200087036";      

        //timestamp create
        timestamp = SimpleCryptLib.getTimestamp();
        System.out.println("timestamp:" + timestamp);

        //generateSign
        data = timestamp + serviceName + operationName;
        signature = SimpleCryptLib.generateSign(data, secretKey);

        //generateKey
        encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

        //encrypt
        encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

        //decrypt
        decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

        //sha256
        hashedData = SimpleCryptLib.sha256(password);

        NaverShopnImage NaverShopnImage = new NaverShopnImage();
        System.out.println("NaverShopnImage.getYesterday():" + NaverShopnImage.getYesterday());
        System.out.println("NaverShopnImage.getYesterday():" + NaverShopnImage.getToday());

        System.out.println("accessLicense : [" + accessLicense + "]");
        System.out.println("secretKey : [" + secretKey + "]");
        System.out.println("serviceName : [" + serviceName + "]");
        System.out.println("operationName : [" + operationName + "]");
        System.out.println("timestamp : [" + timestamp + "]");
        System.out.println("signature : [" + signature + "]");
        System.out.println("encryptKey : [" + new String(Hex.encode(encryptKey)) + "]");
        System.out.println("encryptedData : [" + encryptedData + "]");
        System.out.println("decryptedData : [" + decryptedData + "]");
        System.out.println("sha256Data : [" + hashedData + "]");

        /*String xmldata = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mall=\"http://mall.checkout.platform.nhncorp.com/\" xmlns:base=\"http://base.checkout.platform.nhncorp.com/\">" +
             "<soapenv:Header/>" +
             "<soapenv:Body>" +
                "<mall:GetOrderInfoRequest>" +
                   "<base:RequestID>?</base:RequestID>" +
                   "<base:AccessCredentials>" +
                      "<base:AccessLicense>"+ accessLicense +"</base:AccessLicense>" +
                      "<base:Timestamp>"+ timestamp +"</base:Timestamp>" +
                      "<base:Signature>"+ signature +"</base:Signature>" +
                   "</base:AccessCredentials>" +
                   "<base:DetailLevel>Full</base:DetailLevel>" + //<!--  value Full, Compact  )
                   "<base:Version>2.0</base:Version>" +
                   "<OrderID>"+ orderID +"</OrderID>" +
                "</mall:GetOrderInfoRequest>" +
             "</soapenv:Body>" +
          "</soapenv:Envelope>";*/

        System.out.println("NaverShopnImage.getYesterday():" + NaverShopnImage.getYesterday());
        System.out.println("NaverShopnImage.getToday():" + NaverShopnImage.getToday());
        String imglist = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">"
                + "<soap:Header/>" + "<soap:Body>" + "<shop:UploadImageRequest>" + "<!--Optional:-->"
                + "<shop:RequestID>njoyny2</shop:RequestID>" + "<shop:AccessCredentials>"
                + "<shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>" + "<shop:Timestamp>"
                + timestamp + "</shop:Timestamp>" + "<shop:Signature>" + signature + "</shop:Signature>"
                + "</shop:AccessCredentials>" + "<shop:Version>2.0</shop:Version>"
                + "<SellerId>njoyny2</SellerId>" + "<ImageURLList>" + "<!--Zero or more repetitions:-->"
                + "<shop:URL>http://img.buynjoy.com/images_2011_1/b2c/thumb/12/X/X_van5502.jpg</shop:URL>"
                + "</ImageURLList>" + "</shop:UploadImageRequest>" + "</soap:Body>" + "</soap:Envelope>";

        //Create socket
        String hostname = "sandbox.api.naver.com";
        //String hostname = "api.naver.com";
        int port = 80;
        InetAddress addr = InetAddress.getByName(hostname);
        Socket sock = new Socket(addr, port);

        //Send header 
        String path = "/ShopN/ImageService";
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
        // You can use "UTF8" for compatibility with the Microsoft virtual machine.
        wr.write("POST " + path + " HTTP/1.0 \r\n");
        wr.write("Host: sandbox.api.naver.com \r\n");
        //wr.write("Host: api.naver.com \r\n");
        //wr.write("Content-Length: " + xmldata.length() + "\r\n");
        wr.write("Content-Length: " + imglist.length() + "\r\n");
        wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n");
        wr.write("SOAPAction: \"http://sandbox.api.naver.com/ShopN/ImageService\" \r\n");
        //wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n");
        wr.write("\r\n");

        //Send data
        //wr.write(xmldata);
        wr.write(imglist);
        wr.flush();
        // InputStream test = new InputStream(sock.getInputStream(),"UTF-8");   

        // Response
        BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8"));
        String line = "";
        String line_total = "";
        String tmp = "";
        String tmp2 = "";
        String newxml = "";

        while ((line = rd.readLine()) != null) {
            if (line.startsWith("<?xml")) {
                line = line.replaceAll("&#xd;", " ");
                line_total = line_total + line;
                System.out.println(line);
            }

        }

        StringBuffer sf = new StringBuffer();
        /* while((line = rd.readLine()) != null){
           if (line.startsWith("<?xml")){
              sf.append(line+"\n");        //   .
           }
        }*/

        //char[] bufferResult = new char[1048576];
        /* char[] bufferResult = new char[60000000];
         int index = -1;
         while((index = rd.read(bufferResult)) != -1) {
                
        sf.append(bufferResult, 135, index); //response   133 135 
                
         }*/

        //line_total = sf.toString().trim();        
        System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");

        line_total = line_total.replaceAll("n:", "");
        //System.out.println(sf.toString().trim());   

        //xml2
        InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8"));

        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);

        System.out.println("%%%%%%%%%%%%%%%%2222%%%%%%%%%%%%%%%%%");

        Element element = document.getRootElement();
        List envel_list = element.getChildren();
        List body_list = null;
        List body_list1 = null;
        List result_list = null;
        List result_list1 = null;
        List result_list2 = null;
        List result_list3 = null;
        List result_list4 = null;
        List result_list5 = null;
        List info_list = null;
        List contr_group_list = null;
        List contr_info_list = null;

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        CallableStatement cStmt = null;

        //conn.setAutoCommit(false);

        long UNIT_ID = 0;
        long cnt = 0;
        long interface_seq = 0;
        long DEL_QTY = 0;
        long ITEM_ID = 0;
        String ITEM_NAME = null;

        System.out.println("CategoryId.size:" + envel_list.size());
        Element envel_el = (Element) envel_list.get(0);
        body_list = envel_el.getChildren();

        //System.out.println("+++++++11+++++++++++el.getName() : " + envel_el.getChildren());

        //System.out.println("body_list.size:"+body_list.size());
        Element body_el = (Element) body_list.get(0);
        result_list = body_el.getChildren("ImageList");

        //System.out.println("++++++++22++++++++++el.getName() : " + body_el.getChildren());
        for (int h = 0; h < result_list.size(); h++) {

            Element body_el1 = (Element) result_list.get(h);

            result_list1 = body_el1.getChildren("Image");
            //System.out.println("result_list1.size:"+result_list1.size());

            //System.out.println("++++++++33++++++++++el.getName() : " + body_el1.getChildren());
            for (int i = 0; i < result_list1.size(); i++) {

                Element body_el2 = (Element) result_list1.get(i);
                System.out.println("Source:" + body_el2.getChildText("Source"));
                System.out.println("URL:" + body_el2.getChildText("URL"));
                /*
                // 
                                 StringBuffer setOrder = new StringBuffer();
                                 setOrder.append(" insert  \n");
                                 setOrder.append(" into mirus_navershopnctg(  \n");
                                 setOrder.append("     CategoryName, Id, Name, Last, insert_date ,modify_date \n");
                                 setOrder.append(" ) values (  \n");
                                 setOrder.append("     ?, ?, ?, ?, sysdate,null  \n");
                                 setOrder.append(" )  \n");
                                 
                                 pstmt = conn.prepareStatement(setOrder.toString());
                                         
                                 System.out.println("query:"+setOrder.toString());
                                 
                                 int insert_cnt = 0;
                                 
                                 try {
                                         pstmt.clearParameters();
                                 
                                         //
                                         pstmt.setString(1, body_el2.getChildText("CategoryName") );                           // CategoryName
                                         pstmt.setLong( 2, Long.parseLong(body_el2.getChildText("Id")));     // Id
                                         pstmt.setString(3 , body_el2.getChildText("Name"));                                 //Name
                                         pstmt.setString(4 , body_el2.getChildText("Last"));   // Last
                        
                                         pstmt.executeUpdate();
                                 
                                         System.out.println("\n+ insert_cnt ["+i+"]\n");
                                 
                                 
                                     } catch(Exception e) {
                                           response_type="FALSE";
                                             e.printStackTrace();
                                             conn.rollback();
                                             break;
                                     }
                            conn.commit();
                                 
                                     if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}}
                        
                        
                */

                /*
                Element body_el3 = (Element) result_list1.get(i);
                result_list3 = body_el3.getChildren("OrderProductList");
                        
                        
                        
                Element body_el4 = (Element) result_list1.get(i);
                result_list4 = body_el4.getChildren("Shipping");
                        
                */
                /*            
                for (int j = 0; j < result_list2.size(); j++) {
                           
                   Element body_el5 = (Element) result_list2.get(j);//
                   Element body_el7 = (Element) result_list4.get(j);//
                   Element body_el8 = (Element) result_list3.get(j);
                   result_list5 = body_el8.getChildren("OrderProduct");//
                   //result_list5  = (Element) result_list3.get(j);//
                           
                   System.out.println("$$55555$$");
                   if(body_el5.getChildText("OrderStatusCode").equals("OD0002")){//  
                        
                   pstmt = conn.prepareStatement(selectChk.toString());
                   pstmt.setString(1, body_el5.getChildText("OrderID"));
                        
                      rs = pstmt.executeQuery();
                      if(rs.next()) {
                          cnt = rs.getLong("cnt");
                      }
                        
                   System.out.println("  cnt:"+cnt);
                   if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}}
                    if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}}
                           
                   System.out.println("result_list5.size():"+result_list5.size());
                        
                        
                   for (int k = 0; k < result_list5.size(); k++) {
                              
                      Element body_el9 = (Element) result_list5.get(k);
                        
                      ITEM_NAME = body_el9.getChildText("ProductName");
                      DEL_QTY = Long.parseLong(body_el9.getChildText("Quantity"));
                                                                    
                      pstmt = conn.prepareStatement(getInterfacedata);                           
                      System.out.println("body_el9.getChildText:"+body_el9.getChildText("ProductID"));
                      System.out.println("body_el9.getChildText:"+body_el9.getChildText("ProductOption"));
                      pstmt.setLong(1, Long.parseLong(body_el9.getChildText("ProductID")));
                      pstmt.setString(2, body_el9.getChildText("ProductOption"));
                      pstmt.setLong(3, Long.parseLong(body_el9.getChildText("ProductID")));
                        
                         rs = pstmt.executeQuery();
                         if(rs.next()) {
                             UNIT_ID = rs.getLong("UNIT_ID");
                             ITEM_ID = rs.getLong("ITEM_ID");
                             //DEL_QTY = rs.getLong("DEL_QTY");
                         }
                      System.out.println("UNIT_ID:"+UNIT_ID);
                      System.out.println("ITEM_ID:"+ITEM_ID);
                      System.out.println("ITEM_NAME:"+ITEM_NAME);
                      if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}}
                       if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}}
                   }//  1 .
                        
                        
                   System.out.println("1111 333331");
                         String getInterfaceSeq = " select ktc_njoyny_hmall_if_seq.nextval interfaceSeq from dual ";
                        
                         pstmt = conn.prepareStatement(getInterfaceSeq);
                      rs = pstmt.executeQuery();
                      if(rs.next()) {
                          interface_seq = rs.getLong("interfaceSeq");
                      }
                        
                         System.out.println("+ interface_seq ["+interface_seq+"]");
                        
                         if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}}
                         if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}}
                        
                        
                           
                          if(cnt == 0) { //    ..
                             System.out.println("body_el5.getChildText:"+body_el5.getChildText("OrderID"));
                                     
                             if(NaverShopnImage.run2(body_el5.getChildText("OrderID")).equals("SUCCESS")){// 
                                        
                                 StringBuffer setOrder = new StringBuffer();
                                 setOrder.append(" insert  \n");
                                 setOrder.append(" into ktc_njoyny_hmall_if(  \n");
                                 setOrder.append("     h_order_no, seq, order_date, recv_date, item_id,   \n");
                                 setOrder.append("     unit_id, item_name, price, qty, orderer_name,   \n");
                                 setOrder.append("     orderer_phone, orderer_cell_phone, orderer_eng_name, orderer_resi_no, orderer_email,  \n");
                                 setOrder.append("     msg_for_mall, del_plan_date, receiver_name, receiver_phone, receiver_cell_phone,   \n");
                                 setOrder.append("     receiver_zip_code, receiver_addr1, receiver_addr2, msg_for_outbnd, interface_date, \n");
                                 setOrder.append("     interface_seq, sysregdt, coven_id \n");
                                 setOrder.append(" ) values (  \n");
                                 setOrder.append("     'naver_'||?, ktc_njoyny_hmall_if_seq.nextval, to_date(?,'yyyy/mm/dd hh24:mi:ss'), sysdate, ?,  \n");
                                 setOrder.append("     ?, ?, ?, ?, ?,  \n");
                                 setOrder.append("     ?, ?, ?, ?, ?,  \n");
                                 setOrder.append("     ?, sysdate+5, ?, ?, ?,  \n");
                                 setOrder.append("     ?, ?, ?, ?, sysdate,  \n");
                                 setOrder.append("     ?, sysdate, ? \n");
                                 setOrder.append(" )  \n");
                        
                                 pstmt = conn.prepareStatement(setOrder.toString());
                        
                                 int insert_cnt = 0;
                        
                                 try {
                                         pstmt.clearParameters();
                        
                                         //
                                         pstmt.setLong(1, Long.parseLong(body_el5.getChildText("OrderID")) );                           // h_order_no
                                         System.out.println(body_el5.getChildText("OrderID"));
                                         pstmt.setString(2 , body_el5.getChildText("OrderDateTime").substring(0,10));                                 //order_date
                                         System.out.println(body_el5.getChildText("OrderDateTime").substring(0,10));
                                         pstmt.setLong(3 , ITEM_ID);     // item_id
                                           System.out.println(ITEM_ID);
                                           pstmt.setLong(4 , UNIT_ID);   // unit_id
                                         System.out.println(UNIT_ID);
                              
                                         pstmt.setString(5 , ITEM_NAME);     // ITEM_NAME
                                         System.out.println(ITEM_NAME);
                                         pstmt.setLong(6 , Long.parseLong(body_el5.getChildText("TotalProductAmount")));       //price ->  0.95    +  + 
                                         System.out.println(Long.parseLong(body_el5.getChildText("TotalProductAmount")));
                                         pstmt.setLong(7 , DEL_QTY);    //qty
                                         System.out.println(DEL_QTY);
                        
                                         pstmt.setString(8 , new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8"));                             // orderer_name
                                         System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8"));
                                         pstmt.setString(9 , NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el5.getChildText("OrdererTel")), "UTF-8")));                               //orderer_phone
                                         System.out.println(NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererTel")), "UTF-8")));
                                         pstmt.setString(10, NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el5.getChildText("OrdererTel")), "UTF-8")));               // orderer_cell_phone
                                         pstmt.setString(11, null);                      // orderer_eng_name
                                         pstmt.setString(12, null);                      // orderer_resi_no
                                         pstmt.setString(13, null);                      // orderer_email
                                         pstmt.setString(14, body_el7.getChildText("ShippingMessage"));                      // msg_for_mall
                                         pstmt.setString(15, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("Recipient")), "UTF-8")); // receiver_name
                                         System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("Recipient")), "UTF-8"));
                        
                                         pstmt.setString(16, NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("RecipientTel1")), "UTF-8")));                    // receiver_phone
                                         System.out.println(NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8")));
                        
                                         pstmt.setString(17, NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("RecipientTel1")), "UTF-8")));                    // receiver_cell_phone
                                         System.out.println(NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8")));
                        
                                         pstmt.setString(18, body_el7.getChildText("ZipCode"));                              //receiver_zip_code
                                         pstmt.setString(19, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("ShippingAddress1")), "UTF-8"));                           //receiver_addr1
                                         System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress1")), "UTF-8"));
                        
                                         pstmt.setString(20, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("ShippingAddress2")), "UTF-8"));                            //receiver_addr2
                                         System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress2")), "UTF-8"));
                        
                                         pstmt.setString(21, body_el7.getChildText("ShippingMessage"));                                  // msg_for_outbnd
                                         System.out.println(body_el7.getChildText("ShippingMessage"));
                        
                                         pstmt.setLong(22, interface_seq);                                       // interface_seq
                                         pstmt.setString(23, "26050");                                                   // coven_id
                        
                                         pstmt.executeUpdate();
                        
                                         System.out.println("\n+ insert_cnt ["+i+"]\n");
                        
                        
                                     } catch(Exception e) {
                                           response_type="FALSE";
                                             e.printStackTrace();
                                             conn.rollback();
                                             break;
                                     }
                            conn.commit();
                        
                                     if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}}
                            System.out.println("  ");
                            System.out.println("interface_seq:"+interface_seq);
                                  //  ....
                                  cStmt = conn.prepareCall("{ call CREAT_NJOYNY_HMALL_ORDER(?,?,?) }");
                               cStmt.setLong(1, interface_seq);
                               cStmt.registerOutParameter(2, Types.VARCHAR);
                               cStmt.registerOutParameter(3, Types.VARCHAR);
                               cStmt.executeUpdate();
                               String r_code = cStmt.getString(2);
                               String r_msg = cStmt.getString(3);
                            System.out.println("++++++++++++++++r_code : " + r_code);
                            System.out.println("++++++++++++++++r_msg : " + r_msg);
                                  conn.commit();
                            System.out.println("  ");   
                               if(cStmt != null){ try{ cStmt.close(); } catch(Exception e){ response_type="FALSE";}}
                               conn.setAutoCommit(true);
                              response_type="TRUE";
                              }else{
                                 System.out.println("  " );
                              }
                              }else{
                                      System.out.println("  =.." );
                              }
                                 cnt = 0; // ..
                        
                        
                        
                              
                   }
                }
                */

            }
        }

    } catch (Exception e) {
        System.out.println("run() : " + e.getMessage());
        response_type = "FALSE";
    } finally {
    }

    return response_type;
}

From source file:HandleCert.java

License:Open Source License

public static void main(String args[]) throws Exception {

    String certText = " -----BEGIN CERTIFICATE-----"
            + "MIIEMTCCAxmgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMCREsx"
            + "DDAKBgNVBAgTA0NQSDEMMAoGA1UEBxMDQ1BIMQswCQYDVQQKEwJrdTENMAsGA1UE"
            + "CxMEZGlrdTEbMBkGA1UEAxMSYmVuamFtaW4gdGVzdCBjZXJ0MSEwHwYJKoZIhvcN"
            + "AQkBFhJic2Vkb2Nub3RAaG9tZS5jb20wHhcNMDkwNjI0MTIwMDA1WhcNMDkwNzA1"
            + "MTIwMDA1WjBCMQkwBwYDVQQGEwAxCTAHBgNVBAoMADEqMCgGA1UEAwwhQmVuamFt"
            + "aW4gU2Vkb2MgYmVuamlAcm5kLmZlaWRlLm5vMIIBIjANBgkqhkiG9w0BAQEFAAOC"
            + "AQ8AMIIBCgKCAQEAkG5iTutuzw/2h113a/iVE/Or4LP0BVJhwII/SfeG/PPOH59j"
            + "33r0J6WEXI1As5bodbMdgMun9+sI21SgaZKCbfWSVuZZ+YeagiwltXIdG2Zr8qc7"
            + "WLYs54j477AKsKVpeHQtB4gKIladQFl6wMVRGUndJZYTJ2YzUGyvieXRqvoBBvai"
            + "XdFLaJftkVfP9TmiU1HOfXdL/+9FY5pTTkZEKcjjBHGFeVo7QUe2/+BTQbLYaAGy"
            + "roRdhY3VSeJVwMQk4SubBAPQZzp7Q4SRc53JJG8t7vv5DolOtuIRJYUQVSSiSNH5"
            + "H8U7ycJ7Fos2I3L31kNPO7G2TUV3t5X32O0ZNQIDAQABo4HtMIHqMB0GA1UdDgQW"
            + "BBSdALZ+6sYgzzjA/d1wgwIBM+v3fjCBugYDVR0jBIGyMIGvgBQgW5dnSYG7fYsa"
            + "INeLhwG6zoVqrKGBi6SBiDCBhTELMAkGA1UEBhMCREsxDDAKBgNVBAgTA0NQSDEM"
            + "MAoGA1UEBxMDQ1BIMQswCQYDVQQKEwJrdTENMAsGA1UECxMEZGlrdTEbMBkGA1UE"
            + "AxMSYmVuamFtaW4gdGVzdCBjZXJ0MSEwHwYJKoZIhvcNAQkBFhJic2Vkb2Nub3RA"
            + "aG9tZS5jb22CCQDyJQJf3qgF1jAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUA"
            + "A4IBAQBgQM23MO8Fcc9x/ZzWUrAZ8h0hZ43Gh1t+tRXBmrccCUUaxwAhzeaH6nqX"
            + "wJv6kmt6rD/5cLxhkCKTGD+ZM9b7UrJk3mYlK6fvsZyhyxY9BjgqdlWxuhDy/k+I"
            + "+P72ZRkeU2qCz4W3ehCg0LoS+vdZeqNpWXDmk0TE0qUPYsZiFV+8ITcm2miCq2DX"
            + "P8bpiwXH7/FCJea6PevmEWzg8JyaDhfvsDnmotKmi8zT9uOWHhX0k7NsycJomBYw"
            + "9DCdknsCHikrosM53mvMhnx2zPpMUnZP+mg+nyt+gFc71hWSNrJ9oCGuareAoEVT"
            + "+6B066WzHlAe7chufSBcSq0wDhc6" + "-----END CERTIFICATE-----"
            + "2009 Jun 24 14:00:05 (Confusa) notice: Sending certificate with hash 8ab05b7acf3d08483980af6aec051aaf822c0984 and auth-token 8ab05b7acf3d08483980af6aec051aaf822c0984 to user from ip 192.38.109.188"
            + "<BR>";

    Security.addProvider(new BouncyCastleProvider());

    HandleCert hc = new HandleCert();
    /*String certStr = hc.filterCertStr(certText);
    X509Certificate cert = hc.parseCertificate(certStr);
    KeyPair kp = hc.generateKeys();//  w w  w .java 2  s  .  c  o  m
    X509Certificate crt = (X509Certificate) hc.createMasterCert(kp.getPublic(),kp.getPrivate());
    //System.out.println(certstr);
    String filename = "SLCS.crt"; 
    hc.writeCertToFile(crt, filename, kp);   */

}

From source file:NaverShopnSendItem_down.java

private String run4(String ProductId, String n_item_id, Integer cnt) { // 
    // //from   w  w  w. j a  v a 2 s. co m
    // 
    String response_type = "FALSE";
    NaverShopnSendItem_down NaverShopnSendItem_test = new NaverShopnSendItem_down();
    System.out.println("run4");
    try {
        /*   */

        //   
        SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
        Security.addProvider(new BouncyCastleProvider());

        String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
        String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

        String serviceName = "ProductService"; // 
        String id = "eugink";
        String password = "asdf0101";
        String timestamp = null;
        String signature = null;
        String data = null;
        String item_id = "";

        byte[] encryptKey = null;

        String encryptedData = null;
        String decryptedData = null;
        String hashedData = null;

        String operationName = "GetOption";
        String ResponseType = "";

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        CallableStatement cStmt = null;

        operationName = "ManageOption";

        // String orderID = "200087036";

        // timestamp create
        timestamp = SimpleCryptLib.getTimestamp();
        System.out.println("timestamp:" + timestamp);
        System.out.println("ManageOption");

        // generateSign
        data = timestamp + serviceName + operationName;
        signature = SimpleCryptLib.generateSign(data, secretKey);

        // generateKey
        encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

        // encrypt
        encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

        // decrypt
        decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

        // sha256
        hashedData = SimpleCryptLib.sha256(password);

        //   
        StringBuffer unitlistsql = new StringBuffer(); // 

        try {
            StringBuffer selectUnit = new StringBuffer();

            selectUnit.append(" select unit_name,co_unit_id,unit_id,  vir_stock_qty  ,use_yn \n");
            selectUnit.append(" from ( \n");
            selectUnit.append(
                    "  select nvl(b.coven_id,0) coven_id,a.unit_name,nvl(b.co_unit_id,0) co_unit_id,a.unit_id,(CASE WHEN  vir_stock_qty <= 0 then 1 else vir_stock_qty end) vir_stock_qty,a.use_yn  \n");
            selectUnit.append(" from ktc_unit a,ktc_unit_interlock b \n");
            selectUnit.append(" where a.unit_id = b.unit_id(+) \n");
            selectUnit.append(" and a.item_id = ? \n");
            selectUnit.append(" )where  coven_id in (27346,0)    \n");

            //System.out.println("selectUnit.toString():"+ selectUnit.toString());
            HashMap unitList = new HashMap();
            pstmt = conn.prepareStatement(selectUnit.toString());

            // pstmt.clearParameters();

            // 
            pstmt.setString(1, n_item_id);
            rs = pstmt.executeQuery();
            int list_cnt = 1;

            while (rs.next()) {

                HashMap rowData = new HashMap();
                rowData.put("unit_name", rs.getString("unit_name"));
                rowData.put("co_unit_id", rs.getString("co_unit_id"));
                rowData.put("unit_id", rs.getString("unit_id"));
                rowData.put("vir_stock_qty", rs.getString("vir_stock_qty"));
                rowData.put("use_yn", rs.getString("use_yn"));
                unitList.put(Integer.toString(list_cnt), rowData);

                list_cnt = list_cnt + 1;
            }

            /* unit xml  */

            unitlistsql.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n ");
            unitlistsql.append(
                    "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\"> ");
            unitlistsql.append(
                    "   <soap:Header/>                                                                                                    ");
            unitlistsql.append(
                    "   <soap:Body>                                                                                                       ");
            unitlistsql.append(
                    "      <shop:ManageOptionRequest>                                                                                     ");
            unitlistsql.append(
                    "         <!--Optional:-->                                                                                            ");
            unitlistsql.append("         <shop:RequestID>njoyny2</shop:RequestID>");
            unitlistsql.append("         <shop:AccessCredentials>");
            unitlistsql.append("            <shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>");
            unitlistsql.append("            <shop:Timestamp>" + timestamp + "</shop:Timestamp>");
            unitlistsql.append("            <shop:Signature>" + signature + "</shop:Signature>");
            unitlistsql.append("         </shop:AccessCredentials>");
            unitlistsql.append("         <shop:Version>2.0</shop:Version>");
            unitlistsql.append("         <SellerId>njoyny2</SellerId>");

            unitlistsql.append(
                    "         <Option>                                                                                                    ");
            unitlistsql.append("            <shop:ProductId>" + ProductId
                    + "</shop:ProductId>                                                                       ");
            unitlistsql.append(
                    "            <!--Optional:-->                                                                                         ");
            unitlistsql.append(
                    "                        <shop:Combination>                                         ");

            unitlistsql.append("                     <shop:Names> ");
            unitlistsql.append("                        <shop:Name1><![CDATA[]]></shop:Name1> ");
            unitlistsql.append("                     </shop:Names> ");

            unitlistsql.append("                     <shop:ItemList>   ");

            System.out.println("!!!!cnt:" + cnt);
            String unit_name = "";
            String co_unit_id = "";
            String unit_id = "";
            String vir_stock_qty = "";
            String use_yn = "";
            HashMap rowData1 = null;

            for (int j = 1; j <= cnt; j++) {

                rowData1 = (HashMap) unitList.get(String.valueOf(j));

                unit_name = NaverShopnSendItem_test.parsingSpecialforXml((String) rowData1.get("unit_name"))
                        .replaceAll(":", "-"); // njoyny id
                co_unit_id = (String) rowData1.get("co_unit_id"); // shopN
                // id
                unit_id = (String) rowData1.get("unit_id");
                vir_stock_qty = (String) rowData1.get("vir_stock_qty");
                use_yn = (String) rowData1.get("use_yn");

                unitlistsql.append(
                        "                           <shop:Item>                                          ");
                if (!co_unit_id.equals("0")) {
                    unitlistsql.append("                              <shop:Id>" + co_unit_id
                            + "</shop:Id>                                ");
                }
                unitlistsql.append("                              <shop:Value1>" + unit_name
                        + "</shop:Value1>                            ");
                unitlistsql.append("                              <shop:Quantity>" + vir_stock_qty
                        + "</shop:Quantity>                            ");
                unitlistsql.append("                              <shop:SellerManagerCode>" + unit_id
                        + "</shop:SellerManagerCode>                          ");
                unitlistsql.append("                              <shop:Usable>" + use_yn
                        + "</shop:Usable>                        ");
                unitlistsql.append(
                        "                           </shop:Item>                                         ");

            }

            unitlistsql.append("                     </shop:ItemList>   ");
            unitlistsql.append(
                    "                        </shop:Combination>                                        ");
            unitlistsql.append(
                    "         </Option>                                                                                                   ");
            unitlistsql.append(
                    "      </shop:ManageOptionRequest>                                                                                    ");
            unitlistsql.append(
                    "   </soap:Body>                                                                                                      ");
            unitlistsql.append(
                    "</soap:Envelope>                                                                                                     ");

            /* unit xml  */

            System.out.println("unitlist:" + unitlistsql.toString());
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                    response_type = "FALSE";
                }
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {
                    response_type = "FALSE";
                }
            }

        } catch (Exception e) {
            System.out.println("run4() : " + e.getMessage());
        } finally {
        }

        //System.out.println(unitlistsql.toString());

        String line_total = "";
        URL url = new URL("http://ec.api.naver.com/ShopN/ProductService");
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        //      .  true.
        con.setDoInput(true);
        con.setUseCaches(false);
        con.setDefaultUseCaches(false);
        // Header  
        con.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");

        // BODY  
        OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
        wr.write(unitlistsql.toString());
        wr.flush();

        //   
        String inputLine = null;
        BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));

        while ((inputLine = rd.readLine()) != null) {
            line_total = line_total + inputLine;
            //System.out.println(inputLine);
        }

        rd.close();
        wr.close();

        line_total = line_total.replaceAll("n:", "");
        System.out.println(line_total);

        // xml2
        InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8"));

        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);

        Element element = document.getRootElement();
        List envel_list = element.getChildren();
        //System.out.println("envel_list:" + envel_list);

        List body_list = null;
        List body_list1 = null;
        List result_list = null;
        List result_list1 = null;
        List result_list2 = null;
        List result_list3 = null;
        List result_list4 = null;
        List result_list5 = null;
        List info_list = null;
        List contr_group_list = null;
        List contr_info_list = null;

        pstmt = null;
        rs = null;
        cStmt = null;

        //System.out.println("envel_list.size:" + envel_list.size());
        Element envel_el = (Element) envel_list.get(0);
        body_list = envel_el.getChildren();

        //System.out.println("body_list.size:" + body_list.size());
        Element body_el = (Element) body_list.get(0);
        result_list = body_el.getChildren("ManageProductResponse");

        ResponseType = body_el.getChildText("ResponseType");
        ProductId = body_el.getChildText("ProductId");
        //System.out.println("ResponseType:"+ body_el.getChildText("ResponseType"));
        System.out.println("ProductId:" + body_el.getChildText("ProductId"));

        StringBuffer optlistsql = new StringBuffer();
        if (ResponseType.equals("SUCCESS")) {
            //   

            NaverShopnSendItem_test.run3(ProductId, n_item_id);

        }

    } catch (Exception e) {
        System.out.println("run111() : " + e.getMessage());
    } finally {
    }

    return response_type;
}

From source file:NaverShopnSendItem_down.java

private String run3(String ProductId, String n_item_id) { //   
    System.out.println("run3");
    String response_type = "FALSE";
    NaverShopnSendItem_down NaverShopnSendItem_test = new NaverShopnSendItem_down();
    try {/*from   ww  w  . ja v  a2 s  . co  m*/
        SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
        Security.addProvider(new BouncyCastleProvider());

        String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
        String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

        String serviceName = "ProductService"; // 
        String id = "eugink";
        String password = "asdf0101";
        String timestamp = null;
        String signature = null;
        String data = null;
        String item_id = "";

        byte[] encryptKey = null;

        String encryptedData = null;
        String decryptedData = null;
        String hashedData = null;

        String operationName = "GetOption";
        String ResponseType = "";

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        CallableStatement cStmt = null;
        // String orderID = "200087036";

        // timestamp create
        timestamp = SimpleCryptLib.getTimestamp();
        System.out.println("timestamp:" + timestamp);
        System.out.println("ProductService");

        // generateSign
        data = timestamp + serviceName + operationName;
        signature = SimpleCryptLib.generateSign(data, secretKey);

        // generateKey
        encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

        // encrypt
        encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

        // decrypt
        decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

        // sha256
        hashedData = SimpleCryptLib.sha256(password);

        StringBuffer optlistsql = new StringBuffer();
        optlistsql.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n ");
        optlistsql.append(
                "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\"> ");
        optlistsql.append(
                "   <soap:Header/>                                                                                                    ");
        optlistsql.append(
                "   <soap:Body>                                                                                                       ");
        optlistsql.append(
                "      <shop:GetOptionRequest>                                                                                     ");
        optlistsql.append("         <shop:RequestID>njoyny2</shop:RequestID>");
        optlistsql.append("         <shop:AccessCredentials>");
        optlistsql.append("            <shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>");
        optlistsql.append("            <shop:Timestamp>" + timestamp + "</shop:Timestamp>");
        optlistsql.append("            <shop:Signature>" + signature + "</shop:Signature>");
        optlistsql.append("         </shop:AccessCredentials>");
        optlistsql.append("         <shop:Version>2.0</shop:Version>");
        optlistsql.append("         <SellerId>njoyny2</SellerId>");
        optlistsql.append("            <shop:ProductId>" + ProductId
                + "</shop:ProductId>                                                                       ");
        optlistsql.append(
                "        </shop:GetOptionRequest>                                                                                         ");
        optlistsql.append("    </soap:Body>                                         ");
        optlistsql.append("    </soap:Envelope>                                         ");

        String line_total = "";
        URL url = new URL("http://ec.api.naver.com/ShopN/ProductService");
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        //      .  true.
        con.setDoInput(true);
        con.setUseCaches(false);
        con.setDefaultUseCaches(false);
        // Header  
        con.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");

        // BODY  
        OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
        wr.write(optlistsql.toString());
        wr.flush();

        //   
        String inputLine = null;
        BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));

        while ((inputLine = rd.readLine()) != null) {
            line_total = line_total + inputLine;
            //System.out.println(inputLine);
        }

        rd.close();
        wr.close();

        line_total = line_total.replaceAll("n:", "");
        //System.out.println(line_total);

        // xml2
        ByteArrayInputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8"));

        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);

        Element element = document.getRootElement();
        List envel_list = element.getChildren();
        //System.out.println("envel_list:" + envel_list);

        List body_list = null;
        List body_list1 = null;
        List result_list = null;
        List result_list1 = null;
        List result_list2 = null;
        List result_list3 = null;
        List result_list4 = null;
        List result_list5 = null;
        List info_list = null;
        List contr_group_list = null;
        List contr_info_list = null;

        Element envel_el = (Element) envel_list.get(0);
        body_list = envel_el.getChildren();

        Element body_el = (Element) body_list.get(0);
        result_list = body_el.getChildren("Option");

        Element body_el1 = (Element) result_list.get(0);
        result_list1 = body_el1.getChildren("Combination");

        Element body_el2 = (Element) result_list1.get(0);
        result_list2 = body_el2.getChildren("ItemList");

        Element body_el3 = (Element) result_list2.get(0);
        result_list3 = body_el3.getChildren("Item");

        Element body_el4 = null;
        int cnt = 0;
        for (int h = 0; h < result_list3.size(); h++) {

            body_el4 = (Element) result_list3.get(h);

            StringBuffer unitCnt = new StringBuffer();

            unitCnt.append(" select count(*) cnt \n");
            unitCnt.append(" from  \n");
            unitCnt.append(" ktc_unit_interlock \n");
            unitCnt.append(" where coven_id = 27346 and unit_id = ? \n");

            // pstmt.clearParameters();
            pstmt = conn.prepareStatement(unitCnt.toString());
            pstmt.setLong(1, Long.parseLong(body_el4.getChildText("SellerManagerCode")));

            // pstmt.setString(1, body_el3.getChildText("Value")); //
            // h_order_no
            rs = pstmt.executeQuery();

            while (rs.next()) {
                cnt = rs.getInt("cnt");
            }

            System.out.println("cnt:" + cnt);
            if (rs != null)
                try {
                    rs.close();
                } catch (Exception e) {
                }
            if (pstmt != null)
                try {
                    pstmt.close();
                } catch (Exception e) {
                }

            if (cnt == 0) {

                StringBuffer setCovenID = new StringBuffer();
                setCovenID.append(
                        " insert into ktc_unit_interlock(coven_id , co_unit_id , item_id , unit_id ,insert_date,update_date)  \n");
                setCovenID.append(" values (27346,?,?,?,sysdate,sysdate)  \n");

                //System.out.println("setCovenIDinsert::"+ setCovenID.toString());

                pstmt = conn.prepareStatement(setCovenID.toString());

                int insert_cnt = 0;

                try {
                    // pstmt.clearParameters();

                    // 

                    pstmt.setString(1, body_el4.getChildText("Id")); // id
                    pstmt.setString(2, n_item_id); // id
                    pstmt.setString(3, body_el4.getChildText("SellerManagerCode")); // unit_id

                    pstmt.executeUpdate();
                    System.out.println("insert end");

                    if (rs != null)
                        try {
                            rs.close();
                        } catch (Exception e) {
                        }
                    if (pstmt != null)
                        try {
                            pstmt.close();
                        } catch (Exception e) {
                        }
                } catch (Exception e) {
                    response_type = "FALSE";
                    e.printStackTrace();
                    conn.rollback();
                }
            } else {
                StringBuffer setCovenID = new StringBuffer();
                setCovenID.append(" update ktc_unit_interlock set  \n");
                setCovenID.append(" co_unit_id = ? ,item_id = ? ,update_date = sysdate  \n");
                setCovenID.append(" where coven_id = 27346 and unit_id = ? \n");

                pstmt = conn.prepareStatement(setCovenID.toString());

                int insert_cnt = 0;

                try {
                    // pstmt.clearParameters();

                    // 

                    pstmt.setString(1, body_el4.getChildText("Id")); // id
                    pstmt.setString(2, n_item_id); // id
                    pstmt.setString(3, body_el4.getChildText("SellerManagerCode")); // unit_id

                    pstmt.executeUpdate();
                    System.out.println("end update");
                    if (rs != null)
                        try {
                            rs.close();
                        } catch (Exception e) {
                        }
                    if (pstmt != null)
                        try {
                            pstmt.close();
                        } catch (Exception e) {
                        }
                } catch (Exception e) {
                    response_type = "FALSE";
                    e.printStackTrace();
                    conn.rollback();
                }
            }

        }

        ResponseType = body_el.getChildText("ResponseType");
        ProductId = body_el.getChildText("ProductId");

    } catch (Exception e) {
        System.out.println("run3() : " + e.getMessage());
        response_type = "FALSE";
    } finally {
    }

    return response_type;
}

From source file:NaverShopnSendItem_down.java

private String run2(String imgUrl) { // 

    String response_type = "FALSE";
    NaverShopnSendItem_down NaverShopnSendItem_test = new NaverShopnSendItem_down();
    try {/*from ww  w. ja va 2 s  .  c  o  m*/
        SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
        Security.addProvider(new BouncyCastleProvider());

        String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
        String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

        String serviceName = "ImageService"; // 
        String id = "eugink";
        String password = "asdf0101";
        String timestamp = null;
        String signature = null;
        String data = null;

        byte[] encryptKey = null;

        String encryptedData = null;
        String decryptedData = null;
        String hashedData = null;

        String operationName = "UploadImage";
        // String orderID = "200087036";

        // timestamp create
        timestamp = SimpleCryptLib.getTimestamp();
        System.out.println("timestamp:" + timestamp);
        System.out.println("ImageService");

        // generateSign
        data = timestamp + serviceName + operationName;
        signature = SimpleCryptLib.generateSign(data, secretKey);

        // generateKey
        encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

        // encrypt
        encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

        // decrypt
        decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

        // sha256
        hashedData = SimpleCryptLib.sha256(password);

        String imglist = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">"
                + "<soap:Header/>" + "<soap:Body>" + "<shop:UploadImageRequest>" + "<!--Optional:-->"
                + "<shop:RequestID>njoyny2</shop:RequestID>" + "<shop:AccessCredentials>"
                + "<shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>" + "<shop:Timestamp>"
                + timestamp + "</shop:Timestamp>" + "<shop:Signature>" + signature + "</shop:Signature>"
                + "</shop:AccessCredentials>" + "<shop:Version>2.0</shop:Version>"
                + "<SellerId>njoyny2</SellerId>" + "<ImageURLList>" + "<!--Zero or more repetitions:-->"
                + "<shop:URL>" + imgUrl + "</shop:URL>" + "</ImageURLList>" + "</shop:UploadImageRequest>"
                + "</soap:Body>" + "</soap:Envelope>";

        // Create socket
        String hostname = "ec.api.naver.com";
        // String hostname = "api.naver.com";
        int port = 80;
        InetAddress addr = InetAddress.getByName(hostname);
        Socket sock = new Socket(addr, port);

        // Send header
        String path = "/ShopN/ImageService";
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
        // You can use "UTF8" for compatibility with the Microsoft virtual
        // machine.
        wr.write("POST " + path + " HTTP/1.0 \r\n");
        wr.write("Host: ec.api.naver.com \r\n");
        // wr.write("Host: api.naver.com \r\n");
        // wr.write("Content-Length: " + xmldata.length() + "\r\n");
        wr.write("Content-Length: " + imglist.length() + "\r\n");
        wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n");
        wr.write("SOAPAction: \"http://ec.api.naver.com/ShopN/ImageService\" \r\n");
        // wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n");
        wr.write("\r\n");

        // Send data
        // wr.write(xmldata);
        wr.write(imglist);
        wr.flush();
        // InputStream test = new
        // InputStream(sock.getInputStream(),"UTF-8");

        // Response
        BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8"));
        String line = "";
        String line_total = "";
        String tmp = "";
        String tmp2 = "";
        String newxml = "";

        while ((line = rd.readLine()) != null) {
            if (line.startsWith("<?xml")) {
                line = line.replaceAll("&#xd;", " ");
                line_total = line_total + line;
                //System.out.println(line);
            }

        }
        rd.close();
        wr.close();

        line_total = line_total.replaceAll("n:", "");
        //System.out.println(line_total);

        line_total = line_total.replaceAll("n:", "");
        // System.out.println(sf.toString().trim());

        // xml2
        InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8"));

        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);

        Element element = document.getRootElement();
        List envel_list = element.getChildren();
        List body_list = null;
        List body_list1 = null;
        List result_list = null;
        List result_list1 = null;
        List result_list2 = null;
        List result_list3 = null;
        List result_list4 = null;
        List result_list5 = null;
        List info_list = null;
        List contr_group_list = null;
        List contr_info_list = null;

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        CallableStatement cStmt = null;

        // conn.setAutoCommit(false);

        long UNIT_ID = 0;
        long cnt = 0;
        long interface_seq = 0;
        long DEL_QTY = 0;
        long ITEM_ID = 0;
        String ITEM_NAME = null;

        Element envel_el = (Element) envel_list.get(0);
        body_list = envel_el.getChildren();

        Element body_el = (Element) body_list.get(0);
        result_list = body_el.getChildren("ImageList");

        for (int h = 0; h < result_list.size(); h++) {

            Element body_el1 = (Element) result_list.get(h);

            result_list1 = body_el1.getChildren("Image");

            for (int i = 0; i < result_list1.size(); i++) {

                Element body_el2 = (Element) result_list1.get(i);

                response_type = body_el2.getChildText("URL");

            }
        }

    } catch (Exception e) {
        System.out.println("run2() : " + e.getMessage());
        response_type = "FALSE";
    } finally {
    }

    return response_type;
}

From source file:NaverShopnSendItem_down.java

public String run(String InputItem) {
    StringBuffer itemlist = new StringBuffer(); // 

    String response_type = "FALSE";
    PreparedStatement pstmt = null;
    ResultSet rs = null;//from  w  w w.  j  av a2 s  . c om
    CallableStatement cStmt = null;

    try {

        StringBuffer selectItem = new StringBuffer();

        selectItem.append(" select  \n");
        selectItem.append("  a.ITEM_ID               , \n");
        selectItem.append(
                "  (select b.co_item_id from ktc_item_interlock b where coven_id = 27346 and b.item_id = a.item_id and rownum= 1)     co_item_id      , \n");
        //selectItem.append("  (select CASE WHEN  sum(decode(use_yn,'Y',vir_stock_qty,0)) < 0 then 0 else sum(decode(use_yn,'Y',vir_stock_qty,0)) end  from ktc_unit where item_id = a.item_id    ) qty        , \n");
        selectItem.append(
                "  (select  sum((CASE WHEN  vir_stock_qty <= 0 then 1 else vir_stock_qty end)) from ktc_unit where item_id = a.item_id    and rownum= 1) qty        , \n");
        selectItem.append("  a.ITEM_GB                 , \n");
        selectItem.append("  a.PRE_ITEM_NAME            , \n");
        selectItem.append("  a.MODEL                 , \n");
        selectItem.append("  a.STD_CTG_ID            , \n");
        selectItem.append("  a.START_DATETIME         , \n");
        selectItem.append("  a.END_DATETIME           , \n");
        selectItem.append(
                "  decode( (select sum(decode(use_yn,'Y',vir_stock_qty,0))  from ktc_unit where item_id = a.item_id    )  , 0, 'SUSP' , decode(a.ITEM_STAT_CODE,120103,'SALE', 'SUSP'))   item_stat_code     , \n");// SALE()// SUSP()// QSTK())
        selectItem.append(
                "  (select b.co_ctg_id from ktc_ctg_interlock b where b.coven_id = 27346 and b.sctg_id in (select c.sctg_id from ktc_ctgitem c where c.item_id = a.item_id) and rownum  = 1)     co_ctg_id     , \n"); // 
        // 
        selectItem.append(
                "  decode((select count(DC_SALE_PRICE) from KTC_SITEITEM where ITEM_ID = a.ITEM_ID and SITE_ID = 10 and sysdate between START_DATETIME and END_DATETIME and sysdate between DC_START_DATETIME and DC_END_DATETIME and rownum = 1), 0, (select SALE_PRICE from KTC_SITEITEM where ITEM_ID = a.ITEM_ID  and SITE_ID = 10 and sysdate between START_DATETIME and END_DATETIME and rownum = 1),decode((select DC_SALE_PRICE from KTC_SITEITEM where ITEM_ID = a.ITEM_ID  and SITE_ID = 10 and sysdate between START_DATETIME and END_DATETIME and rownum = 1),0,(select SALE_PRICE from KTC_SITEITEM where ITEM_ID = a.ITEM_ID  and SITE_ID = 10 and sysdate between START_DATETIME and END_DATETIME and rownum = 1),(select DC_SALE_PRICE from KTC_SITEITEM where ITEM_ID = a.ITEM_ID  and SITE_ID = 10 and sysdate between START_DATETIME and END_DATETIME and rownum = 1))) as SALE_PRICE, \n");
        selectItem.append("  a.MIN_ORDER_QTY          , \n");
        selectItem.append("  a.EMP_ID                , \n");
        selectItem.append("  a.IMPORT_VEN_NAME        , \n");
        selectItem.append("  a.PACKER_CODE             , \n");
        selectItem.append("  a.PACK_MATR_CODE          , \n");
        selectItem.append("  a.STOCK_DIS_YN            , \n");
        selectItem.append("  a.VEN_ID                , \n");
        selectItem.append("  a.TAX_GB_CODE             , \n");
        selectItem.append("  a.ORDER_UNIT_CODE         , \n");
        selectItem.append("  a.CON_CARD_YN             , \n");
        selectItem.append("  a.CON_CARD_PRICE         , \n");
        selectItem.append("  a.ACCOUNT_METHOD_CODE     , \n");
        selectItem.append("  a.DELY_AREA_CODE          , \n");
        selectItem.append("  a.LEADTIME_CODE           , \n");
        selectItem.append("  decode(a.LOW_PRICE_YN,'Y',3,1)  LOW_PRICE_YN           , \n");
        selectItem.append("  a.LOW_PRICE_STD           , \n");
        selectItem.append("  a.LOW_PRICE_DELY_FEE      , \n");
        selectItem.append("  a.BUY_TYPE_CODE          , \n");
        selectItem.append("  a.DELI_TYPE_CODE          , \n");
        selectItem.append("  a.WHCENTER_CODE          , \n");
        selectItem.append("  a.GIFT_PACK_YN            , \n");
        selectItem.append("  a.GIFT_PACK_FEE           , \n");
        selectItem.append("  a.BRAND_ID                , \n");
        selectItem.append("  a.QUICK_YN                , \n");
        selectItem.append("  a.NOINTEREST_YN           , \n");
        selectItem.append("  a.NEW_YN                  , \n");
        selectItem.append("  a.RECOMM_YN              , \n");
        selectItem.append("  a.BEST_YN                 , \n");
        selectItem.append("  a.GIFT_SET_ID             , \n");
        selectItem.append("  a.GIFT_OFFER_CNT_CODE     , \n");
        selectItem.append("  a.GIFT_ACC_CNT            , \n");
        selectItem.append("  a.GIFT_LIMIT_CNT          , \n");
        selectItem.append("  a.GIFT_START_DATETIME     , \n");
        selectItem.append("  a.GIFT_END_DATETIME       , \n");
        selectItem.append("  a.HEADCOPY                , \n");
        selectItem.append("  a.ITEM_DESC                , \n");
        selectItem.append("  a.ETC                     , \n");
        selectItem.append("  a.IMG_SET_ID              , \n");
        selectItem.append("  a.GG_PRICE_METH_CODE      , \n");
        selectItem.append("  a.GG_SLIDE_YN             , \n");
        selectItem.append("  a.GG_BUY_PRICE            , \n");
        selectItem.append("  a.GG_SALE_PRICE           , \n");
        selectItem.append("  a.GG_SLIDE_PRICE          , \n");
        selectItem.append("  a.GG_SLIDE_QTY            , \n");
        selectItem.append("  a.GG_SALE_QTY             , \n");
        selectItem.append("  a.GG_NET_COMMISSION      , \n");
        selectItem.append("  a.GG_COMMISSION_CODE     , \n");
        selectItem.append("  a.INSERT_DATE             , \n");
        selectItem.append("  a.INSERT_ID              , \n");
        selectItem.append("  a.MODIFY_DATE             , \n");
        selectItem.append("  a.MODIFY_ID               , \n");
        selectItem.append(
                "  (select code_val from ktc_code where code_id = a.ORIGIN_NAME )    ORIGIN_NAME         , \n");
        selectItem.append("  a.BT_YN                   , \n");
        selectItem.append("  a.ITEM_NAME               , \n");
        selectItem.append("  a.MAKING_VEN_CODE        , \n");
        selectItem.append("  a.IMGX                    , \n");
        selectItem.append("  a.IMGL1                   , \n");
        selectItem.append("  a.IMGL2                   , \n");
        selectItem.append("  a.IMGM1                   , \n");
        selectItem.append("  a.IMGM2                   , \n");
        selectItem.append("  a.IMGS1                   , \n");
        selectItem.append("  a.IMGS2                   , \n");
        selectItem.append("  a.ITMID                   , \n");
        selectItem.append("  a.STORE_ID               , \n");
        selectItem.append("  a.REG_METHOD_GB           , \n");
        selectItem.append("  a.REG_VEN_ID              , \n");
        selectItem.append("  a.VOD_PATH               , \n");
        selectItem.append("  a.RTN_YN                  , \n");
        selectItem.append("  a.MALL_NAME              , \n");
        selectItem.append("  a.MALL_URL                , \n");
        selectItem.append("  a.HUSOISU_YN              , \n");
        selectItem.append("  a.PENALTY_YN              , \n");
        selectItem.append("  a.SEQ_NUM                 , \n");
        selectItem.append("  a.CASH_DISCOUNT_YN        , \n");
        selectItem.append("  a.TWELVE_H_YN             , \n");
        selectItem.append("  a.FIX_FEE_YN              , \n");
        selectItem.append("  a.BUYER_DELY_FEE_YN       , \n");
        selectItem.append("  a.SETYN                   , \n");
        selectItem.append("  a.VIAKTC                  , \n");
        selectItem.append("  a.PREBUYING               , \n");
        selectItem.append("  a.ANOTHER_MARKET_YN       , \n");
        selectItem.append("  a.SPECIAL_DC_FORBID       , \n");
        selectItem.append("  a.CHINA_COMMERCE_YN       , \n");
        selectItem.append("  a.MALL_URL2               , \n");
        selectItem.append("  a.COUPON_MEMO             , \n");
        selectItem.append("  a.FASHIONPLUS_YN          , \n");
        selectItem.append("  a.INTERPARK_YN            , \n");
        selectItem.append("  a.BUYER_DELY_FEE_PRICE    , \n");
        selectItem.append("  a.SINGLE_PLANNING         , \n");
        selectItem.append("  a.CURRENCY                , \n");
        selectItem.append("  a.OUTSIDE_ID              , \n");
        selectItem.append("  a.SINGLE_ITEM_YN          , \n");
        selectItem.append("  a.STYLE_E2A               , \n");
        selectItem.append("  a.CODYITEM_1              , \n");
        selectItem.append("  a.CODYITEM_2              , \n");
        selectItem.append("  a.CODYITEM_3              , \n");
        selectItem.append("  a.CODYITEM_4              , \n");
        selectItem.append("  a.REJECT_DESC             , \n");
        selectItem.append("  a.SHIPPLAN_DATE           , \n");
        selectItem.append("  a.RESERVSHIP_YN           , \n");
        selectItem.append("  a.ELEC_SAFE                \n");
        /*selectItem.append("  a.ELEC_SAFE         ,       \n");
                
        selectItem.append("  b.kind           , \n");
        selectItem.append("  b.itemid           , \n");
        selectItem.append("  b.string1        ,       \n");      
        selectItem.append("  b.string2        ,       \n");      
        selectItem.append("  b.string3        ,       \n");      
        selectItem.append("  b.string4        ,      \n");      
        selectItem.append("  b.string5        ,       \n");      
        selectItem.append("  b.string6         ,      \n");      
        selectItem.append("  b.string7          ,     \n");      
        selectItem.append("  b.string8        ,       \n");      
        selectItem.append("  b.string9        ,       \n");               
        selectItem.append("  b.string10         ,      \n");      
        selectItem.append("  b.string11         ,      \n");      
        selectItem.append("  b.string12         ,      \n");      
        selectItem.append("  b.string13         ,      \n");      
        selectItem.append("  b.string14         ,      \n");      
        selectItem.append("  b.string15               \n");      */

        //selectItem.append(" from ktc_item a ,mirus_detailitem b \n");
        selectItem.append(" from ktc_item a  \n");
        selectItem.append(" where a.item_id > 5000000  \n");
        //selectItem.append(" and a.item_id = b.itemid \n");   

        //selectItem.append(" and a.ven_id in (select ven_id from ktc_vendor where van_status = 120846 ) \n"); // 
        // 
        // 20120109
        // 
        //selectItem.append(" and a.std_ctg_id in ( select ctg_id from ktc_stdctg where prnt_ctg_id=5994 )  \n"); // 
        selectItem.append(" and a.item_id = ? \n");

        //System.out.println("selectItem:"+selectItem.toString());
        /* 20120723   */

        /*   */

        try {

            if (rs != null)
                try {
                    rs.close();
                } catch (Exception e) {
                }
            if (pstmt != null)
                try {
                    pstmt.close();
                } catch (Exception e) {
                }

            // NaverShopnSendItem_test NaverShopnSendItem_test= new
            // NaverShopnSendItem_test();

            pstmt = conn.prepareStatement(selectItem.toString());
            pstmt.setString(1, InputItem);
            System.out.println("InputItem:" + InputItem);
            rs = pstmt.executeQuery();
            System.out.println("rs:" + rs.getRow());
            while (rs.next()) {
                //System.out.println("selectItem in:"+selectItem.toString());               

                SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
                Security.addProvider(new BouncyCastleProvider());

                String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
                String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

                String serviceName = "ProductService"; // 
                String id = "eugink";
                String password = "asdf0101";
                String timestamp = null;
                String signature = null;
                String data = null;

                byte[] encryptKey = null;

                String encryptedData = null;
                String decryptedData = null;
                String hashedData = null;

                String operationName = "ManageProduct";
                String ResponseType = "";

                // String orderID = "200087036";

                // timestamp create
                timestamp = SimpleCryptLib.getTimestamp();
                System.out.println("timestamp:" + timestamp);
                System.out.println("ManageProduct");
                // generateSign
                data = timestamp + serviceName + operationName;
                signature = SimpleCryptLib.generateSign(data, secretKey);

                // generateKey
                encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

                // encrypt
                encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

                // decrypt
                decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

                // sha256
                hashedData = SimpleCryptLib.sha256(password);

                NaverShopnSendItem_down NaverShopnSendItem_test = new NaverShopnSendItem_down();

                String ProductId = "";
                String item_id = "";
                String n_item_id = "";

                item_id = rs.getString("co_item_id");
                n_item_id = rs.getString("item_id");

                /*
                 * CLOB 
                 */

                // 1.StringBuffer, char[], Reader . 
                StringBuffer stringbuffer = new StringBuffer();
                char[] charbuffer = new char[1024];
                Reader reader = null; // CLOB  .
                // 2. ResultSet  CLOB  Reader .
                reader = rs.getCharacterStream("ITEM_DESC");
                int read = 0;
                // 3.  StringBuffer append . 1024 ..
                while ((read = reader.read(charbuffer, 0, 1024)) != -1) {
                    stringbuffer.append(charbuffer, 0, read);
                }
                // 4.  StringBuffer append    .
                String rpl_cont = stringbuffer.toString();
                // 5. StringBuffer  . ( ,      .)
                stringbuffer.delete(0, stringbuffer.capacity());

                itemlist.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n ");
                itemlist.append(
                        "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">");
                itemlist.append("   <soap:Header/>");
                itemlist.append("   <soap:Body>");
                itemlist.append("      <shop:ManageProductRequest>");
                itemlist.append("         <shop:RequestID>njoyny2</shop:RequestID>");
                itemlist.append("         <shop:AccessCredentials>");
                itemlist.append("            <shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>");
                itemlist.append("            <shop:Timestamp>" + timestamp + "</shop:Timestamp>");
                itemlist.append("            <shop:Signature>" + signature + "</shop:Signature>");
                itemlist.append("         </shop:AccessCredentials>");
                itemlist.append("         <shop:Version>2.0</shop:Version>");
                itemlist.append("         <SellerId>njoyny2</SellerId>");
                itemlist.append("         <Product>");
                if (item_id != null) {
                    itemlist.append("            <shop:ProductId>" + item_id + "</shop:ProductId>"); // item_id
                    // 
                    // :null
                    // :id()
                }
                itemlist.append("            <shop:StatusType>SUSP</shop:StatusType>"); // SALE
                // ()
                // SUSP()
                // QSTK())
                itemlist.append("            <shop:SaleType>NEW</shop:SaleType>"); // 
                // 
                // 
                // 
                // NEW:
                itemlist.append(
                        "            <shop:CategoryId>" + rs.getString("co_ctg_id") + "</shop:CategoryId>"); // 
                // ??
                itemlist.append("            <shop:LayoutType>BASIC</shop:LayoutType>"); // BASIC
                // :
                // 
                // IMAGE:
                // 
                itemlist.append("            <shop:Name><![CDATA["
                        + NaverShopnSendItem_test.removeXssString(
                                NaverShopnSendItem_test.parsingSpecialforXml(rs.getString("item_name")))
                        + "]]></shop:Name>"); // 
                itemlist.append("            <shop:SellerManagementCode>" + rs.getString("item_id")
                        + "</shop:SellerManagementCode>"); // 
                itemlist.append("            <shop:Model>");
                itemlist.append("               <shop:ManufacturerName><![CDATA["
                        + rs.getString("MAKING_VEN_CODE") + "]]></shop:ManufacturerName>"); // 
                // itemlist.append("               <shop:BrandName><![CDATA["+
                // rs.getString("brand_id") +"]]></shop:BrandName>" );
                // //
                itemlist.append("            </shop:Model>");
                itemlist.append("            <shop:OriginArea>"); // 
                // GetOriginAreaList
                itemlist.append("               <shop:Code>03</shop:Code>"); // 
                // 
                itemlist.append("            </shop:OriginArea>");
                itemlist.append("            <shop:TaxType>TAX</shop:TaxType>"); // 
                itemlist.append("            <shop:MinorPurchasable>Y</shop:MinorPurchasable>"); // 
                // */
                itemlist.append("            <shop:Image>");
                itemlist.append("               <shop:Representative>"); // 
                // 450*450
                itemlist.append("                  <shop:URL><![CDATA["
                        + NaverShopnSendItem_test.run2(rs.getString("IMGX")) + "]]></shop:URL>");

                // itemlist.append("                  <shop:URL><![CDATA[http://beta.shop1.phinf.naver.net/20120829_211/nmp_1346214765097FUx6u_JPEG/45862043648053663_117747847.jpg]]></shop:URL>"
                // );
                itemlist.append("               </shop:Representative>");
                itemlist.append("            </shop:Image>");

                // String DetailContent =
                // NaverShopnSendItem_test.parsingSpecialforXml("/ :"+rs.getString("MAKING_VEN_CODE")+"/"+
                // rs.getString("ORIGIN_NAME")+"<br>"+
                // rs.getString("ITEM_DESC")) ;
                itemlist.append("            <shop:DetailContent><![CDATA[" + "/ :"
                        + rs.getString("MAKING_VEN_CODE") + "/" + rs.getString("ORIGIN_NAME") + "<br>"
                        + rpl_cont + "]]></shop:DetailContent>"); // 
                // itemlist.append("            <shop:DetailContent><![CDATA["+"/ :"+rs.getString("MAKING_VEN_CODE")+"/"+
                // rs.getString("ORIGIN_NAME")+ ""
                // +"]]></shop:DetailContent>" ); //
                itemlist.append("            <shop:AfterServiceTelephoneNumber><![CDATA[" + "02-1577-3212"
                        + "]]></shop:AfterServiceTelephoneNumber>"); // AS()
                itemlist.append("            <shop:AfterServiceGuideContent><![CDATA["
                        + "     ."
                        + "]]></shop:AfterServiceGuideContent>"); // A/S
                itemlist.append("            <shop:PurchaseReviewExposure>Y</shop:PurchaseReviewExposure>"); // 
                itemlist.append(
                        "            <shop:KnowledgeShoppingProductRegistration>Y</shop:KnowledgeShoppingProductRegistration>"); // 
                itemlist.append(
                        "            <shop:SalePrice>" + rs.getString("SALE_PRICE") + "</shop:SalePrice>"); // 
                itemlist.append(
                        "            <shop:StockQuantity>" + rs.getString("qty") + "</shop:StockQuantity>");

                itemlist.append("            <shop:Delivery>");
                itemlist.append("            <shop:Type>1</shop:Type>");
                itemlist.append("            <shop:BundleGroupAvailable>N</shop:BundleGroupAvailable>");
                itemlist.append("            <shop:PayType>2</shop:PayType>"); //  1  3 
                itemlist.append(
                        "            <shop:FeeType>" + rs.getString("low_price_yn") + "</shop:FeeType>"); //  1  3 
                itemlist.append(
                        "            <shop:BaseFee>" + rs.getString("LOW_PRICE_DELY_FEE") + "</shop:BaseFee>"); //
                itemlist.append(
                        "            <shop:ReturnDeliveryCompanyPriority>0</shop:ReturnDeliveryCompanyPriority>"); //
                itemlist.append("            <shop:ReturnFee>5000</shop:ReturnFee>"); // 
                itemlist.append("            <shop:ExchangeFee>5000</shop:ExchangeFee>"); //
                itemlist.append("            </shop:Delivery>");

                /*
                 *   start 20121112
                 */

                /*itemlist.append("            <shop:ProductSummary>");  // 20121112
                        
                if("3".equals(rs.getString("kind"))||"4".equals(rs.getString("kind"))){
                           
                   itemlist.append(" <shop:Shoes> ");  // ShoesSummaryType
                   itemlist.append(" <shop:Material>:" + rs.getString("string1") +"/:"+ rs.getString("string2") +"</shop:Material> "); // 
                   itemlist.append(" <shop:Color>" + rs.getString("string3") + "</shop:Color> "); //
                   itemlist.append(" <shop:Size>" + rs.getString("string4") + "</shop:Size> "); //
                   itemlist.append(" <shop:Height>" + rs.getString("string5") + "</shop:Height> "); //
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string6") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Caution>" + rs.getString("string8") + "</shop:Caution> "); //
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string9") + "</shop:WarrantyPolicy> "); //
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string10") + "</shop:AfterServiceDirector> "); //a/s               
                   itemlist.append(" </shop:Shoes> ");  //
                           
                }else if("1".equals(rs.getString("kind"))||"2".equals(rs.getString("kind"))){
                           
                   itemlist.append(" <shop:Wear> "); // WearSummaryType
                   itemlist.append(" <shop:Material>" + rs.getString("string1") + "</shop:Material> "); //
                   itemlist.append(" <shop:Color>" + rs.getString("string2") + "</shop:Color> "); //
                   itemlist.append(" <shop:Size>" + rs.getString("string3") + "</shop:Size> "); //
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string4") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Caution>" + rs.getString("string6") + "</shop:Caution> "); // 
                   //itemlist.append(" <shop:PackDate> string </shop:PackDate> "); //
                   itemlist.append(" <shop:PackDateText>" + rs.getString("string7") + "</shop:PackDateText> "); //   
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string8") + "</shop:WarrantyPolicy> "); //
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string9") + "</shop:AfterServiceDirector> ");   //a/s               
                   itemlist.append(" </shop:Wear>"); //
                           
                }else if("5".equals(rs.getString("kind"))||"6".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:Bag> ");  // BagSummaryType
                   itemlist.append(" <shop:Type>" + rs.getString("string1") + "</shop:Tye> "); //
                   itemlist.append(" <shop:Material>" + rs.getString("string2") + "</shop:Material> "); //
                   itemlist.append(" <shop:Color>" + rs.getString("string3") + "</shop:Color> "); //
                   itemlist.append(" <shop:Size>" + rs.getString("string4") + "</shop:Size> "); //
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string5") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Caution>" + rs.getString("string7") + "</shop:Caution> "); //
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string8") + "</shop:WarrantyPolicy> "); //
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string9") + "</shop:AfterServiceDirector> ");   //a/s               
                   itemlist.append(" </shop:Wear>");  //
                           
                }else if("7".equals(rs.getString("kind"))||"8".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:FashionItems> ");  // FashionItemsSummaryType
                   itemlist.append(" <shop:Type>" + rs.getString("string1") + "</shop:Tye> "); //
                   itemlist.append(" <shop:Material>" + rs.getString("string2") + "</shop:Material> "); //
                   itemlist.append(" <shop:Size>" + rs.getString("string3") + "</shop:Size> "); //
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string4") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Caution>" + rs.getString("string6") + "</shop:Caution> "); // 
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string7") + "</shop:WarrantyPolicy> "); //
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string8") + "</shop:AfterServiceDirector> ");    //a/s               
                   itemlist.append(" </shop:FashionItems>");  //
                           
                }else if("13".equals(rs.getString("kind"))||"14".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:HomeAppliances> ");  //() HomeAppliancesSummaryType
                   itemlist.append(" <shop:ItemName>" + rs.getString("string1") + "</shop:ItemName> ");  //
                   itemlist.append(" <shop:ModelName>" + rs.getString("string1") + "</shop:ModelName> "); //
                   //itemlist.append(" <shop:Certified> string </shop:Certified> "); //  
                   itemlist.append(" <shop:RatedVoltage>" + rs.getString("string3") + "</shop:RatedVoltage> "); //
                   itemlist.append(" <shop:PowerConsumption>" + rs.getString("string3") + "</shop:PowerConsumption> "); //
                   itemlist.append(" <shop:EnergyEfficiencyRating>" + rs.getString("string3") + "</shop:EnergyEfficiencyRating> "); //
                   itemlist.append(" <shop:ReleaseDate>" + rs.getString("string4") + "</shop:ReleaseDate> "); //  'yyyy-mm'
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string5") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Size>" + rs.getString("string7") + "</shop:Size> "); //
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string8") + "</shop:WarrantyPolicy> "); //
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string9") + "</shop:AfterServiceDirector> ");    //a/s               
                   itemlist.append(" </shop:HomeAppliances>");  //()
                           
                }else if("17".equals(rs.getString("kind"))||"18".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:MedicalAppliances> "); // MedicalAppliancesSummaryType
                   itemlist.append(" <shop:ItemName>" + rs.getString("string1") + "</shop:ItemName> "); //
                   itemlist.append(" <shop:ModelName>" + rs.getString("string1") + "</shop:ModelName> "); //
                   itemlist.append(" <shop:LicenceNo>" + rs.getString("string2") + "</shop:LicenceNo> "); // 
                   //itemlist.append(" <shop:AdvertisingCertified> string </shop:AdvertisingCertified> "); //
                   //itemlist.append(" <shop:Certified> string </shop:Certified> "); //kc
                   itemlist.append(" <shop:RatedVoltage>" + rs.getString("string4") + "</shop:RatedVoltage> "); //
                   itemlist.append(" <shop:PowerConsumption>" + rs.getString("string4") + "</shop:PowerConsumption> "); //
                   itemlist.append(" <shop:ReleaseDate>" + rs.getString("string5") + "</shop:ReleaseDate> "); // 'yyyy-mm'
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string6") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Purpose>" + rs.getString("string8") + "</shop:Purpose> "); //
                   itemlist.append(" <shop:Usage>" + rs.getString("string8") + "</shop:Usage> "); //
                   itemlist.append(" <shop:Caution>" + rs.getString("string9") + "</shop:Caution> "); //
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string10") + "</shop:WarrantyPolicy> ");  //
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string11") + "</shop:AfterServiceDirector> ");   //a/s               
                   itemlist.append(" </shop:MedicalAppliances>"); //
                           
                }else if("11".equals(rs.getString("kind"))||"12".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:Cosmetic>"); // CosmeticSummaryType
                   itemlist.append(" <shop:Capacity>" + rs.getString("string1") + "</shop:Capacity> ");   // 
                   itemlist.append(" <shop:Specification>" + rs.getString("string2") + "</shop:Specification> "); // 
                   //itemlist.append(" <shop:ExpirationDate> string </shop:ExpirationDate> "); //  
                   itemlist.append(" <shop:ExpirationDateText>" + rs.getString("string3") + "</shop:ExpirationDateText> "); //  ()
                   itemlist.append(" <shop:Usage>" + rs.getString("string4") + "</shop:Usage> "); //
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string5") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Distributor>" + rs.getString("string5") + "</shop:Distributor> "); //
                   itemlist.append(" <shop:MainIngredient>" + rs.getString("string7") + "</shop:MainIngredient> "); //
                   //itemlist.append(" <shop:Certified> string </shop:Certified> "); //  Y,N
                   itemlist.append(" <shop:Caution>" + rs.getString("string9") + "</shop:Caution> "); //
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string10") + "</shop:WarrantyPolicy> "); //
                   itemlist.append(" <shop:CustomerServicePhoneNumber>" + rs.getString("string11") + "</shop:CustomerServicePhoneNumber> ");  //                  
                   itemlist.append(" </shop:Cosmetic>"); //
                           
                }else if("9".equals(rs.getString("kind"))||"10".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:Jewellery> "); // JewellerySummaryType
                   itemlist.append(" <shop:Material>" + rs.getString("string1") + "</shop:Material> "); //
                   itemlist.append(" <shop:Purity>" + rs.getString("string1") + "</shop:Purity> "); //
                   itemlist.append(" <shop:BandMaterial>" + rs.getString("string1") + "</shop:BandMaterial> "); //
                   itemlist.append(" <shop:Weight>" + rs.getString("string2") + "</shop:Weight> "); //
                   itemlist.append(" <shop:Manufacturer>" + rs.getString("string3") + "</shop:Manufacturer> "); //
                   itemlist.append(" <shop:Producer>" + rs.getString("string4") + "</shop:Producer> "); //
                   itemlist.append(" <shop:Size>" + rs.getString("string5") + "</shop:Size> "); //
                   itemlist.append(" <shop:Caution>" + rs.getString("string6") + "</shop:Caution> "); //
                   itemlist.append(" <shop:Specification>" + rs.getString("string7") + "</shop:Specification> "); //
                   //itemlist.append(" <shop:ProvideWarranty>" + rs.getString("string8") + "</shop:ProvideWarranty> "); // Y,N
                   itemlist.append(" <shop:ProvideWarranty>N</shop:ProvideWarranty> "); // Y,N
                   itemlist.append(" <shop:WarrantyPolicy>" + rs.getString("string9") + "</shop:WarrantyPolicy> "); // 
                   itemlist.append(" <shop:AfterServiceDirector>" + rs.getString("string10") + "</shop:AfterServiceDirector> ");   //a/s               
                   itemlist.append(" </shop:Jewellery>"); //
                           
                }else if("15".equals(rs.getString("kind"))||"16".equals(rs.getString("kind"))){   
                           
                   itemlist.append(" <shop:DietFood> ");      //    DietFoodSummaryType
                   itemlist.append(" <shop:FoodType>" + rs.getString("string1") + "</shop:FoodType> "); //
                   itemlist.append(" <shop:Producer>" + rs.getString("string2") + "</shop:Producer> "); //
                   itemlist.append(" <shop:Location>" + rs.getString("string2") + "</shop:Location> "); //
                   //itemlist.append(" <shop:PackDate> string </shop:PackDate> "); //
                   itemlist.append(" <shop:PackDateText>" + rs.getString("string3") + "</shop:PackDateText> "); //()
                   //itemlist.append(" <shop:ExpirationDate> string </shop:ExpirationDate> "); //  
                   itemlist.append(" <shop:ExpirationDateText>" + rs.getString("string3") + "</shop:ExpirationDateText> "); //  ()
                   itemlist.append(" <shop:Weight>" + rs.getString("string4") + "</shop:Weight> "); //
                   itemlist.append(" <shop:Amount>" + rs.getString("string4") + "</shop:Amount> "); // 
                   itemlist.append(" <shop:Ingredients>" + rs.getString("string5") + "</shop:Ingredients> "); //  
                   itemlist.append(" <shop:NutritionFacts>" + rs.getString("string6") + "</shop:NutritionFacts> "); //
                   itemlist.append(" <shop:Specification>" + rs.getString("string7") + "</shop:Specification> "); //
                   itemlist.append(" <shop:CautionAndSideEffect>" + rs.getString("string8") + "</shop:CautionAndSideEffect> "); //,   
                   itemlist.append(" <shop:NonMedicinalUsesMessage>" + rs.getString("string9") + "</shop:NonMedicinalUsesMessage> "); //      
                   itemlist.append(" <shop:GeneticallyModified>" + rs.getString("string10") + "</shop:GeneticallyModified> "); //      y,n
                   //itemlist.append(" <shop:AdvertisingCertified> string </shop:AdvertisingCertified> "); //   
                   itemlist.append(" <shop:ImportDeclarationCheck>" + rs.getString("string12") + "</shop:ImportDeclarationCheck> "); //     y,n
                   itemlist.append(" <shop:CustomerServicePhoneNumber>" + rs.getString("string13") + "</shop:CustomerServicePhoneNumber> "); // 
                   itemlist.append(" </shop:DietFood>   ");      //   
                           
                }
                */

                /*
                 *   end 20121112
                 */

                //itemlist.append("            </shop:ProductSummary>");               

                itemlist.append("      </Product>");
                itemlist.append("      </shop:ManageProductRequest>");
                itemlist.append("      </soap:Body>");
                itemlist.append("      </soap:Envelope>");

                System.out.println("#################################################");
                System.out.println("itemlist.toString():" + itemlist.toString());
                System.out.println("#################################################");
                /************************************/
                int pre_cnt = 0;
                /*
                StringBuffer unitCnt1 = new StringBuffer();
                        
                unitCnt1.append(" select count(*) cnt \n");
                unitCnt1.append(" from ( \n");
                unitCnt1.append("  select nvl(b.coven_id,0) coven_id,a.unit_name,nvl(b.co_unit_id,0) co_unit_id,a.unit_id,a.vir_stock_qty,a.use_yn  \n");
                unitCnt1.append(" from ktc_unit a,ktc_unit_interlock b \n");
                unitCnt1.append(" where a.unit_id = b.unit_id(+)  \n");
                unitCnt1.append(" and a.item_id = ? \n");
                unitCnt1.append(" )where  coven_id in (27346)    \n");
                        
                        
                try {
                   PreparedStatement pstmt3 = null;
                   ResultSet rs3 = null;
                        
                        
                   pstmt3 = conn.prepareStatement(unitCnt1.toString());
                   pstmt3.setString(1, n_item_id); // h_order_no
                   rs3 = pstmt3.executeQuery();
                           
                        
                   while (rs3.next()) {
                      pre_cnt = rs3.getInt("cnt");
                   }
                        
                        
                   if (pre_cnt > 0) {
                      NaverShopnSendItem_test.run4(item_id, n_item_id, pre_cnt); // 
                        
                   }
                        
                        
                   if (rs3 != null)
                      try {
                rs3.close();
                      } catch (Exception e) {
                      }
                   if (pstmt3 != null)
                      try {
                pstmt3.close();
                      } catch (Exception e) {
                      }
                } catch (Exception e) {
                   System.out.println("() : " + e.getMessage());
                } finally {
                }      */

                /**********************************/

                /*if (item_id != null && pre_cnt > 0) { //     .
                   try {
                      StringBuffer unitCnt = new StringBuffer();
                        
                      unitCnt.append(" select count(*) cnt \n");
                      unitCnt.append(" from ( \n");
                      unitCnt.append("  select decode(b.coven_id,27346,b.coven_id,0) coven_id,a.unit_name,decode(b.coven_id,27346,b.co_unit_id,0) co_unit_id,a.unit_id,a.vir_stock_qty,a.use_yn   \n");
                      unitCnt.append(" from ktc_unit a,ktc_unit_interlock b \n");
                      unitCnt.append(" where a.unit_id = b.unit_id(+)  \n");
                      unitCnt.append(" and a.item_id = ? \n");
                      unitCnt.append(" )where  coven_id in (27346,0)    \n");
                        
                      System.out.println("   !!!!!!!!!!!!");
                      try {
                PreparedStatement pstmt3 = null;
                ResultSet rs3 = null;
                        
                        
                pstmt3 = conn.prepareStatement(unitCnt.toString());
                pstmt3.setString(1, n_item_id); // h_order_no
                rs3 = pstmt3.executeQuery();
                int cnt = 0;
                        
                while (rs3.next()) {
                   cnt = rs3.getInt("cnt");
                }
                        
                        
                if (cnt > 0) {
                   NaverShopnSendItem_test.run4(item_id, n_item_id, cnt); // 
                        
                }
                        
                        
                if (rs3 != null)
                   try {
                      rs3.close();
                   } catch (Exception e) {
                   }
                if (pstmt3 != null)
                   try {
                      pstmt3.close();
                   } catch (Exception e) {
                   }
                      } catch (Exception e) {
                System.out.println("() : " + e.getMessage());
                      } finally {
                      }
                   } catch (Exception e) {
                      System.out.println("() : " + e.getMessage());
                   } finally {
                   }
                }
                */

                String line_total = "";
                URL url = new URL("http://ec.api.naver.com/ShopN/ProductService");
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                con.setDoOutput(true);
                con.setRequestMethod("POST");
                con.setDoOutput(true);
                //      .  true.
                con.setDoInput(true);
                con.setUseCaches(false);
                con.setDefaultUseCaches(false);
                // Header  
                con.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");

                // BODY  
                OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
                wr.write(itemlist.toString());
                wr.flush();

                //   
                String inputLine = null;
                BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));

                while ((inputLine = rd.readLine()) != null) {
                    line_total = line_total + inputLine;

                }
                System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
                System.out.println("response message:" + line_total);
                System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
                rd.close();
                wr.close();

                /*
                               line_total = line_total.replaceAll("n:", "");
                               //System.out.println(line_total);
                        
                               // xml2
                               InputStream in = new ByteArrayInputStream(
                                     line_total.getBytes("UTF-8"));
                        
                               SAXBuilder builder = new SAXBuilder();
                               Document document = builder.build(in);
                        
                               Element element = document.getRootElement();
                               List envel_list = element.getChildren();
                               //System.out.println("envel_list:" + envel_list);
                        
                               List body_list = null;
                               List body_list1 = null;
                               List result_list = null;
                               List result_list1 = null;
                               List result_list2 = null;
                               List result_list3 = null;
                               List result_list4 = null;
                               List result_list5 = null;
                               List info_list = null;
                               List contr_group_list = null;
                               List contr_info_list = null;
                        
                               PreparedStatement pstmt2 = null;
                               ResultSet rs2 = null;
                               CallableStatement cStmt2 = null;
                        
                               Element envel_el = (Element) envel_list.get(0);
                               body_list = envel_el.getChildren();
                        
                               Element body_el = (Element) body_list.get(0);
                               result_list = body_el.getChildren("ManageProductResponse");
                        
                               ResponseType = body_el.getChildText("ResponseType");
                               ProductId = body_el.getChildText("ProductId");
                               */

                /*
                if (ResponseType.equals("SUCCESS")) {
                        
                   if (item_id == null) {
                        
                      StringBuffer setCovenID = new StringBuffer();
                      setCovenID.append(" insert into ktc_item_interlock(coven_id , co_item_id , item_id ,insert_date,update_date)  \n");
                      setCovenID.append(" values (27346,?,?,sysdate,sysdate)  \n");
                        
                        
                      pstmt2 = conn.prepareStatement(setCovenID
                   .toString());
                        
                      int insert_cnt = 0;
                        
                      try {
                // pstmt2.clearParameters();
                        
                // 
                pstmt2.setString(1, ProductId);
                pstmt2.setString(2, n_item_id); // h_order_no
                System.out.println("ProductId:" + ProductId);
                System.out.println("n_item_id:" + n_item_id);
                        
                pstmt2.executeUpdate();
                System.out.println("end insert");
                if (rs2 != null)
                   try {
                      rs2.close();
                   } catch (Exception e) {
                   }
                if (pstmt2 != null)
                   try {
                      pstmt2.close();
                   } catch (Exception e) {
                   }
                      } catch (Exception e) {
                response_type = "FALSE";
                e.printStackTrace();
                conn.rollback();
                      }
                   } else {
                        
                        
                      StringBuffer setCovenID = new StringBuffer();
                      setCovenID
                   .append(" update ktc_item_interlock set   \n");
                      setCovenID.append(" update_date = sysdate  \n");
                      setCovenID
                   .append(" where coven_id = 27346 and item_id = ?  \n");
                        
                      int insert_cnt = 0;
                      pstmt2 = conn.prepareStatement(setCovenID
                   .toString());
                        
                      try {
                // pstmt2.clearParameters();
                        
                // 
                        
                pstmt2.setString(1, n_item_id); // h_order_no
                pstmt2.executeUpdate();
                System.out.println("end update");
                if (rs2 != null)
                   try {
                      rs2.close();
                   } catch (Exception e) {
                   }
                if (pstmt2 != null)
                   try {
                      pstmt2.close();
                   } catch (Exception e) {
                   }
                      } catch (Exception e) {
                System.out.println("error() : " + e.getMessage());
                response_type = "FALSE";
                e.printStackTrace();
                conn.rollback();
                      }
                   }
                        
                }
                        
                if (rs2 != null)
                   try {
                      rs2.close();
                   } catch (Exception e) {
                   }
                if (pstmt2 != null)
                   try {
                      pstmt2.close();
                   } catch (Exception e) {
                   }
                */
                /*
                System.out.println("pre_cnt:"+pre_cnt);
                if (item_id == null ||pre_cnt == 0) { //item_id   
                   StringBuffer unitCnt = new StringBuffer();
                   System.out.println("!!!!");
                   unitCnt.append(" select count(*) cnt \n");
                   unitCnt.append(" from ( \n");
                   unitCnt.append("  select decode(b.coven_id,27346,b.coven_id,0) coven_id,a.unit_name,decode(b.coven_id,27346,b.co_unit_id,0) co_unit_id,a.unit_id,a.vir_stock_qty,a.use_yn   \n");
                   unitCnt.append(" from ktc_unit a,ktc_unit_interlock b \n");
                   unitCnt.append(" where a.unit_id = b.unit_id(+)  \n");
                   unitCnt.append(" and a.item_id = ? \n");
                   unitCnt.append(" )where  coven_id in (27346,0)    \n");
                        
                   System.out.println("n_item_id:" + n_item_id);
                   try {
                      PreparedStatement pstmt3 = null;
                      ResultSet rs3 = null;
                        
                        
                      pstmt3 = conn.prepareStatement(unitCnt.toString());
                      pstmt3.setString(1, n_item_id); // h_order_no
                      rs3 = pstmt3.executeQuery();
                      int cnt = 0;
                        
                      while (rs3.next()) {
                cnt = rs3.getInt("cnt");
                      }
                        
                              
                      if (cnt > 0) {
                if (pre_cnt == 0) {
                   System.out.println("ProductId:"+item_id);
                   System.out.println("n_item_id:"+n_item_id);
                   System.out.println("cnt:"+cnt);                           
                   NaverShopnSendItem_test.run4(item_id, n_item_id, cnt); // 
                }else{
                        
                   NaverShopnSendItem_test.run4(ProductId, n_item_id, cnt); // 
                }
                      }
                        
                        
                      if (rs3 != null)
                try {
                   rs3.close();
                } catch (Exception e) {
                }
                      if (pstmt3 != null)
                try {
                   pstmt3.close();
                } catch (Exception e) {
                }
                   } catch (Exception e) {
                      System.out.println("() : " + e.getMessage());
                   } finally {
                   }
                }*/

            }
            System.out.println("itemlist:" + itemlist.toString());
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                    response_type = "FALSE";
                }
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {
                    response_type = "FALSE";
                }
            }

        } catch (Exception e) {
            System.out.println("run_1() : " + e.getMessage());
        } finally {
        }

    } catch (Exception e) {
        System.out.println("run_2() : " + e.getMessage());
        response_type = "FALSE";
    } finally {
    }

    return response_type;
}

From source file:SignPdf.java

License:Open Source License

/**
* Add a signature and a cryptographic timestamp to a pdf document. See www.ietf.org/rfc/rfc3161.txt. Proves that this
* pdf had the current content at the current point in time.
*
* @param originalPdf//  www  . j  a v  a 2 s . c o  m
* @param targetPdf
* @param pk
* @param certChain
* @param revoked
* @param tsaAddress
* address of a rfc 3161 compatible timestamp server
* @param reason
* reason for the signature
* @param location
* location of signing
* @param contact
* emailaddress of the person who is signing
* @throws IOException
* @throws DocumentException
* @throws SignatureException
*/
public static void signAndTimestamp(final InputStream originalPdf, final OutputStream targetPdf,
        final PrivateKey pk, final X509Certificate[] certChain, final CRL[] revoked, final String tsaAddress,
        final String reason, final String location, final String contact)
        throws IOException, DocumentException, SignatureException {
    // only an estimate, depends on the certificates returned by the TSA
    final int timestampSize = 4400;
    Security.addProvider(new BouncyCastleProvider());

    final PdfReader reader = new PdfReader(originalPdf);
    final PdfStamper stamper = PdfStamper.createSignature(reader, targetPdf, '\0');
    final PdfSignatureAppearance sap = stamper.getSignatureAppearance();

    // comment next lines to have an invisible signature
    Rectangle cropBox = reader.getCropBox(1);
    float width = 50;
    float height = 50;
    Rectangle rectangle = new Rectangle(cropBox.getRight(width) - 20, cropBox.getTop(height) - 20,
            cropBox.getRight() - 20, cropBox.getTop() - 20);
    sap.setVisibleSignature(rectangle, 1, null);
    //sap.setVisibleSignature(new Rectangle(450, 650, 500, 700), 1, null);
    sap.setLayer2Text("");

    final PdfSigGenericPKCS sig = new PdfSigGenericPKCS.PPKMS("BC");
    final HashMap<PdfName, Integer> exclusionSizes = new HashMap<PdfName, Integer>();

    // some informational fields
    sig.setReason(reason);
    sig.setLocation(location);
    sig.setContact(contact);
    sig.setName(PdfPKCS7.getSubjectFields(certChain[0]).getField("CN"));
    sig.setDate(new PdfDate(Calendar.getInstance()));

    // signing stuff
    final byte[] digest = new byte[256];
    final byte[] rsaData = new byte[20];
    sig.setExternalDigest(digest, rsaData, "RSA");
    sig.setSignInfo(pk, certChain, revoked);
    final PdfString contents = (PdfString) sig.get(PdfName.CONTENTS);
    // *2 to get hex size, +2 for delimiters
    PdfLiteral contentsLit = new PdfLiteral((contents.toString().length() + timestampSize) * 2 + 2);
    exclusionSizes.put(PdfName.CONTENTS, new Integer(contentsLit.getPosLength()));
    sig.put(PdfName.CONTENTS, contentsLit);

    // certification; will display dialog or blue bar in Acrobat Reader

    sap.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);

    // process all the information set above
    sap.setCryptoDictionary(sig);
    sap.preClose(exclusionSizes);

    // calculate digest (hash)
    try {
        final MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
        final byte[] buf = new byte[8192];
        int n;
        final InputStream inp = sap.getRangeStream();
        while ((n = inp.read(buf)) != -1) {
            messageDigest.update(buf, 0, n);
        }
        final byte[] hash = messageDigest.digest();

        // make signature (SHA1 the hash, prepend algorithm ID, pad, and encrypt with RSA)
        final Signature sign = Signature.getInstance("SHA1withRSA");
        sign.initSign(pk);
        sign.update(hash);
        final byte[] signature = sign.sign();

        // prepare the location of the signature in the target PDF
        contentsLit = (PdfLiteral) sig.get(PdfName.CONTENTS);
        final byte[] outc = new byte[(contentsLit.getPosLength() - 2) / 2];
        final PdfPKCS7 pkcs7 = sig.getSigner();
        pkcs7.setExternalDigest(signature, hash, "RSA");
        final PdfDictionary dic = new PdfDictionary();

        byte[] ssig = pkcs7.getEncodedPKCS7();
        try {
            // try to retrieve cryptographic timestamp from configured tsa server
            ssig = pkcs7.getEncodedPKCS7(null, null, new TSAClientBouncyCastle(tsaAddress), null);
        } catch (final RuntimeException e) {
            log.error("Could not retrieve timestamp from server.", e);
        }
        System.arraycopy(ssig, 0, outc, 0, ssig.length);

        // add the timestamped signature
        dic.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));

        // finish up
        sap.close(dic);
    } catch (final InvalidKeyException e) {
        throw new RuntimeException("Internal implementation error! No such signature type.", e);
    } catch (final NoSuchAlgorithmException e) {
        throw new RuntimeException("Internal implementation error! No such algorithm type.", e);
    }
}

From source file:NaverShopnSendItem.java

private String run4(String ProductId, String n_item_id, Integer cnt) { // 
    // //from w w w  . j  av a2  s  . com
    // 
    String response_type = "FALSE";
    NaverShopnSendItem NaverShopnSendItem = new NaverShopnSendItem();
    System.out.println("run4");
    try {
        /*   */

        //   
        SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
        Security.addProvider(new BouncyCastleProvider());

        String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
        String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

        String serviceName = "ProductService"; // 
        String id = "eugink";
        String password = "asdf0101";
        String timestamp = null;
        String signature = null;
        String data = null;
        String item_id = "";

        byte[] encryptKey = null;

        String encryptedData = null;
        String decryptedData = null;
        String hashedData = null;

        String operationName = "GetOption";
        String ResponseType = "";

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        CallableStatement cStmt = null;

        operationName = "ManageOption";

        // String orderID = "200087036";

        // timestamp create
        timestamp = SimpleCryptLib.getTimestamp();
        System.out.println("timestamp:" + timestamp);
        System.out.println("ManageOption");

        // generateSign
        data = timestamp + serviceName + operationName;
        signature = SimpleCryptLib.generateSign(data, secretKey);

        // generateKey
        encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

        // encrypt
        encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

        // decrypt
        decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

        // sha256
        hashedData = SimpleCryptLib.sha256(password);

        //   
        StringBuffer unitlistsql = new StringBuffer(); // 

        try {
            StringBuffer selectUnit = new StringBuffer();

            selectUnit.append(" select unit_name,co_unit_id,unit_id,  vir_stock_qty  ,use_yn \n");
            selectUnit.append(" from ( \n");
            selectUnit.append(
                    "  select nvl(b.coven_id,0) coven_id,decode(a.use_yn , 'Y',a.unit_name,a.unit_name||'('||a.unit_id||')') unit_name,nvl(b.co_unit_id,0) co_unit_id,a.unit_id,(CASE WHEN  vir_stock_qty <= 0 then decode(use_yn,'Y',1,0) else decode(use_yn,'Y',vir_stock_qty,0) end) vir_stock_qty,decode(a.use_yn,'Y','Y','N') use_yn \n");
            selectUnit.append(" from ktc_unit a,ktc_unit_interlock b \n");
            selectUnit.append(" where a.unit_id = b.unit_id(+) \n");
            selectUnit.append(" and a.unit_name is not null \n");
            selectUnit.append(" and a.item_id = ? \n");
            selectUnit.append(" )where  coven_id in (27346,0)    \n");

            //System.out.println("selectUnit.toString():"+ selectUnit.toString());
            HashMap unitList = new HashMap();
            pstmt = conn.prepareStatement(selectUnit.toString());

            // pstmt.clearParameters();

            // 
            pstmt.setString(1, n_item_id);
            rs = pstmt.executeQuery();
            int list_cnt = 1;

            while (rs.next()) {

                HashMap rowData = new HashMap();
                rowData.put("unit_name", rs.getString("unit_name"));
                rowData.put("co_unit_id", rs.getString("co_unit_id"));
                rowData.put("unit_id", rs.getString("unit_id"));
                rowData.put("vir_stock_qty", rs.getString("vir_stock_qty"));
                rowData.put("use_yn", rs.getString("use_yn"));
                unitList.put(Integer.toString(list_cnt), rowData);

                list_cnt = list_cnt + 1;
            }

            /* unit xml  */

            unitlistsql.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n ");
            unitlistsql.append(
                    "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\"> ");
            unitlistsql.append(
                    "   <soap:Header/>                                                                                                    ");
            unitlistsql.append(
                    "   <soap:Body>                                                                                                       ");
            unitlistsql.append(
                    "      <shop:ManageOptionRequest>                                                                                     ");
            unitlistsql.append(
                    "         <!--Optional:-->                                                                                            ");
            unitlistsql.append("         <shop:RequestID>njoyny2</shop:RequestID>");
            unitlistsql.append("         <shop:AccessCredentials>");
            unitlistsql.append("            <shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>");
            unitlistsql.append("            <shop:Timestamp>" + timestamp + "</shop:Timestamp>");
            unitlistsql.append("            <shop:Signature>" + signature + "</shop:Signature>");
            unitlistsql.append("         </shop:AccessCredentials>");
            unitlistsql.append("         <shop:Version>2.0</shop:Version>");
            unitlistsql.append("         <SellerId>njoyny2</SellerId>");

            unitlistsql.append(
                    "         <Option>                                                                                                    ");
            unitlistsql.append("            <shop:ProductId>" + ProductId
                    + "</shop:ProductId>                                                                       ");
            unitlistsql.append(
                    "            <!--Optional:-->                                                                                         ");
            unitlistsql.append(
                    "                        <shop:Combination>                                         ");

            unitlistsql.append("                     <shop:Names> ");
            unitlistsql.append("                        <shop:Name1><![CDATA[]]></shop:Name1> ");
            unitlistsql.append("                     </shop:Names> ");

            unitlistsql.append("                     <shop:ItemList>   ");

            System.out.println("unitlistsql:" + unitlistsql);
            System.out.println("!!!!cnt:" + cnt);
            String unit_name = "";
            String co_unit_id = "";
            String unit_id = "";
            String vir_stock_qty = "";
            String use_yn = "";
            HashMap rowData1 = null;

            for (int j = 1; j <= cnt; j++) {

                rowData1 = (HashMap) unitList.get(String.valueOf(j));

                unit_name = NaverShopnSendItem.parsingSpecialforXml((String) rowData1.get("unit_name"))
                        .replaceAll(":", "-"); // njoyny id
                co_unit_id = (String) rowData1.get("co_unit_id"); // shopN
                // id
                unit_id = (String) rowData1.get("unit_id");
                vir_stock_qty = (String) rowData1.get("vir_stock_qty");
                use_yn = (String) rowData1.get("use_yn");

                unitlistsql.append(
                        "                           <shop:Item>                                          ");
                if (!co_unit_id.equals("0")) {
                    unitlistsql.append("                              <shop:Id>" + co_unit_id
                            + "</shop:Id>                                ");
                }
                unitlistsql.append("                              <shop:Value1>" + unit_name
                        + "</shop:Value1>                            ");
                unitlistsql.append("                              <shop:Quantity>" + vir_stock_qty
                        + "</shop:Quantity>                            ");
                unitlistsql.append("                              <shop:SellerManagerCode>" + unit_id
                        + "</shop:SellerManagerCode>                          ");
                unitlistsql.append("                              <shop:Usable>" + use_yn
                        + "</shop:Usable>                        ");
                unitlistsql.append(
                        "                           </shop:Item>                                         ");

            }

            unitlistsql.append("                     </shop:ItemList>   ");
            unitlistsql.append(
                    "                        </shop:Combination>                                        ");
            unitlistsql.append(
                    "         </Option>                                                                                                   ");
            unitlistsql.append(
                    "      </shop:ManageOptionRequest>                                                                                    ");
            unitlistsql.append(
                    "   </soap:Body>                                                                                                      ");
            unitlistsql.append(
                    "</soap:Envelope>                                                                                                     ");

            /* unit xml  */

            System.out.println("unitlist:" + unitlistsql.toString());
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                    response_type = "FALSE";
                }
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {
                    response_type = "FALSE";
                }
            }

        } catch (Exception e) {
            System.out.println("run4() : " + e.getMessage());
        } finally {
        }

        //System.out.println(unitlistsql.toString());

        String line_total = "";
        URL url = new URL("http://ec.api.naver.com/ShopN/ProductService");
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        //      .  true.
        con.setDoInput(true);
        con.setUseCaches(false);
        con.setDefaultUseCaches(false);
        // Header  
        con.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");

        // BODY  
        OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
        wr.write(unitlistsql.toString());
        wr.flush();

        //   
        String inputLine = null;
        BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));

        while ((inputLine = rd.readLine()) != null) {
            line_total = line_total + inputLine;
            //System.out.println(inputLine);
        }

        rd.close();
        wr.close();

        line_total = line_total.replaceAll("n:", "");
        System.out.println(line_total);

        // xml2
        InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8"));

        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);

        Element element = document.getRootElement();
        List envel_list = element.getChildren();
        //System.out.println("envel_list:" + envel_list);

        List body_list = null;
        List body_list1 = null;
        List result_list = null;
        List result_list1 = null;
        List result_list2 = null;
        List result_list3 = null;
        List result_list4 = null;
        List result_list5 = null;
        List info_list = null;
        List contr_group_list = null;
        List contr_info_list = null;

        pstmt = null;
        rs = null;
        cStmt = null;

        //System.out.println("envel_list.size:" + envel_list.size());
        Element envel_el = (Element) envel_list.get(0);
        body_list = envel_el.getChildren();

        //System.out.println("body_list.size:" + body_list.size());
        Element body_el = (Element) body_list.get(0);
        result_list = body_el.getChildren("ManageProductResponse");

        ResponseType = body_el.getChildText("ResponseType");
        ProductId = body_el.getChildText("ProductId");
        //System.out.println("ResponseType:"+ body_el.getChildText("ResponseType"));
        System.out.println("ProductId:" + body_el.getChildText("ProductId"));

        StringBuffer optlistsql = new StringBuffer();
        if (ResponseType.equals("SUCCESS")) {
            //   

            NaverShopnSendItem.run3(ProductId, n_item_id);

        }

    } catch (Exception e) {
        System.out.println("run111() : " + e.getMessage());
    } finally {
    }

    return response_type;
}

From source file:NaverShopnSendItem.java

private String run3(String ProductId, String n_item_id) { //   
    System.out.println("run3");
    String response_type = "FALSE";
    NaverShopnSendItem NaverShopnSendItem = new NaverShopnSendItem();
    try {/*from  w  w w . ja v  a 2 s .  c om*/
        SimpleCryptLib SimpleCryptLib = new SimpleCryptLib();
        Security.addProvider(new BouncyCastleProvider());

        String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43";
        String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA==";

        String serviceName = "ProductService"; // 
        String id = "eugink";
        String password = "asdf0101";
        String timestamp = null;
        String signature = null;
        String data = null;
        String item_id = "";

        byte[] encryptKey = null;

        String encryptedData = null;
        String decryptedData = null;
        String hashedData = null;

        String operationName = "GetOption";
        String ResponseType = "";

        PreparedStatement pstmt = null;
        ResultSet rs = null;
        CallableStatement cStmt = null;
        // String orderID = "200087036";

        // timestamp create
        timestamp = SimpleCryptLib.getTimestamp();
        System.out.println("timestamp:" + timestamp);
        System.out.println("ProductService");

        // generateSign
        data = timestamp + serviceName + operationName;
        signature = SimpleCryptLib.generateSign(data, secretKey);

        // generateKey
        encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey);

        // encrypt
        encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8"));

        // decrypt
        decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8");

        // sha256
        hashedData = SimpleCryptLib.sha256(password);

        StringBuffer optlistsql = new StringBuffer();
        optlistsql.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n ");
        optlistsql.append(
                "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\"> ");
        optlistsql.append(
                "   <soap:Header/>                                                                                                    ");
        optlistsql.append(
                "   <soap:Body>                                                                                                       ");
        optlistsql.append(
                "      <shop:GetOptionRequest>                                                                                     ");
        optlistsql.append("         <shop:RequestID>njoyny2</shop:RequestID>");
        optlistsql.append("         <shop:AccessCredentials>");
        optlistsql.append("            <shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>");
        optlistsql.append("            <shop:Timestamp>" + timestamp + "</shop:Timestamp>");
        optlistsql.append("            <shop:Signature>" + signature + "</shop:Signature>");
        optlistsql.append("         </shop:AccessCredentials>");
        optlistsql.append("         <shop:Version>2.0</shop:Version>");
        optlistsql.append("         <SellerId>njoyny2</SellerId>");
        optlistsql.append("            <shop:ProductId>" + ProductId
                + "</shop:ProductId>                                                                       ");
        optlistsql.append(
                "        </shop:GetOptionRequest>                                                                                         ");
        optlistsql.append("    </soap:Body>                                         ");
        optlistsql.append("    </soap:Envelope>                                         ");

        System.out.println("optlistsql:" + optlistsql);
        String line_total = "";
        URL url = new URL("http://ec.api.naver.com/ShopN/ProductService");
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        //      .  true.
        con.setDoInput(true);
        con.setUseCaches(false);
        con.setDefaultUseCaches(false);
        // Header  
        con.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");

        // BODY  
        OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
        wr.write(optlistsql.toString());
        wr.flush();

        //   
        String inputLine = null;
        BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));

        while ((inputLine = rd.readLine()) != null) {
            line_total = line_total + inputLine;
            //System.out.println(inputLine);
        }

        rd.close();
        wr.close();

        line_total = line_total.replaceAll("n:", "");
        //System.out.println(line_total);

        // xml2
        ByteArrayInputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8"));

        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);

        Element element = document.getRootElement();
        List envel_list = element.getChildren();
        //System.out.println("envel_list:" + envel_list);

        List body_list = null;
        List body_list1 = null;
        List result_list = null;
        List result_list1 = null;
        List result_list2 = null;
        List result_list3 = null;
        List result_list4 = null;
        List result_list5 = null;
        List info_list = null;
        List contr_group_list = null;
        List contr_info_list = null;

        Element envel_el = (Element) envel_list.get(0);
        body_list = envel_el.getChildren();

        Element body_el = (Element) body_list.get(0);
        result_list = body_el.getChildren("Option");

        Element body_el1 = (Element) result_list.get(0);
        result_list1 = body_el1.getChildren("Combination");

        Element body_el2 = (Element) result_list1.get(0);
        result_list2 = body_el2.getChildren("ItemList");

        Element body_el3 = (Element) result_list2.get(0);
        result_list3 = body_el3.getChildren("Item");

        Element body_el4 = null;
        int cnt = 0;
        for (int h = 0; h < result_list3.size(); h++) {

            body_el4 = (Element) result_list3.get(h);

            StringBuffer unitCnt = new StringBuffer();

            unitCnt.append(" select count(*) cnt \n");
            unitCnt.append(" from  \n");
            unitCnt.append(" ktc_unit_interlock \n");
            unitCnt.append(" where coven_id = 27346 and unit_id = ? \n");

            // pstmt.clearParameters();
            pstmt = conn.prepareStatement(unitCnt.toString());
            pstmt.setLong(1, Long.parseLong(body_el4.getChildText("SellerManagerCode")));

            // pstmt.setString(1, body_el3.getChildText("Value")); //
            // h_order_no
            rs = pstmt.executeQuery();

            while (rs.next()) {
                cnt = rs.getInt("cnt");
            }

            System.out.println("cnt:" + cnt);
            if (rs != null)
                try {
                    rs.close();
                } catch (Exception e) {
                }
            if (pstmt != null)
                try {
                    pstmt.close();
                } catch (Exception e) {
                }

            if (cnt == 0) {

                StringBuffer setCovenID = new StringBuffer();
                setCovenID.append(
                        " insert into ktc_unit_interlock(coven_id , co_unit_id , item_id , unit_id ,insert_date,update_date)  \n");
                setCovenID.append(" values (27346,?,?,?,sysdate,sysdate)  \n");

                //System.out.println("setCovenIDinsert::"+ setCovenID.toString());

                pstmt = conn.prepareStatement(setCovenID.toString());

                int insert_cnt = 0;

                try {
                    // pstmt.clearParameters();

                    // 

                    pstmt.setString(1, body_el4.getChildText("Id")); // id
                    pstmt.setString(2, n_item_id); // id
                    pstmt.setString(3, body_el4.getChildText("SellerManagerCode")); // unit_id

                    pstmt.executeUpdate();
                    System.out.println("insert end");

                    if (rs != null)
                        try {
                            rs.close();
                        } catch (Exception e) {
                        }
                    if (pstmt != null)
                        try {
                            pstmt.close();
                        } catch (Exception e) {
                        }
                } catch (Exception e) {
                    response_type = "FALSE";
                    e.printStackTrace();
                    conn.rollback();
                }
            } else {
                StringBuffer setCovenID = new StringBuffer();
                setCovenID.append(" update ktc_unit_interlock set  \n");
                setCovenID.append(" co_unit_id = ? ,item_id = ? ,update_date = sysdate  \n");
                setCovenID.append(" where coven_id = 27346 and unit_id = ? \n");

                pstmt = conn.prepareStatement(setCovenID.toString());

                int insert_cnt = 0;

                try {
                    // pstmt.clearParameters();

                    // 

                    pstmt.setString(1, body_el4.getChildText("Id")); // id
                    pstmt.setString(2, n_item_id); // id
                    pstmt.setString(3, body_el4.getChildText("SellerManagerCode")); // unit_id

                    pstmt.executeUpdate();
                    System.out.println("end update111");
                    if (rs != null)
                        try {
                            rs.close();
                        } catch (Exception e) {
                        }
                    if (pstmt != null)
                        try {
                            pstmt.close();
                        } catch (Exception e) {
                        }
                } catch (Exception e) {
                    response_type = "FALSE";
                    e.printStackTrace();
                    conn.rollback();
                }
            }

        }

        ResponseType = body_el.getChildText("ResponseType");
        ProductId = body_el.getChildText("ProductId");

    } catch (Exception e) {
        System.out.println("run3() : " + e.getMessage());
        response_type = "FALSE";
    } finally {
    }

    return response_type;
}