Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for replacing binary multipart data with placeholder content #264

Open
psamsotha opened this issue Jun 17, 2016 · 2 comments
Open
Labels
type: enhancement Enhancement that adds a new feature

Comments

@psamsotha
Copy link

You can see in this Stack Overflow question, that when posting Multipart data, often there is binary data, which causes the resulting snippet to be a large amount of garbled data. It would be nice to have a core preprocessor that allows us to replace that binary content with a placeholder, like <<binary data>>. The component should allow for selecting which parts should be replaced, as not all parts will be binary data.

@wilkinsona wilkinsona added the type: enhancement Enhancement that adds a new feature label Jun 23, 2016
@someok
Copy link

someok commented Oct 30, 2017

You can add a custom OperationPreprocessor:

class RequestPartsModifyingOperationPreprocessor extends OperationPreprocessorAdapter {

    private static final byte[] MOCK_PART_CONTENT = "<binary>".getBytes(StandardCharsets.UTF_8);

    private final OperationRequestFactory requestFactory = new OperationRequestFactory();

    private final OperationRequestPartFactory requestPartFactory = new
        OperationRequestPartFactory();

    @Override
    public OperationRequest preprocess(OperationRequest request) {
        Collection<OperationRequestPart> parts = request.getParts();
        if (CollectionUtils.isEmpty(parts)) {
            return request;
        }

        List<OperationRequestPart> newParts = new ArrayList<>(parts.size());
        OperationRequestPart part;
        for (OperationRequestPart requestPart : parts) {
            if (requestPart.getContent().length > 20) {

                part = requestPartFactory
                    .create(requestPart.getName(), requestPart.getSubmittedFileName(),
                        MOCK_PART_CONTENT, requestPart.getHeaders());
            } else {
                part = requestPart;
            }

            newParts.add(part);
        }

        return this.requestFactory
            .create(request.getUri(), request.getMethod(), request.getContent(),
                request.getHeaders(), request.getParameters(), newParts, request.getCookies());
    }
}

@kaka2507
Copy link

kaka2507 commented Aug 1, 2018

@someok Thank you, I got the same issue and your proposal can help me resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Enhancement that adds a new feature
Projects
None yet
Development

No branches or pull requests

4 participants