适用于 Java 的轻量级 SOAP 客户端库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2410879/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:13:58  来源:igfitidea点击:

Lightweight SOAP Client Library for Java

javasoap

提问by Mike Deck

Can anyone recommend a good Java open source library for building a simple SOAP web service client? I'm looking for something with minimal dependencies and configuration that will work in a Java 5 SE environment. Upgrading to Java 6 isn't really an option on this project and I'd prefer to avoid using a full J2EE container if I can avoid it. I don't need to publish and services, only consume.

任何人都可以推荐一个好的 Java 开源库来构建一个简单的 SOAP Web 服务客户端吗?我正在寻找可以在 Java 5 SE 环境中使用的具有最少依赖项和配置的东西。升级到 Java 6 并不是这个项目的真正选择,如果可以避免的话,我宁愿避免使用完整的 J2EE 容器。我不需要发布和服务,只需要消费。

I'm currently using Axis2 but I have to pull in about 15MB of extra jars just to make a simple call to a web service without a NoClassDefFoundError and I'm looking for something with a lot less bloat.

我目前正在使用 Axis2,但我必须提取大约 15MB 的额外 jar 才能在没有 NoClassDefFoundError 的情况下对 Web 服务进行简单调用,而且我正在寻找一些膨胀更少的东西。

I've also looked at CXF, but I'm reluctant to use it because of it's tight coupling to Spring. Spring isn't a 100% deal breaker, but I'd rather avoid it if possible.

我也看过 CXF,但我不愿意使用它,因为它与 Spring 紧密耦合。Spring 不是 100% 的交易破坏者,但如果可能的话,我宁愿避免它。

Any suggestions?

有什么建议?

采纳答案by stacker

In Spring 3.0 thay have splitted the big spring.jar into modules which will reduce size.

在 Spring 3.0 中,你已经将大 spring.jar 拆分为模块,这将减小大小。

Check Spring Web Services

检查Spring Web 服务

WS Client Example

WS 客户端示例

The drawback would be that you have to manage dependencies between a lot of jar's this could be become complex if don't want to introduce maven. That was the reason (among others like compatibility problems) why I'm still using axis.

缺点是您必须管理许多 jar 之间的依赖关系,如果不想引入 maven,这可能会变得复杂。这就是我仍在使用axis的原因(其中包括兼容性问题)。

回答by Mike Deck

After researching this a while the raw SAAJ API (https://saaj.dev.java.net/) is the only thing I've found that is any more streamlined than the Spring WS library which is built on top of it. The problem with SAAJ is that it's almost unusable unless you're willing to use their extremely verbose API for building up the XML payload of your message. There are ways to get around this and use something like JAXB to generate the actual message contents, but it's not very clean and Spring WS is essentially just that.

在研究了一段时间之后,原始 SAAJ API ( https://saaj.dev.java.net/) 是我发现的唯一比构建在它之上的 Spring WS 库更精简的东西。SAAJ 的问题在于它几乎无法使用,除非您愿意使用他们极其冗长的 API 来构建消息的 XML 有效负载。有一些方法可以解决这个问题,并使用 JAXB 之类的东西来生成实际的消息内容,但这不是很干净,Spring WS 本质上就是这样。

回答by MariuszS

Try simple soap-wslibrary, it is very easy to use.

试试简单的soap-ws库,非常好用。

A lightweight and easy-to-use Java library to handle SOAP on a purely XML level.

一个轻量级且易于使用的 Java 库,用于在纯 XML 级别处理 SOAP。

Sample usage

示例用法

 SoapClient client = SoapClient.builder()
    .endpointUri("http://example.com/endpoint")
    .build();

 client.post(envelope);

Dependency

依赖

<dependency>
    <groupId>org.reficio</groupId>
    <artifactId>soap-client</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

from repository

从存储库

<repository>
    <id>reficio</id>
    <url>http://repo.reficio.org/maven/</url>
</repository>