use of org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx in project incubator-servicecomb-java-chassis by apache.
the class VertxRestDispatcher method onRequest.
private void onRequest(RoutingContext context) {
if (transport == null) {
transport = CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL);
}
HttpServletRequestEx requestEx = new VertxServerRequestToHttpServletRequest(context);
HttpServletResponseEx responseEx = new VertxServerResponseToHttpServletResponse(context.response());
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
context.put(RestConst.REST_PRODUCER_INVOCATION, restProducerInvocation);
restProducerInvocation.invoke(transport, requestEx, responseEx, httpServerFilters);
}
use of org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx in project incubator-servicecomb-java-chassis by apache.
the class ServletRestDispatcher method service.
public void service(HttpServletRequest request, HttpServletResponse response) {
if (transport == null) {
transport = CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL);
}
// 异步场景
final AsyncContext asyncCtx = request.startAsync();
asyncCtx.addListener(restAsyncListener);
asyncCtx.setTimeout(ServletConfig.getServerTimeout());
HttpServletRequestEx requestEx = new StandardHttpServletRequestEx(request);
HttpServletResponseEx responseEx = new StandardHttpServletResponseEx(response);
RestServletProducerInvocation restProducerInvocation = new RestServletProducerInvocation();
restProducerInvocation.invoke(transport, requestEx, responseEx, httpServerFilters);
}
use of org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx 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());
}
Aggregations