用于 Java 的进程内 SOAP 服务服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1792737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In-process SOAP service server for Java
提问by tster
OK, I am developing a program which will be deployed to lots of machines (Windows, Linux, AIX, z/Linux, openVMS, etc.). I want that application to contain a SOAP web service, but I don't want to bundle tomcat or run a separate service for the services (I want them in the same process as the rest of the application).
好的,我正在开发一个将部署到许多机器(Windows、Linux、AIX、z/Linux、openVMS 等)的程序。我希望该应用程序包含 SOAP Web 服务,但我不想捆绑 tomcat 或为这些服务运行单独的服务(我希望它们与应用程序的其余部分在同一进程中)。
Basically what I'm looking for is something where I can define a class (say WebServices). I'm OK with writing WSDL or any other kind of service description as well. The I want something like this:
基本上我正在寻找的是我可以定义一个类的东西(比如WebServices)。我也可以编写 WSDL 或任何其他类型的服务描述。我想要这样的东西:
SOAPServer server = makeMeASoapServer();
//do config on the server
server.add(new WebService(...));
server.listen(port);
Obviously the names and parameters will be different.
显然,名称和参数会有所不同。
I've been looking at Axis, and it seems like it provides this, but I don't know what classes I need to use. Am I crazy in wanting this kind of behavior? I can't believe more people aren't looking for this, I do this all the time with embedded web services within .NET clients.
我一直在看Axis,它似乎提供了这个,但我不知道我需要使用哪些类。我想要这种行为是疯了吗?我不敢相信更多的人没有在寻找这个,我一直在使用 .NET 客户端中的嵌入式 Web 服务这样做。
回答by nos
Seems jdk 6.0 already comes with a jax-ws implementation, and a little server you can embed. I havn't figured out all the pieces but here's a start:
似乎 jdk 6.0 已经带有一个 jax-ws 实现,以及一个可以嵌入的小服务器。我还没有弄清楚所有的部分,但这是一个开始:
mkdir -p helloservice/endpoint/
helloservice/endpoint/Hello.java :
helloservice/endpoint/Hello.java :
package helloservice.endpoint;
import javax.jws.WebService;
@WebService()
public class Hello {
private String message = new String("Hello, ");
public void Hello() {}
public String sayHello(String name) {
return message + name + ".";
}
}
helloservice/endpoint/Server.java:
helloservice/endpoint/Server.java:
package helloservice.endpoint;
import javax.xml.ws.Endpoint;
public class Server {
protected Server() throws Exception {
System.out.println("Starting Server");
Object implementor = new Hello();
String address = "http://localhost:9000/SoapContext/SoapPort";
Endpoint.publish(address, implementor);
}
public static void main(String args[]) throws Exception {
new Server();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
}
Build the thing:
构建事物:
mkdir build
javac -d build helloservice/endpoint/*java
$JAVA_HOME/wsgen -d build -s build -classpath . helloservice.endpoint.Hello
Run the thing:
运行的东西:
java -cp build helloservice.endpoint.Server
Somethings running on http://localhost:9000/SoapContext/SoapPortnow. You can get the wsdl on http://localhost:9000/SoapContext/SoapPort?WSDL
现在在http://localhost:9000/SoapContext/SoapPort上运行的东西。您可以在http://localhost:9000/SoapContext/SoapPort?WSDL上获取 wsdl
Havn't gotten around to making a client yet..
还没有开始做客户..
回答by tster
In addition to nos's great answer, I found a class in Apache axis called SimpleHTTPServerwhich I'm pretty sure does the same thing but only requires Java 1.5 for those of you stuck with 1.5
除了 nos 的好答案之外,我在 Apache 轴中找到了一个名为的类SimpleHTTPServer,我很确定它做了同样的事情,但只需要 Java 1.5 对于那些坚持使用 1.5 的人
I'm not going to explore it since I'm going to use the other solution, so I haven't actually verified it does what I think it does, but I'm pretty sure it does.
我不打算探索它,因为我将使用其他解决方案,所以我还没有真正验证它是否符合我的想法,但我很确定它确实如此。
回答by Stefan L
Most(/all?) Java SOAP server implementations provide a Servlet (the javax.xml.ws.Endpoint approach in another answer does look a bit simpler though...). Some SOAP implementations you could consider are: Apache CXF: cxf.apache.org, Apache Axis2: ws.apache.org/axis2/ or Spring Web Servies: static.springsource.org/spring-ws/site/ .
大多数(/全部?)Java SOAP 服务器实现提供了一个 Servlet(另一个答案中的 javax.xml.ws.Endpoint 方法确实看起来有点简单......)。您可以考虑的一些 SOAP 实现是:Apache CXF:cxf.apache.org、Apache Axis2:ws.apache.org/axis2/ 或 Spring Web Servies:static.springsource.org/spring-ws/site/。
The most popular embedded Java web server seems to be Jetty, you can configureit either programatically (using plain Java or Spring beans) or using a custom XML format.
最流行的嵌入式Java Web服务器似乎是码头,你可以配置或者编程它(使用普通的Java或Spring豆),或使用自定义XML格式。
回答by Sonny
To address the main question directly, another approach would be to go with Jetty's embedded server. See this linkfor details. The links from the aforelinked page help you understand both the simple web server (i.e., one that serves up static pages; though I am fully aware "simple" is a horribly vague term wrt web servers) and the web server that helps you deploy web services.
为了直接解决主要问题,另一种方法是使用 Jetty 的嵌入式服务器。有关详细信息,请参阅此链接。来自上述页面的链接可帮助您了解简单的 Web 服务器(即提供静态页面的服务器;尽管我完全知道“简单”是一个非常模糊的术语 wrt Web 服务器)和帮助您部署 Web 的 Web 服务器服务。

