camel expression - simple expression with header value as an argument - apache-camel

I am trying to set camel Header value using below Expression
.setHeader("amqName").simple("${amqAddressMap.get(header.userTypeID)}", String.class)
where amqAddressMap is an array list and passing header value as argument but it shows invalid expression error
is there any way to execute the code without using using processor class

To access ArrayList inside exchange we need to set it as a property
setProperty("amqAddressMap", constant(amqAddressMap))
So that we can access it using EL like
${exchangeProperty.amqAddressMap.get(${header.userTypeID})}

Related

What does any[]=[] datatype mean in TypeScript?

I'm working on a project in a company and there's a variable declared like this
chainTypeList: any[]=[];
and I'm not able to access it's values like this.
this.chainTypeList.chainTypeCode;
It shows this error : Property 'chainTypeCode' does not exist on type 'any[]'.
This is looks like typescript's typing.
This means that this is an array of any value. An it's initilized as an empty one.
The any value literally means that you can push any value and value type into this array.
You can't access it by using this:
this.chainTypeList.chainTypeCode;
because it's an array and not an object. That's why you get the error:
Property 'chainTypeCode' does not exist on type 'any[]'.
It should only be something like this:
this.chainTypeList
or
this.chainTypeList[0]
If you want a specific position of the array. Just change the number for the position you want to obtain.
chainTypeList: any[]=[];
It is written as TypeScript not JavaScript. You cannot do this if it is pure JavaScript. It means that variable chainTypeList is declared as an array type any (can be any type), which is initialized as an empty array.
and by calling
this.chainTypeList.chainTypeCode;
you are trying to access property named chainTypeCode in the object chainTypeList. However, the program will not be able to find such property because, as it is declared earlier, the variable is an empty array. It does not have the property you are looking for hence the error
Property 'chainTypeCode' does not exist on type 'any[]'.
What does any[]=[] datatype mean in TypeScript?
It's not a datatype.
The any[] part is a datatype. The = [] part is called an "assignment". An assignment binds a value to a name, e.g. in this case, it binds the value [] (an empty array) to the name chainTypeList, meaning that from this point on, dereferencing the name chainTypeList will evaluate to an empty array.
this.chainTypeList.chainTypeCode;
It shows this error : Property 'chainTypeCode' does not exist on type 'any[]'.
Arrays don't have a property called chainTypeCode, so the error is correct.

Camel Simple Expression inside JsonPath Language?

I am trying to use simple expression inside jsonpath . I tried using built in operators such as 'contains','starts with' inside jsonpath to do a comparison with a header value.
I have tried using the contains operator and that works, but the starts with operator fails
What works -
.jsonpath("$.configs[?(#.mask contains '${header.mask}')]")
what does not work
.jsonpath("$.configs[?(#.mask starts with '${header.mask}')]")
starts with does not work..for what reason I dont know..but then using a regex as shown below works
.jsonpath("$.configs[?(#.mask =~ /^\\${header.fileMask}.*?/i)]")

D: Creating an array of templated objects

I'm trying to create an array of Regex objects, like so: Regex[] regexes;.
The compilation fails with main.d(46): Error: template std.regex.Regex(Char) is used as a type.
I find the documentation cryptic. All I understand is that templates generate code on compilation, but I don't see what's preventing me from creating an array of Regex.
There's an existing question on StackOverflow with the same problem, but it deals with C++, not D.
You cannot create a regex object without first instantiating the template with a type. this is because the actual type is generated at compile time based on the instantiation type you give. Regex itself is not an actual type, it is just a template function allowing you to generate a type when instantiated.
In this case you probably want to change:
Regex[] regexes;
into:
Regex!char[] regexes;
to tell the compiler that your regex contains chars as opposed to some derived type. This means specifically you are instantiating the Regex template with the type char.

Delphi SOAP Client adding items to dynamic array

I'm currently developing a client for a SOAP service.
The WSDL import works fine, but I'm facing the problem that I need to add items to a dynamic array.
The declaration in delphi:
Array_Of_attributWS = array of attributWS;
dienstleistungWS = class(TRemotable)
private
[..]
public
[..]
published
property attributeWS: Array_Of_attributWS
Index(IS_OPTN or IS_UNBD or IS_NLBL or IS_UNQL)read GetattributeWS
write SetattributeWS stored attributeWS_Specified;
I want to add an item to attributeWS from an other unit.
To add an item I use this code:
SetLength(dynArray, Length(dynArray)+1);
dynArray[High(dynArray)] := item;
But it wont let me, I get the following error:
E2197 Constant object cannot be passed as var parameter
Is there a way to add an item easy to the dynamic array?
Or is there a way to cast the array to a list so that I can just do .Append(item)?
Delphi Version XE6
Thanks!
If you check the SetattributeWS implementation you will see it simply gets your dynamic array as a const parameter, stores it and marks an internal boolean variable as true (indicating the parameter has been informed).
The const part is the one that causes the E2197 error you are seeing.
The best option is to use a local dynamic array variable of the same type and then:
set its length to the actual length of attributeWS + 1.
copy the original items from attributeWS to the local variable, and then add the new item.
assign this variable to the attributeWS property.
Actually, it would be better to not assign the dynamic array to the request property until you have it filled with all the necessary elements, but that may depend on your needs.

DirectCast (or alternative) with a value from Array Of Type as second argument?

I am writing a Class to error report explicitly to users who sent copied & pasted data via ajax.
I am trying to properly cast Types for INSERTion into sql server.
The user's data is stored in an Object(,). The Types are passed via ByVal ColumnTypes() As Type and stored inline:
{
GetType(Integer), GetType(String), GetType(Integer)
}
for example.
How can a value from the Array Of Type be used as the second argument of DirectCast (or an alternative to DirectCast)?
psuedo
DirectCast(thisVariable, ColumnTypes(0))
for an Integer
Unfortunately there is no way to achieve this. The DirectCast expression can only work with named types. Essentially values that are resolvable at compile time. The expression ColumnTypes(0) is only resolvable at runtime and hence can't be used with DirectCast in this manner.
Instead of DirectCast try using TypeConverter
TypeConverter.ConvertTo(thisVariable, ColumnTypes(0))

Resources