Search in sources :

Example 1 with RestClientRequestImpl

use of io.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.

the class VertxHttpMethod method doMethod.

public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String path = this.createRequestPath(invocation, swaggerRestOperation);
    IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
    HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, swaggerRestOperation, asyncResp);
    RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest);
    RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
    clientRequest.exceptionHandler(e -> {
        LOGGER.error(e.toString());
        asyncResp.fail(invocation.getInvocationType(), e);
    });
    // 从业务线程转移到网络线程中去发送
    httpClientWithContext.runOnContext(httpClient -> {
        this.setCseContext(invocation, clientRequest);
        clientRequest.setTimeout(AbstractTransport.getRequestTimeout());
        try {
            restClientRequest.end();
        } catch (Exception e) {
            LOGGER.error("send http reqeust failed,", e);
            asyncResp.fail(invocation.getInvocationType(), e);
        }
    });
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(io.servicecomb.common.rest.codec.param.RestClientRequestImpl) IpPort(io.servicecomb.foundation.common.net.IpPort) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 2 with RestClientRequestImpl

use of io.servicecomb.common.rest.codec.param.RestClientRequestImpl in project java-chassis by ServiceComb.

the class TestParam method setup.

@Before
public void setup() {
    request = new MockUp<HttpClientRequest>() {

        @Mock
        public HttpClientRequest putHeader(CharSequence name, CharSequence value) {
            this.putHeader(name.toString(), value.toString());
            return request;
        }

        @Mock
        public HttpClientRequest putHeader(String name, String value) {
            List<String> list = clientHttpHeaders.get(name);
            if (list == null) {
                list = new ArrayList<>();
                clientHttpHeaders.put(name, list);
            }
            list.add(value);
            return request;
        }

        @Mock
        public void end(Buffer chunk) {
            clientBodyBuffer = chunk;
        }
    }.getMockInstance();
    clientRequest = new RestClientRequestImpl(request);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RestClientRequestImpl(io.servicecomb.common.rest.codec.param.RestClientRequestImpl) MockUp(mockit.MockUp) Before(org.junit.Before)

Aggregations

RestClientRequestImpl (io.servicecomb.common.rest.codec.param.RestClientRequestImpl)2 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 IpPort (io.servicecomb.foundation.common.net.IpPort)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 MockUp (mockit.MockUp)1 Before (org.junit.Before)1