playframe work can't find the right route - java

I have a strange problem
this is what I have in routes files
GET /path/list controllers.path.getPaths()
GET /path/:id controllers.path.get(id:Int)
when I try to go <domain>/path/list the following error shows up:
For request 'GET /path/list' [Cannot parse parameter id as Int: For
input string: "list"]
I also tried to change the order in routes file
GET /path/:id controllers.path.get(id:Int)
GET /path/list controllers.path.getPaths()
I still get the same error. so my question is
isn't route supposed to match the first path that matches?
what else could be the problem (e.g. java codes)?

From the code you've provided this should work. The routes are not ambiguous because (from Play documentation):
Many routes can match the same request. If there is a conflict, the first route (in declaration order) is used.
if your routes ordering looks like this:
GET /path/list controllers.path.getPaths()
GET /path/:id controllers.path.get(id:Int)
/path/list will match before attempting to extract/transform the id parameter id:Int from the path and throwing.
If you want Play to transform the incoming parameter into a specific Scala type, you can add an explicit type
The only way this would not work is if you attempted to visit a route that did not match list or was not an Int:
For request 'GET /path/lists' [Cannot parse parameter id as Int: For input string: "lists"]

Related

Camel: Skipping multiple header lines in Fixed Length File returns iterator object reference

To Preface this question is exactly what i'm looking for. The only difference is i'm using a fixed Length file.
My problem is using this method I seem to get a Iterator Object returned and not the file with the 3 lined header removed.
The Camel route should consume a .txt file, remove the first 3 lines and then send the result to a file endpoint.
I have tried different variations of the simple language to no avail. I can't find any specific case in the book, documentation or online.
See my Camel Route Below
from(inputFilePath).routeId("MyRoute")
.streamCaching()
.threads(threadPoolSize)
.log("${headers.CamelFileName}: Unmarshalling to Java POJO")
.log("${body} Body Before Transform")
.convertBodyTo(String.class)
.transform().simple("skip(3)")
.log("${body} Body After Transform")
.to(outputFilePath)
Im Expecting for a .txt file to be returned with the first 3 lines removed and the rest of the structure to not be changed.
Instead I get a reference to a iterator Object -->
2019-06-19 14:55:30.497 INFO 2868 --- [ad #2 - Threads] MyRoute : org.apache.camel.util.SkipIterator#4d894ea5 Body After Transform
Any help or suggestions would be greatly appreciated!
Simple function skip(n) is intended to skip n items in List, but your body is String.
You need to get List<String> of lines (Tokenize language) in order to use it.
To join this list back to String you can use eg Bean EIP to call org.apache.commons.lang3.StringUtils.
from(inputFilePath)
.transform(body().tokenize("\n"))
.transform(simple("${skip(3)}"))
.bean(StringUtils.class, "join(${body}, '\n')")
.to(outputFilePath);

Combining a parameter host name with literal url in Thymeleaf

I'm trying to get Thymeleaf to build me a URL where the domain part is a parameter, some fragment is a literal string, and the query parameters are also parameterized.
The documentation offers some examples:
#{${myDomain}/literalUrl}
#{${myDomain}'/literalUrl'}
#{/literalUrl(query=${queryValue})}
#{'/literalUrl'(query=${queryValue})}
#{${myDomain}(query=${queryValue})}
or even
<a th:with="baseUrl=${myDomain}" th:href="#{${baseUrl}}(query=${queryValue})}">
Separately, all of these work well. But if I try to combine them, the domain part suddenly refuses to resolve:
#{${myDomain}/literalUrl(query=${queryValue})} and #{${myDomain}+'/literalUrl'+(query=${queryValue})} each resolve to ${myDomain}/literalUrl?query=queryValue, and
How do I get Thymeleaf to properly generate my url https://example.com/literalUrl?query=queryValue
Don't know if this is a legit solution for your problem, but if you concat the literalUrl with the first parameter, it will work. Down side: you need an additional model parameter.
<a th:href="#{${linkData+path}(q=${queryParam})}">some link</a>
gets
some link
with model params:
mv.addObject("linkData", "https://example.com");
mv.addObject("path", "/literalUrl");
mv.addObject("queryParam", "queryValue");

Using regex to find chars in a string and replace

When returning a string value from an incoming request in my network based app, I have a string like this
'post http://a.com\r\nHost: a.com\r\n'
Issue is that the host is always changing so I need to replace it with my defined host. To accomplish that I tried using regex but am stuck trying to find the 'host:a.com' chars in the string and replacing it with a defined valued.
I tried using this example www.javamex.com/tutorials/regular_expressions/search_replace_loop.shtml#.VUWvt541jqB changing the pattern compile to :([\\d]+) but it still remains unchanged.
My goal is to replace given chars in a string with a defined value and returning the new string with the defined value.
Any pointers?
EDIT:
Sample of a typical incoming request:
Post http://example.com\r\nHost: example.com\r\nConnection: close\r\n
Another incoming request might take this form:
GET http://example2.net\r\nContent-Length: 2\r\nConnection: close\r\nHost: example2.net\r\n
I want to replace it to this forms
Post http://example.com\r\nHost: mycustomhostvalue.com\r\nConnection: close\r\n
GET http://example2.net\r\nContent-Length: 2\r\nConnection: close\r\nHost: mycustomhostvalue.com\r\n
Use a regex to replace it, like this:
content = content.replaceAll("Host:\\s*(\\w)*\\.\\w*", "Host: newhost.com")
This will replace anything after Host: with newHost.com.
Note: as per comment by cfqueryparam, you may want to usea regex like this to cover .co.uk and such:
Host:\\s*.*?(?=\\\\r\\\\n)

Java Play 2.3 Match any route which starts with certain string

is there a way to match only a part from a route.
I need a route definition which should match the following routes
/route
/route/part1
...
The part after "/route" is dynamic and variable. Every route which starts with "/route" should be matched.
My try:
GET /route/<[a-z]+> controllers.Assets.at(path="/public/web", file="static.html")
Error: Action not found For request 'GET /route/home'
GET /route/*file controllers.Assets.at(path="/public/web", file="static.html")
Error: It is not allowed to specify a fixed or default value for parameter: 'file' extracted from the path
Rename and move /public/web/static.html to /app/views/staticFile.scala.html
Change the route to
GET /route/*path controllers.Application.staticFile(path: String)
Add the method to /app/controllers/Application.java
public static Result staticFile(String path) {
return ok(views.html.staticFile.render());
}

From Header Parameter Tag in SipSessionKey is `null`

I'm working on an application, where the SIPSession generated by Mobicents has one of it's attribute coming as null. After digging through the source code, I found out that, the value returned from the SipSession#getId() method is nothing but the SessionKey.
The SessionKey internally uses 4 different parameters to generate the String representation of the key. Out of that, one of the attribute is: fromTag. You can look at the source code of SipSessionKey here. Now, I'm unable to understand, what exactly is that fromTag. When I saw the request which is being sent, there is definitely a vlaue in the From header of the SipRequest. The From header is in the form:
From: <tel:+xxxxxxxxx>
That's it. What is fromTag in there? Why I'm getting it as null?
According to section 8.1.1.3 of RFC 3261, the From header MUST have a tag parameter. This is one of the pieces of data used to identify the dialog. (The others are Call-ID and the tag on the To header, generated by the UAS.) One the examples shown in the RFC is:
From: sip:+12125551212#phone2net.com;tag=887s
When looking at the SIP message received by the Mobicents container, is there a tag parameter on the From header?

Categories

Resources