Recursive/Exploded uri variable with restlet - restlet

Does Restlet support exploded path variable (reference to URI Template RFC)?
An example would be /documents{/path*} where path can be for example "a/b/c/d/e".
This syntax doesn't seem to work with Restlet.
I'm creating a folder navigation api and I can have variable path depth, but I'm trying to have only one resource on the server side to handle all the calls. Is this something I can do with Restlet? I suppose I could create a custom router but if there is another way to do this I would like to know.
Thanks

It is possible to support this using matching modes.
For example:
myRouter.attach("/documents{path}",
MyResource.class).setMatchingMode(Template.START_WITH);
Hope this helps!

I'm doing the following
myRouter.attach("/documents/{path}", MyResource.class).setMatchingMode(Template.START_WITH);
Now I do get inside the resource GET method, but if I request the value of the path variable, I only get the first part (for example, /documents/a/b/c, path returns "a".) I use getRequest().getAttributes().get("path") to retrieve the value. Am I doing something wrong ?
Mathieu

Related

Minecraft Spigot I cannot get String from Component

Hello Support I can't get the String from a Component. I did this with 2 ways with bad results.
TextComponent textComponent = (TextComponent) item.displayname;
return textComponent.content();
The result of this is a error with Casting
and
return PlainTextComponentSerializer.plainText().serialize(item.displayname);
The result of this is Literaly "chat.square_brackets" which is weird.
Please Help. Thanks
I also was having trouble with this. Here's what I found to work for me. Full disclosure that I'm developing my plugin on the PaperMC 1.16 fork and not Spigot. So it's possible that this may not work for you, either because it isn't a part of Spigot or because you are working in a version that this feature is not a part of.
To start, I would first check to make sure that we are both on the same page. For me, the component objects being used are from a package called net.kyori.adventure.text if yours are not provided by this package I don't know that this solution will work for you.
Also as mentioned by others, accessing the displayName directly on the ItemStack isn't going to give the desired results. Instead, you need to do itemStack.getItemMeta().displayName(). This method should then return a net.kyori.adventure.text.Component; once you have the component you need to serialize it using one of the serializers from the previously mentioned package.
That will look something like this:
Component itemDisplayName = itemStack.getItemMeta().displayName()
PlainComponentSerializer plainSerializer = PlainComponentSerializer.plain();
String itemName = plainSerializer.serialize(itemDisplayName);
The package that the serializer is from is: net.kyori.adventure.text.serializer.plain.PlainComponentSerializer
I don't understand how you can access to the displayname field in ItemStack in the Spigot API.
You should use ItemMeta to manage display name. To get the item meta, you should use ItemStack#getItemMeta.
Don't forget to check if the item as a meta with hasItemMeta. You can also use hasDisplayName to be sure that the display name is valid.

How to pass the default language to the Registration page?

Is there a way to pass a specific UI language to the registration page? This is coming from the website and I want it to be the defaut option.
you can send the culture with these headers
c=...
uic=...
https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Localization/AbpLocalizationHeaderRequestCultureProvider.cs#L12
and for MVC use culture parameter like below
/register?culture=tr
must be the first parameter of the query string
and last option; you can always override AbpUserRequestCultureProvider
https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Localization/AbpUserRequestCultureProvider.cs
UPDATE:
According to the implementation it accepts query string parameters as culture like below
?culture=es-MX&ui-culture=es-MX
See https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2103
If you look at the request headers sent by the browser, it includes "Accept-Language". It can look something like this:
en-US,en;q=0.9,es-419;q=0.8,es;q=0.7
Generally, the preference runs in descending order, so here, the browser is saying it prefers U.S. english before anything else. More here about what the q values mean: What is q=0.5 in Accept* HTTP headers?
You can access this value through in the controller.
Request.Headers["Accept-Language"]

Dynamically generate url for HTTP source

I'm trying to call a http endpoint. For that I need to specify a url that uses a query string to filter data.
Sample URL: http://example.com?date=2017-10-04T22:18.007Z
I need to use the current system time as a value for date query string.
I created a script and assigned the generated url with the current datetime to a variable. However, when I assigned that variable for the url field in the source HTTP definition, it did not resolve the variable.
Is there a way to solve this issue?
I do this all the time. As long as your script is running properly (you can test that with the test feature on the script), you are writing the URL value to a global variable (something like $URL), and you are writing that global variable out in your target (something like [URL]), it should work.
If you want to show your script (just where you are creating the URL), and your target URL field that could help narrow down the problem.

Play framework: Dynamic routing depending on version number

I'm trying to dynamically define a version in the URI routing.
My immidiate ideas were to
a)
I've configured in the application.conf a row stating my current version:
myApp.ver = 0.1
I wan't to use it in the routes file as part of the URI, for example:
GET /myApp/{version}/welcome controller.myApp.Welcome()
The idea is not to pass the version number to the Welcome() method
but to get the version from the application.conf file.
I've searched for defining parameters in the route file but didn't find information that helped me.
b) Another idea was to have a variable in the routes, something like:
CurrentVersion = 0.1
in the routes file and use it in the URI.
How can I solve this? I havn't found an example for this.
Thanks.
If you want to do this for every route, it should be possible to set the application.baseUrl to include your version number. To do this conveniently you can define the version in your application.conf instead of the Build.scala file, as described here.
myApp.name = myApp
myApp.ver = 0.1
application.baseUrl = ${myApp.name}/${myApp.ver}
If you want to do it only for some routes, there doesn't seem to be a simple solution. If you could ignore parameters in routes, I'd say use a regexp parameter and verify it in your global router - unfortunately this doesn't seem possible without passing the parameter to the controller.
So I see two other options:
Hardcode the version number in the routes file and do a search and replace every time it changes.
Create a plugin for the sbt build process and let it replace the version in your routes file.
In Play 1.2.x, in your conf/routes file, add a route like this:
GET /myApp/${play.configuration.getProperty("myApp.ver")}/welcome myApp.Welcome()

How do I get only the query string in a Rails route?

I am using a route like this
match "/v1/:method" => "v1#index"
My intention here is capture the name of the api method and then send the request to that method inside the controller.
def index
self.send params[:method], params
end
I figured this would send the other parameters as an argument to the method, but it didn't work. So my question is how can I pass the non-method parameters in a query string?
#query_parameters does exactly what you want:
request.query_parameters
It's also the most efficient solution since it doesn't construct a new hash, like the other ones do.
Stolen from the work of a colleague. I find this a slightly more robust solution, since it will work even if there are changes to the path parameters:
params.except(*request.path_parameters.keys)
I sort of solved this problem by doing this:
params.except("method","action","controller")