예제 #1
0
        public ErrorCommand execute(String ip, String porta, String cpf, String hash)
        {
            ErrorCommand errorCommand = new ErrorCommand();
            Tcp          tcp          = null;

            try
            {
                tcp = new Tcp(ip, Convert.ToInt16(porta));
            }
            catch (IOException e1) {
                errorCommand.setErro(ErrorCommand.COMUNICACAO_NAO_ESTABELECIDA);
                return(errorCommand);
            }

            try
            {
                try
                {
                    byte[] bytesCpf = Conversor.cpfToByte(cpf);
                    byte[] buffer   = criarPacoteCabecalho(CommandCodes.START_PC, CommandCodes.LER_EMPREGADOR,
                                                           new byte[4], new byte[4], bytesCpf,
                                                           (byte)0x00, CommandCodes.END);
                    sendBuffer(buffer, true, tcp);
                    byte[] respostaREP = new byte[Protocol.QTD_BYTES_RETORNO_LEITURA_EMPREGADOR];
                    // Lê resposta do REP
                    respostaREP = readAnswer(tcp, Protocol.QTD_BYTES_RETORNO_LEITURA_EMPREGADOR);
                    int qtdBytesRecebidos = -1;
                    if (respostaREP != null)
                    {
                        qtdBytesRecebidos = respostaREP.Length;
                    }
                    // Trata a resposta do REP
                    errorCommand = tratarResposta(CommandCodes.LER_EMPREGADOR, respostaREP, qtdBytesRecebidos, Protocol.QTD_BYTES_RETORNO_LEITURA_EMPREGADOR);
                    if (errorCommand.getErro() == ErrorCommand.SUCESSO)
                    {
                        errorCommand = this.tratarResposta(0, respostaREP, 0, 0);
                        //					debug(errorCommand); // testes
                    }
                }
                catch (Exception e)
                {
                    errorCommand.setErro(ErrorCommand.OCORREU_EXCECAO);
                }
                tcp.finalizaConexao();
            }
            catch (Exception e)
            {
                errorCommand.setErro(ErrorCommand.ERRO_FINALIZAR_CONEXAO);
            }

            return(errorCommand);
        }
예제 #2
0
        public ErrorCommand execute(String ip, String porta, String cpf, Company company)
        {
            ErrorCommand errorCommand = new ErrorCommand();
            Tcp          tcp          = null;

            try
            {
                tcp = new Tcp(ip, Convert.ToInt16(porta));
            }
            catch (IOException e) {
                errorCommand.setErro(ErrorCommand.SUCESSO);
                return(errorCommand);
            }

            try
            {
                try
                {
                    byte[] bytesCpf = Conversor.cpfToByte(cpf);
                    byte[] cabecalhoDadosGravaEmpregador = Command.criarPacoteCabecalho(CommandCodes.START_PC, CommandCodes.ENVIAR_EMPREGADOR, new byte[] { 0x00, 0x00, 0x00, 0x01 }, new byte[4], bytesCpf, (byte)ErrorCommand.ADICIONAR_SUBSTITUIR, CommandCodes.END);
                    // Envia o cabeçalho
                    sendBuffer(cabecalhoDadosGravaEmpregador, true, tcp);
                    // Lê 1ª resposta do REP
                    byte[] retornoReal       = readAnswer(tcp, Protocol.QTD_BYTES_CABECALHO_CRIPTOGRAFADO);
                    int    qtdBytesRecebidos = -1;
                    if (retornoReal != null)
                    {
                        qtdBytesRecebidos = retornoReal.Length;
                    }
                    // Trata a 1ª resposta do REP
                    errorCommand = tratarResposta(CommandCodes.ENVIAR_EMPREGADOR, retornoReal, qtdBytesRecebidos, Protocol.QTD_BYTES_CABECALHO_CRIPTOGRAFADO);
                    if (errorCommand.getErro() == ErrorCommand.SUCESSO)
                    {
                        cabecalhoDadosGravaEmpregador = criarPacoteCabecalho(CommandCodes.START_PC, CommandCodes.ENVIAR_EMPREGADOR,
                                                                             new byte[] { 0x00, 0x01, 0x00, 0x01 }, new byte[] { 0x00, 0x00, 0x01, 0x0C },
                                                                             bytesCpf, (byte)ErrorCommand.DADOS_OK, CommandCodes.END);

                        byte   checkSumCabecalho    = cabecalhoDadosGravaEmpregador[cabecalhoDadosGravaEmpregador.Length - 2];
                        byte[] dadosGravaEmpregador = criaPacoteDados(checkSumCabecalho, bytesCpf, company);

                        // Envia os dados do empregador
                        sendBuffer(ProtocolUtils.merge(cabecalhoDadosGravaEmpregador, dadosGravaEmpregador), true, tcp);
                        retornoReal = new byte[Protocol.QTD_BYTES_CABECALHO_CRIPTOGRAFADO];
                        // Lê 2ª resposta do REP
                        retornoReal       = readAnswer(tcp, Protocol.QTD_BYTES_CABECALHO_CRIPTOGRAFADO);
                        qtdBytesRecebidos = -1;
                        if (retornoReal != null)
                        {
                            qtdBytesRecebidos = retornoReal.Length;
                        }
                        // Trata a 2ª resposta do REP
                        errorCommand = tratarResposta(CommandCodes.ENVIAR_EMPREGADOR, retornoReal, qtdBytesRecebidos, Protocol.QTD_BYTES_CABECALHO_CRIPTOGRAFADO);
                    }
                }
                catch (Exception e)
                {
                    errorCommand.setErro(ErrorCommand.OCORREU_EXCECAO);
                }
                tcp.finalizaConexao();
            }
            catch (Exception e)
            {
                errorCommand.setErro(ErrorCommand.ERRO_FINALIZAR_CONEXAO);
            }

            return(errorCommand);
        }