7

I have an application that entertains a POST request. To request, I need to define some headers, boundaries and hyphens. In other words, I need to craft the complete request. Which I did successfully using HttpURLConnection. Now, I want to request the application from my Spring application.

Say, I have three applications A(sensor), B(spring) and C(server).

In this case, B will act as a bridge which receives the request from A authenticate it and send it to the C.

I don't want to craft the same request again in Spring it just redirect the request to the server. Is there any mechanism in Spring for this?

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
Root
  • 955
  • 1
  • 16
  • 39
  • Just wondering whether `forward` prefix will be a good option here - http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-redirecting-forward-prefix checking on more sources – aksappy Apr 26 '16 at 06:22
  • Found a similar question here - does this help - http://stackoverflow.com/questions/17955777/redirect-to-an-external-url-from-controller-action-in-spring-mvc – aksappy Apr 26 '16 at 06:23
  • yes this is some thing like `forward` but it not discussed in the question.The `forward` forwards the same request to the internal resource but I want to forward it to the external resource like in question to **C** that is a different application at different place (geographically). – Root Apr 26 '16 at 07:07

1 Answers1

1

There are 3 mechanismes of redirection:

  • forward: you pass the request (and associated response) to another servlet in the same context, meaning in the same web application - AFAIK that's not what you need
  • redirect: you give the client (browser) the location (an URL) where it should re-send a request. You can redirect to any URL, but it supposes that the redirected app will directly accept the client request - as you said B acts as a bridge, I think it is still not what you need
  • proxy: the bridge sends a new request to next hop and will resend the response to its own client. As there is no coupling between the original request and the new one, you can even use a different protocol, for example pipes or a Unix socket if you are on same server. Or you could use Json that is simple to produce and decode in HTML requests and responses. In Windows world, you could even use DCOM or .NET to directly execute methods on the remote server. But even if it is hidden by those tools, you still have to build a new request on the bridge and decode it on the server (except with DCOM/.NET on same server)
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • I don't want to build the request again like you said in case of `proxy`. I have idea of forward and redirect but no idea of proxy. I think I have to look into it if it help not to build the request again. – Root Apr 26 '16 at 08:08
  • I also tried spring redirect and forward. But redirect does not change the request's client ip address so i think it is useless in this case. i could not forward to another url either. – Root Apr 26 '16 at 08:13