use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class BizkeeperHandlerDelegate method forceFallbackCommand.
protected HystrixObservable<Response> forceFallbackCommand(Invocation invocation) {
return new HystrixObservable<Response>() {
@Override
public Observable<Response> observe() {
ReplaySubject<Response> subject = ReplaySubject.create();
final Subscription sourceSubscription = toObservable().subscribe(subject);
return subject.doOnUnsubscribe(sourceSubscription::unsubscribe);
}
@Override
public Observable<Response> toObservable() {
return Observable.create(f -> {
try {
f.onNext(FallbackPolicyManager.getFallbackResponse(handler.groupname, invocation));
} catch (Exception e) {
f.onError(e);
}
});
}
};
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestProducerSchemaFactory method testGetOrCreateProducer.
@Test
public void testGetOrCreateProducer() throws Exception {
OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
Assert.assertEquals("add", operationMeta.getOperationId());
SwaggerProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
ReflectUtils.setField(addBody, "x", 1);
ReflectUtils.setField(addBody, "y", 2);
Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { addBody }) {
@Override
public String getInvocationQualifiedName() {
return "";
}
};
Holder<Response> holder = new Holder<>();
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(3, (int) holder.value.getResult());
invocation.setSwaggerArguments(new Object[] { 1, 2 });
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(true, holder.value.isFailed());
InvocationException exception = (InvocationException) holder.value.getResult();
CommonExceptionData data = (CommonExceptionData) exception.getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestInvokerUtils method testSyncInvokeInvocationWithException.
@Test
public void testSyncInvokeInvocationWithException() throws InterruptedException {
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
new MockUp<SyncResponseExecutor>() {
@Mock
public Response waitResponse() throws InterruptedException {
return Mockito.mock(Response.class);
}
};
Mockito.when(response.isSuccessed()).thenReturn(true);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(operationMeta.getMicroserviceQualifiedName()).thenReturn("test");
try {
InvokerUtils.syncInvoke(invocation);
} catch (InvocationException e) {
Assert.assertEquals(490, e.getStatusCode());
}
}
use of org.apache.servicecomb.swagger.invocation.Response 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 in project incubator-servicecomb-java-chassis by apache.
the class SwaggerProducerOperation method syncInvoke.
public void syncInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
ContextUtils.setInvocationContext(invocation);
Response response = doInvoke(invocation);
ContextUtils.removeInvocationContext();
asyncResp.handle(response);
}
Aggregations