use of org.apache.servicecomb.swagger.invocation.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvcBase method cseResponse.
public Response cseResponse(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 testDoSendResponseResultOKFilter.
@Test
public void testDoSendResponseResultOKFilter(@Mocked Response response) throws Exception {
Headers headers = new Headers();
headers.addHeader("Content-Type", "application/json");
new Expectations() {
{
response.getHeaders();
result = headers;
response.getStatusCode();
result = 123;
response.getReasonPhrase();
result = "reason";
response.getResult();
result = "ok";
}
};
Buffer buffer = Buffer.buffer();
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 setBodyBuffer(Buffer bodyBuffer) {
buffer.appendBuffer(bodyBuffer);
}
}.getMockInstance();
HttpServerFilter filter = new MockUp<HttpServerFilter>() {
@Mock
void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
buffer.appendString("-filter");
}
}.getMockInstance();
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.loadSortedService(HttpServerFilter.class);
httpServerFilters.add(filter);
restInvocation.setHttpServerFilters(httpServerFilters);
restInvocation.sendResponse(response);
Assert.assertEquals("\"ok\"-filter", buffer.toString());
}
use of org.apache.servicecomb.swagger.invocation.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method testDoSendResponseHeaderNull.
@Test
public void testDoSendResponseHeaderNull(@Mocked Response response) throws Exception {
Headers headers = new Headers();
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(null, resultHeaders.getHeaderMap());
}
}
use of org.apache.servicecomb.swagger.invocation.response.Headers in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstJaxrs method cseResponse.
// public Response getUserResponse() {
//
// }
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/cseResponse")
@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;
}
Aggregations