public BPacket put(String key, BValue item) { map.put(key, item); return this; }
public RequestCacheControlStruct(BMap<String, BValue> requestCacheControl) { this.requestCacheControl = requestCacheControl; // Initialize the struct fields to default values we use requestCacheControl.put(REQ_CACHE_CONTROL_NO_TRANSFORM_FIELD, new BBoolean(TRUE)); requestCacheControl.put(REQ_CACHE_CONTROL_MAX_AGE_FIELD, new BInteger(-1)); requestCacheControl.put(REQ_CACHE_CONTROL_MAX_STALE_FIELD, new BInteger(-1)); requestCacheControl.put(REQ_CACHE_CONTROL_MIN_FRESH_FIELD, new BInteger(-1)); }
public RequestCacheControlStruct(StructureTypeInfo structInfo) { requestCacheControl = BLangVMStructs.createBStruct(structInfo); // Initialize the struct fields to default values we use requestCacheControl.put(REQ_CACHE_CONTROL_NO_TRANSFORM_FIELD, new BBoolean(TRUE)); requestCacheControl.put(REQ_CACHE_CONTROL_MAX_AGE_FIELD, new BInteger(-1)); requestCacheControl.put(REQ_CACHE_CONTROL_MAX_STALE_FIELD, new BInteger(-1)); requestCacheControl.put(REQ_CACHE_CONTROL_MIN_FRESH_FIELD, new BInteger(-1)); }
public static BMap<String, BValue> getMatrixParamsMap(String path, HttpCarbonMessage carbonMessage) { BMap<String, BValue> matrixParamsBMap = new BMap<>(); Map<String, Map<String, String>> pathToMatrixParamMap = (Map<String, Map<String, String>>) carbonMessage.getProperty(HttpConstants.MATRIX_PARAMS); Map<String, String> matrixParamsMap = pathToMatrixParamMap.get(path); if (matrixParamsMap != null) { for (Map.Entry<String, String> matrixParamEntry : matrixParamsMap.entrySet()) { matrixParamsBMap.put(matrixParamEntry.getKey(), new BString(matrixParamEntry.getValue())); } } return matrixParamsBMap; }
@Override public void onError(Throwable throwable, HttpCarbonResponse response) { if (response != null) { BMap<String, BValue> webSocketClientEndpoint = ((BMap<String, BValue>) context.getRefArgument(0)); webSocketClientEndpoint.put(WebSocketConstants.CLIENT_RESPONSE_FIELD, HttpUtil.createResponseStruct(context, response)); } countDownLatch.countDown(); throw new BallerinaConnectorException("Error occurred: " + throwable.getMessage()); } }
/** * Populates the HTTP caller with native data. * * @param caller Represents the HTTP caller * @param inboundMsg Represents carbon message * @param config Represents service endpoint configuration */ public static void enrichHttpCallerWithNativeData(BMap<String, BValue> caller, HttpCarbonMessage inboundMsg, Struct config) { caller.addNativeData(HttpConstants.TRANSPORT_MESSAGE, inboundMsg); caller.put(HttpConstants.HTTP_CONNECTOR_CONFIG_FIELD, (BMap<String, BValue>) config.getVMValue()); }
public static void populateEndpoint(WebSocketConnection webSocketConnection, BMap<String, BValue> webSocketEndpoint) { webSocketEndpoint.put(WebSocketConstants.LISTENER_ID_FIELD, new BString(webSocketConnection.getChannelId())); webSocketEndpoint.put(WebSocketConstants.LISTENER_NEGOTIATED_SUBPROTOCOLS_FIELD, new BString(webSocketConnection.getNegotiatedSubProtocol())); webSocketEndpoint.put(WebSocketConstants.LISTENER_IS_SECURE_FIELD, new BBoolean(webSocketConnection.isSecure())); webSocketEndpoint.put(WebSocketConstants.LISTENER_IS_OPEN_FIELD, new BBoolean(webSocketConnection.isOpen())); }
public static void readFirstFrame(WebSocketConnection webSocketConnection, BMap<String, BValue> webSocketConnector) { webSocketConnection.readNextFrame(); webSocketConnector.put(WebSocketConstants.CONNECTOR_IS_READY_FIELD, new BBoolean(true)); }
/** * Populates the push promise struct from native {@code Http2PushPromise}. * * @param pushPromiseStruct the push promise struct * @param pushPromise the native Http2PushPromise */ public static void populatePushPromiseStruct(BMap<String, BValue> pushPromiseStruct, Http2PushPromise pushPromise) { pushPromiseStruct.addNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE, pushPromise); pushPromiseStruct.put(HttpConstants.PUSH_PROMISE_PATH_FIELD, new BString(pushPromise.getPath())); pushPromiseStruct.put(HttpConstants.PUSH_PROMISE_METHOD_FIELD, new BString(pushPromise.getMethod())); }
private static void convertStructToMap(Strand strand, int[] operands, StackFrame sf) { int i = operands[0]; int j = operands[1]; // TODO: do validation for type? BMap newMap = new BMap(BTypes.typeMap); ((BMap) sf.refRegs[i]).getMap().forEach((key, value) -> newMap.put(key, value == null ? null : ((BValue) value).copy(new HashMap<>()))); sf.refRegs[j] = newMap; }
/** * Get error struct. * * @param context Represent ballerina context * @param errMsg Error message * @return Error struct */ public static BError getError(Context context, String errMsg) { BMap<String, BValue> httpErrorRecord = createHTTPErrorRecord(context); httpErrorRecord.put(HTTP_ERROR_MESSAGE, new BString(errMsg)); return BLangVMErrors.createError(context, true, BTypes.typeError, HTTP_ERROR_CODE, httpErrorRecord); }
private BValue[] getSignatureParameters(LocalFileSystemEvent fileEvent) { BMap<String, BValue> eventStruct = new BMap<>(this.structInfo.getType()); eventStruct.put(FILE_EVENT_NAME, new BString(fileEvent.getFileName())); eventStruct.put(FILE_EVENT_OPERATION, new BString(fileEvent.getEvent())); return new BValue[] { eventStruct }; }
public static BError createError(Strand strand, String reason, String detail) { BMap<String, BValue> detailMap = new BMap<>(BTypes.typeMap); if (detail != null) { detailMap.put(ERROR_MESSAGE_FIELD, new BString(detail)); } return generateError(strand, true, BTypes.typeError, reason, detailMap); }
@SuppressWarnings("rawtypes") protected WorkerExecutionContext onHaltFinalized() { BMap<String, BRefType> mbMap = new BMap<>(); channelNames.forEach((k, v) -> { BRefType workerRes = getWorkerResult(v); mbMap.put(k, workerRes); }); this.targetCtx.workerLocal.refRegs[joinVarReg] = (BRefType) mbMap; this.modifyDebugCommands(this.targetCtx, this.currentSignal.getSourceContext()); return BLangScheduler.resume(this.targetCtx, joinTargetIp, true); }
private BMap<String, BValue> listToBValue(List list) { BValueArray array = new BValueArray(new BArrayType(BTypes.typeAny)); for (Object item : list) { array.append(toBValue(item, null)); } BMap<String, BValue> bMap = wrapWithTypeMetadata(JsonSerializerConst.LIST_TAG, array); bMap.put(JsonSerializerConst.LENGTH_TAG, new BInteger(list.size())); return bMap; }
private void checkDirtiness(DataContext dataContext, HttpCarbonMessage outboundRequestMsg) { BMap<String, BValue> requestStruct = ((BMap<String, BValue>) dataContext.context. getNullableRefArgument(HttpConstants.REQUEST_STRUCT_INDEX)); String contentType = HttpUtil.getContentTypeFromTransportMessage(outboundRequestMsg); outboundRequestMsg.setIoException(null); if (requestStruct != null) { if (dirty(requestStruct)) { cleanOutboundReq(outboundRequestMsg, requestStruct, contentType); } else { requestStruct.put(HttpConstants.REQUEST_REUSE_STATUS_INDEX, new BBoolean(HttpConstants.DIRTY_REQUEST)); } } }
@Override public void execute(Context context) { BStruct span = (BStruct) context.getRefArgument(0); String group = context.getStringArgument(0) == null ? TraceConstants.DEFAULT_USER_API_GROUP : context.getStringArgument(0); String spanId = span.getStringField(0); Map<String, String> propertiesToInject = OpenTracerBallerinaWrapper.getInstance().inject(group, spanId); BMap<String, BString> headerMap = new BMap<>(); propertiesToInject.forEach((key, value) -> headerMap.put(key, new BString(value))); context.setReturnValues(headerMap); } }
private static void enrichWithInboundRequestHeaders(BMap<String, BValue> inboundRequestStruct, HttpCarbonMessage inboundRequestMsg) { if (inboundRequestMsg.getHeader(HttpHeaderNames.USER_AGENT.toString()) != null) { String agent = inboundRequestMsg.getHeader(HttpHeaderNames.USER_AGENT.toString()); inboundRequestStruct.put(HttpConstants.REQUEST_USER_AGENT_FIELD, new BString(agent)); inboundRequestMsg.removeHeader(HttpHeaderNames.USER_AGENT.toString()); } }