/** * Call a class constructor with an String parameter * @param className the name of the class to construct * @param parameter to be used for the construction of the class instance * @return an instance of the class * @throws JMeterException if class cannot be created */ public static Object construct(String className, String parameter) throws JMeterException { Object instance = null; try { Class<?> clazz = Class.forName(className); Constructor<?> constructor = clazz.getConstructor(String.class); instance = constructor.newInstance(parameter); } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | NoSuchMethodException | IllegalAccessException | InstantiationException e) { throw new JMeterException(e); } return instance; }
/** * Call no-args constructor for a class. * * @param className name of the class to be constructed * @return an instance of the class * @throws JMeterException if class cannot be created */ public static Object construct(String className) throws JMeterException { Object instance = null; try { instance = ClassUtils.getClass(className).newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new JMeterException(e); } return instance; }
private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException { Object r = null; final String errorString = "Error invoking bsh method: "; try { r = m.invoke(bshInstance, o); } catch (IllegalArgumentException | IllegalAccessException e) { // Programming error final String message = errorString + m.getName(); log.error(message); throw new JMeterError(message, e); } catch (InvocationTargetException e) { // Can occur at run-time // could be caused by the bsh Exceptions: // EvalError, ParseException or TargetError String message = errorString + m.getName(); Throwable cause = e.getCause(); if (cause != null) { message += "\t" + cause.getLocalizedMessage(); } if (shouldLog) { log.error(message); } throw new JMeterException(message, e); } return r; }
/** * Call a class constructor with an integer parameter * @param className name of the class to be constructed * @param parameter the value to be used in the constructor * @return an instance of the class * @throws JMeterException if class cannot be created */ public static Object construct(String className, int parameter) throws JMeterException { Object instance = null; try { Class<?> clazz = ClassUtils.getClass(className); Constructor<?> constructor = clazz.getConstructor(Integer.TYPE); instance = constructor.newInstance(Integer.valueOf(parameter)); } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | NoSuchMethodException | SecurityException | IllegalAccessException | InstantiationException e) { throw new JMeterException(e); } return instance; }
/** * Invoke a public method on a class instance * * @param instance * object on which the method should be called * @param methodName * name of the method to be called * @throws SecurityException * if a security violation occurred while looking for the method * @throws IllegalArgumentException * if the method parameters (none given) do not match the * signature of the method * @throws JMeterException * if something went wrong in the invoked method */ public static void invoke(Object instance, String methodName) throws SecurityException, IllegalArgumentException, JMeterException { Method m; try { m = ClassUtils.getPublicMethod(instance.getClass(), methodName, new Class [] {}); m.invoke(instance, (Object [])null); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new JMeterException(e); } } }
if (ba.length == 0) { log.debug("{} Empty request, ignored", port); throw new JMeterException(); // hack to skip processing throw new JMeterException(); // hack to skip processing throw new JMeterException(); // hack to skip processing log.warn("{} Empty response to http over SSL. Probably waiting for user to authorize the certificate for {}", port, request.getUrl()); throw new JMeterException(); // hack to skip processing
throw new JMeterException("No Parser available");