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;
}
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());
}
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);
}
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);
}
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();
}
Aggregations