Example usage for org.apache.commons.codec EncoderException getMessage

List of usage examples for org.apache.commons.codec EncoderException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.codec EncoderException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.harvard.iq.dvn.unf.Base64Encoding.java

/**
 * Alternative tobase64 method.Encodes the String(byte[]) instead of the array
 *
 * @param digest byte array for encoding in base 64,
 * @param cset String with name of charset
 * @return String base 64 the encoded base64 of digest
 *//*from ww  w.j  ava  2  s  . c o m*/
public static String tobase641(byte[] digest, String cset) {
    byte[] revdigest = changeByteOrder(digest, ByteOrder.nativeOrder());
    String str = null;

    str = new String(revdigest);
    ByteArrayOutputStream btstream = new ByteArrayOutputStream();
    //this make sure is written in big-endian

    DataOutputStream stream = new DataOutputStream(btstream);
    String tobase64 = null;
    //use a charset for encoding
    if (cset == null) {
        cset = DEFAULT_CHAR_ENCODING;
    }
    BCodec bc = new BCodec(cset);
    try {

        tobase64 = (String) bc.encode(str);

    } catch (EncoderException err) {
        mLog.info("base64Encoding: exception" + err.getMessage());
    }
    return tobase64;
}

From source file:com.centurylink.mdw.common.translator.impl.EncodedStringTranslator.java

/**
 * Converts the passed in object to a string
 * @param pObject//from  w w  w. jav a 2  s.  c  o  m
 * @return String
 */
public String toString(Object pObject) {
    String encoded = null;
    try {
        encoded = encoder.encode((String) pObject);
    } catch (EncoderException ex) {
        ex.printStackTrace();
        throw new TranslationException(ex.getMessage());
    }
    return encoded;
}

From source file:edu.lternet.pasta.portal.HarvestReport.java

private String getQualityReportLink(String packageId, String localPath) {
    String link = "";
    URLCodec urlCodec = new URLCodec();

    try {//from   w  w w.jav  a  2  s . co  m
        if (packageId != null && packageId.length() > 0) {
            link = "<a class=\"searchsubcat\" href=\"./reportviewer?packageid=" + packageId;

            if (localPath != null) {
                String encodedPath = urlCodec.encode(localPath);
                link += "&localPath=" + encodedPath;
            }

            link += "\" target=\"_blank\">view</a>";
        }
    } catch (EncoderException e) {
        e.printStackTrace();
        logger.error(e.getMessage());
    }

    return link;
}

From source file:controladores.usuarios.ControladorUsuarios.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  ww  w . ja  v a2 s  .  co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    request.setCharacterEncoding("UTF-8");
    FUsuario faUsu = new FUsuario();
    UsuarioDto usuario;
    Encriptar encript;
    String salida;
    if (request.getParameter("botonRegistro") != null) {
        RolDto suRol = new RolDto();
        suRol.setIdRol(Integer.parseInt(request.getParameter("ruRol")));

        UsuarioDto nuevoUsuario = new UsuarioDto();
        nuevoUsuario.setIdUsuario(Long.parseLong(request.getParameter("ruDocumento")));
        nuevoUsuario.setNombres(request.getParameter("ruNombres"));
        nuevoUsuario.setApellidos(request.getParameter("ruApellidos"));
        nuevoUsuario.setClave(request.getParameter("ruClave"));
        nuevoUsuario.setCorreo(request.getParameter("ruCorreo"));
        nuevoUsuario.setFechaNacimiento(request.getParameter("ruFechaNacimiento"));
        nuevoUsuario.setDireccion(request.getParameter("ruDireccion"));
        nuevoUsuario.setIdCiudad(Integer.parseInt(request.getParameter("ruCiudad")));
        nuevoUsuario.setImagen(null);
        nuevoUsuario.setEstado(1);
        if (request.getParameter("notificaciones") == null) {

        } else if (request.getParameter("notificaciones") != null) {
            nuevoUsuario.setNotifaciones(1);
        }
        salida = faUsu.registrarUsuario(nuevoUsuario, suRol);

        if (salida.equals("ok")) {
            response.sendRedirect(
                    "index.jsp?msg=<strong><i class='glyphicon glyphicon-ok'></i> Registro xitoso!</strong> puede iniciar sesin.&tipoAlert=success");
        } else if (salida.equals("okno")) {
            response.sendRedirect(
                    "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Algo sali mal!</strong> Por favor intentelo de nuevo.&tipoAlert=warning");
        } else {
            response.sendRedirect(
                    "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Ocurri un error!</strong> Detalle: "
                            + salida + "&tipoAlert=danger");
        }
    } else if (request.getParameter("recuperar") != null) {
        encript = new Encriptar();

        usuario = faUsu.obtenerUsuarioPorCorreo(request.getParameter("rcCorreo"));
        String correo = usuario.getCorreo();

        if (!correo.equals("")) {
            try {

                String con = Long.toString(usuario.getIdUsuario());
                String ced = encript.encode(con);

                String url = "http://localhost:8080/FarmersMarket/index.jsp?id=" + (ced);
                String mensaje = "<!DOCTYPE html>";
                mensaje += "<body>";
                mensaje += "<p>Se nos ha notificado la solicitud de recuperar tu contrasea, por favor ingresa al siguiente enlace y sigue las instrucciones"
                        + " para poder obtener tu contrasea lo antes posible</p>";
                mensaje += "<a href=" + url + ">Recuperar contrasea</a>";
                mensaje += "<br>-----------------------------------------------------------------------------------------------------------------";
                mensaje += "<p>Por favor no responder a este correo, es de uso exclusivo para notificaciones y solicitudes."
                        + "<br>No se le dara una respuesta por motivos de administracin y seguridad, si tiene algun inconveniente por favor"
                        + " contacte a nuestros administradores desde nuestro sistema en el siguiente enlace</p>";
                mensaje += "<a href='http://localhost:8080/FarmersMarket/index.jsp'>Farmers Market</a>";
                mensaje += "<br>-----------------------------------------------------------------------------------------------------------------";
                if (Correo.sendMail("Recuperar Contrasea", mensaje, correo)) {
                    response.sendRedirect(
                            "index.jsp?msg=<strong><i class='glyphicon glyphicon-ok'></i> Solicitud enviada!</strong> Por favor revise su correo.&tipoAlert=success");
                } else {
                    response.sendRedirect(
                            "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Ha ocurrido algo!</strong> Vuelva a intentarlo.&tipoAlert=warning");
                }

            } catch (EncoderException ex) {
                response.sendRedirect(
                        "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Ocurri un error!</strong> Detalle: "
                                + ex.getMessage() + "&tipoAlert=danger");
            }
        } else if (correo.equals("")) {
            response.sendRedirect(
                    "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Lo sentimos!</strong> El correo no se encuentra registrado."
                            + correo + "&tipoAlert=warning");
        }
    } else if (request.getParameter("recuperarCodigo") != null) {
        encript = new Encriptar();
        if (request.getParameter("rcCodigo").trim().equals(request.getParameter("codigo"))) {

            try {
                String cedula = encript.Decode(request.getParameter("encriptacion"));
                usuario = faUsu.obtenerUsuarioPorDocumento(Long.parseLong(cedula));
                if (!usuario.getClave().equals("")) {
                    response.sendRedirect(
                            "index.jsp?msg=<strong><i class='glyphicon glyphicon-ok'></i> Hemos recuperado tu contrasea :D es la siguiente: <i>"
                                    + usuario.getClave()
                                    + "</i>!</strong> te recomendamos  cambiarla lo antes posible.&tipoAlert=success");
                } else {
                    response.sendRedirect(
                            "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Ha ocurrido algo!</strong> Vuelva a intentarlo.&tipoAlert=warning");
                }
            } catch (Exception ex) {
                response.sendRedirect(
                        "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Ocurri un error!</strong> Detalle: "
                                + ex.getMessage() + "&tipoAlert=danger");
            }
        } else {
            response.sendRedirect(
                    "index.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> El codigo que ingreso no es correcto!</strong> Intentelo de nuevo.&tipoAlert=warning");
        }
    } else if (request.getParameter("cambiarPass") != null) {

        usuario = faUsu.obtenerUsuarioPorDocumento(Long.parseLong(request.getParameter("ccDocumento")));
        boolean admin = false;
        HttpSession miSesionRoles = request.getSession(false);
        ArrayList<RolDto> rolesActuales;
        rolesActuales = (ArrayList<RolDto>) miSesionRoles.getAttribute("roles");
        for (RolDto rol : rolesActuales) {
            if (rol.getIdRol() == 3) {
                admin = true;
            }
        }
        if (usuario.getClave().equals(request.getParameter("ccClaveAntigua"))) {
            salida = faUsu.cambiarContrasena(request.getParameter("ccClaveNueva"),
                    Long.parseLong(request.getParameter("ccDocumento")));
            if (salida.equals("ok")) {
                if (admin) {
                    response.sendRedirect(
                            "pages/indexadmin.jsp?msg=<strong><i class='glyphicon glyphicon-ok'></i> Su contrasea a sido modificada!</strong>&tipoAlert=success");
                } else {
                    response.sendRedirect(
                            "pages/indexp.jsp?msg=<strong><i class='glyphicon glyphicon-ok'></i> Su contrasea a sido modificada!</strong>&tipoAlert=success");
                }
            } else if (salida.equals("okno")) {
                response.sendRedirect(
                        "pages/indexp.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> Ha ocurrido algo!</strong> Vuelva a intentarlo.&tipoAlert=warning");
            }

        } else {
            if (admin) {
                response.sendRedirect(
                        "pages/indexadmin.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> La contrasea no es correcta!</strong> Vuelva a intentarlo.&tipoAlert=warning");
            } else {
                response.sendRedirect(
                        "pages/indexp.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> La contrasea no es correcta!</strong> Vuelva a intentarlo.&tipoAlert=warning");
            }
        }
    } else if (request.getParameter("idUsuarioConsulta") != null) {

        UsuarioDto informacion = faUsu
                .obtenerUsuarioPorDocumento(Long.parseLong(request.getParameter("idUsuarioConsulta")));
        HttpSession miSesion = request.getSession(true);
        miSesion.setAttribute("infUsuario", informacion);
        response.sendRedirect("pages/informacionusuario.jsp");
    } else if (request.getParameter("actualizarDatos") != null) {
        String correo = faUsu.correoRegistrado(request.getParameter("pffCorreo"),
                Long.parseLong(request.getParameter("auDocumento")));
        if (correo.equals("")) {
            String mensaje = faUsu.actualizarDatos(request.getParameter("pffDireccion"),
                    request.getParameter("pffCorreo"), Long.parseLong(request.getParameter("auDocumento")));
            if (mensaje.equals("ok")) {
                response.sendRedirect(
                        "pages/perfil.jsp?msg=<strong><i class='glyphicon glyphicon-ok'></i> Sus datos han sido modificados!</strong>&tipoAlert=success");
                HttpSession miSesion = request.getSession(false);
                UsuarioDto datosPersona = faUsu
                        .obtenerUsuarioPorDocumento(Long.parseLong(request.getParameter("auDocumento")));
                miSesion.setAttribute("usuarioEntro", datosPersona);
            } else {
                response.sendRedirect(
                        "pages/perfil.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> No se logro actualizar sus datos!</strong> Vuelva a intentarlo.&tipoAlert=warning");
            }
        } else {
            response.sendRedirect(
                    "pages/perfil.jsp?msg=<strong><i class='glyphicon glyphicon-exclamation-sign'></i> El correo ya se encuentra registrado!</strong> Vuelva a intentarlo.&tipoAlert=warning");
        }
    } else {
        response.sendRedirect("pages/indexp.jsp");
    }
}

From source file:org.apache.beehive.netui.core.URLCodec.java

/**
 * URL encodes a string using the default character set
 * @param decoded the string to encode//from   www .j a v a2  s  .  c o m
 * @return the encoded string
 */
public static String encode(final String decoded) {
    try {
        return s_codec.encode(decoded);
    } catch (EncoderException e) {
        throw new IllegalStateException(
                Bundle.getErrorString("URLCodec_encodeException", new String[] { e.getMessage() }), e);
    }
}

From source file:org.efs.openreports.util.EncryptedStringUserType.java

protected String encrypt(String value) {
    try {/*from w  w  w.jav a 2  s.  c  om*/
        return bCodec.encode(value);
    } catch (EncoderException ee) {
        log.warn("ENCRYPT - " + value + " : " + ee.getMessage());
        return value;
    }
}

From source file:org.folg.names.eval.CodeEvaluator.java

@Override
protected boolean match(String name1, String name2) {
    try {//  w ww.j a va  2  s .c o m
        return coder.encode(name1).equals(coder.encode(name2));
    } catch (EncoderException e) {
        logger.warning("Encoder exception on " + name1 + " or " + name2 + " : " + e.getMessage());
    }
    return false;
}

From source file:org.folg.names.eval.SimilarNameAugmenter.java

private boolean add(Map<String, Set<String>> namesToAdd, String target, String source) {
    Normalizer normalizer = Normalizer.getInstance();
    List<String> targets = normalizer.normalize(target, isSurname);
    List<String> sources = normalizer.normalize(source, isSurname);
    if (targets.size() == 1 && sources.size() == 1) {
        target = targets.get(0);//  w w w  . j av  a2s  . c o  m
        source = sources.get(0);
        try {
            if (!source.equals(target)) {
                String sourceCode = coder.encode(source);
                String targetCode = coder.encode(target);
                // only add name to target if it is common
                if (commonNames.contains(target)) {
                    // only add source if it is common, or if its soundex doesn't match target's soundex and we're not omitting rare names
                    if (commonNames.contains(source) || (!omitRare && !sourceCode.equals(targetCode))) {
                        Set<String> names = namesToAdd.get(target);
                        if (names == null) {
                            names = new HashSet<String>();
                            namesToAdd.put(target, names);
                        }
                        names.add(source);
                    }
                } else if (!sourceCode.equals(targetCode)) {
                    uncommonTargets++;
                    logger.info("Source " + source + " not added to uncommon target: " + target);
                }
            }
            return true;
        } catch (EncoderException e) {
            logger.warning("EncoderException " + e.getMessage());
        }
    }
    return false;
}

From source file:org.folg.names.search.Searcher.java

public String getCode(String namePiece) {
    try {/*from   w w  w  .j a  v a 2 s .  c om*/
        return coder.encode(namePiece);
    } catch (EncoderException e) {
        logger.warning("Error encoding " + namePiece + ": " + e.getMessage());
    }
    return "";
}

From source file:org.jax.haplotype.io.SnpStreamUtil.java

/**
 * Write the genotype data from the input csv file to a binary format
 * @param parser/* w  w w. j  a va2 s  .c o  m*/
 *          the parser to use
 * @param inputCsvFile
 *          the input
 * @param outputDirectory
 *          the output dir
 * @param strainsToWrite
 *          the strains
 * @param referenceStrainChromosome
 *          the reference strain (can be null)
 * @return
 *          the reference strain (one is selected if the given reference
 *          strain is null)
 * @throws IOException
 *          if we get one
 */
private static StrainChromosome writeBinaryStrains(GenotypeParser parser, File inputCsvFile,
        File outputDirectory, Set<String> strainsToWrite, StrainChromosome referenceStrainChromosome)
        throws IOException {
    System.out.println("Extracting " + strainsToWrite.size() + " strains from: " + inputCsvFile.getName());
    FileInputStream fis = new FileInputStream(inputCsvFile);
    Set<StrainChromosome> chromoSet = parser.parseGenotypeFromStream(fis, true, strainsToWrite);
    fis.close();

    Iterator<StrainChromosome> chromoIter = chromoSet.iterator();
    if (referenceStrainChromosome == null && chromoIter.hasNext()) {
        referenceStrainChromosome = chromoIter.next();
        System.out.println("Reference Strain: " + referenceStrainChromosome.getStrainName());

        // reset the iterator since we want to make sure we also write
        // out the reference strain
        chromoIter = chromoSet.iterator();
    }

    try {
        while (chromoIter.hasNext()) {
            StrainChromosome nextChromo = chromoIter.next();
            File nextOutputDir = new File(outputDirectory,
                    CHROMOSOME_DIR_PREFIX + nextChromo.getChromosomeNumber());
            nextOutputDir.mkdir();

            // Write the forward stream
            File nextOutputFile = new File(nextOutputDir, URL_CODEC.encode(nextChromo.getStrainName())
                    + StreamingBinaryChromosomeDataSource.SNP_STREAM_FILTER.getEndingString());
            if (!nextOutputFile.exists()) {
                OutputStream nextOutputStream = new BufferedOutputStream(new FileOutputStream(nextOutputFile));
                SnpStreamUtil.writeBinarySnps(referenceStrainChromosome, nextChromo, nextOutputStream,
                        StreamDirection.FORWARD);

                nextOutputStream.close();
            } else {
                throw new IOException("refusing to overwrite " + nextOutputFile.getAbsolutePath());
            }

            // Write the reverse stream
            File nextReverseOutputFile = new File(nextOutputDir, URL_CODEC.encode(nextChromo.getStrainName())
                    + StreamingBinaryChromosomeDataSource.REVERSE_SNP_STREAM_FILTER.getEndingString());
            if (!nextReverseOutputFile.exists()) {
                OutputStream nextReverseOutputStream = new BufferedOutputStream(
                        new FileOutputStream(nextReverseOutputFile));
                SnpStreamUtil.writeBinarySnps(referenceStrainChromosome, nextChromo, nextReverseOutputStream,
                        StreamDirection.REVERSE);

                nextReverseOutputStream.close();
            } else {
                throw new IOException("refusing to overwrite " + nextOutputFile.getAbsolutePath());
            }
        }
    } catch (EncoderException ex) {
        LOG.log(Level.SEVERE, "failed to encode strain name", ex);
        throw new IOException(ex.getMessage());
    }

    return referenceStrainChromosome;
}