use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.
the class CodeGenerator method createFunctionInfoEntry.
/**
* Creates a {@code FunctionInfo} from the given function node in AST.
*
* @param funcNode function node in AST
*/
private void createFunctionInfoEntry(BLangFunction funcNode) {
BInvokableSymbol funcSymbol = funcNode.symbol;
BInvokableType funcType = (BInvokableType) funcSymbol.type;
// Add function name as an UTFCPEntry to the constant pool
int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
funcInfo.flags = funcSymbol.flags;
if (funcNode.receiver != null) {
funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
}
this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(funcNode, funcInfo);
this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangFunction funcNode) {
SymbolEnv fucEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
if (!funcNode.interfaceFunction) {
addReturnIfNotPresent(funcNode);
}
// To preserve endpoint code gen order.
Collections.reverse(funcNode.endpoints);
funcNode.endpoints = rewrite(funcNode.endpoints, fucEnv);
funcNode.body = rewrite(funcNode.body, fucEnv);
funcNode.workers = rewrite(funcNode.workers, fucEnv);
// the struct variable as the first parameter
if (funcNode.receiver != null) {
BInvokableSymbol funcSymbol = funcNode.symbol;
List<BVarSymbol> params = funcSymbol.params;
params.add(0, funcNode.receiver.symbol);
BInvokableType funcType = (BInvokableType) funcSymbol.type;
funcType.paramTypes.add(0, funcNode.receiver.type);
}
result = funcNode;
}
use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangAction actionNode) {
String actionName = actionNode.getName().getValue();
BSymbol actionSymbol = actionNode.symbol;
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, symbolEnv);
if (this.isWithinParameterContext(actionName, NODE_TYPE_ACTION)) {
this.populateSymbols(this.resolveAllVisibleSymbols(actionEnv), actionEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(actionNode.getPosition(), actionNode, this, this.documentServiceContext)) {
// TODO: Handle Annotation attachments
// Visit the endpoints
actionNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, actionEnv));
// Cursor position is calculated against the resource parameter scope resolver since both are similar
cursorPositionResolver = ResourceParamScopeResolver.class;
actionNode.workers.forEach(w -> this.acceptNode(w, actionEnv));
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
this.blockOwnerStack.push(actionNode);
acceptNode(actionNode.body, actionEnv);
this.blockOwnerStack.pop();
}
}
use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.
the class Generator method paramAnnotation.
/**
* Get description annotation of the parameter.
* @param node parent node.
* @param param parameter.
* @return description of the parameter.
*/
private static String paramAnnotation(BLangNode node, BLangVariable param) {
String subName = param.getName() == null ? param.type.tsymbol.name.value : param.getName().getValue();
for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
continue;
}
BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
String attribVal = bLangLiteral.toString();
if ((annotation.getAnnotationName().getValue().equals("Param")) && attribVal.startsWith(subName + ":")) {
return attribVal.split(subName + ":")[1].trim();
}
}
return "";
}
use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.
the class AbstractHTTPAction method send.
/**
* Send outbound request through the client connector. If the Content-Type is multipart, check whether the boundary
* exist. If not get a new boundary string and add it as a parameter to Content-Type, just before sending header
* info through wire. If a boundary string exist at this point, serialize multipart entity body, else serialize
* entity body which can either be a message data source or a byte channel.
*
* @param dataContext holds the ballerina context and callback
* @param outboundRequestMsg Outbound request that needs to be sent across the wire
* @param async whether a handle should be return
* @return connector future for this particular request
* @throws Exception When an error occurs while sending the outbound request via client connector
*/
private void send(DataContext dataContext, HTTPCarbonMessage outboundRequestMsg, boolean async) throws Exception {
BStruct bConnector = (BStruct) dataContext.context.getRefArgument(0);
Struct httpClient = BLangConnectorSPIUtil.toStruct(bConnector);
HttpClientConnector clientConnector = (HttpClientConnector) httpClient.getNativeData(HttpConstants.HTTP_CLIENT);
String contentType = HttpUtil.getContentTypeFromTransportMessage(outboundRequestMsg);
String boundaryString = null;
if (HeaderUtil.isMultipart(contentType)) {
boundaryString = HttpUtil.addBoundaryIfNotExist(outboundRequestMsg, contentType);
}
HttpMessageDataStreamer outboundMsgDataStreamer = new HttpMessageDataStreamer(outboundRequestMsg);
OutputStream messageOutputStream = outboundMsgDataStreamer.getOutputStream();
RetryConfig retryConfig = getRetryConfiguration(httpClient);
HTTPClientConnectorListener httpClientConnectorLister = new HTTPClientConnectorListener(dataContext, retryConfig, outboundRequestMsg, outboundMsgDataStreamer);
HttpResponseFuture future = clientConnector.send(outboundRequestMsg);
if (async) {
future.setResponseHandleListener(httpClientConnectorLister);
} else {
future.setHttpConnectorListener(httpClientConnectorLister);
}
try {
if (boundaryString != null) {
serializeMultiparts(dataContext.context, messageOutputStream, boundaryString);
} else {
serializeDataSource(dataContext.context, messageOutputStream);
}
} catch (IOException | EncoderException serializerException) {
// We don't have to do anything here as the client connector will notify
// the error though the listener
logger.warn("couldn't serialize the message", serializerException);
}
}
Aggregations