use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project servicecomb-java-chassis by apache.
the class TestHighwayVerticle method testHighwayVerticle.
@Test
public void testHighwayVerticle(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject json) {
HighwayServerVerticle highwayVerticle = new HighwayServerVerticle();
URIEndpointObject endpiontObject = new URIEndpointObject("highway://127.0.0.1:9090");
new Expectations() {
{
transport.parseAddress(anyString);
result = endpiontObject;
}
};
Endpoint endpoint = new Endpoint(transport, "highway://127.0.0.1:9090");
new Expectations() {
{
context.config();
result = json;
json.getValue(anyString);
result = endpoint;
}
};
highwayVerticle.init(vertx, context);
@SuppressWarnings("unchecked") Promise<Void> startPromise = Mockito.mock(Promise.class);
highwayVerticle.startListen(startPromise);
MockUtil.getInstance().mockHighwayConfig();
try {
highwayVerticle.startListen(startPromise);
assertTrue(true);
} catch (Exception e) {
Assert.fail();
}
}
use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project servicecomb-java-chassis by apache.
the class TestRestServerVerticle method testRestServerVerticleWithRouter.
@Test
public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Promise<Void> startPromise) throws Exception {
URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080");
new Expectations() {
{
transport.parseAddress("http://127.0.0.1:8080");
result = endpointObject;
}
};
Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080");
new Expectations() {
{
context.config();
result = jsonObject;
jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
result = endpiont;
}
};
RestServerVerticle server = new RestServerVerticle();
// process stuff done by Expectations
server.init(vertx, context);
server.start(startPromise);
}
use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project servicecomb-java-chassis by apache.
the class TestVertxRestTransport method testSendException.
@Test
public void testSendException() {
boolean validAssert;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
Endpoint end = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(end);
Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
try {
validAssert = true;
instance.send(invocation, asyncResp);
} catch (Exception e) {
validAssert = false;
}
Assert.assertFalse(validAssert);
}
use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.
the class RestClientTransportContextFactory method createRequestPath.
protected String createRequestPath(Invocation invocation, RestOperationMeta restOperationMeta) throws Exception {
String path = invocation.getLocalContext(RestConst.REST_CLIENT_REQUEST_PATH);
if (path == null) {
path = restOperationMeta.getPathBuilder().createRequestPath(invocation.getSwaggerArguments());
}
URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
String urlPrefix = endpoint.getFirst(DefinitionConst.URL_PREFIX);
if (StringUtils.isEmpty(urlPrefix) || path.startsWith(urlPrefix)) {
return path;
}
return urlPrefix + path;
}
use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.
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);
}
}
Aggregations