• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Remote address not updated when sending request from one endpoint to other endpoint.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am having trouble solving the following problem. Hopefully, someone can help me solve it.

I have a java app in server (https://server1.com). The IP address of the app hosted in server1 is (200.200.200.200). The app has two endpoints /endpoitOne and /endpointTwo, endpointOne contains the logic to redirect to /endpointTwo.
I send a request from a browser (IP address: 100.100.100.100)


In above code, remoteAddr holds the ip address value: 100.100.100.100.
Since endpointTwo was called from endpointOne, I was expecting the variable remoteAddr to hold the value 200.200.200.200.

Is it possible to send a redirect request to /endpointTwo from server's ip address(200.200.200.200)? Now, If endpointTwo calls endpointThree, endpointThree should see the request coming from server address.


 
Saloon Keeper
Posts: 2656
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

idea Karna wrote:Since endpointTwo was called from endpointOne, I was expecting the variable remoteAddr to hold the value 200.200.200.200.


When you call the sendRedirect method, the result is that the server sends a 302 (or 307) status response to the browser, along with the specified redirection endpoint in a Location header.  The browser then makes a make a new request to the this endpoint.  

As you have found, the request to the second endpoint will be from the browser, not the server.

    Browser                                        Server
100.100.100.100                               200.200.200.200
       |                                             |
       | GET https://server1.com/endpointOne         |
       |-------------------------------------------->|
       |                                             |
       | 302 Moved Temporarily                       |
       | Location: https://server1.com/endpointTwo   |
       |<--------------------------------------------|
       |                                             |
       |                                             |
       |                                             |
       | GET https://server1.com/endpointTwo         |
       |-------------------------------------------->|
       |                                             |
       | 302 Moved Temporarily                       |
       | Location: https://server1.com/endpointThree |
       |<--------------------------------------------|
       |                                             |
   
 
idea Karna
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ron McLeod, Thank you for your response.

If /endpointThree is a page, and If a request is made from browser to /endpointTwo and /endpointTwo calls /endpointThree then can i view the page such that in endpointThree request should come from server address and not from browser.
Is there any thing that i can use to attain such configuration.
 
Saloon Keeper
Posts: 5707
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have the code of endpoint2 make a request to endpoint3, and then have it send the response back to the browser. That's not configuration, though - you would have to implement it that way.
 
Ron McLeod
Saloon Keeper
Posts: 2656
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

idea Karna wrote:If /endpointThree is a page, and If a request is made from browser to /endpointTwo and /endpointTwo calls /endpointThree then can i view the page such that in endpointThree request should come from server address and not from browser.


If you are using redirect, then the request for endpointThree will be from the browser.  If you want to know if the request to endpointThree was due to redirection, then you could add a query parameter to the request URL to indicate that - such as: https://server1.com/endpointThree?redirected
Example using JEE/TomEE:
Test using cURL:
Details showing redirection:
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Java Code Review and Psychology
https://coderanch.com/t/714798/java/Java-Code-Review-Psychology
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!