use of org.apache.servicecomb.common.rest.filter.HttpServerFilter 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.common.rest.filter.HttpServerFilter in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method setup.
@Before
public void setup() {
invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.getSortedService(HttpServerFilter.class);
restInvocation.setHttpServerFilters(httpServerFilters);
}
use of org.apache.servicecomb.common.rest.filter.HttpServerFilter in project incubator-servicecomb-java-chassis by apache.
the class AbstractRestInvocation method prepareInvoke.
protected Response prepareInvoke() throws Throwable {
this.initProduceProcessor();
this.setContext();
invocation.getHandlerContext().put(RestConst.REST_REQUEST, requestEx);
for (HttpServerFilter filter : httpServerFilters) {
Response response = filter.afterReceiveRequest(invocation, requestEx);
if (response != null) {
return response;
}
}
return null;
}
use of org.apache.servicecomb.common.rest.filter.HttpServerFilter in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method setup.
@Before
public void setup() {
ConfigUtil.installDynamicConfig();
scbEngine = SCBBootstrap.createSCBEngineForTest().addProducerMeta("sid1", new TestPathSchema()).run();
operationMeta = scbEngine.getProducerMicroserviceMeta().operationMetas().get("test.sid1.dynamicId");
restOperation = RestMetaUtils.getRestOperationMeta(operationMeta);
new MockUp<System>() {
@Mock
long nanoTime() {
return nanoTime;
}
};
if (responseEx == null) {
responseEx = new StandardHttpServletResponseEx(servletResponse);
}
invocation = new Invocation(endpoint, operationMeta, operationMeta.buildBaseConsumerRuntimeType(), arguments);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.getSortedService(HttpServerFilter.class);
restInvocation.setHttpServerFilters(httpServerFilters);
}
Aggregations