Search in sources :

Example 6 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class TestLocator method createRestOperatonMeta.

protected RestOperationMeta createRestOperatonMeta(String httpMethod, String path) {
    OperationMeta om = new OperationMeta();
    om.setHttpMethod(httpMethod);
    RestOperationMeta rom = new RestOperationMeta();
    rom.setOperationMeta(om);
    rom.setAbsolutePath(path);
    return rom;
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 7 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class TestLocator method testLocateStatic.

@Test
public void testLocateStatic() {
    MicroserviceMeta msm = new MicroserviceMeta("app:ms");
    ServicePathManager spm = new ServicePathManager(msm);
    RestOperationMeta rom = createRestOperatonMeta("GET", "abc/");
    spm.addResource(rom);
    rom = createRestOperatonMeta("POST", "abc/");
    spm.addResource(rom);
    try {
        spm.addResource(rom);
    } catch (Throwable e) {
        Assert.assertEquals("operation with url abc/, method POST is duplicated", e.getMessage());
    }
    Assert.assertEquals(1, spm.getStaticPathOperationMap().size());
    Assert.assertEquals(2, spm.getStaticPathOperationMap().get("abc/").values().size());
    try {
        spm.locateOperation("abcd", "GET");
    } catch (InvocationException e) {
        Assert.assertEquals("Not Found", ((CommonExceptionData) e.getErrorData()).getMessage());
    }
    try {
        spm.locateOperation("abc/", "PUT");
    } catch (InvocationException e) {
        Assert.assertEquals("Method Not Allowed", ((CommonExceptionData) e.getErrorData()).getMessage());
    }
    OperationLocator locator = spm.locateOperation("abc/", "GET");
    Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
    locator.locate(spm, "abc/", "POST");
    Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) InvocationException(io.servicecomb.core.exception.InvocationException) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) CommonExceptionData(io.servicecomb.core.exception.CommonExceptionData) Test(org.junit.Test)

Example 8 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class MockUtil method mockAbstactRestServer.

public void mockAbstactRestServer() {
    new MockUp<AbstractRestServer<HttpServletResponse>>() {

        @Mock
        protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
            RestOperationMeta restOperationMeta = Mockito.mock(RestOperationMeta.class);
            OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
            Executor executor = Mockito.mock(Executor.class);
            operationMeta.setExecutor(executor);
            return restOperationMeta;
        }
    };
}
Also used : Executor(java.util.concurrent.Executor) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 9 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class AbstractRestServer method handleRequest.

protected void handleRequest(RestServerRequestInternal restRequest, HTTP_RESPONSE httpResponse) {
    try {
        RestOperationMeta restOperation = findRestOperation(restRequest);
        OperationMeta operationMeta = restOperation.getOperationMeta();
        operationMeta.getExecutor().execute(() -> {
            try {
                runOnExecutor(restRequest, restOperation, httpResponse);
            } catch (Exception e) {
                LOGGER.error("rest server onRequest error", e);
                sendFailResponse(restRequest, httpResponse, e);
            }
        });
    } catch (Exception e) {
        LOGGER.error("rest server onRequest error", e);
        sendFailResponse(restRequest, httpResponse, e);
    }
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) InvocationException(io.servicecomb.core.exception.InvocationException)

Example 10 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

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(io.servicecomb.common.rest.definition.RestOperationMeta) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Aggregations

RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)23 Test (org.junit.Test)14 OperationMeta (io.servicecomb.core.definition.OperationMeta)12 Invocation (io.servicecomb.core.Invocation)10 AsyncResponse (io.servicecomb.core.AsyncResponse)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)6 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)5 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)5 IpPort (io.servicecomb.foundation.common.net.IpPort)5 HttpClient (io.vertx.core.http.HttpClient)4 Endpoint (io.servicecomb.core.Endpoint)3 InvocationException (io.servicecomb.core.exception.InvocationException)3 RestServerRequestInternal (io.servicecomb.common.rest.codec.RestServerRequestInternal)2 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)2 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)2 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 HashMap (java.util.HashMap)2 MockUp (mockit.MockUp)2