OVerride a url mapping defined in a controller present in a jar - spring-mvc

I am using spring-security-oauth2 jar file. During the oauth verification process it makes a call to "/oauth/token" and hence the method. I want to modify the method..
Is it possible if i can override the url mapping already present? or exlcude the class from jar..
Thanks
Harshit

Related

Prestashop : Decorate a module's service from another module

I want to use the module ps_facebook to send a catalog to Facebook but I need to change the name of the product sent.
I already sought and I found that's the module ps_eventbus that manages to load and decorate datas.
Unfortunately there is no hook. My only possibility is to rewrite a part of this service.
This service is loaded by the module ps_eventbus in the file decorate.yml and I want to change the call of this service by our specific service in our module.
So I wonder if it's possible to override properly the service PrestaShop\Module\PsEventbus\Decorator\ProductDecorator and how to do that ?
I suggest you check the Symfony documentation, here
https://symfony.com/doc/3.4/service_container/service_decoration.html
As it is not directly related to the PrestaShop itself. If this service is public, you can probably decorate it, as shown in the docs.

Get defined Route from Dto

I've created a basic Dto Hit tracker that counts how many times a ServiceStack API is requested. What I'm trying to get now is the Route that was defined for the current Dto in the ServiceBase using Routes.Add. I can get current Url from the HttpContext, however that one is already populated with data. E.g
//Defined Route
/customers/{CustomerID}/orders
//From HttpContext
/customers/123456/orders
Is there way to get the defined route with the parameter {CustomerID} still there?
You can get the Route for the Request with IRequest.GetRoute().
Also if you want to create a Request DTO from a path or URL you can use Metadata.CreateRequestFromUrl() added in the latest v5.1 Release Notes.

Symfony redirect to dynamic route name

I'm using the Symfony CMF Routing Bundle to create dynamic routes (I'm using one example here):
$route = new Route('/dynamic-url');
$route->setMethods("GET");
$route->setDefault('_controller', 'AppBundle:MyRoute:getResponse');
$routeCollection->add('my-dynamic-route', $route);
The response is loaded from the getResponseAction() function inside the MyRouteController:
/**
* No annotations here, because I want the url to be dynamic from the database
*/
public function getResponseAction(Request $request) {
return $this->render('dynamic-page-template.html.twig');
}
When I go to '/dynamic-url', it works.
When in another controller, I want to redirect to this dynamic route, like this:
return $this->redirectToRoute('my-dynamic-route');
But I get this error: "None of the chained routers were able to generate route: Route 'my-dynamic-route' not found"
Also interesting: when I go to '/dynamic-url', the dev bar actually says that the Route name is 'my-dynamic-route'.
Edit
When I load all the routes, I don't see my dynamic route names:
$this->get('router')->getRouteCollection();
I think they should be in this list.
Since it's a dynamic route, which wasn't saved anywhere (like routing.yml ) it will be only availabe for Request where it has been defined. So at the end of Request your app will immediately "forget" about new Route generated at runtime.
When I load all the routes, I don't see my dynamic route names:
$this->get('router')->getRouteCollection();
I think they should be in this list.
Actualy No. It depends on where you call $this->get('router')->getRouteCollection();
Just try to call
dump($this->get('router')->getRouteCollection();)
right before the return statement in your Action where you're adding the my-dynamic-route route. I'm sure you'll see your my-dynamic-route in the list of routes, but if you call it anywhere else - you won't see it.
It's less about symfony rather about stateless nature of web (see Why say that HTTP is a stateless protocol?)
I started to think about this and pointed your question to an routing issue on symfony-cmf. You tagged with #symfony-cmf and i think this would be important feature for us.
I also think, when you persist your route with /my-route you should also ask the router for that name (or in case of the CMF with an content object with that a route.)
If you use the CmfRoutingBundle dynamic router, you should persist your routes to doctrine. The idea of dynamic here is that they can be created at runtime, e.g. in an admin interface or elsewhere by code. The DynamicRouter loads routes from the database.
If you use PHPCR-ODM, the route name is the repository id, typically something like /cms/routes/my-route and you can generate it with that name. If you have access to the route object loaded from the database, you can also generate from that, rather than the path. If you have to hardcode a path in your application, its an indication that probably a normally configured route would be better.
If you just add a route to the route collection on the fly, you would have to make sure that happens in each request, its only available when you add it. With the CMF ChainRouter you could register your own router that does that, but i would not know of a good use case for that. Either you know the route, then you can configure it in the routing.xml|yml|php config file. Or routes are loaded dynamically, in which point you should use DynamicRouter, potentially with a custom route loader.

Programmatically register routes at runtime

I want to be able to annotate some of my controllers with #SomethingProvider so that they automatically serve POST /{original-resource-url}/something URL and tie this URL to a generic handler.
Using a controller with wildcard mapping would not work because not all the resources will have that "something" collection available. Ex:
POST /user/something
POST /product/something
etc.
but not
POST /anything/something
My idea is to scan my controllers at runtime and look for that #SomethingProvider annotation so I can programmatically register the additional "something" endpoints.
I know it has to do with RequestMappingHandlerMapping but I can't figure out how to tap into it to add mappings.
Thanks geniuses

URLs for e-mailing in ASP.NET MVC

How would I generate a proper URL for an MVC application to be included in an e-mail?
This is for my registration system which is separate from my controller/action. Basically, I want to send an email verification to fire an Action on a Controller. I don't want to hardcode the URL in, I would want something like the Url property on the Views.
In your Controller, the UrlHelper is just called "Url" - so:
void Index() {
string s = this.Url.Action("Index", "Controller");
}
The "this" is unnecessary, but it tells you where this Url variable comes from
I used:
Html.BuildUrlFromExpression<AccountController>(c=>c.Confirm(Model.confirmedGUID.Value))
It is part of the HTMLHelper (I think in the MVC Futures) so you may have to pass an instance of the HTMLHelper to your service layer, not sure. I use this directly in my view which renders to an email. That gives you the absolute URL and then I store the domain (http://www.mysite.com) in the config file and append it before the URL.
You should probably make the URL part of the configuration of your application.
I know you can do stuff with e.g. the Server property on your web application, but the application will never know if its IP or domain name is reachable from the outside as it might be hidden behind a proxy or a load balancer.
If I'm reading the question correctly, you need to controller/action outside the MVC code. If so, you will need to simply configure the URL in Application Configuration or some such place, unless you have access to the controller classes and use reflection to get the names.

Resources