Search in sources :

Example 1 with HttpWsConnectorFactory

use of org.wso2.transport.http.netty.contract.HttpWsConnectorFactory 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();
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) WsClientConnectorConfig(org.wso2.transport.http.netty.contract.websocket.WsClientConnectorConfig) HandshakeFuture(org.wso2.transport.http.netty.contract.websocket.HandshakeFuture) WebSocketClientConnector(org.wso2.transport.http.netty.contract.websocket.WebSocketClientConnector) WebSocketClientConnectorListener(org.ballerinalang.net.http.WebSocketClientConnectorListener) WebSocketService(org.ballerinalang.net.http.WebSocketService) HttpWsConnectorFactory(org.wso2.transport.http.netty.contract.HttpWsConnectorFactory) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

Example 2 with HttpWsConnectorFactory

use of org.wso2.transport.http.netty.contract.HttpWsConnectorFactory in project wso2-synapse by wso2.

the class Axis2HttpTransportSender method init.

@Override
public void init(ConfigurationContext configurationContext, TransportOutDescription transportOutDescription) throws AxisFault {
    httpWsConnectorFactory = new DefaultHttpWsConnectorFactory();
    connectionManager = HttpUtils.getConnectionManager();
    bootstrapConfiguration = new BootstrapConfiguration(new HashMap<>());
    targetConfiguration = new TargetConfiguration(configurationContext, transportOutDescription);
    targetConfiguration.build();
}
Also used : TargetConfiguration(org.apache.synapse.transport.netty.config.TargetConfiguration) DefaultHttpWsConnectorFactory(org.wso2.transport.http.netty.contractimpl.DefaultHttpWsConnectorFactory) HashMap(java.util.HashMap) BootstrapConfiguration(org.wso2.transport.http.netty.contractimpl.sender.channel.BootstrapConfiguration)

Example 3 with HttpWsConnectorFactory

use of org.wso2.transport.http.netty.contract.HttpWsConnectorFactory in project wso2-synapse by wso2.

the class TargetRequestHandler method createHttpClient.

public static HttpClientConnector createHttpClient(URL url, MessageContext msgContext, HttpWsConnectorFactory httpWsConnectorFactory, ConnectionManager connectionManager, BootstrapConfiguration bootstrapConfiguration, TargetConfiguration targetConfiguration) throws AxisFault {
    try {
        SenderConfiguration senderConfiguration = new SenderConfiguration();
        populateSenderConfigurations(msgContext, senderConfiguration, targetConfiguration, url);
        return httpWsConnectorFactory.createHttpClientConnector(bootstrapConfiguration, senderConfiguration, connectionManager);
    } catch (Exception ex) {
        throw new AxisFault("Error while creating the HTTP Client Connector. ", ex);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) SenderConfiguration(org.wso2.transport.http.netty.contract.config.SenderConfiguration) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 4 with HttpWsConnectorFactory

use of org.wso2.transport.http.netty.contract.HttpWsConnectorFactory in project wso2-synapse by wso2.

the class Axis2HttpTransportListener method init.

@Override
public void init(ConfigurationContext configurationContext, TransportInDescription transportInDescription) throws AxisFault {
    Scheme scheme = initScheme();
    this.transportInDescription = transportInDescription;
    // build source configuration
    sourceConfiguration = new SourceConfiguration(configurationContext, transportInDescription, scheme, messagingHandlers);
    sourceConfiguration.build();
    sourceConfiguration.getHttpGetRequestProcessor().init(sourceConfiguration.getConfigurationContext());
    ListenerConfiguration listenerConfiguration = initListenerConfiguration();
    httpWsConnectorFactory = new DefaultHttpWsConnectorFactory();
    this.serverConnector = httpWsConnectorFactory.createServerConnector(new ServerBootstrapConfiguration(new HashMap<>()), listenerConfiguration);
}
Also used : Scheme(org.apache.synapse.transport.http.conn.Scheme) DefaultHttpWsConnectorFactory(org.wso2.transport.http.netty.contractimpl.DefaultHttpWsConnectorFactory) ListenerConfiguration(org.wso2.transport.http.netty.contract.config.ListenerConfiguration) SourceConfiguration(org.apache.synapse.transport.netty.config.SourceConfiguration) ServerBootstrapConfiguration(org.wso2.transport.http.netty.contract.config.ServerBootstrapConfiguration)

Example 5 with HttpWsConnectorFactory

use of org.wso2.transport.http.netty.contract.HttpWsConnectorFactory in project wso2-synapse by wso2.

the class Axis2HttpTransportSender method sendRequestToBackendService.

/**
 * Sends an outbound request to the backend service.
 *
 * @param msgCtx axis2 message context
 * @param url    request URL of the backend service
 * @throws IOException if something goes wrong when sending the outbound request to the backend service
 */
private void sendRequestToBackendService(MessageContext msgCtx, URL url) throws IOException {
    HttpCarbonMessage outboundRequestMsg = TargetRequestHandler.createOutboundRequestMsg(url, msgCtx, targetConfiguration);
    HttpClientConnector clientConnector = TargetRequestHandler.createHttpClient(url, msgCtx, httpWsConnectorFactory, connectionManager, bootstrapConfiguration, targetConfiguration);
    TargetRequestHandler.sendRequest(clientConnector, outboundRequestMsg, msgCtx, targetConfiguration);
}
Also used : HttpCarbonMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage) HttpClientConnector(org.wso2.transport.http.netty.contract.HttpClientConnector)

Aggregations

DefaultHttpWsConnectorFactory (org.wso2.transport.http.netty.contractimpl.DefaultHttpWsConnectorFactory)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 AxisFault (org.apache.axis2.AxisFault)1 Scheme (org.apache.synapse.transport.http.conn.Scheme)1 SourceConfiguration (org.apache.synapse.transport.netty.config.SourceConfiguration)1 TargetConfiguration (org.apache.synapse.transport.netty.config.TargetConfiguration)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1 Struct (org.ballerinalang.connector.api.Struct)1 BStruct (org.ballerinalang.model.values.BStruct)1 WebSocketClientConnectorListener (org.ballerinalang.net.http.WebSocketClientConnectorListener)1 WebSocketService (org.ballerinalang.net.http.WebSocketService)1 HttpClientConnector (org.wso2.transport.http.netty.contract.HttpClientConnector)1 HttpWsConnectorFactory (org.wso2.transport.http.netty.contract.HttpWsConnectorFactory)1 ListenerConfiguration (org.wso2.transport.http.netty.contract.config.ListenerConfiguration)1 SenderConfiguration (org.wso2.transport.http.netty.contract.config.SenderConfiguration)1 ServerBootstrapConfiguration (org.wso2.transport.http.netty.contract.config.ServerBootstrapConfiguration)1 HandshakeFuture (org.wso2.transport.http.netty.contract.websocket.HandshakeFuture)1 WebSocketClientConnector (org.wso2.transport.http.netty.contract.websocket.WebSocketClientConnector)1