Search in sources :

Example 1 with Headers

use of io.servicecomb.swagger.invocation.response.Headers in project java-chassis by ServiceComb.

the class SpringmvcProducerResponseMapper method mapResponse.

@SuppressWarnings("unchecked")
@Override
public Response mapResponse(StatusType status, Object response) {
    ResponseEntity<Object> springmvcResponse = (ResponseEntity<Object>) response;
    StatusType responseStatus = new HttpStatus(springmvcResponse.getStatusCode().value(), springmvcResponse.getStatusCode().getReasonPhrase());
    Response cseResponse = Response.status(responseStatus).entity(springmvcResponse.getBody());
    HttpHeaders headers = springmvcResponse.getHeaders();
    Headers cseHeaders = cseResponse.getHeaders();
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        if (entry.getValue() == null || entry.getValue().isEmpty()) {
            continue;
        }
        for (String value : entry.getValue()) {
            cseHeaders.addHeader(entry.getKey(), value);
        }
    }
    return cseResponse;
}
Also used : Response(io.servicecomb.core.Response) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(io.servicecomb.core.context.HttpStatus) StatusType(javax.ws.rs.core.Response.StatusType) Headers(io.servicecomb.swagger.invocation.response.Headers) HttpHeaders(org.springframework.http.HttpHeaders) List(java.util.List)

Example 2 with Headers

use of io.servicecomb.swagger.invocation.response.Headers in project java-chassis by ServiceComb.

the class CseClientHttpResponse method getHeaders.

@Override
public HttpHeaders getHeaders() {
    if (httpHeaders == null) {
        HttpHeaders tmpHeaders = new HttpHeaders();
        // 让spring mvc有body
        tmpHeaders.setContentLength(1);
        Headers headers = response.getHeaders();
        if (headers.getHeaderMap() != null) {
            for (Entry<String, List<Object>> entry : headers.getHeaderMap().entrySet()) {
                for (Object value : entry.getValue()) {
                    tmpHeaders.add(entry.getKey(), String.valueOf(value));
                }
            }
        }
        httpHeaders = tmpHeaders;
    }
    return httpHeaders;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Headers(io.servicecomb.swagger.invocation.response.Headers) HttpHeaders(org.springframework.http.HttpHeaders) List(java.util.List)

Aggregations

Headers (io.servicecomb.swagger.invocation.response.Headers)2 List (java.util.List)2 HttpHeaders (org.springframework.http.HttpHeaders)2 Response (io.servicecomb.core.Response)1 HttpStatus (io.servicecomb.core.context.HttpStatus)1 StatusType (javax.ws.rs.core.Response.StatusType)1 ResponseEntity (org.springframework.http.ResponseEntity)1