private void initTargetChannelProperties(SenderConfiguration senderConfiguration) { this.httpVersion = senderConfiguration.getHttpVersion(); this.chunkConfig = senderConfiguration.getChunkingConfig(); this.socketIdleTimeout = senderConfiguration.getSocketIdleTimeout(Constants.ENDPOINT_TIMEOUT); this.sslConfig = senderConfiguration.getClientSSLConfig(); this.keepAliveConfig = senderConfiguration.getKeepAliveConfig(); this.forwardedExtensionConfig = senderConfiguration.getForwardedExtensionConfig(); }
private boolean getMetricsStatus() { boolean statStatus = false; Set<TransportProperty> transportProperties = ConfigurationBuilder.getInstance().getConfiguration().getTransportProperties(); for (TransportProperty property : transportProperties) { if (property.getName().equalsIgnoreCase("latency.metrics.enabled")) { statStatus = (Boolean) property.getValue(); } } return statStatus; }
public SSLConfig getListenerSSLConfig() { if (scheme == null || !scheme.equalsIgnoreCase(HTTPS_SCHEME)) { return null; } return getSSLConfigForListener(); }
private TransportsConfiguration buildDefaultTransportConfig() { TransportsConfiguration transportsConfiguration = new TransportsConfiguration(); SenderConfiguration httpSender = new SenderConfiguration("http-sender"); SenderConfiguration httpsSender = new SenderConfiguration("https-sender"); httpsSender.setScheme("https"); TransportProperty latencyMetrics = new TransportProperty(); latencyMetrics.setName("latency.metrics.enabled"); latencyMetrics.setValue(true); TransportProperty serverSocketTimeout = new TransportProperty(); serverSocketTimeout.setName("server.bootstrap.socket.timeout"); serverSocketTimeout.setValue(60); TransportProperty clientSocketTimeout = new TransportProperty(); clientSocketTimeout.setName("client.bootstrap.socket.timeout"); clientSocketTimeout.setValue(60); Set<SenderConfiguration> senderConfigurationSet = new HashSet<>(); senderConfigurationSet.add(httpSender); senderConfigurationSet.add(httpsSender); transportsConfiguration.setSenderConfigurations(senderConfigurationSet); Set<TransportProperty> transportPropertySet = new HashSet<>(); transportPropertySet.add(latencyMetrics); transportPropertySet.add(serverSocketTimeout); transportPropertySet.add(clientSocketTimeout); transportsConfiguration.setTransportProperties(transportPropertySet); return transportsConfiguration; }
/** * @deprecated * @return the default transport configuration. */ @Deprecated public static TransportsConfiguration getDefault() { TransportsConfiguration defaultConfig = new TransportsConfiguration(); ListenerConfiguration listenerConfiguration = ListenerConfiguration.getDefault(); HashSet<ListenerConfiguration> listenerConfigurations = new HashSet<>(); listenerConfigurations.add(listenerConfiguration); defaultConfig.setListenerConfigurations(listenerConfigurations); SenderConfiguration senderConfiguration = SenderConfiguration.getDefault(); HashSet<SenderConfiguration> senderConfigurations = new HashSet<>(); senderConfigurations.add(senderConfiguration); defaultConfig.setSenderConfigurations(senderConfigurations); HashSet<TransportProperty> transportProperties = new HashSet<>(); defaultConfig.setTransportProperties(transportProperties); return defaultConfig; }
public TransportsConfiguration () { ListenerConfiguration listenerConfiguration = new ListenerConfiguration(); listenerConfigurations = new HashSet<>(); listenerConfigurations.add(listenerConfiguration); SenderConfiguration senderConfiguration = new SenderConfiguration(); senderConfigurations = new HashSet<>(); senderConfigurations.add(senderConfiguration); }
/** * @deprecated * @return the default listener configuration. */ @Deprecated public static ListenerConfiguration getDefault() { ListenerConfiguration defaultConfig; defaultConfig = new ListenerConfiguration(DEFAULT_KEY, "0.0.0.0", 8080); return defaultConfig; } private String id = DEFAULT_KEY;
/** * @deprecated * @return the default sender configuration. */ @Deprecated public static SenderConfiguration getDefault() { SenderConfiguration defaultConfig; defaultConfig = new SenderConfiguration(DEFAULT_KEY); return defaultConfig; }
private boolean checkForConflicts(ListenerConfiguration listenerConfiguration, HttpServerConnectorContext context) { if (context == null) { return false; } if (listenerConfiguration.getScheme().equalsIgnoreCase("https")) { ListenerConfiguration config = context.getListenerConfiguration(); if (!listenerConfiguration.getKeyStoreFile().equals(config.getKeyStoreFile()) || !listenerConfiguration.getKeyStorePass().equals(config.getKeyStorePass())) { return true; } } return false; }
private void configureProxyServer(ChannelPipeline clientPipeline) { if (proxyServerConfiguration != null && sslConfig != null) { if (proxyServerConfiguration.getProxyUsername() != null && proxyServerConfiguration.getProxyPassword() != null) { clientPipeline.addLast(Constants.PROXY_HANDLER, new HttpProxyHandler(proxyServerConfiguration.getInetSocketAddress(), proxyServerConfiguration.getProxyUsername(), proxyServerConfiguration.getProxyPassword())); } else { clientPipeline.addLast(Constants.PROXY_HANDLER, new HttpProxyHandler(proxyServerConfiguration.getInetSocketAddress())); } } }
private void setProxyAuthorizationHeader(HttpCarbonMessage httpOutboundRequest) { ByteBuf authz = Unpooled.copiedBuffer( senderConfiguration.getProxyServerConfiguration().getProxyUsername() + COLON + senderConfiguration.getProxyServerConfiguration().getProxyPassword(), CharsetUtil.UTF_8); ByteBuf authzBase64 = Base64.encode(authz, false); CharSequence authorization = new AsciiString("Basic " + authzBase64.toString(CharsetUtil.US_ASCII)); httpOutboundRequest.setHeader(HttpHeaderNames.PROXY_AUTHORIZATION.toString(), authorization); authz.release(); authzBase64.release(); } }
private HttpConnectionManager() { trpConfig = buildDefaultTransportConfig(); serverBootstrapConfiguration = HttpConnectorUtil .getServerBootstrapConfiguration(trpConfig.getTransportProperties()); }
/** * @deprecated * @return the default transport property. */ @Deprecated public static TransportProperty getDefault() { return new TransportProperty(); }
/** * Get the Environment {@code TransportsConfiguration} * <p> * Location of the configuration file should be defined in the environment variable 'transports.netty.conf'. * If environment variable is not specified, return the default configuration * * @return TransportsConfiguration defined in the environment */ public TransportsConfiguration getConfiguration() { String nettyTransportsConfigFile = System.getProperty(NETTY_TRANSPORT_CONF, "conf" + File.separator + "transports" + File.separator + "netty-transports.yml"); return getConfiguration(nettyTransportsConfigFile); }
public static void setDefaultTrustStore(SslConfiguration sslConfiguration) { sslConfiguration.setTrustStoreFile(String.valueOf( Paths.get(System.getProperty("ballerina.home"), "bre", "security", "ballerinaTruststore.p12"))); sslConfiguration.setTrustStorePass("ballerina"); }
/** * Extract sender configuration from transport configuration. * * @param transportsConfiguration {@link TransportsConfiguration} which sender configurations should be extracted. * @param scheme scheme of the transport. * @return extracted {@link SenderConfiguration}. */ public static SenderConfiguration getSenderConfiguration(TransportsConfiguration transportsConfiguration, String scheme) { Map<String, SenderConfiguration> senderConfigurations = transportsConfiguration.getSenderConfigurations().stream().collect(Collectors .toMap(senderConf -> senderConf.getScheme().toLowerCase(Locale.getDefault()), config -> config)); return Constants.HTTPS_SCHEME.equals(scheme) ? senderConfigurations.get(Constants.HTTPS_SCHEME) : senderConfigurations.get(Constants.HTTP_SCHEME); }
@Override public HttpClientConnector createHttpClientConnector( Map<String, Object> transportProperties, SenderConfiguration senderConfiguration) { BootstrapConfiguration bootstrapConfig = new BootstrapConfiguration(transportProperties); ConnectionManager connectionManager = new ConnectionManager(senderConfiguration.getPoolConfiguration()); return new DefaultHttpClientConnector(connectionManager, senderConfiguration, bootstrapConfig, clientGroup); }
public SSLConfig getClientSSLConfig() { if (scheme == null || !scheme.equalsIgnoreCase(HTTPS_SCHEME)) { return null; } return getSSLConfigForSender(); }
/** * Parses & creates the object model for the Netty transport yaml configuration file. * * @return TransportsConfiguration */ public static TransportsConfiguration build() { String nettyTransportsConfigFile = System.getProperty(NETTY_TRANSPORT_CONF, "conf" + File.separator + "transports" + File.separator + "netty-transports.yml"); return build(nettyTransportsConfigFile); }
public DefaultHttpClientConnector(ConnectionManager connectionManager, SenderConfiguration senderConfiguration, BootstrapConfiguration bootstrapConfig, EventLoopGroup clientEventGroup) { this.connectionManager = connectionManager; this.http2ConnectionManager = connectionManager.getHttp2ConnectionManager(); this.senderConfiguration = senderConfiguration; initTargetChannelProperties(senderConfiguration); if (Float.valueOf(senderConfiguration.getHttpVersion()) == Constants.HTTP_2_0) { isHttp2 = true; } this.clientEventGroup = clientEventGroup; this.bootstrapConfig = bootstrapConfig; }