Get URL parameter from request - eclipse-scout

how to get URL parameter from HttpServletRequest class, or on another way in FormBasedAccessController?
If I have url: http://example.com/&idcompany=13
I want to access idcompany variable in URL.
Thanks.

Related

How to get actual request URL in routed service when using Zuul service and Spring boot?

I am using zuul service as API gateway for all my micro services.
In zuul filter, I am able to get the requestUrl like below:
import javax.servlet.http.HttpServletRequest;
import com.netflix.zuul.context.RequestContext;
.....
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
String requestUrl = request.getRequestURL();
Here requestUrl: http://localhost:8052/api/userservice/users
In user service, when I am trying to get the request URL in spring boot rest controller using HttpServletRequest:
String requestUrl = request.getRequestURL();
Here requestUrl: http://localhost:8055/userservice/users
I am getting the routed service request url but NOT actual URL which client requested.
How to get actual request URL in routed service ?
You are getting the routed service because when you call the getRequestURL method after the request url has been modified. Calling the same method in a pre filter which order is -50(for example), you can get the actual URL zuul server received.
So far I don't find any method to get the actual URL in a route/post filter after the request is modified, I think one way to solve this problem is define a pre filter to get the actual URL before modified, and put the url into a Threadlocal field, then you can get the url in the route/post filter by accessing the field.
Zuul creates a new Http Request to user service. obviously with different URL.
So in the user service its impossible to get access to original request by design.
Zuul is supposed to encapsulate an original request, not reveal it.
All headers, request parameters, request body should be preserved, it's only a path to be changed.
If for some reason there is a need to get parameters from original request, in Zuul filter they can be extracted and set as Headers to the "new" request before it's sent to user service.
Then in UserService there should also be a filter that will "read" these headers and use the information as required

Spring MVC - get address from request

This is my case, set by step:
Run below page under address:
localhost:8080/user/data/expenses
On this page click link
localhost:8080/user/data/change_button/9_2015
Now my controller is started:
My question:
How can I get information from what side was call my controller. I need exactly this information which is strong below:
localhost:8080 /user/data/expenses
M-Z
Infact there is way to get the referer of the request as it is part of the HTTP header. Just inject HttpServletRequest to the mapped method then get the header named "referer".
request.getHeader("referer");
You need to inject the HttpServletRequest and then use getRequestURI() to get the data. Read the javadoc for #RequestMapping.

How can I set my parameters when I am doing a post?

I have this method:
[HttpPost]
[Route("Post")]
public async Task<IHttpActionResult> Post(int adminTestId)
I am sending the following but it's giving me an error:
POST /api/UserTest/Post
body {"adminTestId":1197}
Can someone tell me how I can set the parameter to the method so it will accept adminTestId?
Here is the message that I am getting:
{"message":"No HTTP resource was found that matches the request URI 'http://localhost:3048/api/UserTest/Post'.","messageDetail":"No action was found on the controller 'UserTest' that matches the request."}
I believe you are setting the incorrect route:
[Route("UsetTest/Post")]
This is assuming api/ is the correct prefix.
In Web API, requests are mapped to actions based on HTTP verbs.
Therefore, you should not include Post in your URL which defeats the purpose of using Web API and violate REST rules.
Post Json
If you want to post json, you want to bind to a model.
Post Integer
If you just want to accept an single integer value, you just post an integer instead of json.

redirect to another url

I'm doing redirection in my servlets but the url is always the same and my post and gat parameters doesn't disappear
RequestDispatcher dispatcher = request.getRequestDispatcher("/");
dispatcher.forward(request, response);
In this exemple the url will not change, but the fetch page will be "/"
And my post and get are not destroyed.
I'm trying to find a real redirection as
header("location:/");
in PHP.
Use sendRedirect() to do a true redirection instead of internal dispatch.
response.sendRedirect("/");
Address bar url reflects the change
Done through the client browser (using location: header)
New request object is created (previous get/post parameters are destroyed)

Url Not Working in My Webservice

I am calling webservice which takes two parameters like category and salt then provide the json output with constructed url but url is not working. PFA url
Service Url:
http://qalisting.corelogic.com/ChaseListingServices/v1.5/test
constructed URL: http://qalisting.corelogic.com/ChaseListingServices/v1.5/listings/search/test/0/4e9c00b32794edfeba257aa0c74f500b
Looking at the error message on your constructed URL, the Service needs to be called using a POST and not a GET Request.
Responding to your comments: it's not the URL which is the problem but how it is called. When you follow a link, such as the one you posted - the browser sends it as a GET request. The service is expecting the JSON arguments as part of the "body" of a POST request. This must be done programmatically.

Resources