Search code examples
javanginxextjsmod-proxylegacy

Design question - How to Invoke Legacy service efficiently?


We have two applications App1 and App2.

App1 - Legacy search application on Java6 (being upgraded to Java 8) with legacy UI; Request payload is a complex string delimited structure

App2 - Java 8 on TomEE 1.7 with accepting Json request payload

Requirement - App2 needs to invoke the App1 service

Currently, App2's UI makes a call to App2 server with JSON payload. App2 server converts JSON to App1 understandable String delimited payload and invokes App1 service. On receiving the response from App1, App2 server converts the response to App2 UI understandable Json

Question - Could there be a better solution avoiding the hop to App2 server side and then to App1? Any better approach like utilizing API Gateway / NGinx / Mod Proxy?


Solution

  • The protocol translator between App1 proprietary "string delimited" protocol and a JSON protocol is implemented in App2 server. A better approach would be to add an additional endpoint to App1 server which accepts JSON requests.

    Each App1 client could choose if it wants to use the old "string delimited" or the new JSON protocol to communicate with the search service. App2 is now able to speak JSON with App1 and the code for the "string delimited" client could be removed from App2.

    This is called "content negotiation" and a good way to migrate from an old proprietary protocol to a more standardized JSON-based RESTful API.

    If the App2 UI client cannot communicate directly with the new App1 server (because the JSON formats of the payloads aren't compatible and need some mapping), you can take a look at some JSON-to-JSON mapping tools, like JsonToJsonMapper.