Java 的进程内 SOAP 服务服务器
好的,我正在开发一个程序,它将部署到很多机器(Windows、Linux、AIX、z/Linux、openVMS 等)。我希望该应用程序包含 SOAP Web 服务,但我不想捆绑 tomcat 或为服务运行单独的服务(我希望它们与应用程序的其余部分位于同一进程中)。
基本上我正在寻找的是可以定义类的东西(比如WebServices
)。我也可以编写 WSDL 或任何其他类型的服务描述。我想要这样的东西:
SOAPServer server = makeMeASoapServer();
//do config on the server
server.add(new WebService(...));
server.listen(port);
显然名称和参数会有所不同。
我一直在研究 Axis,似乎它提供了这一点,但我不知道我需要使用哪些类。我疯狂地想要这种行为吗?我不敢相信更多的人没有在寻找这个,我一直在 .NET 客户端中使用嵌入式 Web 服务来这样做。
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).
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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看来 jdk 6.0 已经附带了 jax-ws 实现,以及一个可以嵌入的小服务器。
我还没有弄清楚所有的部分,但这是一个开始:
helloservice/endpoint/Hello.java :
helloservice/endpoint/Server.java:
构建东西:
运行该东西:
在 http://localhost:9000/ 上运行的东西现在SoapContext/SoapPort。
上获取 wsdl
您可以在 http://localhost:9000/SoapContext/SoapPort?WSDL Havn' 还没有抽出时间去建立客户..
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:
helloservice/endpoint/Hello.java :
helloservice/endpoint/Server.java:
Build the thing:
Run the thing:
Somethings running on http://localhost:9000/SoapContext/SoapPort now.
You can get the wsdl on http://localhost:9000/SoapContext/SoapPort?WSDL
Havn't gotten around to making a client yet..
除了 nos 的出色答案之外,我在 Apache axis 中发现了一个名为
SimpleHTTPServer
的类,我很确定它能做同样的事情,但只需要 Java 1.5,对于那些坚持使用 1.5 的人我不会去来探索它,因为我将使用其他解决方案,所以我实际上还没有验证它是否符合我的想法,但我很确定它确实如此。
In addition to nos's great answer, I found a class in Apache axis called
SimpleHTTPServer
which I'm pretty sure does the same thing but only requires Java 1.5 for those of you stuck with 1.5I'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.
大多数(/全部?)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/ 。
最流行的嵌入式 Java Web 服务器似乎是 Jetty,您可以 以编程方式(使用普通 Java 或 Spring beans)或使用自定义 XML 格式配置。
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/ .
The most popular embedded Java web server seems to be Jetty, you can configure it either programatically (using plain Java or Spring beans) or using a custom XML format.
为了直接解决主要问题,另一种方法是使用 Jetty 的嵌入式服务器。有关详细信息,请参阅此链接。上述链接页面中的链接可帮助您了解简单的 Web 服务器(即提供静态页面的服务器;尽管我完全意识到“简单”对于 Web 服务器来说是一个非常模糊的术语)和帮助您部署 Web 的 Web 服务器服务。
To address the main question directly, another approach would be to go with Jetty's embedded server. See this link for 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.