All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dadiyang.httpinvoker.mocker.MockResponse Maven / Gradle / Ivy

There is a newer version: 1.2.4
Show newest version
package com.github.dadiyang.httpinvoker.mocker;

import com.github.dadiyang.httpinvoker.requestor.HttpResponse;

/**
 * @author huangxuyang
 * @since 2019-05-31
 */
public class MockResponse extends HttpResponse {
    private static final int STATUS_CODE_SUC = 200;

    public MockResponse() {
    }

    public MockResponse(int statusCode, String body) {
        setStatusCode(statusCode);
        setBody(body);
    }

    public MockResponse(String statusMessage, int statusCode) {
        setStatusCode(statusCode);
        setStatusMessage(statusMessage);
    }

    public MockResponse(String body) {
        setStatusCode(STATUS_CODE_SUC);
        setBody(body);
    }

    public MockResponse(int statusCode, String statusMessage, String contentType) {
        super(statusCode, statusMessage, contentType);
    }

    @Override
    public byte[] getBodyAsBytes() {
        byte[] bytes = super.getBodyAsBytes();
        String body = getBody();
        return bytes == null && body != null ? getBody().getBytes() : bytes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy