ScalaTra - how we do internal call forwarding / forwarding

I want to call another internal url from my scalatra controller. I cannot do a simple redirect, as there are some security settings that mean that the user has access only to the first URL.

Is there any way to do this?

+6
source share
2 answers
get("/foo") { servletContext.getRequestDispatcher("/bar").forward(request, response) } 
+3
source

The get () method is defined as (similar to POST, etc.):

 def get(transformers : org.scalatra.RouteTransformer*)(action : => scala.Any) : org.scalatra.Route 

Depending on what you mean by internal redirection, I assume that you just want to perform a different route action. You have several options for what you can do. This seems to work for me:

 val canonicalEndpoint = get("/first/route") { //do things in here } 

Then you could do the following:

 get("/second/route")( canonicalEndpoint.action ) 

And I think you will get the desired answer.

I like to keep the entire get () route response as you can also use it with the scalatra url () function in routing.

+1
source

Source: https://habr.com/ru/post/893332/


All Articles