英文:
Calling Local/Server Node JS Application from Spring Boot Java Web API
问题
我们在本地机器/服务器上安装了一个Node.js实用程序。
使用npm install -g openapi2Arbitaryservice命令安装。
我可以调用这个实用程序,它可以正常工作。它读取一个JSON文件并创建一个服务API。
openapi2Arbitaryservice generateApi myProxySwagSep6 -s ./swagger-petstore.json -d ./aug-2021
当API请求到达Tomcat服务器并携带JSON主体时,我想触发这个操作。我有一个使用Java 8的Spring Boot应用程序。
我尝试使用Java的exec方法在API请求到达服务器时调用这个本地安装的Node.js应用程序并进行处理。
String[] command = { "/bin/bash", "-c", "openapi2ArbitaryService", "generateApi", "myProxySwagSep6", "-s", ".swagger-petstore.json", "-d", "./aug-2021" };
p = Runtime.getRuntime().exec(command);
但是,我得到了"Exit Value 127"的错误。似乎它无法识别openapi2ArbitaryService。
Java调用用户API请求时调用本地/服务器安装的应用程序是否是一个有效的用例?是否应该使用队列将其解耦,然后单独处理,例如作为一个Docker任务?
Golang/Python是否适用于这样的用例?请分享一些想法。
提前感谢!
英文:
we have installed a node js utility on a local machine/server.
using npm install -g openapi2Arbitaryservice
I can call this utility and it is working fine. It reads a json and create a service api.
openapi2Arbitaryservice generateApi myProxySwagSep6 -s ./swagger-petstore.json -d ./aug-2021
I want to trigger this when api request comes to the tomcat server with body of JSON. I have a spring-boot application using java 8.
I was trying to use exec method of java to call this locally installed node js application when an api request comes to the server and do the processing
String[] command = { "/bin/bash", "-c", ,"openapi2ArbitaryService", "generateApi", "myProxySwagSep6", "-s",".swagger-petstore.json", "-d", "./aug-2021" };
p = Runtime.getRuntime().exec(command);
But, i get error "Exit Value 127". It seems it's not able to recognise openapi2ArbitaryService
Is this a valid use-case for java calling local/server installed application on user api requests. Should this be decoupled using a queue and then handled separately e.g as a docker task.
Is Golang/python suitable for such use-cases please share some thoughts.
thanks in advance !
专注分享java语言的经验与见解,让所有开发者获益!
评论