Search in sources :

Example 36 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class AbstractHTTPAction method createOutboundRequestMsg.

protected HTTPCarbonMessage createOutboundRequestMsg(Context context) {
    // Extract Argument values
    BStruct bConnector = (BStruct) context.getRefArgument(0);
    String path = context.getStringArgument(0);
    BStruct requestStruct = ((BStruct) context.getRefArgument(1));
    HTTPCarbonMessage requestMsg = HttpUtil.getCarbonMsg(requestStruct, HttpUtil.createHttpCarbonMessage(true));
    HttpUtil.checkEntityAvailability(context, requestStruct);
    HttpUtil.enrichOutboundMessage(requestMsg, requestStruct);
    prepareOutboundRequest(context, bConnector, path, requestMsg);
    AcceptEncodingConfig acceptEncodingConfig = getAcceptEncodingConfig(getAcceptEncodingConfigFromEndpointConfig(bConnector));
    handleAcceptEncodingHeader(requestMsg, acceptEncodingConfig);
    return requestMsg;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) AcceptEncodingConfig(org.ballerinalang.net.http.AcceptEncodingConfig)

Example 37 with BStruct

use of org.ballerinalang.model.values.BStruct 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 38 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class ConnectionAction method sendOutboundResponseRobust.

private BValue[] sendOutboundResponseRobust(Context context, HTTPCarbonMessage requestMessage, BStruct outboundResponseStruct, HTTPCarbonMessage responseMessage) {
    String contentType = HttpUtil.getContentTypeFromTransportMessage(responseMessage);
    String boundaryString = null;
    if (HeaderUtil.isMultipart(contentType)) {
        boundaryString = HttpUtil.addBoundaryIfNotExist(responseMessage, contentType);
    }
    HttpResponseFuture outboundRespStatusFuture = HttpUtil.sendOutboundResponse(requestMessage, responseMessage);
    BStruct entityStruct = MimeUtil.extractEntity(outboundResponseStruct);
    if (entityStruct != null) {
        if (boundaryString != null) {
            serializeMultiparts(responseMessage, boundaryString, outboundRespStatusFuture, entityStruct);
        } else {
            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 39 with BStruct

use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.

the class ConnectionAction method execute.

@Override
public void execute(Context context) {
    BStruct connectionStruct = (BStruct) context.getRefArgument(0);
    HTTPCarbonMessage inboundRequestMsg = HttpUtil.getCarbonMsg(connectionStruct, null);
    HttpUtil.checkFunctionValidity(connectionStruct, inboundRequestMsg);
    BStruct outboundResponseStruct = (BStruct) context.getRefArgument(1);
    HTTPCarbonMessage outboundResponseMsg = HttpUtil.getCarbonMsg(outboundResponseStruct, HttpUtil.createHttpCarbonMessage(false));
    HttpUtil.prepareOutboundResponse(context, inboundRequestMsg, outboundResponseMsg, outboundResponseStruct);
    if (CacheUtils.isValidCachedResponse(outboundResponseMsg, inboundRequestMsg)) {
        outboundResponseMsg.setProperty(HTTP_STATUS_CODE, HttpResponseStatus.NOT_MODIFIED.code());
        outboundResponseMsg.waitAndReleaseAllEntities();
        outboundResponseMsg.completeMessage();
    }
    BValue[] outboundResponseStatus = sendOutboundResponseRobust(context, inboundRequestMsg, outboundResponseStruct, outboundResponseMsg);
    context.setReturnValues(outboundResponseStatus);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) BValue(org.ballerinalang.model.values.BValue)

Example 40 with BStruct

use of org.ballerinalang.model.values.BStruct 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)

Aggregations

BStruct (org.ballerinalang.model.values.BStruct)460 BValue (org.ballerinalang.model.values.BValue)187 Test (org.testng.annotations.Test)161 BString (org.ballerinalang.model.values.BString)131 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)53 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)39 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)37 BInteger (org.ballerinalang.model.values.BInteger)33 BMap (org.ballerinalang.model.values.BMap)29 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)26 BStructType (org.ballerinalang.model.types.BStructType)25 IOException (java.io.IOException)23 BBoolean (org.ballerinalang.model.values.BBoolean)23 BJSON (org.ballerinalang.model.values.BJSON)22 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)21 StructInfo (org.ballerinalang.util.codegen.StructInfo)21 EventContext (org.ballerinalang.nativeimpl.io.events.EventContext)20 File (java.io.File)17 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)17 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)16