author | lana |
Thu, 11 Aug 2016 15:47:07 +0000 | |
changeset 40243 | 225732b21228 |
parent 36263 | d5333008e409 |
child 43852 | 93a527059d8a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
36263
d5333008e409
8150174: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
34467
diff
changeset
|
2 |
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package javax.xml.soap; |
|
27 |
||
28 |
import java.io.*; |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
29 |
import java.nio.charset.StandardCharsets; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
30 |
import java.nio.file.Files; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
31 |
import java.nio.file.Path; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
32 |
import java.nio.file.Paths; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
33 |
import java.security.AccessController; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
34 |
import java.security.PrivilegedAction; |
12009 | 35 |
import java.util.Properties; |
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
36 |
import java.util.logging.Level; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
37 |
import java.util.logging.Logger; |
12009 | 38 |
|
39 |
||
40 |
class FactoryFinder { |
|
41 |
||
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
42 |
private static final Logger logger = Logger.getLogger("javax.xml.soap"); |
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
43 |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
44 |
private static final ServiceLoaderUtil.ExceptionHandler<SOAPException> EXCEPTION_HANDLER = |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
45 |
new ServiceLoaderUtil.ExceptionHandler<SOAPException>() { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
46 |
@Override |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
47 |
public SOAPException createException(Throwable throwable, String message) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
48 |
return new SOAPException(message, throwable); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
49 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
50 |
}; |
12009 | 51 |
|
52 |
/** |
|
31746
7573de6b8e46
8130753: Sync-up javadoc changes in jax-ws area - includes JAX-B API, JAX-WS API, SAAJ-API
mkos
parents:
28326
diff
changeset
|
53 |
* Finds the implementation {@code Class} object for the given |
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
54 |
* factory type. If it fails and {@code tryFallback} is {@code true} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
55 |
* finds the {@code Class} object for the given default class name. |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
56 |
* The arguments supplied must be used in order |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
57 |
* Note the default class name may be needed even if fallback |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
58 |
* is not to be attempted in order to check if requested type is fallback. |
16791 | 59 |
* <P> |
60 |
* This method is package private so that this code can be shared. |
|
61 |
* |
|
31746
7573de6b8e46
8130753: Sync-up javadoc changes in jax-ws area - includes JAX-B API, JAX-WS API, SAAJ-API
mkos
parents:
28326
diff
changeset
|
62 |
* @return the {@code Class} object of the specified message factory; |
7573de6b8e46
8130753: Sync-up javadoc changes in jax-ws area - includes JAX-B API, JAX-WS API, SAAJ-API
mkos
parents:
28326
diff
changeset
|
63 |
* may not be {@code null} |
16791 | 64 |
* |
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
65 |
* @param factoryClass factory abstract class or interface to be found |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
66 |
* @param deprecatedFactoryId deprecated name of a factory; it is used for types |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
67 |
* where class name is different from a name |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
68 |
* being searched (in previous spec). |
16791 | 69 |
* @param defaultClassName the implementation class name, which is |
70 |
* to be used only if nothing else |
|
31746
7573de6b8e46
8130753: Sync-up javadoc changes in jax-ws area - includes JAX-B API, JAX-WS API, SAAJ-API
mkos
parents:
28326
diff
changeset
|
71 |
* is found; {@code null} to indicate |
16791 | 72 |
* that there is no default class name |
73 |
* @param tryFallback whether to try the default class as a |
|
74 |
* fallback |
|
75 |
* @exception SOAPException if there is a SOAP error |
|
76 |
*/ |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
77 |
@SuppressWarnings("unchecked") |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
78 |
static <T> T find(Class<T> factoryClass, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
79 |
String defaultClassName, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
80 |
boolean tryFallback, String deprecatedFactoryId) throws SOAPException { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
81 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
82 |
ClassLoader tccl = ServiceLoaderUtil.contextClassLoader(EXCEPTION_HANDLER); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
83 |
String factoryId = factoryClass.getName(); |
12009 | 84 |
|
16791 | 85 |
// Use the system property first |
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
86 |
String className = fromSystemProperty(factoryId, deprecatedFactoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
87 |
if (className != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
88 |
Object result = newInstance(className, defaultClassName, tccl); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
89 |
if (result != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
90 |
return (T) result; |
16791 | 91 |
} |
92 |
} |
|
93 |
||
94 |
// try to read from $java.home/lib/jaxm.properties |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
95 |
className = fromJDKProperties(factoryId, deprecatedFactoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
96 |
if (className != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
97 |
Object result = newInstance(className, defaultClassName, tccl); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
98 |
if (result != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
99 |
return (T) result; |
16791 | 100 |
} |
101 |
} |
|
102 |
||
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
103 |
// standard services: java.util.ServiceLoader |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
104 |
T factory = ServiceLoaderUtil.firstByServiceLoader( |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
105 |
factoryClass, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
106 |
logger, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
107 |
EXCEPTION_HANDLER); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
108 |
if (factory != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
109 |
return factory; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
110 |
} |
16791 | 111 |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
112 |
// try to find services in CLASSPATH |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
113 |
className = fromMetaInfServices(deprecatedFactoryId, tccl); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
114 |
if (className != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
115 |
logger.log(Level.WARNING, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
116 |
"Using deprecated META-INF/services mechanism with non-standard property: {0}. " + |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
117 |
"Property {1} should be used instead.", |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
118 |
new Object[]{deprecatedFactoryId, factoryId}); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
119 |
Object result = newInstance(className, defaultClassName, tccl); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
120 |
if (result != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
121 |
return (T) result; |
16791 | 122 |
} |
123 |
} |
|
124 |
||
125 |
// If not found and fallback should not be tried, return a null result. |
|
126 |
if (!tryFallback) |
|
127 |
return null; |
|
128 |
||
129 |
// We didn't find the class through the usual means so try the default |
|
130 |
// (built in) factory if specified. |
|
131 |
if (defaultClassName == null) { |
|
12009 | 132 |
throw new SOAPException( |
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
133 |
"Provider for " + factoryId + " cannot be found", null); |
12009 | 134 |
} |
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
135 |
return (T) newInstance(defaultClassName, defaultClassName, tccl); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
136 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
137 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
138 |
// in most cases there is no deprecated factory id |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
139 |
static <T> T find(Class<T> factoryClass, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
140 |
String defaultClassName, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
141 |
boolean tryFallback) throws SOAPException { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
142 |
return find(factoryClass, defaultClassName, tryFallback, null); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
143 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
144 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
145 |
private static Object newInstance(String className, String defaultClassName, ClassLoader tccl) throws SOAPException { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
146 |
return ServiceLoaderUtil.newInstance( |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
147 |
className, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
148 |
defaultClassName, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
149 |
tccl, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
150 |
EXCEPTION_HANDLER); |
16791 | 151 |
} |
12009 | 152 |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
153 |
// used only for deprecatedFactoryId; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
154 |
// proper factoryId searched by java.util.ServiceLoader |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
155 |
private static String fromMetaInfServices(String deprecatedFactoryId, ClassLoader tccl) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
156 |
String serviceId = "META-INF/services/" + deprecatedFactoryId; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
157 |
logger.log(Level.FINE, "Checking deprecated {0} resource", serviceId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
158 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
159 |
try (InputStream is = |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
160 |
tccl == null ? |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
161 |
ClassLoader.getSystemResourceAsStream(serviceId) |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
162 |
: |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
163 |
tccl.getResourceAsStream(serviceId)) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
164 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
165 |
if (is != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
166 |
String factoryClassName; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
167 |
try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
168 |
BufferedReader rd = new BufferedReader(isr)) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
169 |
factoryClassName = rd.readLine(); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
170 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
171 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
172 |
logFound(factoryClassName); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
173 |
if (factoryClassName != null && !"".equals(factoryClassName)) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
174 |
return factoryClassName; |
16791 | 175 |
} |
176 |
} |
|
177 |
||
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
178 |
} catch (IOException e) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
179 |
// keep original behavior |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
180 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
181 |
return null; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
182 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
183 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
184 |
private static String fromJDKProperties(String factoryId, String deprecatedFactoryId) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
185 |
Path path = null; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
186 |
try { |
36263
d5333008e409
8150174: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
34467
diff
changeset
|
187 |
String JAVA_HOME = getSystemProperty("java.home"); |
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
188 |
path = Paths.get(JAVA_HOME, "conf", "jaxm.properties"); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
189 |
logger.log(Level.FINE, "Checking configuration in {0}", path); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
190 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
191 |
// to ensure backwards compatibility |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
192 |
if (!Files.exists(path)) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
193 |
path = Paths.get(JAVA_HOME, "lib", "jaxm.properties"); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
194 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
195 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
196 |
logger.log(Level.FINE, "Checking configuration in {0}", path); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
197 |
if (Files.exists(path)) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
198 |
Properties props = new Properties(); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
199 |
try (InputStream inputStream = Files.newInputStream(path)) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
200 |
props.load(inputStream); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
201 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
202 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
203 |
// standard property |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
204 |
logger.log(Level.FINE, "Checking property {0}", factoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
205 |
String factoryClassName = props.getProperty(factoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
206 |
logFound(factoryClassName); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
207 |
if (factoryClassName != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
208 |
return factoryClassName; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
209 |
} |
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
210 |
|
34467
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
211 |
// deprecated property |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
212 |
if (deprecatedFactoryId != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
213 |
logger.log(Level.FINE, "Checking deprecated property {0}", deprecatedFactoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
214 |
factoryClassName = props.getProperty(deprecatedFactoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
215 |
logFound(factoryClassName); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
216 |
if (factoryClassName != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
217 |
logger.log(Level.WARNING, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
218 |
"Using non-standard property: {0}. Property {1} should be used instead.", |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
219 |
new Object[]{deprecatedFactoryId, factoryId}); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
220 |
return factoryClassName; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
221 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
222 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
223 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
224 |
} catch (Exception ignored) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
225 |
logger.log(Level.SEVERE, "Error reading SAAJ configuration from [" + path + |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
226 |
"] file. Check it is accessible and has correct format.", ignored); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
227 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
228 |
return null; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
229 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
230 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
231 |
private static String fromSystemProperty(String factoryId, String deprecatedFactoryId) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
232 |
String systemProp = getSystemProperty(factoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
233 |
if (systemProp != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
234 |
return systemProp; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
235 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
236 |
if (deprecatedFactoryId != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
237 |
systemProp = getSystemProperty(deprecatedFactoryId); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
238 |
if (systemProp != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
239 |
logger.log(Level.WARNING, |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
240 |
"Using non-standard property: {0}. Property {1} should be used instead.", |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
241 |
new Object[] {deprecatedFactoryId, factoryId}); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
242 |
return systemProp; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
243 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
244 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
245 |
return null; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
246 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
247 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
248 |
private static String getSystemProperty(String property) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
249 |
logger.log(Level.FINE, "Checking system property {0}", property); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
250 |
String value = AccessController.doPrivileged( |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
251 |
(PrivilegedAction<String>) () -> System.getProperty(property)); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
252 |
logFound(value); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
253 |
return value; |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
254 |
} |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
255 |
|
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
256 |
private static void logFound(String value) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
257 |
if (value != null) { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
258 |
logger.log(Level.FINE, " found {0}", value); |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
259 |
} else { |
024f1ce7da02
8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
mkos
parents:
31746
diff
changeset
|
260 |
logger.log(Level.FINE, " not found"); |
16791 | 261 |
} |
12009 | 262 |
} |
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
263 |
|
12009 | 264 |
} |