Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.transport.http; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.oracle.webservices.internal.api.databinding.DatabindingModeFeature; |
aoqi@0 | 29 | import com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature; |
aoqi@0 | 30 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.api.BindingID; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.WSBinding; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.api.databinding.MetadataReader; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.api.server.Container; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.api.server.SDDocumentSource; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.api.server.WSEndpoint; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.binding.WebServiceFeatureList; |
aoqi@0 | 39 | |
aoqi@0 | 40 | import com.sun.xml.internal.ws.handler.HandlerChainsModel; |
aoqi@0 | 41 | import com.sun.xml.internal.ws.resources.ServerMessages; |
aoqi@0 | 42 | import com.sun.xml.internal.ws.resources.WsservletMessages; |
aoqi@0 | 43 | import com.sun.xml.internal.ws.server.EndpointFactory; |
aoqi@0 | 44 | import com.sun.xml.internal.ws.server.ServerRtException; |
aoqi@0 | 45 | import com.sun.xml.internal.ws.streaming.Attributes; |
aoqi@0 | 46 | import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader; |
aoqi@0 | 47 | import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; |
aoqi@0 | 48 | import com.sun.xml.internal.ws.util.HandlerAnnotationInfo; |
aoqi@0 | 49 | import com.sun.xml.internal.ws.util.exception.LocatableWebServiceException; |
aoqi@0 | 50 | import com.sun.xml.internal.ws.util.xml.XmlUtil; |
aoqi@0 | 51 | import org.xml.sax.EntityResolver; |
aoqi@0 | 52 | |
aoqi@0 | 53 | import javax.xml.namespace.QName; |
aoqi@0 | 54 | import javax.xml.stream.XMLStreamConstants; |
aoqi@0 | 55 | import javax.xml.stream.XMLStreamException; |
aoqi@0 | 56 | import javax.xml.stream.XMLStreamReader; |
aoqi@0 | 57 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 58 | import javax.xml.ws.WebServiceFeature; |
aoqi@0 | 59 | import javax.xml.ws.http.HTTPBinding; |
aoqi@0 | 60 | import javax.xml.ws.soap.MTOMFeature; |
aoqi@0 | 61 | import javax.xml.ws.soap.SOAPBinding; |
aoqi@0 | 62 | import java.io.File; |
aoqi@0 | 63 | import java.io.FileInputStream; |
aoqi@0 | 64 | import java.io.IOException; |
aoqi@0 | 65 | import java.io.InputStream; |
aoqi@0 | 66 | import java.net.MalformedURLException; |
aoqi@0 | 67 | import java.net.URL; |
aoqi@0 | 68 | import java.util.ArrayList; |
aoqi@0 | 69 | import java.util.Arrays; |
aoqi@0 | 70 | import java.util.HashMap; |
aoqi@0 | 71 | import java.util.HashSet; |
aoqi@0 | 72 | import java.util.List; |
aoqi@0 | 73 | import java.util.Map; |
aoqi@0 | 74 | import java.util.Set; |
aoqi@0 | 75 | import java.util.logging.Level; |
aoqi@0 | 76 | import java.util.logging.Logger; |
aoqi@0 | 77 | |
aoqi@0 | 78 | /** |
aoqi@0 | 79 | * Parses {@code sun-jaxws.xml} into {@link WSEndpoint}. |
aoqi@0 | 80 | * <p/> |
aoqi@0 | 81 | * <p/> |
aoqi@0 | 82 | * Since {@code sun-jaxws.xml} captures more information than what {@link WSEndpoint} |
aoqi@0 | 83 | * represents (in particular URL pattern and name), this class |
aoqi@0 | 84 | * takes a parameterization 'A' so that the user of this parser can choose to |
aoqi@0 | 85 | * create another type that wraps {@link WSEndpoint}. |
aoqi@0 | 86 | * <p/> |
aoqi@0 | 87 | * {@link HttpAdapter} and its derived type is used for this often, |
aoqi@0 | 88 | * but it can be anything. |
aoqi@0 | 89 | * |
aoqi@0 | 90 | * @author WS Development Team |
aoqi@0 | 91 | * @author Kohsuke Kawaguchi |
aoqi@0 | 92 | */ |
aoqi@0 | 93 | public class DeploymentDescriptorParser<A> { |
aoqi@0 | 94 | |
aoqi@0 | 95 | public static final String NS_RUNTIME = "http://java.sun.com/xml/ns/jax-ws/ri/runtime"; |
aoqi@0 | 96 | public static final String JAXWS_WSDL_DD_DIR = "WEB-INF/wsdl"; |
aoqi@0 | 97 | |
aoqi@0 | 98 | public static final QName QNAME_ENDPOINTS = new QName(NS_RUNTIME, "endpoints"); |
aoqi@0 | 99 | public static final QName QNAME_ENDPOINT = new QName(NS_RUNTIME, "endpoint"); |
aoqi@0 | 100 | public static final QName QNAME_EXT_METADA = new QName(NS_RUNTIME, "external-metadata"); |
aoqi@0 | 101 | |
aoqi@0 | 102 | public static final String ATTR_FILE = "file"; |
aoqi@0 | 103 | public static final String ATTR_RESOURCE = "resource"; |
aoqi@0 | 104 | |
aoqi@0 | 105 | public static final String ATTR_VERSION = "version"; |
aoqi@0 | 106 | public static final String ATTR_NAME = "name"; |
aoqi@0 | 107 | public static final String ATTR_IMPLEMENTATION = "implementation"; |
aoqi@0 | 108 | public static final String ATTR_WSDL = "wsdl"; |
aoqi@0 | 109 | public static final String ATTR_SERVICE = "service"; |
aoqi@0 | 110 | public static final String ATTR_PORT = "port"; |
aoqi@0 | 111 | public static final String ATTR_URL_PATTERN = "url-pattern"; |
aoqi@0 | 112 | public static final String ATTR_ENABLE_MTOM = "enable-mtom"; |
aoqi@0 | 113 | public static final String ATTR_MTOM_THRESHOLD_VALUE = "mtom-threshold-value"; |
aoqi@0 | 114 | public static final String ATTR_BINDING = "binding"; |
aoqi@0 | 115 | public static final String ATTR_DATABINDING = "databinding"; |
aoqi@0 | 116 | |
aoqi@0 | 117 | public static final List<String> ATTRVALUE_SUPPORTED_VERSIONS = Arrays.asList("2.0", "2.1"); |
aoqi@0 | 118 | |
aoqi@0 | 119 | private static final Logger logger = Logger.getLogger(com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".server.http"); |
aoqi@0 | 120 | |
aoqi@0 | 121 | private final Container container; |
aoqi@0 | 122 | private final ClassLoader classLoader; |
aoqi@0 | 123 | private final ResourceLoader loader; |
aoqi@0 | 124 | private final AdapterFactory<A> adapterFactory; |
aoqi@0 | 125 | |
aoqi@0 | 126 | /** |
aoqi@0 | 127 | * Endpoint names that are declared. |
aoqi@0 | 128 | * Used to catch double definitions. |
aoqi@0 | 129 | */ |
aoqi@0 | 130 | private final Set<String> names = new HashSet<String>(); |
aoqi@0 | 131 | |
aoqi@0 | 132 | /** |
aoqi@0 | 133 | * WSDL/schema documents collected from /WEB-INF/wsdl. Keyed by the system ID. |
aoqi@0 | 134 | */ |
aoqi@0 | 135 | private final Map<String, SDDocumentSource> docs = new HashMap<String, SDDocumentSource>(); |
aoqi@0 | 136 | |
aoqi@0 | 137 | /** |
aoqi@0 | 138 | * @param cl Used to load service implementations. |
aoqi@0 | 139 | * @param loader Used to locate resources, in particular WSDL. |
aoqi@0 | 140 | * @param container Optional {@link Container} that {@link WSEndpoint}s receive. |
aoqi@0 | 141 | * @param adapterFactory Creates {@link HttpAdapter} (or its derived class.) |
aoqi@0 | 142 | */ |
aoqi@0 | 143 | public DeploymentDescriptorParser(ClassLoader cl, ResourceLoader loader, Container container, |
aoqi@0 | 144 | AdapterFactory<A> adapterFactory) throws MalformedURLException { |
aoqi@0 | 145 | classLoader = cl; |
aoqi@0 | 146 | this.loader = loader; |
aoqi@0 | 147 | this.container = container; |
aoqi@0 | 148 | this.adapterFactory = adapterFactory; |
aoqi@0 | 149 | |
aoqi@0 | 150 | collectDocs("/WEB-INF/wsdl/"); |
aoqi@0 | 151 | logger.log(Level.FINE, "war metadata={0}", docs); |
aoqi@0 | 152 | } |
aoqi@0 | 153 | |
aoqi@0 | 154 | /** |
aoqi@0 | 155 | * Parses the {@code sun-jaxws.xml} file and configures |
aoqi@0 | 156 | * a set of {@link HttpAdapter}s. |
aoqi@0 | 157 | */ |
aoqi@0 | 158 | public @NotNull List<A> parse(String systemId, InputStream is) { |
aoqi@0 | 159 | XMLStreamReader reader = null; |
aoqi@0 | 160 | try { |
aoqi@0 | 161 | reader = new TidyXMLStreamReader( |
aoqi@0 | 162 | XMLStreamReaderFactory.create(systemId, is, true), is); |
aoqi@0 | 163 | XMLStreamReaderUtil.nextElementContent(reader); |
aoqi@0 | 164 | return parseAdapters(reader); |
aoqi@0 | 165 | } finally { |
aoqi@0 | 166 | if (reader != null) { |
aoqi@0 | 167 | try { |
aoqi@0 | 168 | reader.close(); |
aoqi@0 | 169 | } catch (XMLStreamException e) { |
aoqi@0 | 170 | throw new ServerRtException("runtime.parser.xmlReader", e); |
aoqi@0 | 171 | } |
aoqi@0 | 172 | } |
aoqi@0 | 173 | try { |
aoqi@0 | 174 | is.close(); |
aoqi@0 | 175 | } catch (IOException e) { |
aoqi@0 | 176 | // ignore |
aoqi@0 | 177 | } |
aoqi@0 | 178 | } |
aoqi@0 | 179 | } |
aoqi@0 | 180 | |
aoqi@0 | 181 | /** |
aoqi@0 | 182 | * Parses the {@code sun-jaxws.xml} file and configures |
aoqi@0 | 183 | * a set of {@link HttpAdapter}s. |
aoqi@0 | 184 | */ |
aoqi@0 | 185 | public @NotNull List<A> parse(File f) throws IOException { |
aoqi@0 | 186 | FileInputStream in = new FileInputStream(f); |
aoqi@0 | 187 | try { |
aoqi@0 | 188 | return parse(f.getPath(), in); |
aoqi@0 | 189 | } finally { |
aoqi@0 | 190 | in.close(); |
aoqi@0 | 191 | } |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | /** |
aoqi@0 | 195 | * Get all the WSDL & schema documents recursively. |
aoqi@0 | 196 | */ |
aoqi@0 | 197 | private void collectDocs(String dirPath) throws MalformedURLException { |
aoqi@0 | 198 | Set<String> paths = loader.getResourcePaths(dirPath); |
aoqi@0 | 199 | if (paths != null) { |
aoqi@0 | 200 | for (String path : paths) { |
aoqi@0 | 201 | if (path.endsWith("/")) { |
aoqi@0 | 202 | if (path.endsWith("/CVS/") || path.endsWith("/.svn/")) { |
aoqi@0 | 203 | continue; |
aoqi@0 | 204 | } |
aoqi@0 | 205 | collectDocs(path); |
aoqi@0 | 206 | } else { |
aoqi@0 | 207 | URL res = loader.getResource(path); |
aoqi@0 | 208 | docs.put(res.toString(), SDDocumentSource.create(res)); |
aoqi@0 | 209 | } |
aoqi@0 | 210 | } |
aoqi@0 | 211 | } |
aoqi@0 | 212 | } |
aoqi@0 | 213 | |
aoqi@0 | 214 | |
aoqi@0 | 215 | private List<A> parseAdapters(XMLStreamReader reader) { |
aoqi@0 | 216 | if (!reader.getName().equals(QNAME_ENDPOINTS)) { |
aoqi@0 | 217 | failWithFullName("runtime.parser.invalidElement", reader); |
aoqi@0 | 218 | } |
aoqi@0 | 219 | |
aoqi@0 | 220 | List<A> adapters = new ArrayList<A>(); |
aoqi@0 | 221 | |
aoqi@0 | 222 | Attributes attrs = XMLStreamReaderUtil.getAttributes(reader); |
aoqi@0 | 223 | String version = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_VERSION); |
aoqi@0 | 224 | if (!ATTRVALUE_SUPPORTED_VERSIONS.contains(version)) { |
aoqi@0 | 225 | failWithLocalName("runtime.parser.invalidVersionNumber", reader, version); |
aoqi@0 | 226 | } |
aoqi@0 | 227 | |
aoqi@0 | 228 | while (XMLStreamReaderUtil.nextElementContent(reader) != XMLStreamConstants.END_ELEMENT) { |
aoqi@0 | 229 | |
aoqi@0 | 230 | if (reader.getName().equals(QNAME_ENDPOINT)) { |
aoqi@0 | 231 | attrs = XMLStreamReaderUtil.getAttributes(reader); |
aoqi@0 | 232 | |
aoqi@0 | 233 | String name = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_NAME); |
aoqi@0 | 234 | if (!names.add(name)) { |
aoqi@0 | 235 | logger.warning( |
aoqi@0 | 236 | WsservletMessages.SERVLET_WARNING_DUPLICATE_ENDPOINT_NAME(/*name*/)); |
aoqi@0 | 237 | } |
aoqi@0 | 238 | |
aoqi@0 | 239 | String implementationName = |
aoqi@0 | 240 | getMandatoryNonEmptyAttribute(reader, attrs, ATTR_IMPLEMENTATION); |
aoqi@0 | 241 | Class<?> implementorClass = getImplementorClass(implementationName, reader); |
aoqi@0 | 242 | |
aoqi@0 | 243 | MetadataReader metadataReader = null; |
aoqi@0 | 244 | ExternalMetadataFeature externalMetadataFeature = null; |
aoqi@0 | 245 | |
aoqi@0 | 246 | // parse subelements to instantiate externalMetadataReader, if necessary ... |
aoqi@0 | 247 | XMLStreamReaderUtil.nextElementContent(reader); |
aoqi@0 | 248 | if (reader.getEventType() != XMLStreamConstants.END_ELEMENT) { |
aoqi@0 | 249 | externalMetadataFeature = configureExternalMetadataReader(reader); |
aoqi@0 | 250 | if (externalMetadataFeature != null) { |
aoqi@0 | 251 | metadataReader = externalMetadataFeature.getMetadataReader(implementorClass.getClassLoader(), false); |
aoqi@0 | 252 | } |
aoqi@0 | 253 | } |
aoqi@0 | 254 | |
aoqi@0 | 255 | QName serviceName = getQNameAttribute(attrs, ATTR_SERVICE); |
aoqi@0 | 256 | if (serviceName == null) { |
aoqi@0 | 257 | serviceName = EndpointFactory.getDefaultServiceName(implementorClass, metadataReader); |
aoqi@0 | 258 | } |
aoqi@0 | 259 | |
aoqi@0 | 260 | QName portName = getQNameAttribute(attrs, ATTR_PORT); |
aoqi@0 | 261 | if (portName == null) { |
aoqi@0 | 262 | portName = EndpointFactory.getDefaultPortName(serviceName, implementorClass, metadataReader); |
aoqi@0 | 263 | } |
aoqi@0 | 264 | |
aoqi@0 | 265 | //get enable-mtom attribute value |
aoqi@0 | 266 | String enable_mtom = getAttribute(attrs, ATTR_ENABLE_MTOM); |
aoqi@0 | 267 | String mtomThreshold = getAttribute(attrs, ATTR_MTOM_THRESHOLD_VALUE); |
aoqi@0 | 268 | String dbMode = getAttribute(attrs, ATTR_DATABINDING); |
aoqi@0 | 269 | String bindingId = getAttribute(attrs, ATTR_BINDING); |
aoqi@0 | 270 | if (bindingId != null) { |
aoqi@0 | 271 | // Convert short-form tokens to API's binding ids |
aoqi@0 | 272 | bindingId = getBindingIdForToken(bindingId); |
aoqi@0 | 273 | } |
aoqi@0 | 274 | WSBinding binding = createBinding(bindingId, implementorClass, enable_mtom, mtomThreshold, dbMode); |
aoqi@0 | 275 | if (externalMetadataFeature != null) { |
aoqi@0 | 276 | binding.getFeatures().mergeFeatures(new WebServiceFeature[]{externalMetadataFeature}, |
aoqi@0 | 277 | true); |
aoqi@0 | 278 | } |
aoqi@0 | 279 | |
aoqi@0 | 280 | String urlPattern = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_URL_PATTERN); |
aoqi@0 | 281 | |
aoqi@0 | 282 | // TODO use 'docs' as the metadata. If wsdl is non-null it's the primary. |
aoqi@0 | 283 | boolean handlersSetInDD = setHandlersAndRoles(binding, reader, serviceName, portName); |
aoqi@0 | 284 | |
aoqi@0 | 285 | EndpointFactory.verifyImplementorClass(implementorClass, metadataReader); |
aoqi@0 | 286 | SDDocumentSource primaryWSDL = getPrimaryWSDL(reader, attrs, implementorClass, metadataReader); |
aoqi@0 | 287 | |
aoqi@0 | 288 | WSEndpoint<?> endpoint = WSEndpoint.create( |
aoqi@0 | 289 | implementorClass, !handlersSetInDD, |
aoqi@0 | 290 | null, |
aoqi@0 | 291 | serviceName, portName, container, binding, |
aoqi@0 | 292 | primaryWSDL, docs.values(), createEntityResolver(), false |
aoqi@0 | 293 | ); |
aoqi@0 | 294 | adapters.add(adapterFactory.createAdapter(name, urlPattern, endpoint)); |
aoqi@0 | 295 | } else { |
aoqi@0 | 296 | failWithLocalName("runtime.parser.invalidElement", reader); |
aoqi@0 | 297 | } |
aoqi@0 | 298 | } |
aoqi@0 | 299 | return adapters; |
aoqi@0 | 300 | } |
aoqi@0 | 301 | |
aoqi@0 | 302 | /** |
aoqi@0 | 303 | * @param ddBindingId binding id explicitlyspecified in the DeploymentDescriptor or parameter |
aoqi@0 | 304 | * @param implClass Endpoint Implementation class |
aoqi@0 | 305 | * @param mtomEnabled represents mtom-enabled attribute in DD |
aoqi@0 | 306 | * @param mtomThreshold threshold value specified in DD |
aoqi@0 | 307 | * @return is returned with only MTOMFeature set resolving the various precendece rules |
aoqi@0 | 308 | */ |
aoqi@0 | 309 | private static WSBinding createBinding(String ddBindingId, Class implClass, |
aoqi@0 | 310 | String mtomEnabled, String mtomThreshold, String dataBindingMode) { |
aoqi@0 | 311 | // Features specified through DD |
aoqi@0 | 312 | WebServiceFeatureList features; |
aoqi@0 | 313 | |
aoqi@0 | 314 | MTOMFeature mtomfeature = null; |
aoqi@0 | 315 | if (mtomEnabled != null) { |
aoqi@0 | 316 | if (mtomThreshold != null) { |
aoqi@0 | 317 | mtomfeature = new MTOMFeature(Boolean.valueOf(mtomEnabled), |
aoqi@0 | 318 | Integer.valueOf(mtomThreshold)); |
aoqi@0 | 319 | } else { |
aoqi@0 | 320 | mtomfeature = new MTOMFeature(Boolean.valueOf(mtomEnabled)); |
aoqi@0 | 321 | } |
aoqi@0 | 322 | } |
aoqi@0 | 323 | |
aoqi@0 | 324 | BindingID bindingID; |
aoqi@0 | 325 | if (ddBindingId != null) { |
aoqi@0 | 326 | bindingID = BindingID.parse(ddBindingId); |
aoqi@0 | 327 | features = bindingID.createBuiltinFeatureList(); |
aoqi@0 | 328 | |
aoqi@0 | 329 | if (checkMtomConflict(features.get(MTOMFeature.class), mtomfeature)) { |
aoqi@0 | 330 | throw new ServerRtException(ServerMessages.DD_MTOM_CONFLICT(ddBindingId, mtomEnabled)); |
aoqi@0 | 331 | } |
aoqi@0 | 332 | } else { |
aoqi@0 | 333 | bindingID = BindingID.parse(implClass); |
aoqi@0 | 334 | // Since bindingID is coming from implclass, |
aoqi@0 | 335 | // mtom through Feature annotation or DD takes precendece |
aoqi@0 | 336 | |
aoqi@0 | 337 | features = new WebServiceFeatureList(); |
aoqi@0 | 338 | if (mtomfeature != null) { // this wins over MTOM setting in bindingID |
aoqi@0 | 339 | features.add(mtomfeature); |
aoqi@0 | 340 | } |
aoqi@0 | 341 | features.addAll(bindingID.createBuiltinFeatureList()); |
aoqi@0 | 342 | } |
aoqi@0 | 343 | |
aoqi@0 | 344 | if (dataBindingMode != null) { |
aoqi@0 | 345 | features.add(new DatabindingModeFeature(dataBindingMode)); |
aoqi@0 | 346 | } |
aoqi@0 | 347 | |
aoqi@0 | 348 | return bindingID.createBinding(features.toArray()); |
aoqi@0 | 349 | } |
aoqi@0 | 350 | |
aoqi@0 | 351 | private static boolean checkMtomConflict(MTOMFeature lhs, MTOMFeature rhs) { |
aoqi@0 | 352 | if (lhs == null || rhs == null) { |
aoqi@0 | 353 | return false; |
aoqi@0 | 354 | } |
aoqi@0 | 355 | return lhs.isEnabled() ^ rhs.isEnabled(); |
aoqi@0 | 356 | } |
aoqi@0 | 357 | |
aoqi@0 | 358 | /** |
aoqi@0 | 359 | * JSR-109 defines short-form tokens for standard binding Ids. These are |
aoqi@0 | 360 | * used only in DD. So stand alone deployment descirptor should also honor |
aoqi@0 | 361 | * these tokens. This method converts the tokens to API's standard |
aoqi@0 | 362 | * binding ids |
aoqi@0 | 363 | * |
aoqi@0 | 364 | * @param lexical binding attribute value from DD. Always not null |
aoqi@0 | 365 | * @return returns corresponding API's binding ID or the same lexical |
aoqi@0 | 366 | */ |
aoqi@0 | 367 | public static @NotNull String getBindingIdForToken(@NotNull String lexical) { |
aoqi@0 | 368 | if (lexical.equals("##SOAP11_HTTP")) { |
aoqi@0 | 369 | return SOAPBinding.SOAP11HTTP_BINDING; |
aoqi@0 | 370 | } else if (lexical.equals("##SOAP11_HTTP_MTOM")) { |
aoqi@0 | 371 | return SOAPBinding.SOAP11HTTP_MTOM_BINDING; |
aoqi@0 | 372 | } else if (lexical.equals("##SOAP12_HTTP")) { |
aoqi@0 | 373 | return SOAPBinding.SOAP12HTTP_BINDING; |
aoqi@0 | 374 | } else if (lexical.equals("##SOAP12_HTTP_MTOM")) { |
aoqi@0 | 375 | return SOAPBinding.SOAP12HTTP_MTOM_BINDING; |
aoqi@0 | 376 | } else if (lexical.equals("##XML_HTTP")) { |
aoqi@0 | 377 | return HTTPBinding.HTTP_BINDING; |
aoqi@0 | 378 | } |
aoqi@0 | 379 | return lexical; |
aoqi@0 | 380 | } |
aoqi@0 | 381 | |
aoqi@0 | 382 | /** |
aoqi@0 | 383 | * Creates a new "Adapter". |
aoqi@0 | 384 | * <p/> |
aoqi@0 | 385 | * Normally 'A' would be {@link HttpAdapter} or some derived class. |
aoqi@0 | 386 | * But the parser doesn't require that to be of any particular type. |
aoqi@0 | 387 | */ |
aoqi@0 | 388 | public static interface AdapterFactory<A> { |
aoqi@0 | 389 | A createAdapter(String name, String urlPattern, WSEndpoint<?> endpoint); |
aoqi@0 | 390 | } |
aoqi@0 | 391 | |
aoqi@0 | 392 | /** |
aoqi@0 | 393 | * Checks the deployment descriptor or {@link @WebServiceProvider} annotation |
aoqi@0 | 394 | * to see if it points to any WSDL. If so, returns the {@link SDDocumentSource}. |
aoqi@0 | 395 | * |
aoqi@0 | 396 | * @return The pointed WSDL, if any. Otherwise null. |
aoqi@0 | 397 | */ |
aoqi@0 | 398 | private SDDocumentSource getPrimaryWSDL(XMLStreamReader xsr, Attributes attrs, Class<?> implementorClass, MetadataReader metadataReader) { |
aoqi@0 | 399 | |
aoqi@0 | 400 | String wsdlFile = getAttribute(attrs, ATTR_WSDL); |
aoqi@0 | 401 | if (wsdlFile == null) { |
aoqi@0 | 402 | wsdlFile = EndpointFactory.getWsdlLocation(implementorClass, metadataReader); |
aoqi@0 | 403 | } |
aoqi@0 | 404 | |
aoqi@0 | 405 | if (wsdlFile != null) { |
aoqi@0 | 406 | if (!wsdlFile.startsWith(JAXWS_WSDL_DD_DIR)) { |
aoqi@0 | 407 | logger.log(Level.WARNING, "Ignoring wrong wsdl={0}. It should start with {1}. Going to generate and publish a new WSDL.", new Object[]{wsdlFile, JAXWS_WSDL_DD_DIR}); |
aoqi@0 | 408 | return null; |
aoqi@0 | 409 | } |
aoqi@0 | 410 | |
aoqi@0 | 411 | URL wsdl; |
aoqi@0 | 412 | try { |
aoqi@0 | 413 | wsdl = loader.getResource('/' + wsdlFile); |
aoqi@0 | 414 | } catch (MalformedURLException e) { |
aoqi@0 | 415 | throw new LocatableWebServiceException( |
aoqi@0 | 416 | ServerMessages.RUNTIME_PARSER_WSDL_NOT_FOUND(wsdlFile), e, xsr); |
aoqi@0 | 417 | } |
aoqi@0 | 418 | if (wsdl == null) { |
aoqi@0 | 419 | throw new LocatableWebServiceException( |
aoqi@0 | 420 | ServerMessages.RUNTIME_PARSER_WSDL_NOT_FOUND(wsdlFile), xsr); |
aoqi@0 | 421 | } |
aoqi@0 | 422 | SDDocumentSource docInfo = docs.get(wsdl.toExternalForm()); |
aoqi@0 | 423 | assert docInfo != null; |
aoqi@0 | 424 | return docInfo; |
aoqi@0 | 425 | } |
aoqi@0 | 426 | |
aoqi@0 | 427 | return null; |
aoqi@0 | 428 | } |
aoqi@0 | 429 | |
aoqi@0 | 430 | /** |
aoqi@0 | 431 | * Creates an {@link EntityResolver} that consults {@code /WEB-INF/jax-ws-catalog.xml}. |
aoqi@0 | 432 | */ |
aoqi@0 | 433 | private EntityResolver createEntityResolver() { |
aoqi@0 | 434 | try { |
aoqi@0 | 435 | return XmlUtil.createEntityResolver(loader.getCatalogFile()); |
aoqi@0 | 436 | } catch (MalformedURLException e) { |
aoqi@0 | 437 | throw new WebServiceException(e); |
aoqi@0 | 438 | } |
aoqi@0 | 439 | } |
aoqi@0 | 440 | |
aoqi@0 | 441 | protected String getAttribute(Attributes attrs, String name) { |
aoqi@0 | 442 | String value = attrs.getValue(name); |
aoqi@0 | 443 | if (value != null) { |
aoqi@0 | 444 | value = value.trim(); |
aoqi@0 | 445 | } |
aoqi@0 | 446 | return value; |
aoqi@0 | 447 | } |
aoqi@0 | 448 | |
aoqi@0 | 449 | protected QName getQNameAttribute(Attributes attrs, String name) { |
aoqi@0 | 450 | String value = getAttribute(attrs, name); |
aoqi@0 | 451 | if (value == null || value.equals("")) { |
aoqi@0 | 452 | return null; |
aoqi@0 | 453 | } else { |
aoqi@0 | 454 | return QName.valueOf(value); |
aoqi@0 | 455 | } |
aoqi@0 | 456 | } |
aoqi@0 | 457 | |
aoqi@0 | 458 | protected String getNonEmptyAttribute(XMLStreamReader reader, Attributes attrs, String name) { |
aoqi@0 | 459 | String value = getAttribute(attrs, name); |
aoqi@0 | 460 | if (value != null && value.equals("")) { |
aoqi@0 | 461 | failWithLocalName( |
aoqi@0 | 462 | "runtime.parser.invalidAttributeValue", |
aoqi@0 | 463 | reader, |
aoqi@0 | 464 | name); |
aoqi@0 | 465 | } |
aoqi@0 | 466 | return value; |
aoqi@0 | 467 | } |
aoqi@0 | 468 | |
aoqi@0 | 469 | protected String getMandatoryAttribute(XMLStreamReader reader, Attributes attrs, String name) { |
aoqi@0 | 470 | String value = getAttribute(attrs, name); |
aoqi@0 | 471 | if (value == null) { |
aoqi@0 | 472 | failWithLocalName("runtime.parser.missing.attribute", reader, name); |
aoqi@0 | 473 | } |
aoqi@0 | 474 | return value; |
aoqi@0 | 475 | } |
aoqi@0 | 476 | |
aoqi@0 | 477 | protected String getMandatoryNonEmptyAttribute(XMLStreamReader reader, Attributes attributes, |
aoqi@0 | 478 | String name) { |
aoqi@0 | 479 | String value = getAttribute(attributes, name); |
aoqi@0 | 480 | if (value == null) { |
aoqi@0 | 481 | failWithLocalName("runtime.parser.missing.attribute", reader, name); |
aoqi@0 | 482 | } else if (value.equals("")) { |
aoqi@0 | 483 | failWithLocalName( |
aoqi@0 | 484 | "runtime.parser.invalidAttributeValue", |
aoqi@0 | 485 | reader, |
aoqi@0 | 486 | name); |
aoqi@0 | 487 | } |
aoqi@0 | 488 | return value; |
aoqi@0 | 489 | } |
aoqi@0 | 490 | |
aoqi@0 | 491 | /** |
aoqi@0 | 492 | * Parses the handler and role information and sets it |
aoqi@0 | 493 | * on the {@link WSBinding}. |
aoqi@0 | 494 | * |
aoqi@0 | 495 | * @return true if <handler-chains> element present in DD |
aoqi@0 | 496 | * false otherwise. |
aoqi@0 | 497 | */ |
aoqi@0 | 498 | protected boolean setHandlersAndRoles(WSBinding binding, XMLStreamReader reader, QName serviceName, QName portName) { |
aoqi@0 | 499 | |
aoqi@0 | 500 | if (reader.getEventType() == XMLStreamConstants.END_ELEMENT || |
aoqi@0 | 501 | !reader.getName().equals(HandlerChainsModel.QNAME_HANDLER_CHAINS)) { |
aoqi@0 | 502 | return false; |
aoqi@0 | 503 | } |
aoqi@0 | 504 | |
aoqi@0 | 505 | HandlerAnnotationInfo handlerInfo = HandlerChainsModel.parseHandlerFile( |
aoqi@0 | 506 | reader, classLoader, serviceName, portName, binding); |
aoqi@0 | 507 | |
aoqi@0 | 508 | binding.setHandlerChain(handlerInfo.getHandlers()); |
aoqi@0 | 509 | if (binding instanceof SOAPBinding) { |
aoqi@0 | 510 | ((SOAPBinding) binding).setRoles(handlerInfo.getRoles()); |
aoqi@0 | 511 | } |
aoqi@0 | 512 | |
aoqi@0 | 513 | // move past </handler-chains> |
aoqi@0 | 514 | XMLStreamReaderUtil.nextContent(reader); |
aoqi@0 | 515 | return true; |
aoqi@0 | 516 | } |
aoqi@0 | 517 | |
aoqi@0 | 518 | protected ExternalMetadataFeature configureExternalMetadataReader(XMLStreamReader reader) { |
aoqi@0 | 519 | |
aoqi@0 | 520 | ExternalMetadataFeature.Builder featureBuilder = null; |
aoqi@0 | 521 | while (QNAME_EXT_METADA.equals(reader.getName())) { |
aoqi@0 | 522 | |
aoqi@0 | 523 | if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { |
aoqi@0 | 524 | Attributes attrs = XMLStreamReaderUtil.getAttributes(reader); |
aoqi@0 | 525 | String file = getAttribute(attrs, ATTR_FILE); |
aoqi@0 | 526 | if (file != null) { |
aoqi@0 | 527 | if (featureBuilder == null) { |
aoqi@0 | 528 | featureBuilder = ExternalMetadataFeature.builder(); |
aoqi@0 | 529 | } |
aoqi@0 | 530 | featureBuilder.addFiles(new File(file)); |
aoqi@0 | 531 | } |
aoqi@0 | 532 | |
aoqi@0 | 533 | String res = getAttribute(attrs, ATTR_RESOURCE); |
aoqi@0 | 534 | if (res != null) { |
aoqi@0 | 535 | if (featureBuilder == null) { |
aoqi@0 | 536 | featureBuilder = ExternalMetadataFeature.builder(); |
aoqi@0 | 537 | } |
aoqi@0 | 538 | featureBuilder.addResources(res); |
aoqi@0 | 539 | } |
aoqi@0 | 540 | } |
aoqi@0 | 541 | |
aoqi@0 | 542 | XMLStreamReaderUtil.nextElementContent(reader); |
aoqi@0 | 543 | } |
aoqi@0 | 544 | |
aoqi@0 | 545 | return buildFeature(featureBuilder); |
aoqi@0 | 546 | } |
aoqi@0 | 547 | |
aoqi@0 | 548 | private ExternalMetadataFeature buildFeature(ExternalMetadataFeature.Builder builder) { |
aoqi@0 | 549 | return builder != null ? builder.build() : null; |
aoqi@0 | 550 | } |
aoqi@0 | 551 | |
aoqi@0 | 552 | protected static void fail(String key, XMLStreamReader reader) { |
aoqi@0 | 553 | logger.log(Level.SEVERE, "{0}{1}", new Object[]{key, reader.getLocation().getLineNumber()}); |
aoqi@0 | 554 | throw new ServerRtException( |
aoqi@0 | 555 | key, |
aoqi@0 | 556 | Integer.toString(reader.getLocation().getLineNumber())); |
aoqi@0 | 557 | } |
aoqi@0 | 558 | |
aoqi@0 | 559 | protected static void failWithFullName(String key, XMLStreamReader reader) { |
aoqi@0 | 560 | throw new ServerRtException( |
aoqi@0 | 561 | key, |
aoqi@0 | 562 | reader.getLocation().getLineNumber(), |
aoqi@0 | 563 | reader.getName()); |
aoqi@0 | 564 | } |
aoqi@0 | 565 | |
aoqi@0 | 566 | protected static void failWithLocalName(String key, XMLStreamReader reader) { |
aoqi@0 | 567 | throw new ServerRtException( |
aoqi@0 | 568 | key, |
aoqi@0 | 569 | reader.getLocation().getLineNumber(), |
aoqi@0 | 570 | reader.getLocalName()); |
aoqi@0 | 571 | } |
aoqi@0 | 572 | |
aoqi@0 | 573 | protected static void failWithLocalName(String key, XMLStreamReader reader, String arg) { |
aoqi@0 | 574 | throw new ServerRtException( |
aoqi@0 | 575 | key, |
aoqi@0 | 576 | reader.getLocation().getLineNumber(), |
aoqi@0 | 577 | reader.getLocalName(), |
aoqi@0 | 578 | arg); |
aoqi@0 | 579 | } |
aoqi@0 | 580 | |
aoqi@0 | 581 | protected Class loadClass(String name) { |
aoqi@0 | 582 | try { |
aoqi@0 | 583 | return Class.forName(name, true, classLoader); |
aoqi@0 | 584 | } catch (ClassNotFoundException e) { |
aoqi@0 | 585 | logger.log(Level.SEVERE, e.getMessage(), e); |
aoqi@0 | 586 | throw new ServerRtException( |
aoqi@0 | 587 | "runtime.parser.classNotFound", |
aoqi@0 | 588 | name); |
aoqi@0 | 589 | } |
aoqi@0 | 590 | } |
aoqi@0 | 591 | |
aoqi@0 | 592 | |
aoqi@0 | 593 | /** |
aoqi@0 | 594 | * Loads the class of the given name. |
aoqi@0 | 595 | * |
aoqi@0 | 596 | * @param xsr Used to report the source location information if there's any error. |
aoqi@0 | 597 | */ |
aoqi@0 | 598 | private Class getImplementorClass(String name, XMLStreamReader xsr) { |
aoqi@0 | 599 | try { |
aoqi@0 | 600 | return Class.forName(name, true, classLoader); |
aoqi@0 | 601 | } catch (ClassNotFoundException e) { |
aoqi@0 | 602 | logger.log(Level.SEVERE, e.getMessage(), e); |
aoqi@0 | 603 | throw new LocatableWebServiceException( |
aoqi@0 | 604 | ServerMessages.RUNTIME_PARSER_CLASS_NOT_FOUND(name), e, xsr); |
aoqi@0 | 605 | } |
aoqi@0 | 606 | } |
aoqi@0 | 607 | |
aoqi@0 | 608 | } |