use of org.apache.servicecomb.swagger.invocation.context.HttpStatus in project incubator-servicecomb-java-chassis by apache.
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 = null;
if (HttpStatus.isSuccess(responseStatus)) {
cseResponse = realMapper.mapResponse(responseStatus, springmvcResponse.getBody());
} else {
// not support fail response mapper now
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;
}
use of org.apache.servicecomb.swagger.invocation.context.HttpStatus in project java-chassis by ServiceComb.
the class TestConfig method testHttpStatus.
@Test
public void testHttpStatus() {
StatusType oStatus = new HttpStatus(204, "InternalServerError");
Assert.assertEquals("InternalServerError", oStatus.getReasonPhrase());
}
use of org.apache.servicecomb.swagger.invocation.context.HttpStatus in project incubator-servicecomb-java-chassis by apache.
the class TestConfig method testHttpStatus.
@Test
public void testHttpStatus() {
StatusType oStatus = new HttpStatus(204, "InternalServerError");
Assert.assertEquals("InternalServerError", oStatus.getReasonPhrase());
}
use of org.apache.servicecomb.swagger.invocation.context.HttpStatus 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 = null;
if (HttpStatus.isSuccess(responseStatus)) {
cseResponse = realMapper.mapResponse(responseStatus, springmvcResponse.getBody());
} else {
// not support fail response mapper now
cseResponse = Response.status(responseStatus).entity(springmvcResponse.getBody());
}
HttpHeaders headers = springmvcResponse.getHeaders();
for (Entry<String, List<String>> entry : headers.entrySet()) {
if (entry.getValue() == null) {
continue;
}
for (String value : entry.getValue()) {
cseResponse.addHeader(entry.getKey(), value);
}
}
return cseResponse;
}
use of org.apache.servicecomb.swagger.invocation.context.HttpStatus in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method scheduleInvocation_flowControlReject.
@SuppressWarnings("deprecation")
@Test
public void scheduleInvocation_flowControlReject() {
new Expectations(operationMeta) {
{
operationMeta.getProviderQpsFlowControlHandler();
result = (Handler) (invocation, asyncResp) -> asyncResp.producerFail(new InvocationException(new HttpStatus(429, "Too Many Requests"), new CommonExceptionData("rejected by qps flowcontrol")));
}
};
Holder<Integer> status = new Holder<>();
Holder<String> reasonPhrase = new Holder<>();
Holder<Integer> endCount = new Holder<>(0);
Holder<String> responseBody = new Holder<>();
responseEx = new AbstractHttpServletResponse() {
@SuppressWarnings("deprecation")
@Override
public void setStatus(int sc, String sm) {
status.value = sc;
reasonPhrase.value = sm;
}
@Override
public void flushBuffer() {
endCount.value = endCount.value + 1;
}
@Override
public void setContentType(String type) {
assertEquals("application/json; charset=utf-8", type);
}
@Override
public void setBodyBuffer(Buffer bodyBuffer) {
responseBody.value = bodyBuffer.toString();
}
};
initRestInvocation();
restInvocation.scheduleInvocation();
assertEquals(Integer.valueOf(429), status.value);
assertEquals("Too Many Requests", reasonPhrase.value);
assertEquals("{\"message\":\"rejected by qps flowcontrol\"}", responseBody.value);
assertEquals(Integer.valueOf(1), endCount.value);
}
Aggregations