com.sun.xml.internal.ws.developer.JAXWSProperties

2019-03-25 15:20发布

问题:

We used the class JAXWSProperties from the com.sun.* package in the code in order to set timeout properties like this:

import com.sun.xml.internal.ws.developer.JAXWSProperties;
...
Map<String, Object> ctxt = ((BindingProvider) port).getRequestContext();
ctxt.put(JAXWSProperties.CONNECT_TIMEOUT, 10000);

It compiles fine in the local Eclipse, but not on a continuous integration system (both using JDK 1.6). From researching this problem, I learned that the com.sun.* package should be avoided.

So my questions are:

  • What causes the failed import at compile time?
  • What should be used instead of JAXWSProperties?

回答1:

I've just had pretty much the same problem while converting one of our projects to run under Maven.

The solution I found, isn't really an ideal solution, in fact it's more of a "cludge" than a "fix," although it does run through the compiler OK. Like you I did a bit of research on this issue, and found a comment from Sun saying that these packages are hidden from the compiler, but are available to the JVM.

So, the solution I found was to simply find the string to which the constant was pointing, and use that locally.

In your case it would be:

final static String CONNECT_TIMEOUT = "com.sun.xml.internal.ws.connect.timeout";
....
Map<String, Object> ctxt = ((BindingProvider) port).getRequestContext();
ctxt.put(CONNECT_TIMEOUT, 10000);

As I mentioned, this isn't ideal, and can not be guaranteed to work in future compiler releases, so use with care.



标签: jax-ws java