Example usage for org.springframework.restdocs.operation OperationRequestPartFactory OperationRequestPartFactory

List of usage examples for org.springframework.restdocs.operation OperationRequestPartFactory OperationRequestPartFactory

Introduction

In this page you can find the example usage for org.springframework.restdocs.operation OperationRequestPartFactory OperationRequestPartFactory.

Prototype

OperationRequestPartFactory

Source Link

Usage

From source file:io.github.restdocsext.jersey.JerseyRequestConverter.java

/**
 * Create an {@code OperationRequestPart} from a Jersey {@code FormDataBodyPart}.
 *
 * @param part the Jersey part./*from   w w w . j a  v a 2  s  .co  m*/
 * @return the converted operation request part.
 */
// can't test this on it's own as the part is not a body part entity
private static OperationRequestPart createOperationRequestPart(FormDataBodyPart part) {
    final HttpHeaders partHeaders = extractHeaders(part.getHeaders());
    final List<String> contentTypeHeader = partHeaders.get(HttpHeaders.CONTENT_TYPE);
    if (part.getMediaType() != null && contentTypeHeader == null) {
        partHeaders.setContentType(
                org.springframework.http.MediaType.parseMediaType(part.getMediaType().toString()));
    }

    final String filename = StringUtils.hasText(part.getContentDisposition().getFileName())
            ? part.getContentDisposition().getFileName()
            : null;
    return new OperationRequestPartFactory().create(part.getName(), filename, part.getEntityAs(byte[].class),
            partHeaders);
}