简体   繁体   English

我该如何实施以下内容?

[英]How can I implement the following?

I have a java program that has some number of classes. 我有一个具有某些类的Java程序。 Three methods taken input A and give output B. I need to make these methods available as a web service so that I can ask something like http://test.com/method?input=A and the result B is returned. 三种方法采用输入A并给出输出B。我需要将这些方法用作Web服务,以便我可以询问类似http://test.com/method?input=A的问题,然后返回结果B。 I don't want to re-write my existing code. 我不想重写我现有的代码。 Is there something which is available such as a web service framework for JAVA that can allow me to create a web service interface for these three methods. 是否有可用的东西,例如JAVA的Web服务框架,可以让我为这三种方法创建Web服务接口。 What is the easiest way? 最简单的方法是什么?

I have ran into many acronyms and other stuff during my research such as dynamic project, JAVA EE, Glassfish etc... What can implement my requirement? 在研究过程中,我遇到了许多首字母缩写词和其他内容,例如动态项目,JAVA EE,Glassfish等。什么可以实现我的要求? Thanks! 谢谢!

The easiest way to do quick Java services I've found is Restlet . 我发现,进行快速Java服务的最简单方法是Restlet

You can use their tutorials to get a webserver up and running like literally 20 minutes from scratch. 您可以使用他们的教程来启动Web服务器并从头开始运行20分钟。 The Restlet below should work right out of the box as a skeleton framework. 下面的Restlet应该可以作为框架直接使用。 You'll replace the call of String b = ... of course, and replace it with your own library. 当然,您将替换对String b = ...的调用,并将其替换为您自己的库。

public class Main extends Application {

    public static void main(String[] args) {
        Main main = new Main();
        main.start();
    }

    private void start() {
        Component c = new Component();
        c.getServers().add(Protocol.HTTP, 80);
        Application app = new Main();
        c.getDefaultHost().attach(app);
        c.start();
    }

    public Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach("/method/{input}", new Restlet(getContext()) {
            public void handle(Request request, Response response) {
                String a = request.getAttributes().get("input").toString();
                String b = MyLibraries.compute(a);
                response.setEntity(b, MediaType.TEXT_HTML);
            }
        });
        return router;
    }

}

如果您在Java EE 6服务器上运行,则可以使用JAX-RS: http : //docs.oracle.com/javaee/6/tutorial/doc/gilik.html

You will probably need some sort of web framework -- Glassfish is one example. 您可能需要某种Web框架-Glassfish是一个示例。 Basically, your application is not built to receive web requests, so you need some sort of container (eg a Servlet Container like Tomcat http://en.wikipedia.org/wiki/Web_container ). 基本上,您的应用程序不是为接收Web请求而构建的,因此您需要某种容器(例如Servlet容器,例如Tomcat http://en.wikipedia.org/wiki/Web_container )。

I think "restlet" is a little servlet container that might suit your needs. 我认为“ restlet”是一个可能符合您需求的小servlet容器。

Check it out: http://www.restlet.org/ 检查一下: http : //www.restlet.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM