/** * Copy the current immutable object by setting a value for the {@link Header#getHeaderName() headerName} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for headerName * @return A modified copy of the {@code this} object */ public final ImmutableHeader withHeaderName(String value) { if (this.headerName.equals(value)) return this; String newValue = Objects.requireNonNull(value, "headerName"); return new ImmutableHeader(newValue, this.headerValue); }
/** * This instance is equal to all instances of {@code ImmutableHeader} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableHeader && equalTo((ImmutableHeader) another); }
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(); } }
/** * Copy the current immutable object by setting a value for the {@link Header#getHeaderValue() headerValue} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for headerValue * @return A modified copy of the {@code this} object */ public final ImmutableHeader withHeaderValue(String value) { if (this.headerValue.equals(value)) return this; String newValue = Objects.requireNonNull(value, "headerValue"); return new ImmutableHeader(this.headerName, newValue); }
@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(); } }
/** * Builds a new {@link ImmutableHeader ImmutableHeader}. * @return An immutable instance of Header * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableHeader build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableHeader(headerName, headerValue); }