Search in sources :

Example 31 with BallerinaConnectorException

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;
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

Example 32 with BallerinaConnectorException

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;
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) HashMap(java.util.HashMap) BString(org.ballerinalang.model.values.BString)

Aggregations

BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)32 Struct (org.ballerinalang.connector.api.Struct)9 BString (org.ballerinalang.model.values.BString)9 BStruct (org.ballerinalang.model.values.BStruct)9 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)7 HashMap (java.util.HashMap)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 URITemplateException (org.ballerinalang.net.uri.URITemplateException)4 BValue (org.ballerinalang.model.values.BValue)3 HttpResource (org.ballerinalang.net.http.HttpResource)3 URI (java.net.URI)2 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)2 AnnAttrValue (org.ballerinalang.connector.api.AnnAttrValue)2 BLangConnectorSPIUtil (org.ballerinalang.connector.api.BLangConnectorSPIUtil)2 Executor (org.ballerinalang.connector.api.Executor)2 ParamDetail (org.ballerinalang.connector.api.ParamDetail)2 Resource (org.ballerinalang.connector.api.Resource)2