use of org.wso2.transport.http.netty.message.HTTPCarbonMessage 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);
}
use of org.wso2.transport.http.netty.message.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class CreateSessionIfAbsent method execute.
@Override
public void execute(Context context) {
try {
BStruct requestStruct = ((BStruct) context.getRefArgument(0));
// TODO check below line
HTTPCarbonMessage httpCarbonMessage = HttpUtil.getCarbonMsg(requestStruct, HttpUtil.createHttpCarbonMessage(true));
String cookieHeader = httpCarbonMessage.getHeader(HttpConstants.COOKIE_HEADER);
String path = (String) httpCarbonMessage.getProperty(HttpConstants.BASE_PATH);
Session session = (Session) httpCarbonMessage.getProperty(HttpConstants.HTTP_SESSION);
if (cookieHeader != null) {
try {
String sessionId = HttpUtil.getSessionID(cookieHeader);
// return value from cached session
if (session != null && sessionId.equals(session.getId())) {
session = session.setAccessed();
context.setReturnValues(HttpUtil.createSessionStruct(context, session));
return;
}
session = SessionManager.getInstance().getHTTPSession(sessionId);
} catch (NoSuchElementException e) {
// ignore throwable
logger.info("Failed to get session: Incorrect Session cookie");
}
if (session == null) {
session = SessionManager.getInstance().createHTTPSession(path);
} else if (session != null && session.getPath().equals(path)) {
// path validity check
session.setNew(false);
session.setAccessed();
} else {
throw new BallerinaException("Failed to get session: " + path + " is not an allowed path");
}
} else {
// cached session will return of this function is called twice.
if (session != null) {
session = session.setAccessed();
context.setReturnValues(HttpUtil.createSessionStruct(context, session));
return;
}
// create session since request doesn't have a cookie
session = SessionManager.getInstance().createHTTPSession(path);
}
httpCarbonMessage.setProperty(HttpConstants.HTTP_SESSION, session);
httpCarbonMessage.removeHeader(HttpConstants.COOKIE_HEADER);
context.setReturnValues(HttpUtil.createSessionStruct(context, session));
return;
} catch (IllegalStateException e) {
throw new BallerinaException(e.getMessage(), e);
}
}
use of org.wso2.transport.http.netty.message.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningFuncInvFromDiffPkg.
@Test(description = "Test assigning function invocation from different package", enabled = false)
public void testAssigningFuncInvFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/func-inv-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarPkgFunc":8876}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarPkgFunc").asText(), "8876");
}
use of org.wso2.transport.http.netty.message.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningGlobalVarToServiceVarFromDiffPkg.
@Test(description = "Test assigning global variable to service variable from different package", enabled = false)
public void testAssigningGlobalVarToServiceVarFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/assign-to-service-var-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"serviceVarString":"stringval"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("serviceVarString").asText(), "stringval");
}
use of org.wso2.transport.http.netty.message.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningFuncInvFromSamePkg.
@Test(description = "Test assigning function invocation from same package", enabled = false)
public void testAssigningFuncInvFromSamePkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/func-inv-from-same-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarFunc":423277.72343}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarFunc").asText(), "423277.72343");
}
Aggregations