Request based routing by header parameter values in Rest DSL in camel - apache-camel

I want to route the messages to different routes based on the data coming in header parameters.
rest()
.tag("API")
.id("eventRest")
.post("/data").description("Post a new settlement data record")
.consumes("application/json")
.param().type(RestParamType.header).name("channelID").endParam().to("direct:customRoute")
Here If I've the different param then this one should bypass and continue the rest of the flow in my program.

Related

How to accept multiple attachment along with other string data in spring boot rest endpoint(post) using #ModelAttribute?

I have a RestController which is supposed to accept json data from front end. The data contains userId and mutilple files. From front end(reactjs) I am sending as shown in the image below but not able to receive at the controller.
My controller method is here:
Here is my EnrolmentDto class:
Anyone help me please.

Why using parameters of React Router instead of passing them through?

What is the purpose of passing data through parameters on the Route using react-router?
let's take an example of a chat in which on the left you have a list of chats and on the right you show the chat that the user has selected. Many website (Instagram for example) would pass the id of the chat as a parameter of the url.
My question is: as you probably have the id of the chat you want to get the data from, what is the purpose of passing it as a parameter to the URL instead of just call a function that fetches the data of that chat directly?
One reason is that if you reload the page you will lose in which conversation you were and instead of remaining in the same conversation you will get an error or start from "state 0", also if you want to share the URL or bookmark it to go to that exact conversation, you will need the parameter in the URL

URL with parameter containing a list of values in `toD` gets collapsed into a single value

I have a Camel route which calls a web service, and one of the parameters this service expects is a URL parameter containing a list of values, ie. p1 in myhost/myuri?p1=foo&p1=bar.
I am putting that in a toD URI, as the parameter values need to be dynamic, ie. <camel:toD uri="http4://myhost/myuri?p1=foo&p1=bar" > (omitted Camel parameters and variables for brevity's sake).
Camel is converting this to p1=%5Bfoo%2C+bar%5D (url-encoded p1=[foo, bar]), which is not accepted by the backend service. I have no control over this backend service and cannot expect its interface to change in the future.
Is there any way I can force Camel to call the backend service the way I want to, instead of it collecting the parameter with multiple values into an array-like format?
Another approach would be to use CamelHttpQuery header to along with to, not toD endpoint
<setHeader headerName="CamelHttpQuery"><simple>p1=foo&p1=bar</simple></setHeader>
<to uri="http4://myhost/myuri">

Playframework forwarding json values to a form

I am new to Playframework and AngularJS and developing an application in AngularJS on the front end and Playframework on the back end.
I am facing one scenario: when the user clicks a menu link (Show students), it should show all the students. In the play action, the data is sent as json. Now the problem is if the data is sent as Json, then I don't see the option for which page it should forward to.
Alternatively, I have to use the normal playframework style like forwarding to page with list of values.
//This is the current playframework code I use. Here I set the values to students form
// This is not the way I want
public static Result getAllEmployees(){
List<Student> all = Student.find.all();
JsonNode json = Json.toJson(all);
return ok(views.html.students.render(all));
}
//This is the way I want
public static Result getAllEmployees(){
List<Student> all = Student.find.all();
JsonNode json = Json.toJson(all);
return ok(json); // no option for specifying the page.
}
Is there anyway to do it?
They are both valid approaches to returning data, but the first returns a whole html page, for example in response to a #routes.Employees.getAllEmployees reference in your view. The second one returns just a Json content type response, for example in response to a Javascript request or AngularJS $http.get. The methods need to have different names (they can't both be called getAllEmployees). Both of them will have entries in the routes file. They will be different entries the way you have written them, so perhaps something like:
GET /employee controllers.Employees.getAllEmployees
GET /api/employee controllers.Employees.apiGetAllEmployees
(Disclaimer: I haven't done this in AngularJS yet, but the principle should be similar.)

Grab a variable from the URL and then pass it to a controller CakePHP 2.0

I'm trying to build a sort of Wordpress-esque CMS system to a project I'm building. I want the user to be able to create pages on the fly, and for them to appear in certain areas of the website.
I have made something similar in Symfony2, where the controller grabs a specific variable from the URL (as definded in the route.yml file, usually $id etc) and I then use the variable in the controller to display whatever content it relates to in the database.
However, I'm not used to CakePHP 2.0, and struggling to find what I need. I know it's possible, but I don't know the best way to achieve it. Especially as CakePHP uses a different routes file than Symfony.
How would I grab a variable from the URL and pass it for use inside a controller?
By variable do you mean GET query string parameters, like in /foo?key=value? You can access them in the controller through the request object: $this->request->query['key'].
If you are looking for something more integrated you can use CakePHP's default routes or make your own.
The default routes work with URLs like /controller/action/param1/param2 and pass the parameters to the action by position. For instance /posts/view/521 maps to a call to view(521) in PostsController, and /posts/byMonth/2012/02 maps to a call to byMonth("2012","02").
You can also use named parameters and the URLs look like /controller/action/key1:value1/key2:value2. In controller actions you would read them with $this->params['named']['key1'].
With custom routes you can make your URLs anything you want. You're not forced to the /controller/action pattern; you can make /archives/2012-02 map to PostsController::byMonth(2012,2), or have /512-post-title map to PostsController::view(512).
Typically you would start out with the default routes and add custom routes when you decide you need them. You can read all about the default and custom routes in http://book.cakephp.org/2.0/en/development/routing.html
Short answer: it depends.
If you're looking to pass parameters to a function, you don't need to mess with routes at all; every non-named URL path segment is processed in order and handed to the action as method parameters (so /controller/action/1234 passes "1234" as the first parameter to the action method in the controller controller class).
Named parameters allow you to pass parameters anywhere in the URL string, and to make them optional. The form is just key:value and they're accessed via $this->params['named'] in the controller.
The last option is prefix routing. The best place to get to speed on that is naturally the CakePHP Cookbook, but the general gist is that in a route definition, you can name a path component in the URL by prefixing it with a colon, identically to how the default routes show :controller, :plugin and :action. You can define any name you like, even optionally applying regex pattern requirements and then access it through $this->params['variablename'] in the controller.

Resources