use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class CseClientHttpRequest method createRequestMeta.
protected RequestMeta createRequestMeta(String httpMethod, URI uri) {
String microserviceName = uri.getAuthority();
MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance().createMicroserviceReferenceConfig(microserviceName);
MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
if (servicePathManager == null) {
throw new Error(String.format("no schema defined for %s:%s", microserviceMeta.getAppId(), microserviceMeta.getMicroserviceName()));
}
OperationLocator locator = servicePathManager.consumerLocateOperation(path, httpMethod);
RestOperationMeta swaggerRestOperation = locator.getOperation();
OperationMeta operationMeta = locator.getOperation().getOperationMeta();
ReferenceConfig referenceConfig = microserviceReferenceConfig.createReferenceConfig(operationMeta);
Map<String, String> pathParams = locator.getPathVarMap();
return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class RestClientTransportContextFactory method createHttpClientRequest.
protected Future<HttpClientRequest> createHttpClientRequest(Invocation invocation) {
try {
RestOperationMeta restOperationMeta = RestMetaUtils.getRestOperationMeta(invocation.getOperationMeta());
HttpClientWithContext httpClientWithContext = findHttpClientPool(invocation);
URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
HttpMethod method = HttpMethod.valueOf(restOperationMeta.getHttpMethod());
RequestOptions requestOptions = new RequestOptions().setHost(endpoint.getHostOrIp()).setPort(endpoint.getPort()).setSsl(endpoint.isSslEnabled()).setMethod(method).setURI(createRequestPath(invocation, restOperationMeta));
return httpClientRequestFactory.create(invocation, httpClientWithContext.getHttpClient(), requestOptions);
} catch (Throwable e) {
throw new InvocationException(BAD_REQUEST, FAILED_TO_CREATE_REST_CLIENT_TRANSPORT_CONTEXT, e.getMessage(), e);
}
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class RestClientTransportContextFactory method doCreate.
protected RestClientTransportContext doCreate(Invocation invocation, HttpClientRequest httpClientRequest) throws Throwable {
RestOperationMeta restOperationMeta = RestMetaUtils.getRestOperationMeta(invocation.getOperationMeta());
HttpClientWithContext httpClientWithContext = findHttpClientPool(invocation);
return new RestClientTransportContext(restOperationMeta, httpClientWithContext.context(), httpClientRequest, boundaryFactory);
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class DefaultHttpClientFilter method extractResponse.
protected Response extractResponse(Invocation invocation, HttpServletResponseEx responseEx) {
Object result = invocation.getHandlerContext().get(RestConst.READ_STREAM_PART);
if (result != null) {
return Response.create(responseEx.getStatusType(), result);
}
OperationMeta operationMeta = invocation.getOperationMeta();
JavaType responseType = invocation.findResponseType(responseEx.getStatus());
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
ProduceProcessor produceProcessor = findProduceProcessor(swaggerRestOperation, responseEx);
if (produceProcessor == null) {
// This happens outside the runtime such as Servlet filter response. Here we give a default json parser to it
// and keep user data not get lose.
String msg = String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported", swaggerRestOperation.getHttpMethod(), swaggerRestOperation.getAbsolutePath(), responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
LOGGER.warn(msg);
produceProcessor = ProduceProcessorManager.INSTANCE.findDefaultProcessor();
}
try {
result = produceProcessor.decodeResponse(responseEx.getBodyBuffer(), responseType);
Response response = Response.create(responseEx.getStatusType(), result);
if (response.isFailed()) {
LOGGER.warn("invoke operation [{}] failed, status={}, msg={}", invocation.getMicroserviceQualifiedName(), responseEx.getStatusType().getStatusCode(), result == null ? "" : result.toString());
}
return response;
} catch (Exception e) {
LOGGER.error("failed to decode response body, exception is [{}]", e.getMessage());
String msg = String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported", swaggerRestOperation.getHttpMethod(), swaggerRestOperation.getAbsolutePath(), responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
if (HttpStatus.isSuccess(responseEx.getStatus())) {
return Response.createConsumerFail(new InvocationException(400, responseEx.getStatusType().getReasonPhrase(), new CommonExceptionData(msg), e));
}
return Response.createConsumerFail(new InvocationException(responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), new CommonExceptionData(msg), e));
}
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class VertxHttpMethod method getMethod.
private HttpMethod getMethod(Invocation invocation) {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
String method = swaggerRestOperation.getHttpMethod();
return HttpMethod.valueOf(method);
}
Aggregations