use of io.restassured.internal.RequestSpecificationImpl in project rest-assured by rest-assured.
the class RequestSpecBuilder method addRequestSpecification.
/**
* Merge this builder with settings from another specification. Note that the supplied specification
* can overwrite data in the current specification. The following settings are overwritten:
* <ul>
* <li>Port</li>
* <li>Authentication scheme</
* <li>Content type</li>
* <li>Request body</li>
* </ul>
* The following settings are merged:
* <ul>
* <li>Parameters</li>
* <li>Cookies</li>
* <li>Headers</li>
* <li>Filters</li>
* </ul>
*
* @param specification The specification to add
* @return The request specification builder
*/
public RequestSpecBuilder addRequestSpecification(RequestSpecification specification) {
if (!(specification instanceof RequestSpecificationImpl)) {
throw new IllegalArgumentException("Specification must be of type " + RequestSpecificationImpl.class.getClass() + ".");
}
RequestSpecificationImpl rs = (RequestSpecificationImpl) specification;
SpecificationMerger.merge((RequestSpecificationImpl) spec, rs);
return this;
}
use of io.restassured.internal.RequestSpecificationImpl in project rest-assured by rest-assured.
the class MockMvcRequestSenderImpl method logRequestIfApplicable.
private void logRequestIfApplicable(HttpMethod method, String uri, String originalPath, Object[] unnamedPathParams) {
if (requestLoggingFilter == null) {
return;
}
final RequestSpecificationImpl reqSpec = new RequestSpecificationImpl("http://localhost", RestAssured.UNDEFINED_PORT, "", new NoAuthScheme(), Collections.<Filter>emptyList(), null, true, ConfigConverter.convertToRestAssuredConfig(config), logRepository, null);
reqSpec.setMethod(method.toString());
reqSpec.path(uri);
reqSpec.buildUnnamedPathParameterTuples(unnamedPathParams);
if (params != null) {
new ParamLogger(params) {
protected void logParam(String paramName, Object paramValue) {
reqSpec.param(paramName, paramValue);
}
}.logParams();
}
if (queryParams != null) {
new ParamLogger(queryParams) {
protected void logParam(String paramName, Object paramValue) {
reqSpec.queryParam(paramName, paramValue);
}
}.logParams();
}
if (formParams != null) {
new ParamLogger(formParams) {
protected void logParam(String paramName, Object paramValue) {
reqSpec.formParam(paramName, paramValue);
}
}.logParams();
}
if (headers != null) {
for (Header header : headers) {
reqSpec.header(header);
}
}
if (cookies != null) {
for (Cookie cookie : cookies) {
reqSpec.cookie(cookie);
}
}
if (requestBody != null) {
if (requestBody instanceof byte[]) {
reqSpec.body((byte[]) requestBody);
} else if (requestBody instanceof File) {
String contentType = findContentType();
String charset = null;
if (StringUtils.isNotBlank(contentType)) {
charset = CharsetExtractor.getCharsetFromContentType(contentType);
}
if (charset == null) {
charset = Charset.defaultCharset().toString();
}
String string = fileToString((File) requestBody, charset);
reqSpec.body(string);
} else {
reqSpec.body(requestBody);
}
}
if (multiParts != null) {
for (MockMvcMultiPart multiPart : multiParts) {
reqSpec.multiPart(new MultiPartSpecBuilder(multiPart.getContent()).controlName(multiPart.getControlName()).fileName(multiPart.getFileName()).mimeType(multiPart.getMimeType()).build());
}
}
String uriPath = PathSupport.getPath(uri);
String originalUriPath = PathSupport.getPath(originalPath);
requestLoggingFilter.filter(reqSpec, null, new FilterContextImpl(uri, originalUriPath, uriPath, uri, uri, new Object[0], method.toString(), null, Collections.<Filter>emptyList().iterator(), new HashMap<String, Object>()));
}
Aggregations