java 如何在 jax-ws 客户端中隐藏警告(可能)由 jax-ws 库引起

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

How to hide warning in jax-ws client which (maybe) caused by jax-ws library

javaweb-servicesjax-ws

提问by FJE

I'm using netbeans to generate web service client in my application. And my program using jax-ws library to set timeout in calling web service.

我正在使用 netbeans 在我的应用程序中生成 Web 服务客户端。我的程序使用 jax-ws 库来设置调用 Web 服务的超时时间。

Problem arise because it generate a lot of this warning message whenever i start this program.:

出现问题是因为每当我启动这个程序时它都会生成很多这样的警告消息。:

Dec 13, 2010 4:35:21 PM [com.sun.xml.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2004/10/wsat}ATAlwaysCapability" was evaluated as "UNKNOWN".

Dec 13, 2010 4:35:21 PM [com.sun.xml.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2004/10/wsat}ATAssertion" was evaluated as "UNKNOWN".

Dec 13, 2010 4:35:21 PM [com.sun.xml.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0019: Suboptimal policy alternative selected on the client side with fitness "UNKNOWN".

2010 年 12 月 13 日下午 4:35:21 [com.sun.xml.ws.policy.EffectiveAlternativeSelector] selectAlternatives 警告:WSP0075:策略断言“{ http://schemas.xmlsoap.org/ws/2004/10/wsat} ATAlwaysCapability”被评估为“未知”。

2010 年 12 月 13 日下午 4:35:21 [com.sun.xml.ws.policy.EffectiveAlternativeSelector] selectAlternatives 警告:WSP0075:策略断言“{ http://schemas.xmlsoap.org/ws/2004/10/wsat} ATAssertion”被评估为“未知”。

2010 年 12 月 13 日下午 4:35:21 [com.sun.xml.ws.policy.EffectiveAlternativeSelector] selectAlternatives 警告:WSP0019:在客户端选择了次优策略替代方案,适应度为“未知”。

I found the same problem with mine in here: http://forums.java.net/node/707265, but it also have no answer until now.

我在这里发现了同样的问题:http: //forums.java.net/node/707265,但直到现在它也没有答案。

Is there any way to hide this warning? I try to search using google, and can't find any match answer for this problem..

有没有办法隐藏这个警告?我尝试使用 google 进行搜索,但找不到此问题的任何匹配答案..

采纳答案by Andreas Veithen

My guess is that the WSDL from which the client was generated contains policy assertions related to WS-AtomicTransaction. Since WS-AtomicTransaction requires a transaction manager and the JRE doesn't contain one, it's not surprising that the JAX-WS runtime in the JRE has no support for WS-AtomicTransaction and doesn't understand these policy assertions.

我的猜测是生成客户端的 WSDL 包含与 WS-AtomicTransaction 相关的策略断言。由于 WS-AtomicTransaction 需要一个事务管理器,而 JRE 不包含一个,因此 JRE 中的 JAX-WS 运行时不支持 WS-AtomicTransaction 并且不理解这些策略断言也就不足为奇了。

If you don't need WS-AtomicTransaction, then you have two options to get rid of these warnings:

如果您不需要 WS-AtomicTransaction,那么您有两种选择可以摆脱这些警告:

  • Configure logging to suppress these warnings.
  • Remove the assertions from the WSDL.
  • 配置日志记录以抑制这些警告。
  • 从 WSDL 中删除断言。

If you need WS-AtomicTransaction, then you will probably have to run the code in an application server or as a Java EE application client.

如果您需要 WS-AtomicTransaction,那么您可能必须在应用程序服务器中或作为 Java EE 应用程序客户端运行代码。

回答by Alexander Pavlov

You must be using an outdated version of jax-ws (I didn't find EffectiveAlternativeSelector in my 2.2.1 copy), but let me try.

您必须使用过时的 jax-ws 版本(我在 2.2.1 副本中没有找到 EffectiveAlternativeSelector),但让我尝试一下。

  1. Create a logging.properties file on some path accessible while launching your application (at the very least you may use the one found at $JAVA_HOME/lib/logging.properties)
  2. Add the following line to that file: com.sun.xml.ws.policy.EffectiveAlternativeSelector.level=OFF
  3. Launch your application as
  1. 在启动应用程序时在某个可访问的路径上创建一个 logging.properties 文件(至少您可以使用在 中找到的那个$JAVA_HOME/lib/logging.properties
  2. 将以下行添加到该文件中: com.sun.xml.ws.policy.EffectiveAlternativeSelector.level=OFF
  3. 启动您的应用程序

java -Djava.util.logging.config.file=/path/to/your/logging.properties MainClass

java -Djava.util.logging.config.file=/path/to/your/logging.properties MainClass

回答by Batavia

i think turning of the debugging isn't a solution

我认为关闭调试不是解决方案

http://dannythorpe.com/2012/01/04/java-wcf-usingaddressing-warning/describes a way to fix this.

http://dannythorpe.com/2012/01/04/java-wcf-usingaddressing-warning/描述了解决此问题的方法。

回答by moe

The @SupressWarnings() does not help in this case. That annotation is to tell the compiler to not warn you when you are potentially misusing some java type. These ws warnings are getting piped into System.err

@SupressWarnings() 在这种情况下没有帮助。该注释是为了告诉编译器在您可能误用某些 Java 类型时不要警告您。这些 ws 警告被传送到 System.err

回答by macieks

9 years after the question, but maybe someone else needs to set this in java code in 2019.

问题提出 9 年后,但也许其他人需要在 2019 年在 Java 代码中设置它。

If you just want to hide the warnings (instead of solving the underlying issue) you can easily set the the logging level in your code like this and no messages should appear:

如果您只想隐藏警告(而不是解决潜在问题),您可以像这样轻松地在代码中设置日志记录级别,并且不应出现任何消​​息:

      PolicyLogger logger = PolicyLogger.getLogger(EffectiveAlternativeSelector.class);
      logger.setLevel(Level.OFF);

回答by Acn

Is @SupressWarning(value="?") of any use here ?

@SupressWarning(value="?") 在这里有用吗?