从Spring Boot Java Web API调用本地/服务器Node.js应用程序

huangapple 未分类评论68阅读模式
英文:

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 !

huangapple
  • 本文由 发表于 2021年9月6日 22:29:42
  • 转载请务必保留本文链接:https://java.coder-hub.com/69076202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定