Search in sources :

Example 11 with Http2PushPromise

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

the class PushPromiseNativeFunctionTest method testSetHeader.

@Test(description = "Test setHeader function of PushPromise")
public void testSetHeader() {
    BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
    Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
    String headerName = "header1";
    String headerValue = "value1";
    http2PushPromise.addHeader(headerName, headerValue);
    HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
    String targetHeaderValue = "value2";
    BString key = new BString(headerName);
    BString value = new BString(targetHeaderValue);
    BValue[] inputArg = { promise, key, value };
    BValue[] returnVal = BRunUtil.invoke(result, "testSetHeader", inputArg);
    Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVal[0] instanceof BStruct);
    Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
    Assert.assertEquals(retrievedHttp2PushPromise.getHeader(headerName), targetHeaderValue);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 12 with Http2PushPromise

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

the class PushPromiseNativeFunctionTest method testRemoveHeader.

@Test(description = "Test removeHeader function of PushPromise")
public void testRemoveHeader() {
    BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
    Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
    String headerName = "header1";
    String headerValue = "value1";
    http2PushPromise.addHeader(headerName, headerValue);
    HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
    BString key = new BString(headerName);
    BValue[] inputArg = { promise, key };
    BValue[] returnVal = BRunUtil.invoke(result, "testRemoveHeader", inputArg);
    Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVal[0] instanceof BStruct);
    Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
    Assert.assertNull(retrievedHttp2PushPromise.getHeader(headerName));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 13 with Http2PushPromise

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

the class PushPromiseNativeFunctionTest method testRemoveAllHeaders.

@Test(description = "Test removeAllHeaders function of PushPromise")
public void testRemoveAllHeaders() {
    BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
    Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
    String header1Name = "header1";
    String header1Value = "value1";
    http2PushPromise.addHeader(header1Name, header1Value);
    String header2Name = "header2";
    String header2Value = "value2";
    http2PushPromise.addHeader(header2Name, header2Value);
    HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
    BValue[] inputArg = { promise };
    BValue[] returnVal = BRunUtil.invoke(result, "testRemoveAllHeaders", inputArg);
    Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVal[0] instanceof BStruct);
    Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
    Assert.assertNull(retrievedHttp2PushPromise.getHeader(header1Name));
    Assert.assertNull(retrievedHttp2PushPromise.getHeader(header2Name));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 14 with Http2PushPromise

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

the class RejectPromise method execute.

@Override
public void execute(Context context, CallableUnitCallback 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.rejectPushResponse(http2PushPromise);
    // TODO: Implement a listener to see the progress
    context.setReturnValues(new BBoolean(true));
    callback.notifySuccess();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HttpClientConnector(org.wso2.transport.http.netty.contract.HttpClientConnector) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BBoolean(org.ballerinalang.model.values.BBoolean) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 15 with Http2PushPromise

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

the class AddHeader 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);
    String headerValue = context.getStringArgument(1);
    http2PushPromise.addHeader(headerName, headerValue);
    context.setReturnValues();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise)

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