use of org.wso2.transport.http.netty.config.Parameter in project siddhi by wso2.
the class TimeWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.siddhiAppContext = siddhiAppContext;
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
if (attributeExpressionExecutors.length == 1) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else {
throw new SiddhiAppValidationException("Time window should only have one parameter (<int|long|time> " + "windowTime), but found " + attributeExpressionExecutors.length + " input attributes");
}
}
use of org.wso2.transport.http.netty.config.Parameter in project siddhi by wso2.
the class DocumentationUtils method addExtensionMetaDataIntoNamespaceList.
/**
* Generate extension meta data from the annotated data in the class
*
* @param namespaceList The list of namespaces to which the new extension will be added
* @param extensionClass Class from which meta data should be extracted from
* @param logger The maven plugin logger
*/
private static void addExtensionMetaDataIntoNamespaceList(List<NamespaceMetaData> namespaceList, Class<?> extensionClass, Log logger) {
Extension extensionAnnotation = extensionClass.getAnnotation(Extension.class);
if (extensionAnnotation != null) {
// Discarding extension classes without annotation
ExtensionMetaData extensionMetaData = new ExtensionMetaData();
// Finding extension type
String extensionType = null;
for (Map.Entry<ExtensionType, Class<?>> entry : ExtensionType.getSuperClassMap().entrySet()) {
Class<?> superClass = entry.getValue();
if (superClass.isAssignableFrom(extensionClass) && superClass != extensionClass) {
extensionType = entry.getKey().getValue();
break;
}
}
// Discarding the extension if it belongs to an unknown type
if (extensionType == null) {
logger.warn("Discarding extension (belonging to an unknown extension type): " + extensionClass.getCanonicalName());
return;
}
extensionMetaData.setName(extensionAnnotation.name());
extensionMetaData.setDescription(extensionAnnotation.description());
// Adding query parameters
ParameterMetaData[] parameters = new ParameterMetaData[extensionAnnotation.parameters().length];
for (int i = 0; i < extensionAnnotation.parameters().length; i++) {
Parameter parameterAnnotation = extensionAnnotation.parameters()[i];
ParameterMetaData parameter = new ParameterMetaData();
parameter.setName(parameterAnnotation.name());
parameter.setType(Arrays.asList(parameterAnnotation.type()));
parameter.setDescription(parameterAnnotation.description());
parameter.setOptional(parameterAnnotation.optional());
parameter.setDynamic(parameterAnnotation.dynamic());
parameter.setDefaultValue(parameterAnnotation.defaultValue());
parameters[i] = parameter;
}
extensionMetaData.setParameters(Arrays.asList(parameters));
// Adding system parameters
SystemParameterMetaData[] systemParameters = new SystemParameterMetaData[extensionAnnotation.systemParameter().length];
for (int i = 0; i < extensionAnnotation.systemParameter().length; i++) {
SystemParameter systemParameterAnnotation = extensionAnnotation.systemParameter()[i];
SystemParameterMetaData systemParameter = new SystemParameterMetaData();
systemParameter.setName(systemParameterAnnotation.name());
systemParameter.setDescription(systemParameterAnnotation.description());
systemParameter.setDefaultValue(systemParameterAnnotation.defaultValue());
systemParameter.setPossibleParameters(Arrays.asList(systemParameterAnnotation.possibleParameters()));
systemParameters[i] = systemParameter;
}
extensionMetaData.setSystemParameters(Arrays.asList(systemParameters));
// Adding return attributes
ReturnAttributeMetaData[] returnAttributes = new ReturnAttributeMetaData[extensionAnnotation.returnAttributes().length];
for (int i = 0; i < extensionAnnotation.returnAttributes().length; i++) {
ReturnAttribute parameterAnnotation = extensionAnnotation.returnAttributes()[i];
ReturnAttributeMetaData returnAttribute = new ReturnAttributeMetaData();
returnAttribute.setName(parameterAnnotation.name());
returnAttribute.setType(Arrays.asList(parameterAnnotation.type()));
returnAttribute.setDescription(parameterAnnotation.description());
returnAttributes[i] = returnAttribute;
}
extensionMetaData.setReturnAttributes(Arrays.asList(returnAttributes));
// Adding examples
ExampleMetaData[] examples = new ExampleMetaData[extensionAnnotation.examples().length];
for (int i = 0; i < extensionAnnotation.examples().length; i++) {
Example exampleAnnotation = extensionAnnotation.examples()[i];
ExampleMetaData exampleMetaData = new ExampleMetaData();
exampleMetaData.setSyntax(exampleAnnotation.syntax());
exampleMetaData.setDescription(exampleAnnotation.description());
examples[i] = exampleMetaData;
}
extensionMetaData.setExamples(Arrays.asList(examples));
// Finding the namespace
String namespaceName = extensionAnnotation.namespace();
if (Objects.equals(namespaceName, "")) {
namespaceName = Constants.CORE_NAMESPACE;
}
// Finding the relevant namespace in the namespace list
NamespaceMetaData namespace = null;
for (NamespaceMetaData existingNamespace : namespaceList) {
if (Objects.equals(existingNamespace.getName(), namespaceName)) {
namespace = existingNamespace;
break;
}
}
// Creating namespace if it doesn't exist
if (namespace == null) {
namespace = new NamespaceMetaData();
namespace.setName(namespaceName);
namespace.setExtensionMap(new TreeMap<>());
namespaceList.add(namespace);
}
// Adding to the relevant extension metadata list in the namespace
List<ExtensionMetaData> extensionMetaDataList = namespace.getExtensionMap().computeIfAbsent(extensionType, k -> new ArrayList<>());
extensionMetaDataList.add(extensionMetaData);
}
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.
@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
Swagger swagger = new Swagger();
Info info = new Info();
info.setTitle(api.getName());
info.setDescription(api.getDescription());
info.setVersion(api.getVersion());
swagger.setInfo(info);
Map<String, Path> stringPathMap = new HashMap();
for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
String uriTemplateString = uriTemplate.getUriTemplate();
List<Parameter> parameterList = getParameters(uriTemplateString);
if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
parameterList.add(getDefaultBodyParameter());
}
Operation operation = new Operation();
operation.setParameters(parameterList);
operation.setOperationId(uriTemplate.getTemplateId());
operation.addResponse("200", getDefaultResponse());
if (stringPathMap.containsKey(uriTemplateString)) {
Path path = stringPathMap.get(uriTemplateString);
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
} else {
Path path = new Path();
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
stringPathMap.put(uriTemplateString, path);
}
}
swagger.setPaths(stringPathMap);
swagger.setPaths(stringPathMap);
return Json.pretty(swagger);
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getParameters.
/**
* Returns parameters, given http binding operation, verb and content type
*
* @param bindingOperation {@link BindingOperation} object
* @param verb HTTP verb
* @param contentType Content type
* @return parameters, given http binding operation, verb and content type
*/
private List<WSDLOperationParam> getParameters(BindingOperation bindingOperation, String verb, String contentType) {
List<WSDLOperationParam> params = new ArrayList<>();
Operation operation = bindingOperation.getOperation();
// or content type is not provided
if (APIMWSDLUtils.canContainBody(verb) && !APIMWSDLUtils.hasFormDataParams(contentType)) {
WSDLOperationParam param = new WSDLOperationParam();
param.setName("Payload");
param.setParamType(WSDLOperationParam.ParamTypeEnum.BODY);
params.add(param);
if (log.isDebugEnabled()) {
log.debug("Adding default Param for operation:" + operation.getName() + ", contentType: " + contentType);
}
return params;
}
if (operation != null) {
Input input = operation.getInput();
if (input != null) {
Message message = input.getMessage();
if (message != null) {
Map map = message.getParts();
map.forEach((name, partObj) -> {
WSDLOperationParam param = new WSDLOperationParam();
param.setName(name.toString());
if (log.isDebugEnabled()) {
log.debug("Identified param for operation: " + operation.getName() + " param: " + name);
}
if (APIMWSDLUtils.canContainBody(verb)) {
if (log.isDebugEnabled()) {
log.debug("Operation " + operation.getName() + " can contain a body.");
}
// In POST, PUT operations, parameters always in body according to HTTP Binding spec
if (APIMWSDLUtils.hasFormDataParams(contentType)) {
param.setParamType(WSDLOperationParam.ParamTypeEnum.FORM_DATA);
if (log.isDebugEnabled()) {
log.debug("Param " + name + " type was set to formData.");
}
}
// no else block since if content type is not form-data related, there can be only one
// parameter which is payload body. This is handled in the first if block which is
// if (canContainBody(verb) && !hasFormDataParams(contentType)) { .. }
} else {
// In GET operations, parameters always query or path as per HTTP Binding spec
if (isUrlReplacement(bindingOperation)) {
param.setParamType(WSDLOperationParam.ParamTypeEnum.PATH);
if (log.isDebugEnabled()) {
log.debug("Param " + name + " type was set to Path.");
}
} else {
param.setParamType(WSDLOperationParam.ParamTypeEnum.QUERY);
if (log.isDebugEnabled()) {
log.debug("Param " + name + " type was set to Query.");
}
}
}
Part part = (Part) partObj;
param.setDataType(part.getTypeName().getLocalPart());
if (log.isDebugEnabled()) {
log.debug("Param " + name + " data type was set to " + param.getDataType());
}
params.add(param);
});
}
}
}
return params;
}
use of org.wso2.transport.http.netty.config.Parameter in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromQueryParameterConditionToDTO.
/**
* Converts a Query Parameter Condition model object into a DTO
*
* @param condition Query Parameter Condition model object
* @return DTO object that was derived from Query Parameter Condition model object
*/
public static ThrottleConditionDTO fromQueryParameterConditionToDTO(QueryParameterCondition condition) {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.QUERY_PARAMS_CONDITION_TYPE);
throttleConditionDTO.setQueryParameterCondition(new QueryParameterConditionDTO());
throttleConditionDTO = updateFieldsFromConditionToDTO(condition, throttleConditionDTO);
throttleConditionDTO.getQueryParameterCondition().setParameterName(condition.getParameter());
throttleConditionDTO.getQueryParameterCondition().setParameterValue(condition.getValue());
return throttleConditionDTO;
}
Aggregations