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

org.zodiac.sentinel.base.fallback.SentinelBlockHttpResponse Maven / Gradle / Ivy

package org.zodiac.sentinel.base.fallback;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.AbstractClientHttpResponse;
import org.zodiac.commons.http.standard.HttpMediaType;
import org.zodiac.commons.util.Colls;

public class SentinelBlockHttpResponse extends AbstractClientHttpResponse {

    private String blockResponse = "RestTemplate request block by sentinel";

    public SentinelBlockHttpResponse() {
    }

    public SentinelBlockHttpResponse(String blockResponse) {
        this.blockResponse = blockResponse;
    }

    @Override
    public int getRawStatusCode() throws IOException {
        return HttpStatus.OK.value();
    }

    @Override
    public String getStatusText() throws IOException {
        return blockResponse;
    }

    @Override
    public void close() {
        // nothing do
    }

    @Override
    public InputStream getBody() throws IOException {
        return new ByteArrayInputStream(blockResponse.getBytes());
    }

    @Override
    public HttpHeaders getHeaders() {
        Map> headers = Colls.map();
        headers.put(HttpHeaders.CONTENT_TYPE,
                Arrays.asList(HttpMediaType.APPLICATION_JSON_UTF8_VALUE));
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.putAll(headers);
        return httpHeaders;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy