Java Code Examples for org.apache.servicecomb.core.Invocation#findResponseType()
The following examples show how to use
org.apache.servicecomb.core.Invocation#findResponseType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufManager.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
public static OperationProtobuf getOrCreateOperation(Invocation invocation) { RuntimeCacheKey cacheKey = new RuntimeCacheKey(invocation.getInvocationType(), invocation.getOperationMeta().getMicroserviceQualifiedName(), invocation.findResponseType(Status.OK.getStatusCode())); OperationProtobuf operationProtobuf = RUNTIME_CACHE.get(cacheKey); if (operationProtobuf == null) { synchronized (LOCK) { MicroserviceMeta microserviceMeta = invocation.getMicroserviceMeta(); ScopedProtobufSchemaManager scopedProtobufSchemaManager = microserviceMeta.getExtData(EXT_ID); if (scopedProtobufSchemaManager == null) { scopedProtobufSchemaManager = new ScopedProtobufSchemaManager(); microserviceMeta.putExtData(EXT_ID, scopedProtobufSchemaManager); } operationProtobuf = RUNTIME_CACHE.get(cacheKey); if (operationProtobuf == null) { operationProtobuf = new OperationProtobuf(scopedProtobufSchemaManager, invocation); RUNTIME_CACHE.put(cacheKey, operationProtobuf); } } } return operationProtobuf; }
Example 2
Source File: TestDefaultHttpClientFilter.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void testAfterReceiveResponseNullProduceProcessor(@Mocked Invocation invocation, @Mocked HttpServletResponseEx responseEx, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation) throws Exception { CommonExceptionData data = new CommonExceptionData("abcd"); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); result = swaggerRestOperation; invocation.findResponseType(403); result = SimpleType.constructUnsafe(CommonExceptionData.class); responseEx.getStatus(); result = 403; responseEx.getStatusType(); result = Status.FORBIDDEN; responseEx.getBodyBuffer(); result = Buffer.buffer(JsonUtils.writeValueAsString(data).getBytes()); } }; Response response = filter.afterReceiveResponse(invocation, responseEx); Assert.assertEquals(403, response.getStatusCode()); Assert.assertEquals("Forbidden", response.getReasonPhrase()); Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass()); InvocationException invocationException = response.getResult(); Assert.assertEquals( 403, invocationException.getStatusCode()); Assert.assertEquals( "CommonExceptionData [message=abcd]", invocationException.getErrorData().toString()); }
Example 3
Source File: OperationProtobuf.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private void initResponseCodec(ScopedProtobufSchemaManager scopedProtobufSchemaManager, Invocation invocation) { ProtoMapper mapper = scopedProtobufSchemaManager.getOrCreateProtoMapper(invocation.getSchemaMeta()); Message responseMessage = mapper.getResponseMessage(invocation.getOperationMeta().getOperationId()); JavaType responseType = invocation.findResponseType(Status.OK.getStatusCode()); if (!invocation.isConsumer()) { initProviderResponseCode(responseMessage, mapper, responseType); } else { initConsumerResponseCode(responseMessage, mapper, responseType); } anyResponseRootSerializer = new ResponseRootSerializer(mapper.createRootSerializer(ProtoConst.ANY, Object.class), false, true); anyResponseRootDeserializer = new ResponseRootDeserializer<>( mapper.createRootDeserializer(ProtoConst.ANY, Object.class), false); }