/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package genapp;

import java.awt.Dimension;
import java.io.DataOutputStream;
import java.io.IOException;
import static java.lang.Thread.sleep;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
import wsestampillas.Respuesta;
import wsestampillas.TramaImpreso;
import zebra.zpl.ZebraZpl;
import zpl.constant.ZebraFont;
import zpl.model.ZebraLabel;
import zpl.model.ZebraPrintException;
import zpl.model.element.ZebraBarCode128;
import zpl.model.element.ZebraQRBarCode;
import zpl.model.element.ZebraText;
import zpl.utils.ZebraUtils;

/**
 *
 * @author USER
 */
public class PrintEstampillas extends javax.swing.JFrame {

    /**
     * Creates new form PrintEstampillas
     */
    public PrintEstampillas() {
        initComponents();
         this.setTitle("Imprimir Estampillas");
         this.setSize(new Dimension(454, 236));
        this.setMinimumSize(new Dimension(454, 236));
         this.setResizable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setToolTipText("Imprimir Estampillas");

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jLabel1.setText("Ingrese ID");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("Inmantec");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setSelected(true);
        jRadioButton2.setText("Zebra");

        buttonGroup2.add(jRadioButton3);
        jRadioButton3.setSelected(true);
        jRadioButton3.setText("Primera Impresión");

        buttonGroup2.add(jRadioButton4);
        jRadioButton4.setText("Reemprimir");

        jButton1.setText("Consultar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jRadioButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jRadioButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(74, 74, 74)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jRadioButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jRadioButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jTextField1)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(57, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton1))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jRadioButton4))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jRadioButton2))))
                    .addComponent(jSeparator1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(48, 48, 48))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        
        Long id= Long.parseLong(jTextField1.getText());
        int tipo=0;
        if (jRadioButton3.isSelected()) {
            tipo=1;
        }else if (jRadioButton4.isSelected()) {
            tipo=2;
        }
        
        System.out.println(id +" "+tipo+" "+getMD5(id));
         viewInterfaz vp = new viewInterfaz();
         
         new FirstThread(vp).start();
        new SecondThread(id,tipo,getMD5(id),vp).start(); 
//         vp.setVisible(true);
//         
//       List<Respuesta> respuesta=  getEstampillas(id,tipo,getMD5(id));
//      System.out.println(respuesta.get(0).getCodEstado());
//      System.out.println("vienen "+respuesta.size());
//      if (respuesta.get(0).getCodEstado()!=-1) {
//          
//          if (jRadioButton1.isSelected()) {
//              
//                 printImantec(respuesta,vp);
//          }else if (jRadioButton2.isSelected()) {
//              
//                printZPL(respuesta,vp);
//          }
//      }else{
//          vp.setVisible(false);
//          //JOptionPane.showMessageDialog(error, "Hello World");
//          JOptionPane.showMessageDialog(null, "No se encontraron registros",
//                  "Error", JOptionPane.ERROR_MESSAGE);
//          
//      }
        
    }//GEN-LAST:event_jButton1ActionPerformed

    
    class FirstThread extends Thread {
  public FirstThread (viewInterfaz vp) {
     vp.setVisible(true);
  }
}
    
    class SecondThread extends Thread {
  public SecondThread (Long id ,int tipo, String token,viewInterfaz vp) {
      //List<Respuesta> respuesta=  getEstampillas(id,tipo,getMD5(id));
      List<Respuesta> respuesta=  getEstampillas(id,tipo,token);
      System.out.println(respuesta.get(0).getCodEstado());
      System.out.println("vienen "+respuesta.size());
      if (respuesta.get(0).getCodEstado()!=-1) {
          
          if (jRadioButton1.isSelected()) {
              
                 printImantec(respuesta,vp);
          }else if (jRadioButton2.isSelected()) {
              
                printZPL(respuesta,vp);
          }
      }else{
          vp.setVisible(false);
          //JOptionPane.showMessageDialog(error, "Hello World");
          JOptionPane.showMessageDialog(null, "No se encontraron registros",
                  "Error", JOptionPane.ERROR_MESSAGE);
          
      }
  }
    }
    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
 char []p={'1','2','3','4','5','6','7','8','9','0','.'};
        int b=0;
        for(int i=0;i<=10;i++){
        if (p[i]==evt.getKeyChar()){b=1;}
 
        }
        if(b==0){evt.consume();  getToolkit().beep(); }
    }//GEN-LAST:event_jTextField1KeyTyped

    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PrintEstampillas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PrintEstampillas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PrintEstampillas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PrintEstampillas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PrintEstampillas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    public void printImantec(List<Respuesta> respuestas,viewInterfaz vp) {
        HttpURLConnection con;
        ResourceBundle parametros = ResourceBundle.getBundle("parametros");
        int i = 0;
        int cantidad = respuestas.size();
        String tipoTransporte;
        TramaImpreso trama = new TramaImpreso();
        String token = getMD5(respuestas.get(0).getIdSolicitud());
        String traza = "";

        for (Respuesta respuesta : respuestas) {
            if (respuesta.getTipoEmpresa() == 1) {
                tipoTransporte = "TRANSPORTE TERRESTRE DE PASAJEROS";
            } else {
                tipoTransporte = "TRANSPORTE TERRESTRE DE CARGA";
            }

//           try {
                traza = parametros.getString("url") + "/service/printercommand.lua?"
                        + "command=PP9%2C278%3AAN7%3A+NASC+8%3A+FT+%22Univers+Bold%22%2C6%2C0%2C99%3A+PT+%22"
                        + "ESTAMPILLA+PRO-DESARROLLO+FRONTERIZO%22%3A+PP9%2C259%3AFT+%22Univers+Bold%22%2C6%2C0%2C99%3A+PT+%22" + tipoTransporte
                        + "%22%3A+PP407%2C147%3ABARSET+%22CODE128C%22%2C2%2C1%2C1%2C64%3A+PB+%22" + respuesta.getReferenciaImpreso()
                        + "%22%3A+PP412%2C79%3AFT+%22CG+Times+Bold%22%2C5%2C0%2C99%3A+PT+%22" + respuesta.getReferenciaImpreso()
                        + "%22%3A+PP437%2C44%3AFT+%22CG+Times+Bold%22%2C9%2C0%2C99%3A+PT+%22%24+" + respuesta.getValor()
                        + "%22%3A+PP17%2C66%3AFT+%22CG+Times+Bold%22%2C8%2C0%2C99%3A+PT+%22" + respuesta.getEmpresa()
                        + "%22%3A+PP17%2C38%3AFT+%22CG+Times+Bold%22%2C8%2C0%2C99%3A+PT+%22NIT%3A" + respuesta.getNit()
                        + "%22%3A+PP414%2C279%3ABARSET+%22QRCODE%22%2C1%2C1%2C3%2C2%2C1%3A+PB+%22https%3A%2F%2Fwww.abcpagos.com%2F"
                        + "estampilla_norte_santander%2Fadmin%2Fpages%2Fvalida.php%3Freferencia%3D" + respuesta.getReferenciaImpreso()
                        + "%22%3A+PF";

                trama.setTipo(respuesta.getTipo());
                if (respuesta.getTipo() == 1) {
                    trama.setIdImpreso(respuesta.getIdImpreso());
                } else {
                    trama.setIdReImpreso(respuesta.getIdReImpreso());
                }

                trama.setIdSolicitud(respuesta.getIdSolicitud());
                trama.setReferencia(respuesta.getReferenciaImpreso());
                trama.setTrama(traza);

//                con = (HttpURLConnection) (new URL((new StringBuilder()).append(traza).toString())).openConnection();
//                con.setRequestMethod("GET");
//                con.setRequestProperty("Content-Type",
//                        "application/x-www-form-urlencoded");
//                con.setRequestProperty("Content-Length", ""
//                        + Integer.toString(respuesta.getReferenciaImpreso().getBytes().length));
//                con.setRequestProperty("Content-Language", "en-US");
//                con.setUseCaches(false);
//                con.setDoInput(true);
//                con.setDoOutput(true);
//
//                //Send request
//               DataOutputStream wr = new DataOutputStream(con.getOutputStream());
//                wr.writeBytes(respuesta.getReferenciaImpreso());
//                wr.flush();
//                wr.close();
//
//                //Get Response
//                con.getInputStream();
                getTramaEstampilla(trama, token);
//
//            } catch (IOException ex) {
//                System.out.println("Error envio");
//                System.out.println(traza);
//                Logger.getLogger(PrintEstampillas.class.getName()).log(Level.SEVERE, null, ex);
//            }
            i++;
            
            
            vp.texto.setText("Imprimiendo " + i + " Estampillas de " + cantidad);
            //setMensaje("Imprimiendo " + i + " Estampillas de " + cantidad); // imprimiar cantidad en interfaz
        }/// end for
        System.out.println("cuantos "+i);
        JOptionPane.showMessageDialog(null,  "Proceso completado!!!");
        vp.setVisible(false);

    }

    public void printZPL(List<Respuesta> respuestas,viewInterfaz vp) {
        ResourceBundle parametros = ResourceBundle.getBundle("parametros");
        int i = 0;
        int cantidad = respuestas.size();
        String tipoTransporte;
        TramaImpreso trama = new TramaImpreso();
        String token = getMD5(respuestas.get(0).getIdSolicitud());
        String traza = "";

        for (Respuesta respuesta : respuestas) {
            if (respuesta.getTipoEmpresa() == 1) {
                tipoTransporte = "TRANSPORTE TERRESTRE DE PASAJEROS";
            } else {
                tipoTransporte = "TRANSPORTE TERRESTRE DE CARGA";
            }
            ZebraLabel zebraLabel = new ZebraLabel(912, 912);
            zebraLabel.setDefaultZebraFont(ZebraFont.ZEBRA_ZERO);

            zebraLabel.addElement(new ZebraText(25, 45, "ESTAMPILLA PRO-DESARROLLO FRONTERIZO", 6));
            zebraLabel.addElement(new ZebraText(25, 74, tipoTransporte, 6));

            //Add Code Bar 
            zebraLabel.addElement(new ZebraQRBarCode(445, 200, "https://www.abcpagos.com/estampilla_norte_santander/admin/pages/valida.php?referencia=" + respuesta.getReferenciaImpreso()));
            zebraLabel.addElement(new ZebraBarCode128(365, 244, respuesta.getReferenciaImpreso(), 40, 1, 3));
            zebraLabel.addElement(new ZebraText(435, 260, respuesta.getReferenciaImpreso(), 5));

            zebraLabel.addElement(new ZebraText(25, 257, respuesta.getEmpresa(), 6));
            zebraLabel.addElement(new ZebraText(25, 297, respuesta.getNit(), 6));

            zebraLabel.addElement(new ZebraText(460, 298, "$", 6));
            zebraLabel.addElement(new ZebraText(475, 298, String.valueOf(respuesta.getValor()), 6));

            traza = zebraLabel.getZplCode();
            System.out.println(traza);

//            try {
//                ZebraUtils.printZpl(zebraLabel, parametros.getString("url"), Integer.parseInt(parametros.getString("puerto")));
                trama.setTipo(respuesta.getTipo());
                if (respuesta.getTipo() == 1) {
                    trama.setIdImpreso(respuesta.getIdImpreso());
                } else {
                    trama.setIdReImpreso(respuesta.getIdReImpreso());
                }

                trama.setIdSolicitud(respuesta.getIdSolicitud());
                trama.setReferencia(respuesta.getReferenciaImpreso());
                trama.setTrama(traza);

                getTramaEstampilla(trama, token);
//            } catch (ZebraPrintException ex) {
//                System.out.println("Error envio");
//                System.out.println(trama);
//                Logger.getLogger(ZebraZpl.class.getName()).log(Level.SEVERE, null, ex);
//            }

            i++;
           vp.texto.setText("Imprimiendo " + i + " Estampillas de " + cantidad);
            //setMensaje("Imprimiendo " + i + " Estampillas de " + cantidad); // imprimiar cantidad en interfaz
        }/// end for
        JOptionPane.showMessageDialog(null,  "Proceso completado!!!");
        
        vp.setVisible(false);
    }
    
    public void viewPanel(){
    
        viewInterfaz vp = new viewInterfaz();
        vp.setVisible(true);
        
    }
    

    public List<Respuesta> getEstampillas(long idSolicitud, int tipo, String token) {
        
        List<Respuesta> resp=null;
        
        wsestampillas.WsEstampillasNorteSantander_Service service = new wsestampillas.WsEstampillasNorteSantander_Service();
        wsestampillas.WsEstampillasNorteSantander port = service.getWsEstampillasNorteSantanderPort();
        BindingProvider bindingProvider = (BindingProvider) port;
            List<Handler> handlerChain = bindingProvider.getBinding().getHandlerChain();
            handlerChain.add(new HandlerTrama());
            bindingProvider.getBinding().setHandlerChain(handlerChain);
            Map<String, Object> requestContext = bindingProvider.getRequestContext();
            requestContext.put("com.sun.xml.internal.ws.request.timeout", 5000);
        Instant durationStart = Instant.now();
        resp= port.getEstampillas(idSolicitud, tipo, token);
        Instant durationEnd = Instant.now();
            Duration duration = Duration.between(durationStart, durationEnd);
        processRequest(bindingProvider,String.valueOf( idSolicitud), duration.toMillis());
        
        return resp;
    }

    public Boolean getTramaEstampilla(TramaImpreso trama, String token) {
       
        Boolean res=false;
        wsestampillas.WsEstampillasNorteSantander_Service service = new wsestampillas.WsEstampillasNorteSantander_Service();
        wsestampillas.WsEstampillasNorteSantander port = service.getWsEstampillasNorteSantanderPort();
        BindingProvider bindingProvider = (BindingProvider) port;
            List<Handler> handlerChain = bindingProvider.getBinding().getHandlerChain();
            handlerChain.add(new HandlerTrama());
            bindingProvider.getBinding().setHandlerChain(handlerChain);
            Map<String, Object> requestContext = bindingProvider.getRequestContext();
            requestContext.put("com.sun.xml.internal.ws.request.timeout", 5000);
        Instant durationStart = Instant.now();
        res= port.getTramaEstampilla(trama, token);
        Instant durationEnd = Instant.now();
        Duration duration = Duration.between(durationStart, durationEnd);
        processRequest(bindingProvider,String.valueOf( trama.getIdSolicitud()), duration.toMillis());
       
        
        
        return res;
        
        
        
    }

     protected Map<String, String> processRequest(BindingProvider bindingProvider, String referencia, long duracion) {
        Map<String, Object> responseContext = bindingProvider.getResponseContext();
        String requestBody = (String) responseContext.get("com.realtech.request");
        String responseBody = (String) responseContext.get("com.realtech.response");

        requestBody = requestBody.replace("&lt;", "<");
        requestBody = requestBody.replace("&gt;", ">");

        responseBody = responseBody.replace("&lt;", "<");
        responseBody = responseBody.replace("&gt;", ">");

        Map<String, String> trama = new HashMap<>();
        trama.put("request", requestBody);
        trama.put("response", responseBody);
        System.out.println("Envio:" + requestBody + "Respues:" + responseBody);

      

        return trama;
    }
    public String getMD5(long id) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMdd");
        String input = sdf.format(calendar.getTime()) + "Cl4R3alth*N0t-e" + id;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashtext = number.toString(16);

            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

}
