Search in sources :

Example 46 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class ResponseNativeFunctionNegativeTest method testRemoveHeaderNegative.

@Test
@SuppressWarnings("unchecked")
public void testRemoveHeaderNegative() {
    BStruct outResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inRespStruct);
    BStruct entity = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, entityStruct);
    String range = "Range";
    HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add("Expect", "100-continue");
    entity.addNativeData(ENTITY_HEADERS, httpHeaders);
    outResponse.addNativeData(MESSAGE_ENTITY, entity);
    BString key = new BString(range);
    BValue[] inputArg = { outResponse, key };
    BValue[] returnVals = BRunUtil.invoke(result, "testRemoveHeader", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVals[0] instanceof BStruct);
    BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
    HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    Assert.assertNull(returnHeaders.get("range"));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 47 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class ResponseNativeFunctionNegativeTest method testRemoveAllHeadersNegative.

@Test
@SuppressWarnings("unchecked")
public void testRemoveAllHeadersNegative() {
    BStruct outResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inRespStruct);
    BValue[] inputArg = { outResponse };
    BValue[] returnVals = BRunUtil.invoke(result, "testRemoveAllHeaders", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVals[0] instanceof BStruct);
    BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
    HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    Assert.assertNull(returnHeaders.get("Expect"));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 48 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class ResponseNativeFunctionSuccessTest method testSetHeader.

@Test
@SuppressWarnings("unchecked")
public void testSetHeader() {
    String range = "Range";
    String rangeValue = "bytes=500-999; a=4";
    BString key = new BString(range);
    BString value = new BString(rangeValue);
    BValue[] inputArg = { key, value };
    BValue[] returnVals = BRunUtil.invoke(result, "testSetHeader", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVals[0] instanceof BStruct);
    BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
    HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    Assert.assertEquals(returnHeaders.get(range), rangeValue);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 49 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class ResponseNativeFunctionSuccessTest method testAddHeader.

@Test
@SuppressWarnings("unchecked")
public void testAddHeader() {
    BStruct outResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inResStruct);
    String headerName = "header1";
    String headerValue = "abc, xyz";
    BString key = new BString(headerName);
    BString value = new BString(headerValue);
    BValue[] inputArg = { outResponse, key, value };
    BValue[] returnVals = BRunUtil.invoke(result, "testAddHeader", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVals[0] instanceof BStruct);
    BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
    HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    Assert.assertEquals(returnHeaders.get(headerName), headerValue);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 50 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class MessageUtils method generateHTTPMessage.

public static HTTPTestRequest generateHTTPMessage(String path, String method, List<Header> headers, String payload) {
    HTTPTestRequest carbonMessage = getHttpTestRequest(path, method);
    HttpHeaders httpHeaders = carbonMessage.getHeaders();
    if (headers != null) {
        for (Header header : headers) {
            httpHeaders.set(header.getName(), header.getValue());
        }
    }
    if (payload != null) {
        carbonMessage.addHttpContent(new DefaultLastHttpContent(Unpooled.wrappedBuffer(payload.getBytes())));
    } else {
        carbonMessage.addHttpContent(new DefaultLastHttpContent());
    }
    return carbonMessage;
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) Header(org.wso2.carbon.messaging.Header) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent)

Aggregations

HttpHeaders (io.netty.handler.codec.http.HttpHeaders)286 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)149 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)83 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)73 Test (org.junit.Test)68 Test (org.junit.jupiter.api.Test)57 Test (org.testng.annotations.Test)51 HttpRequest (io.netty.handler.codec.http.HttpRequest)43 HttpResponse (io.netty.handler.codec.http.HttpResponse)40 AsciiString (io.netty.util.AsciiString)29 ByteBuf (io.netty.buffer.ByteBuf)27 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)27 BStruct (org.ballerinalang.model.values.BStruct)26 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)22 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)22 HttpServletResponse (javax.servlet.http.HttpServletResponse)20 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)19 Cookie (io.netty.handler.codec.http.cookie.Cookie)19 BValue (org.ballerinalang.model.values.BValue)19 ChannelPromise (io.netty.channel.ChannelPromise)18