use of org.ballerinalang.connector.api.Struct in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
try {
Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
// Creating server connector
Struct serviceEndpointConfig = serviceEndpoint.getStructField(HttpConstants.SERVICE_ENDPOINT_CONFIG);
ListenerConfiguration listenerConfiguration = getListerConfig(serviceEndpointConfig);
ServerConnector httpServerConnector = HttpConnectionManager.getInstance().createHttpServerConnector(listenerConfiguration);
serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVER_CONNECTOR, httpServerConnector);
// Adding service registries to native data
WebSocketServicesRegistry webSocketServicesRegistry = new WebSocketServicesRegistry();
HTTPServicesRegistry httpServicesRegistry = new HTTPServicesRegistry(webSocketServicesRegistry);
serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVICE_REGISTRY, httpServicesRegistry);
serviceEndpoint.addNativeData(HttpConstants.WS_SERVICE_REGISTRY, webSocketServicesRegistry);
// set filters
setFilters(serviceEndpointConfig, serviceEndpoint);
context.setReturnValues((BValue) null);
} catch (Throwable throwable) {
BStruct errorStruct = HttpUtil.getHttpConnectorError(context, throwable);
context.setReturnValues(errorStruct);
}
}
use of org.ballerinalang.connector.api.Struct in project ballerina by ballerina-lang.
the class Stop method execute.
@Override
public void execute(Context context) {
Struct serverEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
getServerConnector(serverEndpoint).stop();
context.setReturnValues();
}
use of org.ballerinalang.connector.api.Struct in project ballerina by ballerina-lang.
the class HttpResource method buildHttpResource.
public static HttpResource buildHttpResource(Resource resource, HttpService httpService) {
HttpResource httpResource = new HttpResource(resource, httpService);
Annotation resourceConfigAnnotation = getResourceConfigAnnotation(resource);
if (resourceConfigAnnotation == null) {
if (log.isDebugEnabled()) {
log.debug("resourceConfig not specified in the Resource instance, using default sub path");
}
httpResource.setPath(resource.getName());
httpResource.prepareAndValidateSignatureParams();
return httpResource;
}
Struct resourceConfig = resourceConfigAnnotation.getValue();
httpResource.setPath(resourceConfig.getStringField(PATH_FIELD));
httpResource.setMethods(getAsStringList(resourceConfig.getArrayField(METHODS_FIELD)));
httpResource.setConsumes(getAsStringList(resourceConfig.getArrayField(CONSUMES_FIELD)));
httpResource.setProduces(getAsStringList(resourceConfig.getArrayField(PRODUCES_FIELD)));
httpResource.setEntityBodyAttributeValue(resourceConfig.getStringField(BODY_FIELD));
httpResource.setCorsHeaders(CorsHeaders.buildCorsHeaders(resourceConfig.getStructField(CORS_FIELD)));
httpResource.setTransactionInfectable(resourceConfig.getBooleanField(TRANSACTION_INFECTABLE_FIELD));
processResourceCors(httpResource, httpService);
httpResource.prepareAndValidateSignatureParams();
return httpResource;
}
use of org.ballerinalang.connector.api.Struct in project ballerina by ballerina-lang.
the class HttpService method buildHttpService.
public static HttpService buildHttpService(Service service) {
HttpService httpService = new HttpService(service);
Annotation serviceConfigAnnotation = getHttpServiceConfigAnnotation(service);
if (serviceConfigAnnotation == null) {
log.debug("serviceConfig not specified in the Service instance, using default base path");
// service name cannot start with / hence concat
httpService.setBasePath(HttpConstants.DEFAULT_BASE_PATH.concat(httpService.getName()));
} else {
Struct serviceConfig = serviceConfigAnnotation.getValue();
httpService.setBasePath(serviceConfig.getStringField(BASE_PATH_FIELD));
httpService.setCompression(serviceConfig.getEnumField(COMPRESSION_FIELD));
httpService.setCorsHeaders(CorsHeaders.buildCorsHeaders(serviceConfig.getStructField(CORS_FIELD)));
httpService.setWebSocketUpgradeConfig(serviceConfig.getStructField(WEBSOCKET_UPGRADE_FIELD));
}
List<HttpResource> resources = new ArrayList<>();
for (Resource resource : httpService.getBallerinaService().getResources()) {
HttpResource httpResource = HttpResource.buildHttpResource(resource, httpService);
try {
httpService.getUriTemplate().parse(httpResource.getPath(), httpResource, new HttpResourceElementFactory());
} catch (URITemplateException | UnsupportedEncodingException e) {
throw new BallerinaConnectorException(e.getMessage());
}
resources.add(httpResource);
}
httpService.setResources(resources);
httpService.setAllAllowedMethods(DispatcherUtil.getAllResourceMethods(httpService));
return httpService;
}
use of org.ballerinalang.connector.api.Struct in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
try {
Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
Struct serviceEndpointConfig = serviceEndpoint.getStructField(EndpointConstants.ENDPOINT_CONFIG);
EndpointConfiguration configuration = EndpointUtils.getEndpointConfiguration(serviceEndpointConfig);
io.grpc.ServerBuilder serverBuilder;
if (configuration.getSslConfig() != null) {
SslContext sslCtx = new SSLHandlerFactory(configuration.getSslConfig()).createHttp2TLSContextForServer();
serverBuilder = GrpcServicesBuilder.initService(configuration, sslCtx);
} else {
serverBuilder = GrpcServicesBuilder.initService(configuration, null);
}
serviceEndpoint.addNativeData(SERVICE_BUILDER, serverBuilder);
context.setReturnValues();
} catch (Throwable throwable) {
BStruct err = getConnectorError(context, throwable);
context.setError(err);
}
}
Aggregations