org.apache.jorphan.util.JOrphanUtils Java Examples
The following examples show how to use
org.apache.jorphan.util.JOrphanUtils.
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 |
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: SynthesisReportGui.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(ActionEvent ev) { if (ev.getSource() == saveTable) { JFileChooser chooser = FileDialoger .promptToSaveFile("synthesis.csv"); if (chooser == null) { return; } FileWriter writer = null; try { writer = new FileWriter(chooser.getSelectedFile()); // TODO // Charset ? CSVSaveService.saveCSVStats(getAllDataAsTable(model, FORMATS, getLabels(COLUMNS)), writer, saveHeaders.isSelected()); } catch (IOException e) { log.warn(e.getMessage()); } finally { JOrphanUtils.closeQuietly(writer); } } }
Example #3
Source File: MD5.java From jmeter-plugins with Apache License 2.0 | 6 votes |
/** * {@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 #4
Source File: DNSJavaDecoder.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@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 #5
Source File: RedisDataSet.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Override public void iterationStart(LoopIterationEvent event) { Jedis connection = null; try { connection = pool.getResource(); // Get data from list's head String line = getDataFromConnection(connection, redisKey); if(line == null) { // i.e. no more data (nil) throw new JMeterStopThreadException("End of redis data detected"); } if (getRecycleDataOnUse()) { addDataToConnection(connection, redisKey, line); } final String names = variableNames; if (vars == null) { vars = JOrphanUtils.split(names, ","); } final JMeterContext context = getThreadContext(); JMeterVariables threadVars = context.getVariables(); String[] values = JOrphanUtils.split(line, delimiter, false); for (int a = 0; a < vars.length && a < values.length; a++) { threadVars.put(vars[a], values[a]); } } finally { pool.returnResource(connection); } }
Example #6
Source File: RedisDataSet.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Override public void testStarted(String distributedHost) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(getMaxActive()); config.setMaxIdle(getMaxIdle()); config.setMinIdle(getMinIdle()); config.setMaxWait(getMaxWait()); config.setWhenExhaustedAction((byte)getWhenExhaustedAction()); config.setTestOnBorrow(getTestOnBorrow()); config.setTestOnReturn(getTestOnReturn()); config.setTestWhileIdle(getTestWhileIdle()); config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun()); config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); config.setSoftMinEvictableIdleTimeMillis(getSoftMinEvictableIdleTimeMillis()); int port = Protocol.DEFAULT_PORT; if(!JOrphanUtils.isBlank(this.port)) { port = Integer.parseInt(this.port); } int timeout = Protocol.DEFAULT_TIMEOUT; if(!JOrphanUtils.isBlank(this.timeout)) { timeout = Integer.parseInt(this.timeout); } int database = Protocol.DEFAULT_DATABASE; if(!JOrphanUtils.isBlank(this.database)) { database = Integer.parseInt(this.database); } String password = null; if(!JOrphanUtils.isBlank(this.password)) { password = this.password; } this.pool = new JedisPool(config, this.host, port, timeout, password, database); }
Example #7
Source File: RawRequestSourcePreProcessor.java From jmeter-plugins with Apache License 2.0 | 5 votes |
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); } }
Example #8
Source File: RandomCSVDataSetConfig.java From jmeter-bzm-plugins with Apache License 2.0 | 4 votes |
public String[] getDestinationVariableKeys() { String vars = getVariableNames(); return hasVariablesNames() ? JOrphanUtils.split(vars, ",") : getReader().getHeader(); }
Example #9
Source File: CassandraSampler.java From jmeter-cassandra with Apache License 2.0 | 4 votes |
@Override public SampleResult sample(Entry e) { log.debug("sampling CQL"); SampleResult res = new SampleResult(); res.setSampleLabel(getName()); res.setSamplerData(toString()); res.setDataType(SampleResult.TEXT); res.setContentType("text/plain"); // $NON-NLS-1$ res.setDataEncoding(ENCODING); // Assume we will be successful res.setSuccessful(true); res.setResponseMessageOK(); res.setResponseCodeOK(); res.sampleStart(); Session conn = null; try { if(JOrphanUtils.isBlank(getSessionName())) { throw new IllegalArgumentException("Variable Name must not be null in "+getName()); } try { conn = CassandraConnection.getSession(getSessionName()); } finally { res.latencyEnd(); // use latency to measure connection time } res.setResponseHeaders(conn.toString()); res.setResponseData(execute(conn)); } catch (Exception ex) { res.setResponseMessage(ex.toString()); res.setResponseCode("000"); res.setResponseData(ex.getMessage().getBytes()); res.setSuccessful(false); } // Doesn't apply // finally { // close(conn); // } // TODO: process warnings? Set Code and Message to success? res.sampleEnd(); return res; }
Example #10
Source File: HexStringUDPDecoder.java From jmeter-plugins with Apache License 2.0 | 4 votes |
public byte[] decode(byte[] buf) { return JOrphanUtils.baToHexString(buf).getBytes(); }
Example #11
Source File: VariableFromCsvFileReader.java From jmeter-plugins with Apache License 2.0 | 4 votes |
/** * Parses (name, value) pairs from the input and returns the result as a Map, with the option to skip the first line. * The name is taken from the first column and value from the second column. If an input line contains only one * column its value is defaulted to an empty string. Any extra columns are ignored. * * If the input contains headers, call with skipLines equal to the number of lines of headers. A negative value for * skipLines yields the same result as 0. * * @param prefix a prefix to apply to the mapped variable names * @param separator the field delimiter * @param skipLines the number of lines at the beginning of the input to skip * @return a map of (name, value) pairs */ public Map<String, String> getDataAsMap(String prefix, String separator, int skipLines) { if (separator.isEmpty()) { throw new IllegalArgumentException("CSV separator cannot be empty"); } Map<String, String> variables = new HashMap<>(); if (input != null) { try { String line; int lineNum = 0; StringBuilder multiLineValue = new StringBuilder(); String multiLineVariable = null; while ((line = input.readLine()) != null) { if (++lineNum > skipLines) { if (line.startsWith("#")) { continue; } String[] lineValues = JOrphanUtils.split(line, separator, false); if (lineValues.length == 1) { if (multiLineValue.length() > 0 && lineValues[0].endsWith("\"")) { multiLineValue.append(lineValues[0].substring(0, lineValues[0].length() - 1)); variables.put(prefix + multiLineVariable, multiLineValue.toString()); // reset memory multiLineValue.setLength(0); multiLineVariable = null; } else if (multiLineValue.length() > 0) { multiLineValue.append(lineValues[0]).append('\n'); } else { log.warn("Less than 2 columns at line: " + line); variables.put(prefix + lineValues[0], ""); } } else if (lineValues.length >= 2) { if (lineValues[1].startsWith("\"")) { // multi line value multiLineVariable = lineValues[0]; multiLineValue.append(lineValues[1].substring(1)).append('\n'); } else { variables.put(prefix + lineValues[0], lineValues[1]); } } } } } catch (IOException ex) { log.error("Error while reading: " + ex.getMessage()); } } return variables; }
Example #12
Source File: WebSocketSampler.java From jmeter-websocket with Apache License 2.0 | 4 votes |
protected String encodeSpaces(String path) { return JOrphanUtils.replaceAllChars(path, ' ', "%20"); // $NON-NLS-1$ }