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(); }
@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(); } }
/** * Fill a builder with attribute values from the provided {@code Header} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Header instance) { Objects.requireNonNull(instance, "instance"); headerName(instance.getHeaderName()); headerValue(instance.getHeaderValue()); return this; }