Search in sources :

Example 1 with Session

use of org.ballerinalang.net.http.session.Session in project ballerina by ballerina-lang.

the class SetMaxInactiveInterval method execute.

@Override
public void execute(Context context) throws IllegalFormatException {
    try {
        BStruct sessionStruct = ((BStruct) context.getRefArgument(0));
        int timeInterval = (int) context.getIntArgument(0);
        Session session = (Session) sessionStruct.getNativeData(HttpConstants.HTTP_SESSION);
        if (timeInterval == 0) {
            throw new IllegalStateException("Failed to set max time interval: Time interval: " + timeInterval);
        }
        if (session != null && session.isValid()) {
            session.setMaxInactiveInterval(timeInterval);
        } else {
            throw new IllegalStateException("Failed to set max time interval: No such session in progress");
        }
    } catch (IllegalStateException e) {
        throw new BallerinaException(e.getMessage(), e);
    }
    context.setReturnValues();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) Session(org.ballerinalang.net.http.session.Session)

Example 2 with Session

use of org.ballerinalang.net.http.session.Session in project ballerina by ballerina-lang.

the class GetAttributeNames method execute.

@Override
public void execute(Context context) {
    try {
        BStruct sessionStruct = ((BStruct) context.getRefArgument(0));
        Session session = (Session) sessionStruct.getNativeData(HttpConstants.HTTP_SESSION);
        if (session != null && session.isValid()) {
            context.setReturnValues(new BStringArray(session.getAttributeNames()));
        } else {
            throw new IllegalStateException("Failed to get attribute names: No such session in progress");
        }
    } catch (IllegalStateException e) {
        throw new BallerinaException(e.getMessage(), e);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BStringArray(org.ballerinalang.model.values.BStringArray) Session(org.ballerinalang.net.http.session.Session)

Example 3 with Session

use of org.ballerinalang.net.http.session.Session in project ballerina by ballerina-lang.

the class GetCreationTime method execute.

@Override
public void execute(Context context) {
    try {
        BStruct sessionStruct = ((BStruct) context.getRefArgument(0));
        Session session = (Session) sessionStruct.getNativeData(HttpConstants.HTTP_SESSION);
        if (session != null && session.isValid()) {
            context.setReturnValues(new BInteger(session.getCreationTime()));
        } else {
            throw new IllegalStateException("Failed to get creation time: No such session in progress");
        }
    } catch (IllegalStateException e) {
        throw new BallerinaException(e.getMessage(), e);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BInteger(org.ballerinalang.model.values.BInteger) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) Session(org.ballerinalang.net.http.session.Session)

Example 4 with Session

use of org.ballerinalang.net.http.session.Session in project ballerina by ballerina-lang.

the class Invalidate method execute.

@Override
public void execute(Context context) {
    try {
        BStruct sessionStruct = ((BStruct) context.getRefArgument(0));
        Session session = (Session) sessionStruct.getNativeData(HttpConstants.HTTP_SESSION);
        if (session != null && session.isValid()) {
            session.invalidate();
        } else {
            throw new IllegalStateException("Failed to invalidate session: No such session in progress");
        }
    } catch (IllegalStateException e) {
        throw new BallerinaException(e.getMessage(), e);
    }
    context.setReturnValues();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) Session(org.ballerinalang.net.http.session.Session)

Example 5 with Session

use of org.ballerinalang.net.http.session.Session in project ballerina by ballerina-lang.

the class IsNew method execute.

@Override
public void execute(Context context) {
    try {
        BStruct sessionStruct = ((BStruct) context.getRefArgument(0));
        Session session = (Session) sessionStruct.getNativeData(HttpConstants.HTTP_SESSION);
        if (session != null && session.isValid()) {
            context.setReturnValues(new BBoolean(session.isNew()));
        } else {
            throw new IllegalStateException("Failed to get session status: No such session in progress");
        }
    } catch (IllegalStateException e) {
        throw new BallerinaException(e.getMessage(), e);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BBoolean(org.ballerinalang.model.values.BBoolean) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) Session(org.ballerinalang.net.http.session.Session)

Aggregations

Session (org.ballerinalang.net.http.session.Session)15 BStruct (org.ballerinalang.model.values.BStruct)14 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)14 BInteger (org.ballerinalang.model.values.BInteger)3 NoSuchElementException (java.util.NoSuchElementException)2 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)2 BBoolean (org.ballerinalang.model.values.BBoolean)1 BString (org.ballerinalang.model.values.BString)1 BStringArray (org.ballerinalang.model.values.BStringArray)1 BValue (org.ballerinalang.model.values.BValue)1 AnnAttachmentInfo (org.ballerinalang.util.codegen.AnnAttachmentInfo)1 AnnAttributeValue (org.ballerinalang.util.codegen.AnnAttributeValue)1