How to get OriginalRequest from HTTP Request in ServerWebExchange - spring

I am using Spring Cloud Gateway, and am trying to figure out how to get the "OriginalRequest" from the ServerWebExchange Request (so that I can use the URI).
I can see the OriginalRequest in the IntelliJ debugger (please see screenshot below). The issue that I am having is that it does not appear to be a public field (please see the last screenshot).
Do you know how I can access the OriginalRequest? Thanks a lot!

I was able to get the URI for the OriginalRequest from the ServerWebExchange by doing the following:
serverWebExchange.getAttribute<LinkedHashSet<URI?>?>(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR)?.firstOrNull()
Credit to this Gist for showing me how to get it in Java:
LinkedHashSet<URI> attr = serverWebExchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR);

Related

Http Post request in Microsoft Bot Composer

I have tried below but http request got fails is there I missing something can anyone guide me please. In postman by using qnaId in the body I am getting the correspond queastion and answer in json response. The same I have tried in composer with Http request but it fails.
{
"qnaId" : "1164"
}
enter image description here
enter image description here
The same I tried in Postman and successfully got the response.
enter image description here
Thanks....
I think the issue is that $Qna is not a valid memory variable. Per documentation, you need to set this in either conversation, dialog, turn or user scopes. I had missed the section in the post here where the response was being set to $Qna. That's not valid. So, it needs something like turn.Qna or dialog.Qna.
Additionally, the use of $ should be used only for string interpolation, not in setting the variable name. turn.Qna would set it and you would utilize it in a string as: "You said: ${turn.Qna}"

django-rest-auth throws error with URL versioning

Using Django Rest Auth for authentication in my DRF based app. Issue is, the logout URL does not work when I add URL versioning.
Calling: /v1/rest-auth/logout/ (POST)
Throws error: TypeError: post() got an unexpected keyword argument 'version'
urls.py:
URL_VERSION = r'^(?P<version>v[1])'
url(f'{URL_VERSION}/rest-auth/', include('rest_auth.urls'))
Other end-points e.g. login via /v1/rest-auth/login/ works okay with and without the URL_VERSION.
What could I be missing?
This issue was fixed recently.
https://github.com/Tivix/django-rest-auth/pull/373
The new version will be on pypi very shortly. Please pull the master branch version for now if possible.

406 Not Acceptable: Spring 3.2 + JSON + AJAX

Searched tons of sites and even stackoverflow but have not found a solution to this problem. Looks like lot of people have encountered this problem but its seems a unified solution is missing that encompasses all the aspect. Have already spent 1.5 days on it.
I see the method is getting invoked but somewhere #ResponseBody is not getting translated properly. Can someone take a look and let me know what the problem is. I have Uploaded the code on github. Link to source code on github
#RequestMapping(value = "/find_user", method = RequestMethod.GET)
public #ResponseBody List<String> findUser(#RequestParam("term") String name) {
log.info("Search string for user name: " + name);
List<String> users = new ArrayList<String>();
users.add("Sam");
users.add("Dan");
return users;
}
Browser screen shot below with 406 response
Please note: Ah! How painful. This setup works with Spring 3.1.4 and not with 3.2.X
God, it almost kills me. I tried whatever I can, still stuck there. But finally I figured it out. The reason is Spring, download Spring 3.1.1 and replace all the jars with 3.1.1jars, and it works. All your config is good.
I also faced up with a same problem. After debugging Spring I found that ServletPathExtensionContentNegotiationStrategy tries to determine media type based on an extension in the URL. (Probably, because it cannot deduce what media type it should return from Accept header which contained */* in my case.)
So, one of the way to fix this is to rename URL in mapping by replacing .html by .json.

Grails Ajax Login

I want to take use of the ajax login feature of the spring security plugin.
I am completely stuck getting a JSON success response from the loginController into my GWT client.
As I understood from the documentation I need to post my params to the url /j_spring_security_check and spring security is redirecting me to the right action.
If I look into my LoginController I see nothing of the actual login logic and its a bit magic for me where all the login/db stuff is done. Further spring security always redirects to action auth instead of using AjaxAuth even if I add the header "X-Requested-With" to post. If I do my post to the url /login/ajaxAuth I am getting a 401 which is OK because its written down in the controller(even if i dont know why we need to return a 401 here). Maybe I am doing something completely wrong :-)
My basic questions are:
Where can I find the login logic?
What parameter do I have to provide?
Which URL do I have to use?
What do I have to do if I dont want to use the username but instead and email field?
Thanks for all your help!
Looks like you're correctly implemented it, maybe there some small bug, like a typo.
Btw:
It's implemented at filter, that process your request before actual controllers. At your case it will be UsernamePasswordAuthenticationFilter (or RequestHolderAuthenticationFilter). Controller is used there only to render an additional data. As for ajax auth, it uses /login/ajaxSuccess, that renders a JSON response
By default it uses j_username & j_password. And you can use ajax=true parameter, instead of X-Request-With header
/j_spring_security_check by default
You can implement your own GrailsUserDetailsService (or extend GormUserDetailsService), and setup it as a spring bean, with name userDetailsService, at resources.xml
You can also turn on logging for Spring Security by:
log4j {
debug 'org.codehaus.groovy.grails.plugins.springsecurity',
'org.springframework.security'
}
maybe it will be helpful
I am using Grails 2.1.1 and ran into this same issue. Tried all the above things but still couldnt get my AJAX login to call the ajaxSuccess method.
However when it failed it was calling authFail?ajax=true.
After digging in more, here is what I did:
Added grails.plugins.springsecurity.successHandler.targetUrlParameter = 'ajaxUrl' in my Config.groovy
Added <input type="hidden" name="ajaxUrl" value="/login/ajaxSuccess" /> in my AJAX login form
Not sure why it fixed, but it seemed to work for me.
Just posting this solution for users who get stuck and come to this ticket for solution.

WebDAV query for Exchange

I am trying to read a public calendar (in public folders) in my Exchange server.
I am sending the following query to my Exchange server, and the server replies with 400 - Bad Request.
<?xml version=""1.0""?>
<g:searchrequest xmlns:g=""DAV:"">
<g:sql>
SELECT
""urn:schemas:httpmail:subject"",
""urn:schemas:calendar:location"",
""urn:schemas:calendar:dtstart"",
""urn:schemas:calendar:dtend""
FROM
Scope('SHALLOW TRAVERSAL OF ""https://server/public/SomeFolder/SomeCalendar/""')
</g:sql>
</g:searchrequest>
Now that same query works with this store URL:
https://server/exchange/username/calendar/
So I know that's the URL that is wrong in the query.
If I paste the problematic URL in my web browser, it will come up with the calendar, so the URL does seem fine though.
Any help appreciated.
Thanks
Xavier
Try
https://server/public/SomeFolder/SomeCalendar/?cmd=contents
Thanks SillyMonkey for your input.
Your URL returned the same error but I have found out the problem was with the endpoint I was connecting to to submit the query.
I was posting the query to this URI:
string uri = string.Format("{0}/exchange/{1}", server, credentials.UserName);
and now changed it to:
string uri = string.Format("{0}/public", server);
I am a bit surprised that I have to use different endpoints depending whether I am querying the user's mailbox or the public folders, but it seems to be the way it is.

Resources