This question already has an answer here:
How do dynamic "from" endpoints and exchanges work in camel?
(1 answer)
Closed 6 years ago.
I want to read files from a folder that correspond to a regex like this
from("direct:queuealpha").process(new DateTagGenerator()).from("file:///folder1/folder2/?delete=false&include=.*(${headers.timetag}).*);
So DateTagGenerator sets a header with a value I want to use in the regex as input. I tried escaping {, $ and } as well as using simple but I am obviously doing sth wrong.
How can I dynamically create a value for a header or the body, which can then be used for a regex?
Since Camel 2.16 you can use the Content Enricher with dynamic endpoints ([doc][1]) and in particular the pollEnrich (as you are using a file endpont)
from("direct:queuealpha")
.process(new DateTagGenerator())
.pollEnrich.simple("file:/folder1/folder2/?delete=false&include=${headers.timetagExpr}")
.process(…) // you can now process the message
.to(…); // and send it onward
Related
I have created a basic CRUD API using Dropwizard and Spring. In the body of my response object, I am receiving the following:
)]}',
{
"id":10,
"initiator":2,
"target":1,
"statusId":1,
"created":"2018-04-30T14:45:01.173"
}
I checked the API using curl, postman, and programatically during testing with rest assured, and the invalid characters )]}', are always present. Postman seems to be capable of ignoring them and displaying a pretty printed output, however rest assured, and I'm guessing most JSON parsers, can't parse it correctly.
Questions:
What are they?
Why are they present?
How do I remove them?
I've been writing REST APIs for years and I've never seen anything like this. This is my first time using dropwizard so I'm optimistically hoping it is some configuration I have missed.
Apart from the the invalid characters, functionally the API works fine.
This is an inherited codebase, and other APIs return these characters also. For the purposes of testing in rest assured the invalid characters are filtered out before processing the response. While this seems acceptable to me as a workaround in the short term, long term any future consumers of the API will all have to perform the workaround, and ideally this would be fixed in the API itself.
Not aware of DropWizard but it is there to prevent json-hijacking.
In Spring there is a MappingJackson2HttpMessageConverter class.
which has same feature, but prefix is different "{} &&"
/**
* Indicate whether the JSON output by this view should be prefixed with "{} &&". Default is false.
* <p>Prefixing the JSON string in this manner is used to help prevent JSON Hijacking.
* The prefix renders the string syntactically invalid as a script so that it cannot be hijacked.
* This prefix does not affect the evaluation of JSON, but if JSON validation is performed on the
* string, the prefix would need to be ignored.
*/
public void setPrefixJson(boolean prefixJson) {
this.prefixJson = prefixJson;
}
You can relate to this.
Edit 1:
Spring version 4.2.0.RELEASE onwards, default prefix has been updated to )]}',
This question already has an answer here:
How do you actually parse values in YAML in Java? [duplicate]
(1 answer)
Closed 6 years ago.
I want to write java program to read set of data from YAML file in cloud foundry.
#Define CDN domains
---
domains:
name : CDN1
quality : 200..300
cost : low
location: http://
name: CDN2
quality: 400..500
cost: high
location: http://
Then, in the program based on the name and quality it should redirect the first request to new location.
Can anyone help me for this?
I`m entirely new in YAML!
Based on my search, I can use snacked YAML or bean YAML, but I don't know what difference is.
You can use Jackson to read YAML, which is widely supported in Spring: https://github.com/FasterXML/jackson-dataformat-yaml
I am required to pass an arithmetic operation like 2+8 to a restful back-end and receive the result. I know that a simple operation can be handled in frontend using javascript, but i just want to follow the requirement.
I send the operations with the following uri:
http://localhost:8080/?question=2+5
and in the back-end i have:
#RequestMapping("/")
public String getAnswer(#RequestParam("question") String question){
System.out.println("recieved question is: "+question);
return botService.Evaluator(question);
}
When i print the question it is like 2 3 so there is no operation there.
And the component complains with:
javax.script.ScriptException: <eval>:1:2 Expected ; but found 5
2 5
^ in <eval> at line number 1 at column number 2
So, why the + is missing?
and how can i fix it?
Use the URLEncoder class to make sure any special characters are encoded safely for transport.
You need to encode the '+' symbol as the server will just translate it as a space.
Send...
http://localhost:8080/?question=2%2B5
You need URL Encoding here. for more details regarding URL Encoding please have a look in below link.
URL Encoding
I Used MessageFormat to format the contents of a file with parameters and get so a formated string with correct parameters.
(I used it to format email body.finally I had one file per email body, the application needs to send a lot of different emails, so I got a lot of preformatted body files)
So far, I had six parameters.
Problem: Things are changing and now I have more than 6 parameters today ....
I realize that MessageFormat is limited to 6 parameters!
What can I do? Is there an alternative to MessageFormat? or the only solution is to put each email line in properties ( and hope not to have more than 6 per line parameters !)
Thanks,
Christophe.
Use a templating library. Freemarker for example.
since you've tagged this as 'spring' you could use the Apache Velocity templating engine (VelocityEngineFactoryBean), wire it into your class as a VelocityEngine.
You could then use VelocityEngineUtils.mergeTemplateIntoString() passing the name of the template file (stored in your classpath)
This question already has answers here:
How do I preserve the existing query string in a mod_rewrite rule
(2 answers)
Closed 8 years ago.
We are trying to redirect bin-ends2 to wines.jsp with a number of parameters passed over to the application server. Apache is stripping the parameters off and so the application server fdoes not know what yo put in the page. The Apache config is:
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [PT]
Does anyone know how to make this work?
You need to add QSA flag to your rule when you introduce new query string parameters and would like to preserve (better say, include) existing query string.
Your rule should be
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [QSA,PT]
Useful link: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa