use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class HttpUtil method extractBasicConfig.
@Deprecated
private static void extractBasicConfig(Annotation configInfo, Set<ListenerConfiguration> listenerConfSet) {
AnnAttrValue hostAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HOST);
AnnAttrValue portAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_PORT);
AnnAttrValue keepAliveAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEEP_ALIVE);
AnnAttrValue transferEncoding = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRANSFER_ENCODING);
AnnAttrValue chunking = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CHUNKING);
AnnAttrValue maxUriLength = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_URL_LENGTH);
AnnAttrValue maxHeaderSize = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_HEADER_SIZE);
AnnAttrValue maxEntityBodySize = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_ENTITY_BODY_SIZE);
AnnAttrValue versionAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTP_VERSION);
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
if (portAttrVal != null && portAttrVal.getIntValue() > 0) {
listenerConfiguration.setPort(Math.toIntExact(portAttrVal.getIntValue()));
listenerConfiguration.setScheme(HttpConstants.PROTOCOL_HTTP);
if (hostAttrVal != null && hostAttrVal.getStringValue() != null) {
listenerConfiguration.setHost(hostAttrVal.getStringValue());
} else {
listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
}
// chunking. Once we start supporting gzip, deflate, etc, we need to parse down the config.
if (transferEncoding != null && !HttpConstants.ANN_CONFIG_ATTR_CHUNKING.equalsIgnoreCase(transferEncoding.getStringValue())) {
throw new BallerinaConnectorException("Unsupported configuration found for Transfer-Encoding : " + transferEncoding.getStringValue());
}
if (chunking != null) {
ChunkConfig chunkConfig = getChunkConfig(chunking.getStringValue());
listenerConfiguration.setChunkConfig(chunkConfig);
} else {
listenerConfiguration.setChunkConfig(ChunkConfig.AUTO);
}
if (keepAliveAttrVal != null) {
KeepAliveConfig keepAliveConfig = getKeepAliveConfig(keepAliveAttrVal.getStringValue());
listenerConfiguration.setKeepAliveConfig(keepAliveConfig);
} else {
listenerConfiguration.setKeepAliveConfig(KeepAliveConfig.AUTO);
}
RequestSizeValidationConfig requestSizeValidationConfig = listenerConfiguration.getRequestSizeValidationConfig();
if (maxUriLength != null) {
if (maxUriLength.getIntValue() > 0) {
requestSizeValidationConfig.setMaxUriLength(Math.toIntExact(maxUriLength.getIntValue()));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxUriLength : " + maxUriLength.getIntValue());
}
}
if (maxHeaderSize != null) {
if (maxHeaderSize.getIntValue() > 0) {
requestSizeValidationConfig.setMaxHeaderSize(Math.toIntExact(maxHeaderSize.getIntValue()));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxHeaderSize : " + maxHeaderSize.getIntValue());
}
}
if (maxEntityBodySize != null) {
if (maxEntityBodySize.getIntValue() > 0) {
requestSizeValidationConfig.setMaxEntityBodySize(Math.toIntExact(maxEntityBodySize.getIntValue()));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxEntityBodySize : " + maxEntityBodySize.getIntValue());
}
}
if (versionAttrVal != null) {
listenerConfiguration.setVersion(versionAttrVal.getStringValue());
}
listenerConfiguration.setId(getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
listenerConfSet.add(listenerConfiguration);
}
}
use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class HTTPServicesRegistry method registerService.
/**
* Register a service into the map.
*
* @param service requested serviceInfo to be registered.
*/
public void registerService(Service service) {
String accessLogConfig = HttpConnectionManager.getInstance().getHttpAccessLoggerConfig();
if (accessLogConfig != null) {
try {
((BLogManager) BLogManager.getLogManager()).setHttpAccessLogHandler(accessLogConfig);
} catch (IOException e) {
throw new BallerinaConnectorException("Invalid file path: " + accessLogConfig, e);
}
}
HttpService httpService = HttpService.buildHttpService(service);
// TODO check with new method
// HttpUtil.populateKeepAliveAndCompressionStatus(service, annotation);
// TODO: Add websocket services to the service registry when service creation get available.
servicesInfoMap.put(httpService.getBasePath(), httpService);
logger.info("Service deployed : " + service.getName() + " with context " + httpService.getBasePath());
// basePath will get cached after registering service
sortedServiceURIs.add(httpService.getBasePath());
sortedServiceURIs.sort((basePath1, basePath2) -> basePath2.length() - basePath1.length());
// If WebSocket upgrade path is available, then register the name of the WebSocket service.
Struct websocketConfig = httpService.getWebSocketUpgradeConfig();
if (websocketConfig != null) {
registerWebSocketUpgradePath(WebSocketUtil.getProgramFile(httpService.getBallerinaService().getResources()[0]), websocketConfig, httpService.getBasePath());
}
}
use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class HttpConnectionManager method createHttpServerConnector.
public ServerConnector createHttpServerConnector(ListenerConfiguration listenerConfig) {
String listenerInterface = listenerConfig.getHost() + ":" + listenerConfig.getPort();
HttpServerConnectorContext httpServerConnectorContext = serverConnectorPool.get(listenerInterface);
if (httpServerConnectorContext != null) {
if (checkForConflicts(listenerConfig, httpServerConnectorContext)) {
throw new BallerinaConnectorException("Conflicting configuration detected for listener " + "configuration id " + listenerConfig.getId());
}
httpServerConnectorContext.incrementReferenceCount();
return httpServerConnectorContext.getServerConnector();
}
if (isHTTPTraceLoggerEnabled()) {
listenerConfig.setHttpTraceLogEnabled(true);
}
serverBootstrapConfiguration = HTTPConnectorUtil.getServerBootstrapConfiguration(trpConfig.getTransportProperties());
ServerConnector serverConnector = httpConnectorFactory.createServerConnector(serverBootstrapConfiguration, listenerConfig);
httpServerConnectorContext = new HttpServerConnectorContext(serverConnector, listenerConfig);
serverConnectorPool.put(serverConnector.getConnectorID(), httpServerConnectorContext);
httpServerConnectorContext.incrementReferenceCount();
addStartupDelayedHTTPServerConnector(listenerInterface, serverConnector);
return serverConnector;
}
use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class WebSubDispatcher method findResource.
/**
* This method finds the matching resource for the incoming request.
*
* @param servicesRegistry the WebSubServicesRegistry including registered WebSub Services
* @param httpCarbonMessage incoming message.
* @return matching resource.
*/
static HttpResource findResource(WebSubServicesRegistry servicesRegistry, HTTPCarbonMessage httpCarbonMessage) {
HttpResource resource = null;
String protocol = (String) httpCarbonMessage.getProperty(HttpConstants.PROTOCOL);
if (protocol == null) {
throw new BallerinaConnectorException("protocol not defined in the incoming request");
}
try {
HttpService service = HttpDispatcher.findService(servicesRegistry, httpCarbonMessage);
if (service == null) {
throw new BallerinaConnectorException("no service found to handle the service request");
// Finer details of the errors are thrown from the dispatcher itself, ideally we shouldn't get here.
}
resource = WebSubResourceDispatcher.findResource(service, httpCarbonMessage);
} catch (Throwable throwable) {
handleError(httpCarbonMessage, throwable);
}
return resource;
}
use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class Start method execute.
@Override
public void execute(Context context) {
HttpWsConnectorFactory connectorFactory = HttpUtil.createHttpWsConnectionFactory();
Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
Struct clientEndpointConfig = clientEndpoint.getStructField(HttpConstants.CLIENT_ENDPOINT_CONFIG);
Object configs = clientEndpointConfig.getNativeData(WebSocketConstants.CLIENT_CONNECTOR_CONFIGS);
if (configs == null || !(configs instanceof WsClientConnectorConfig)) {
throw new BallerinaConnectorException("Initialize the service before starting it");
}
WebSocketClientConnector clientConnector = connectorFactory.createWsClientConnector((WsClientConnectorConfig) configs);
WebSocketClientConnectorListener clientConnectorListener = new WebSocketClientConnectorListener();
Object serviceConfig = clientEndpointConfig.getNativeData(WebSocketConstants.CLIENT_SERVICE_CONFIG);
if (serviceConfig == null || !(serviceConfig instanceof WebSocketService)) {
throw new BallerinaConnectorException("Initialize the service before starting it");
}
WebSocketService wsService = (WebSocketService) serviceConfig;
HandshakeFuture handshakeFuture = clientConnector.connect(clientConnectorListener);
handshakeFuture.setHandshakeListener(new WsHandshakeListener(context, wsService, clientConnectorListener));
context.setReturnValues();
}
Aggregations