I would like to achieve something like below:
from("direct:dataload")
.beanRef("headerUpdater")
.log("Log: " + simple("${in.header.contentType}").getText())
//.unmarshal().beanio(simple("${in.header.contentType}").getText(), "content")
.unmarshal(new BeanIODataFormat(
"file://C://Users//admr229//Documents//mappings.xml", "clients"))
.to("bean:headerFooterValidator")
.split(body())
.process(dataValidator).choice()
.when(header("error").isNotNull())
.to("seda:saveErrorsForReport").otherwise()
.to("seda:updateLive")
.end();
I have commented out the line which I cannot make. I wanted to pass dynamic values from previous endpoint's output to initialize beanio.
Only thing I can think of is using recipient list which will dynamically choose a predefined endpoint. Because, for my case, that endpoint will have unmarshall with beanio, unlike something like "activemq:queue:test", which is purely text.
I hope I have made my question clear. Please let me know if you need any further details.
I am using camel 2.15.2
You can use the data format component [1] where you can specify beanio as the data format, and build the uri dynamic [2]
[1] - http://camel.apache.org/dataformat-component.html
[2] - http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
you can use do something like this but, again this not dynamic I guess as it need to have properties set before brining up the context.
.unmarshal().beanio(mapping, streamName)
Related
I am new to API testing and am using Katalon to develop the tests. I've Googled any question I could think of and couldn't find anything to answer my question.
We have an API with the following Body
[
"${idValue1}",
"${idValue2}",
"${idValue3}",
"${idValue4}",
"${idValue5}",
]
I believe the purpose of this one is to delete multiple records at once by id. The script that we have in the step definition is
response = WS.sendRequest(findTestObject('EquipmentAPI/data-objects/DELETE Equipment By Ids', [('host') : GlobalVariable.host, ('idValues') : GlobalVariable.equipId]))
GlobalVariable.equipId = WS.getElementPropertyValue(response, 'data[0].id')
There are other step definitions that run before this one to set the Global Variables for use. I was able to generate the string array without issue.
Is this something that's possible? Please help!
Please let me know if further information is needed. Thanks.
I extracted from a previous response an Object of tuple with the following regex :
.check(regex(""""idSc":(.{1,8}),"pasTemps":."codePasTemps":(.),"""").ofType[(String,String)].findAll.saveAs ("OBJECTS1"))
So I get my object :
OBJECTS1 -> List((1657751,2), (1658105,2), (4557378,2), (1657750,1), (916,1), (917,2), (1658068,1), (1658069,2), (4557379,2), (1658082,1), (4557367,1), (4557368,1), (1660865,2), (1660866,2), (1658122,1), (921,1), (922,2), (923,2), (1660875,1), (1660876,2), (1660877,2), (1658300,1), (1658301,1), (1658302,1), (1658309,1), (1658310,1), (2996562,1), (4638455,1))
After that I did a Foreach and need to extract every couple to add them in next requests So we tried :
.foreach("${OBJECTS1}", "couple") {
exec(http("request_foreach47"
.get("/ctr/web/api/seriegraph/bydates/${couple(0)}/${couple(1)}/1552863600000/1554191743799")
.headers(headers_27))
}
But I get the message : named 'couple' does not support index access
I also though that to use 2 regex on the couple to extract both part could work but I haven't found any way to use a regex on a session variable. (Even if its not needed for this case but possible im really interessed to learn how as it could be usefull)
If would be really thankfull if you could provided me help. (Im using Gatling 2 but can,'t use a more recent version as its for work and others scripts have been develloped with Gatling2)
each "couple" is a scala tuple which can't be indexed into like a collection. Fortunately the gatling EL has a function that handles tuples.
so instead of
.get("/ctr/web/api/seriegraph/bydates/${couple(0)}/${couple(1)}/1552863600000/1554191743799")
you can use
.get("/ctr/web/api/seriegraph/bydates/${couple._1}/${couple._2}/1552863600000/1554191743799")
I'm working on a simple rails app that does SMS. I am leveraging Twilio for this via the twilio_ruby gem. I have 10 different phone numbers that I want to be able to send SMS from randomly.
I know if I do something like this:
numbers = ["281-555-1212", "821-442-2222", "810-440-2293"]
numbers.sample
281-555-1212
It will randomly pull one of the values from the array, which is exactly what I want. The problem is I don't want to hardcode all 10 of these numbers into the app or commit them to version control.
So I'm listing them in yaml (secrets.yml) along with my Twilio SID/Token. How can I build an array out of the 10 yaml fields i.e. twilio_num_1, twilio_num_2, etc, etc so that I can call numbers.sample?
Or is there a better way to do this?
You can also use
twilio_numbers:
- 281-555-1122
- 817-444-2222
- 802-333-2222
thus you don't have to write the numbers in one line.
Figured this out through trial and error.
In secrets.yml
twilio_numbers: ["281-555-1122","817-444-2222","802-333-2222"]
In my code:
Rails.application.secrets.twilio_numbers.sample
Works like a charm.
create a file: config/twilio_numbers.yml
---
- 281-555-1122
- 817-444-2222
- 802-333-2222
and load it in your config/application.rb like this:
config.twilio_numbers = YAML.load_file 'config/twilio_numbers.yml'
you can then access the array from inside any file like this:
Rails.application.config.twilio_numbers
=> ["281-555-1122", "817-444-2222", "802-333-2222"]
I have a google-cloud-endpoints, in the docs, I did'nt find how to write a PATCH method.
My request:
curl -XPATCH localhost:8080/_ah/api/hellogreeting/1 -d '{"message": "Hi"}'
My method handler looks like this:
from models import Greeting
from messages import GreetingMessage
#endpoints.method(ID_RESOURCE, Greeting,`
path='hellogreeting/{id}', http_method='PATCH',
name='greetings.patch')
def greetings_patch(self, request):
request.message, request.username
greeting = Greeting.get_by_id(request.id)
greeting.message = request.message # It's ok, cuz message exists in request
greeting.username = request.username # request.username is None. Writing the IF conditions in each string(checking on empty), I think it not beatifully.
greeting.put()
return GreetingMessage(message=greeting.message, username=greeting.username)
So, now in Greeting.username field will be None. And it's wrong.
Writing the IF conditions in each string(checking on empty), I think it not beatifully.
So, what is the best way for model updating partially?
I do not think there is one in Cloud Endpoints, but you can code yours easily like the example below.
You will need to decide how you want your patch to behave, in particular when it comes to attributes that are objects : should you also apply the patch on the object attribute (in which case use recursion) or should you just replace the original object attribute with the new one like in my example.
def apply_patch(origin, patch):
for name in dir( patch ):
if not name.startswith( '__' ):
setattr(origin,name,getattr(patch,name))
I'm trying to set a property called "articleId" on the exchange's body and I thought the most explicit way to do this would be to use bean(). However, I can't get it to work. When I have the following in my route:
.bean(body(Article.class), "setArticleId(${header.articleId})")
I get this error message:
Caused by: org.apache.camel.component.bean.MethodNotFoundException: Method with name: setArticleId(${header.articleId}) not found on bean: bodyAs[com.example.model.Article] of type: org.apache.camel.builder.ValueBuilder
My solution has been to use a processor() and a few lines of code in order to set the articleId property from the header value, but to me that seems like overkill.
I've been complaining on camel-users that there isn't a good way to do this. For now here is how I tackle it:
.setHeader("dummy").ognl("request.body.articleId = request.headers.articleId")
Which requires adding camel-ognl dependency.
UPDATE
Actually, there is also a language endpoint that can do this without the setHeader, but you have to say transform=false or else it replaces your body with the result:
.to("language:ognl:request.body.articleId = request.headers.articleId?transform=false") // remember ?transform=false
I think you need to spend some time to go through this page, if you don't know how to tell camel which method of the bean you want it invoke.
If you just want to set the exchange property, you can just use the DSL
setProperty("articleId", body());
to do this kind of work.