use of org.ballerinalang.connector.api.AnnAttrValue 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.AnnAttrValue in project ballerina by ballerina-lang.
the class HttpUtil method extractHttpsConfig.
private static void extractHttpsConfig(Annotation configInfo, Set<ListenerConfiguration> listenerConfSet) {
// Retrieve secure port from either http of ws configuration annotation.
AnnAttrValue httpsPortAttrVal;
if (configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTPS_PORT) == null) {
httpsPortAttrVal = configInfo.getAnnAttrValue(WebSocketConstants.ANN_CONFIG_ATTR_WSS_PORT);
} else {
httpsPortAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTPS_PORT);
}
AnnAttrValue keyStoreFileAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEY_STORE_FILE);
AnnAttrValue keyStorePasswordAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEY_STORE_PASS);
AnnAttrValue certPasswordAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CERT_PASS);
AnnAttrValue trustStoreFileAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRUST_STORE_FILE);
AnnAttrValue trustStorePasswordAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRUST_STORE_PASS);
AnnAttrValue sslVerifyClientAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_SSL_VERIFY_CLIENT);
AnnAttrValue sslEnabledProtocolsAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_SSL_ENABLED_PROTOCOLS);
AnnAttrValue ciphersAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CIPHERS);
AnnAttrValue sslProtocolAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_SSL_PROTOCOL);
AnnAttrValue hostAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HOST);
AnnAttrValue certificateValidationEnabledAttrValue = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_VALIDATE_CERT_ENABLED);
AnnAttrValue cacheSizeAttrValue = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CACHE_SIZE);
AnnAttrValue cacheValidityPeriodAttrValue = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CACHE_VALIDITY_PERIOD);
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
if (httpsPortAttrVal != null && httpsPortAttrVal.getIntValue() > 0) {
listenerConfiguration.setPort(Math.toIntExact(httpsPortAttrVal.getIntValue()));
listenerConfiguration.setScheme(HttpConstants.PROTOCOL_HTTPS);
if (hostAttrVal != null && hostAttrVal.getStringValue() != null) {
listenerConfiguration.setHost(hostAttrVal.getStringValue());
} else {
listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
}
if (keyStoreFileAttrVal == null || keyStoreFileAttrVal.getStringValue() == null) {
// TODO get from language pack, and add location
throw new BallerinaConnectorException("Keystore location must be provided for secure connection");
}
if (keyStorePasswordAttrVal == null || keyStorePasswordAttrVal.getStringValue() == null) {
// TODO get from language pack, and add location
throw new BallerinaConnectorException("Keystore password value must be provided for secure connection");
}
if (certPasswordAttrVal == null || certPasswordAttrVal.getStringValue() == null) {
// TODO get from language pack, and add location
throw new BallerinaConnectorException("Certificate password value must be provided for secure connection");
}
if ((trustStoreFileAttrVal == null || trustStoreFileAttrVal.getStringValue() == null) && sslVerifyClientAttrVal != null) {
// TODO get from language pack, and add location
throw new BallerinaException("Truststore location must be provided to enable Mutual SSL");
}
if ((trustStorePasswordAttrVal == null || trustStorePasswordAttrVal.getStringValue() == null) && sslVerifyClientAttrVal != null) {
// TODO get from language pack, and add location
throw new BallerinaException("Truststore password value must be provided to enable Mutual SSL");
}
listenerConfiguration.setTLSStoreType(HttpConstants.PKCS_STORE_TYPE);
listenerConfiguration.setKeyStoreFile(keyStoreFileAttrVal.getStringValue());
listenerConfiguration.setKeyStorePass(keyStorePasswordAttrVal.getStringValue());
listenerConfiguration.setCertPass(certPasswordAttrVal.getStringValue());
if (sslVerifyClientAttrVal != null) {
listenerConfiguration.setVerifyClient(sslVerifyClientAttrVal.getStringValue());
}
if (trustStoreFileAttrVal != null) {
listenerConfiguration.setTrustStoreFile(trustStoreFileAttrVal.getStringValue());
}
if (trustStorePasswordAttrVal != null) {
listenerConfiguration.setTrustStorePass(trustStorePasswordAttrVal.getStringValue());
}
if (certificateValidationEnabledAttrValue != null && certificateValidationEnabledAttrValue.getBooleanValue()) {
listenerConfiguration.setValidateCertEnabled(certificateValidationEnabledAttrValue.getBooleanValue());
if (cacheSizeAttrValue != null) {
listenerConfiguration.setCacheSize((int) cacheSizeAttrValue.getIntValue());
}
if (cacheValidityPeriodAttrValue != null) {
listenerConfiguration.setCacheValidityPeriod((int) cacheValidityPeriodAttrValue.getIntValue());
}
}
List<Parameter> serverParams = new ArrayList<>();
Parameter serverCiphers;
if (sslEnabledProtocolsAttrVal != null && sslEnabledProtocolsAttrVal.getStringValue() != null) {
serverCiphers = new Parameter(HttpConstants.ANN_CONFIG_ATTR_SSL_ENABLED_PROTOCOLS, sslEnabledProtocolsAttrVal.getStringValue());
serverParams.add(serverCiphers);
}
if (ciphersAttrVal != null && ciphersAttrVal.getStringValue() != null) {
serverCiphers = new Parameter(HttpConstants.ANN_CONFIG_ATTR_CIPHERS, ciphersAttrVal.getStringValue());
serverParams.add(serverCiphers);
}
if (!serverParams.isEmpty()) {
listenerConfiguration.setParameters(serverParams);
}
if (sslProtocolAttrVal != null) {
listenerConfiguration.setSSLProtocol(sslProtocolAttrVal.getStringValue());
}
listenerConfiguration.setId(getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
listenerConfSet.add(listenerConfiguration);
}
}
use of org.ballerinalang.connector.api.AnnAttrValue in project ballerina by ballerina-lang.
the class CorsPopulator method populateAndGetCorsHeaders.
private static CorsHeaders populateAndGetCorsHeaders(Annotation configAnnotInfo) {
CorsHeaders corsHeaders = new CorsHeaders();
if (configAnnotInfo == null) {
return corsHeaders;
}
AnnAttrValue allowOriginAttr = configAnnotInfo.getAnnAttrValue(HttpConstants.ALLOW_ORIGIN);
if (allowOriginAttr != null) {
corsHeaders.setAllowOrigins(DispatcherUtil.getValueList(allowOriginAttr, null));
}
AnnAttrValue allowCredentials = configAnnotInfo.getAnnAttrValue(HttpConstants.ALLOW_CREDENTIALS);
if (allowCredentials != null) {
corsHeaders.setAllowCredentials(allowCredentials.getBooleanValue() ? 1 : 0);
}
AnnAttrValue allowMethodsAttr = configAnnotInfo.getAnnAttrValue(HttpConstants.ALLOW_METHODS);
if (allowMethodsAttr != null) {
corsHeaders.setAllowMethods(DispatcherUtil.getValueList(allowMethodsAttr, null));
}
AnnAttrValue allowHeadersAttr = configAnnotInfo.getAnnAttrValue(HttpConstants.ALLOW_HEADERS);
if (allowHeadersAttr != null) {
corsHeaders.setAllowHeaders(DispatcherUtil.getValueList(allowHeadersAttr, null));
}
AnnAttrValue maxAgeAttr = configAnnotInfo.getAnnAttrValue(HttpConstants.MAX_AGE);
if (maxAgeAttr != null) {
corsHeaders.setMaxAge(maxAgeAttr.getIntValue());
}
AnnAttrValue exposeHeadersAttr = configAnnotInfo.getAnnAttrValue(HttpConstants.EXPOSE_HEADERS);
if (exposeHeadersAttr != null) {
corsHeaders.setExposeHeaders(DispatcherUtil.getValueList(exposeHeadersAttr, null));
}
return corsHeaders;
}
Aggregations