Search in sources :

Example 6 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class ClientRestArgsFilter method beforeSendRequest.

@Override
public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) {
    RestClientRequestImpl restClientRequest = (RestClientRequestImpl) invocation.getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    try {
        RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
        requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
    } catch (Throwable e) {
        throw ExceptionFactory.convertConsumerException(e);
    }
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 7 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class DefaultHttpClientFilter method afterReceiveResponse.

@Override
public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
    OperationMeta operationMeta = invocation.getOperationMeta();
    ResponseMeta responseMeta = operationMeta.findResponseMeta(responseEx.getStatus());
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    ProduceProcessor produceProcessor = findProduceProcessor(swaggerRestOperation, responseEx);
    if (produceProcessor == null) {
        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));
        Exception exception = ExceptionFactory.createConsumerException(new CommonExceptionData(msg));
        return Response.consumerFailResp(exception);
    }
    Object result = null;
    try {
        result = produceProcessor.decodeResponse(responseEx.getBodyBuffer(), responseMeta.getJavaType());
    } catch (Exception e) {
        return Response.consumerFailResp(e);
    }
    Response response = Response.create(responseEx.getStatusType(), result);
    for (String headerName : responseEx.getHeaderNames()) {
        Collection<String> headerValues = responseEx.getHeaders(headerName);
        for (String headerValue : headerValues) {
            response.getHeaders().addHeader(headerName, headerValue);
        }
    }
    return response;
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) ProduceProcessor(org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ResponseMeta(org.apache.servicecomb.swagger.invocation.response.ResponseMeta) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 8 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class MockUtil method mockOperationLocator.

public void mockOperationLocator() {
    new MockUp<OperationLocator>() {

        @Mock
        public RestOperationMeta getOperation() {
            RestOperationMeta rom = new RestOperationMeta();
            rom.init(Mockito.mock(OperationMeta.class));
            return rom;
        }
    };
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) MockUp(mockit.MockUp) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 9 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class CseClientHttpRequest method createRequestMeta.

private RequestMeta createRequestMeta(String httpMetod, URI uri) {
    String microserviceName = uri.getAuthority();
    ReferenceConfig referenceConfig = ReferenceConfigUtils.getForInvoke(microserviceName);
    MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
    if (servicePathManager == null) {
        throw new Error(String.format("no schema defined for %s:%s", microserviceMeta.getAppId(), microserviceMeta.getName()));
    }
    OperationLocator locator = servicePathManager.consumerLocateOperation(path, httpMetod);
    RestOperationMeta swaggerRestOperation = locator.getOperation();
    Map<String, String> pathParams = locator.getPathVarMap();
    return new RequestMeta(referenceConfig, swaggerRestOperation, pathParams);
}
Also used : OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ReferenceConfig(org.apache.servicecomb.core.provider.consumer.ReferenceConfig) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 10 with RestOperationMeta

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);
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Aggregations

RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)24 Test (org.junit.Test)14 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)11 Endpoint (org.apache.servicecomb.core.Endpoint)4 Invocation (org.apache.servicecomb.core.Invocation)4 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)3 URLPathBuilder (org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)3 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 RestClientRequestImpl (org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)2 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)2 Context (io.vertx.core.Context)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpMethod (io.vertx.core.http.HttpMethod)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1