use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class InitEndpoint method getListerConfig.
private ListenerConfiguration getListerConfig(Struct endpointConfig) {
String host = endpointConfig.getStringField(HttpConstants.ENDPOINT_CONFIG_HOST);
long port = endpointConfig.getIntField(HttpConstants.ENDPOINT_CONFIG_PORT);
String keepAlive = endpointConfig.getEnumField(HttpConstants.ENDPOINT_CONFIG_KEEP_ALIVE);
String transferEncoding = endpointConfig.getEnumField(HttpConstants.ENDPOINT_CONFIG_TRANSFER_ENCODING);
String chunking = endpointConfig.getEnumField(HttpConstants.ENDPOINT_CONFIG_CHUNKING);
Struct sslConfig = endpointConfig.getStructField(HttpConstants.ENDPOINT_CONFIG_SECURE_SOCKET);
String httpVersion = endpointConfig.getStringField(HttpConstants.ENDPOINT_CONFIG_VERSION);
Struct requestLimits = endpointConfig.getStructField(HttpConstants.ENDPOINT_REQUEST_LIMITS);
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
if (host == null || host.isEmpty()) {
listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
} else {
listenerConfiguration.setHost(host);
}
listenerConfiguration.setPort(Math.toIntExact(port));
listenerConfiguration.setKeepAliveConfig(HttpUtil.getKeepAliveConfig(keepAlive));
// chunking. Once we start supporting gzip, deflate, etc, we need to parse down the config.
if ((!transferEncoding.isEmpty()) && !HttpConstants.ANN_CONFIG_ATTR_CHUNKING.equalsIgnoreCase(transferEncoding)) {
throw new BallerinaConnectorException("Unsupported configuration found for Transfer-Encoding : " + transferEncoding);
}
listenerConfiguration.setChunkConfig(HttpUtil.getChunkConfig(chunking));
// Set Request validation limits.
if (requestLimits != null) {
setRequestSizeValidationConfig(requestLimits, listenerConfiguration);
}
// Set HTTP version
if (httpVersion != null) {
listenerConfiguration.setVersion(httpVersion);
}
if (sslConfig != null) {
return setSslConfig(sslConfig, listenerConfiguration);
}
listenerConfiguration.setServerHeader(getServerName());
return listenerConfiguration;
}
use of org.ballerinalang.connector.api.BallerinaConnectorException in project ballerina by ballerina-lang.
the class URIUtil method extractMatrixParams.
public static String extractMatrixParams(String path, Map<String, Map<String, String>> matrixParams) {
if (path.startsWith("/")) {
path = path.substring(1);
}
String[] pathSplits = path.split("\\?");
String[] pathSegments = pathSplits[0].split("/");
String pathToMatrixParam = "";
for (String pathSegment : pathSegments) {
String[] splitPathSegment = pathSegment.split(";");
pathToMatrixParam = pathToMatrixParam.concat("/" + splitPathSegment[0]);
Map<String, String> segmentMatrixParams = new HashMap<>();
for (int i = 1; i < splitPathSegment.length; i++) {
String[] splitMatrixParam = splitPathSegment[i].split("=");
if (splitMatrixParam.length != 2) {
throw new BallerinaConnectorException(String.format("Found non-matrix parameter '%s' in path '%s'", splitPathSegment[i], path));
}
segmentMatrixParams.put(splitMatrixParam[0], splitMatrixParam[1]);
}
matrixParams.put(pathToMatrixParam, segmentMatrixParams);
}
for (int i = 1; i < pathSplits.length; i++) {
pathToMatrixParam = pathToMatrixParam.concat("?").concat(pathSplits[i]);
}
return pathToMatrixParam;
}
Aggregations