Root
Root

Reputation: 995

How to redirect Spring request to another application?

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?

Upvotes: 7

Views: 3213

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148965

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)

Upvotes: 1

Related Questions