static List<Header> getHeadersFromRecordedFile(final Optional<String> recordedRequestHeaderFile){ if(!recordedRequestHeaderFile.isPresent()){ return ImmutableList.of(); } try (final Stream<String> linesStream = Files.lines(Paths.get(recordedRequestHeaderFile.get()))) { final String contentWithoutFirstLine = linesStream.skip(1).collect(Collectors.joining(System.lineSeparator())); try (final Reader reader = CharSource.wrap(contentWithoutFirstLine).openStream()) { final Properties properties = new Properties(); properties.load(reader); return properties.entrySet().stream() .filter(entry -> entry.getKey() instanceof String && entry.getValue() instanceof String) .map(entry -> ImmutableHeader.builder().headerName((String) entry.getKey()).headerValue((String) entry.getValue()).build()) .collect(Collectors.toList()); } } catch (final IOException e) { LOGGER.error("Can not read recorded request headers", e); } return ImmutableList.of(); }
/** * Creates an immutable copy of a {@link Header} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Header instance */ public static ImmutableHeader copyOf(Header instance) { if (instance instanceof ImmutableHeader) { return (ImmutableHeader) instance; } return ImmutableHeader.builder() .from(instance) .build(); }
@Override public final List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size() != 2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, METHOD + method.getName() + " should have 2 parameters: " + method.getName() + "(const char *Header, const char *Content)"); return Collections.emptyList(); } final String headerName = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final String headerValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(1)); final Header header = ImmutableHeader.builder().headerName(headerName).headerValue(headerValue).build(); visitor.getGlobalHeaders().add(header); visitor.readSupportedFunction(method.getName(), ctx); return Collections.emptyList(); } }
@Override public final List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size() != 2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, METHOD + method.getName() + " should have 2 parameters: " + method.getName() + "(const char *Header, const char *Content)"); return Collections.emptyList(); } final String headerName = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final String headerValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(1)); final Header header = ImmutableHeader.builder().headerName(headerName).headerValue(headerValue).build(); visitor.getCurrentHeaders().add(header); visitor.readSupportedFunction(method.getName(), ctx); return Collections.emptyList(); } }