开发者

Ideal web service protocol for single-operation Java program with many parameters?

开发者 https://www.devze.com 2023-03-20 06:25 出处:网络
I have been tasked with 开发者_如何学Cmaking an existing Java program available via a web service that will be invoked through a PHP form.

I have been tasked with 开发者_如何学Cmaking an existing Java program available via a web service that will be invoked through a PHP form.

The program performs biological simulations and takes a large number of input parameters (around 30 different double, double[], and String fields). These parameters are usually setup as instance variables for an "Input" class which is passed into the the program, which in turn produces an "Output" class (which itself has many important fields). For example, this is how they usually call the program:

Input in = new Input();

in.a = 3.14;

in.b = 42;

in.c = 2.71;

Output out = (new Program()).run(in);

I am looking for a way to turn this into a web service in the easiest way possible. Ideally, I would want it to work like this:

1) The PHP client form formats an array containing the input data and sends it to the service.

2) The Java web service automatically parses this data and uses it to populate an Input instance.

3) The web service invokes the program and produces an Output instance, which is is formatted and sent back to the client.

4) The client retrieves the input formatted as an associative array.

I have already tried a few different methods (such as a SOAP operation and wrapping the data in XML), but nothing seems as elegant as I would like. The problem is that the program's Input variable specifications are likely to change, and I would prefer the only maintenance for such changes to be on the PHP form end.

Unfortunately, I don't have enough experience with web services to make an educated decision on what my setup should be like. Does anyone have any advice for what the most effective solution would be?


IMHO JSON RESFULL will be the best. Look here http://db.tmtec.biz/blogs/index.php/json-restful-web-service-in-java


If your program is stand alone java use jetty as an embedded web server. If the application is already running as a web application skip this.

The second phase is creating web service. I'd recommend you restful web service. It is easier to implement and maintain than SOAP. You can use XML or JSON format for data. I'd probably recommend you JSON.

Now it is up to you. If you already use some kind of web framework, check whether it supports REST. If you do not use any framework you can implement some kind of REST API using simple servlet that implements doPost(), parses input (JSON) and calls implementation.


There are a lot of possibilities. You should search for data serialization formats and choose the most suitable for this purpose.

One possibility would be to use Protocol Buffers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号