use of org.apache.servicecomb.swagger.invocation.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstJaxrs method response.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/response")
@GET
public Response response(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method testDoSendResponseHeaderNormal.
@Test
public void testDoSendResponseHeaderNormal(@Mocked Response response) throws Exception {
Headers headers = new Headers();
headers.addHeader("h1", "h1v1");
headers.addHeader("h1", "h1v2");
headers.addHeader("h2", "h2v");
new Expectations() {
{
response.getResult();
result = new Error("stop");
response.getHeaders();
result = headers;
}
};
Headers resultHeaders = new Headers();
responseEx = new MockUp<HttpServletResponseEx>() {
private Map<String, Object> attributes = new HashMap<>();
@Mock
public void setAttribute(String key, Object value) {
this.attributes.put(key, value);
}
@Mock
public Object getAttribute(String key) {
return this.attributes.get(key);
}
@Mock
void addHeader(String name, String value) {
resultHeaders.addHeader(name, value);
}
}.getMockInstance();
initRestInvocation();
try {
restInvocation.sendResponse(response);
Assert.fail("must throw exception");
} catch (Error e) {
Assert.assertEquals(headers.getHeaderMap(), resultHeaders.getHeaderMap());
}
}
use of org.apache.servicecomb.swagger.invocation.response.Headers 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.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvc method cseResponse.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/cseResponse", method = RequestMethod.GET)
public Response cseResponse(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class CseClientHttpResponse method getHeaders.
@Override
public HttpHeaders getHeaders() {
if (httpHeaders == null) {
HttpHeaders tmpHeaders = new HttpHeaders();
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;
}
Aggregations