Java Code Examples for org.apache.jorphan.util.JOrphanUtils#baToHexString()

The following examples show how to use org.apache.jorphan.util.JOrphanUtils#baToHexString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JMeterProxyControl.java    From jsflight with Apache License 2.0 6 votes vote down vote up
public String[] getCertificateDetails()
{
    if (isDynamicMode())
    {
        try
        {
            X509Certificate caCert = (X509Certificate)sslKeyStore.getCertificate(KeyToolUtils.getRootCAalias());
            if (caCert == null)
            {
                return new String[] { "Could not find certificate" };
            }
            return new String[] { caCert.getSubjectX500Principal().toString(),
                    "Fingerprint(SHA1): " + JOrphanUtils.baToHexString(DigestUtils.sha1(caCert.getEncoded()), ' '),
                    "Created: " + caCert.getNotBefore().toString() };
        }
        catch (GeneralSecurityException e)
        {
            LOG.error("Problem reading root CA from keystore", e);
            return new String[] { "Problem with root certificate", e.getMessage() };
        }
    }
    return null; // should not happen
}
 
Example 2
Source File: MD5.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String str = ((CompoundVariable) values[0]).execute();
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("md5");
    } catch (NoSuchAlgorithmException ex) {
        return "Error creating digest: " + ex;
    }

    String res = JOrphanUtils.baToHexString(digest.digest(str.getBytes()));

    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, res);
    }

    return res;
}
 
Example 3
Source File: DNSJavaDecoder.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] decode(byte[] buf) {
    Message m;
    try {
        m = new Message(buf);
    } catch (IOException ex) {
        throw new RuntimeException("Cannot decode DNS message: " + JOrphanUtils.baToHexString(buf), ex);
    }
    return m.toString().getBytes();
}
 
Example 4
Source File: RawRequestSourcePreProcessor.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private synchronized String readNextChunk(int capacity)
        throws IOException {
    if (capacity == 0) {
        throw new EndOfFileException("Zero chunk size, possibly end of file reached.");
    }

    ByteBuffer buf = ByteBuffer.allocateDirect(capacity);
    byte[] dst = new byte[capacity];


    int cnt = file.read(buf);
    //log.debug("Read " + cnt);
    if (cnt != capacity) {
        throw new IOException("Expected chunk size (" + capacity + ") differs from read bytes count (" + cnt + ")");
    }

    buf.flip();
    buf.get(dst);
    if (log.isDebugEnabled()) {
        log.debug("Chunk : " + new String(dst));
    }

    if (isHexEncode()) {
        return JOrphanUtils.baToHexString(dst);
    } else {
        return new String(dst, binaryCharset);
    }
}