Search in sources :

Example 1 with Http2PushPromise

use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.

the class GetPromisedResponse method execute.

@Override
public void execute(Context context, CallableUnitCallback callback) {
    DataContext dataContext = new DataContext(context, callback);
    BStruct pushPromiseStruct = (BStruct) context.getRefArgument(1);
    Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, null);
    if (http2PushPromise == null) {
        throw new BallerinaException("invalid push promise");
    }
    BStruct bConnector = (BStruct) context.getRefArgument(0);
    HttpClientConnector clientConnector = (HttpClientConnector) bConnector.getNativeData(HttpConstants.HTTP_CLIENT);
    clientConnector.getPushResponse(http2PushPromise).setPushResponseListener(new PushResponseListener(dataContext), http2PushPromise.getPromisedStreamId());
}
Also used : DataContext(org.ballerinalang.net.http.DataContext) BStruct(org.ballerinalang.model.values.BStruct) HttpClientConnector(org.wso2.transport.http.netty.contract.HttpClientConnector) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 2 with Http2PushPromise

use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.

the class Promise method execute.

@Override
public void execute(Context context) {
    BStruct connectionStruct = (BStruct) context.getRefArgument(0);
    HTTPCarbonMessage inboundRequestMsg = HttpUtil.getCarbonMsg(connectionStruct, null);
    HttpUtil.serverConnectionStructCheck(inboundRequestMsg);
    BStruct pushPromiseStruct = (BStruct) context.getRefArgument(1);
    Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, HttpUtil.createHttpPushPromise(pushPromiseStruct));
    HttpResponseFuture outboundRespStatusFuture = HttpUtil.pushPromise(inboundRequestMsg, http2PushPromise);
    BValue[] outboundResponseStatus = handleResponseStatus(context, outboundRespStatusFuture);
    context.setReturnValues(outboundResponseStatus);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BValue(org.ballerinalang.model.values.BValue) HttpResponseFuture(org.wso2.transport.http.netty.contract.HttpResponseFuture)

Example 3 with Http2PushPromise

use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.

the class PushPromisedResponse method execute.

@Override
public void execute(Context context) {
    BStruct connectionStruct = (BStruct) context.getRefArgument(0);
    HTTPCarbonMessage inboundRequestMsg = HttpUtil.getCarbonMsg(connectionStruct, null);
    HttpUtil.serverConnectionStructCheck(inboundRequestMsg);
    BStruct pushPromiseStruct = (BStruct) context.getRefArgument(1);
    Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, null);
    if (http2PushPromise == null) {
        throw new BallerinaException("invalid push promise");
    }
    BStruct outboundResponseStruct = (BStruct) context.getRefArgument(2);
    HTTPCarbonMessage outboundResponseMsg = HttpUtil.getCarbonMsg(outboundResponseStruct, HttpUtil.createHttpCarbonMessage(false));
    HttpUtil.prepareOutboundResponse(context, inboundRequestMsg, outboundResponseMsg, outboundResponseStruct);
    BValue[] outboundResponseStatus = pushResponseRobust(context, inboundRequestMsg, outboundResponseStruct, outboundResponseMsg, http2PushPromise);
    context.setReturnValues(outboundResponseStatus);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BValue(org.ballerinalang.model.values.BValue) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 4 with Http2PushPromise

use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.

the class PushPromisedResponse method pushResponseRobust.

private BValue[] pushResponseRobust(Context context, HTTPCarbonMessage requestMessage, BStruct outboundResponseStruct, HTTPCarbonMessage responseMessage, Http2PushPromise http2PushPromise) {
    BStruct entityStruct = MimeUtil.extractEntity(outboundResponseStruct);
    HttpResponseFuture outboundRespStatusFuture = HttpUtil.pushResponse(requestMessage, responseMessage, http2PushPromise);
    if (entityStruct != null) {
        MessageDataSource outboundMessageSource = EntityBodyHandler.getMessageDataSource(entityStruct);
        serializeMsgDataSource(responseMessage, outboundMessageSource, outboundRespStatusFuture, entityStruct);
    }
    return handleResponseStatus(context, outboundRespStatusFuture);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) MessageDataSource(org.ballerinalang.runtime.message.MessageDataSource) HttpResponseFuture(org.wso2.transport.http.netty.contract.HttpResponseFuture)

Example 5 with Http2PushPromise

use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.

the class GetHeader method execute.

@Override
public void execute(Context context) {
    BStruct pushPromiseStruct = (BStruct) context.getRefArgument(0);
    Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, HttpUtil.createHttpPushPromise(pushPromiseStruct));
    String headerName = context.getStringArgument(0);
    context.setReturnValues(new BString(http2PushPromise.getHeader(headerName)));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString)

Aggregations

Http2PushPromise (org.wso2.transport.http.netty.message.Http2PushPromise)18 BStruct (org.ballerinalang.model.values.BStruct)17 BString (org.ballerinalang.model.values.BString)8 BValue (org.ballerinalang.model.values.BValue)8 Test (org.testng.annotations.Test)6 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)3 HttpClientConnector (org.wso2.transport.http.netty.contract.HttpClientConnector)2 HttpResponseFuture (org.wso2.transport.http.netty.contract.HttpResponseFuture)2 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)2 BBoolean (org.ballerinalang.model.values.BBoolean)1 BStringArray (org.ballerinalang.model.values.BStringArray)1 DataContext (org.ballerinalang.net.http.DataContext)1 MessageDataSource (org.ballerinalang.runtime.message.MessageDataSource)1