com.sun.xml.ws.transport.httpspi.servlet.DeploymentDescriptorParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxws-rt Show documentation
Show all versions of jaxws-rt Show documentation
JAX-WS Runtime with module descriptor
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.ws.transport.httpspi.servlet;
import com.sun.xml.ws.util.xml.XmlUtil;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import static javax.xml.stream.XMLStreamConstants.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.http.HTTPBinding;
import javax.xml.ws.soap.MTOMFeature;
import javax.xml.ws.soap.SOAPBinding;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Parses {@code sun-jaxws.xml}
*
* @author Jitendra Kotamraju
*/
public class DeploymentDescriptorParser {
private final ClassLoader classLoader;
private final ResourceLoader loader;
private final AdapterFactory adapterFactory;
// securite xml processing always enabled - parsing deployment descriptor ...
private static final XMLInputFactory xif = XmlUtil.newXMLInputFactory(true);
/**
* Endpoint names that are declared.
* Used to catch double definitions.
*/
private final Set names = new HashSet();
/**
* WSDL/schema documents collected from /WEB-INF/wsdl. Keyed by the system ID.
*/
private final List docs = new ArrayList();
/**
*
* @param cl
* Used to load service implementations.
* @param loader
* Used to locate resources, in particular WSDL.
* @param adapterFactory
* Creates {@link EndpointAdapter} (or its derived class.)
*/
public DeploymentDescriptorParser(ClassLoader cl, ResourceLoader loader, AdapterFactory adapterFactory) throws IOException {
classLoader = cl;
this.loader = loader;
this.adapterFactory = adapterFactory;
collectDocs("/WEB-INF/wsdl/");
logger.log(Level.FINE, "war metadata={0}", docs);
}
/**
* Parses the {@code sun-jaxws.xml} file and configures
* a set of {@link EndpointAdapter}s.
*/
public List parse(String systemId, InputStream is) {
XMLStreamReader reader = null;
try {
synchronized(xif) {
reader = xif.createXMLStreamReader(systemId, is);
}
nextElementContent(reader);
return parseAdapters(reader);
} catch(IOException e) {
throw new WebServiceException(e);
} catch(XMLStreamException xe) {
throw new WebServiceException(xe);
} finally {
if (reader != null) {
try {
reader.close();
} catch (XMLStreamException e) {
// ignore
}
}
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
private static int nextElementContent(XMLStreamReader reader) throws XMLStreamException {
do {
int state = reader.next();
if (state == START_ELEMENT || state == END_ELEMENT || state == END_DOCUMENT) {
return state;
}
} while(true);
}
/**
* Parses the {@code sun-jaxws.xml} file and configures
* a set of {@link EndpointAdapter}s.
*/
public List parse(File f) throws IOException {
FileInputStream in = new FileInputStream(f);
try {
return parse(f.getPath(), in);
} finally {
in.close();
}
}
/**
* Get all the WSDL & schema documents recursively.
*/
private void collectDocs(String dirPath) throws IOException {
Set paths = loader.getResourcePaths(dirPath);
if (paths != null) {
for (String path : paths) {
if (path.endsWith("/")) {
if(path.endsWith("/CVS/") || path.endsWith("/.svn/")) {
continue;
}
collectDocs(path);
} else {
URL res = loader.getResource(path);
docs.add(res);
}
}
}
}
private List parseAdapters(XMLStreamReader reader) throws IOException, XMLStreamException {
if (!reader.getName().equals(QNAME_ENDPOINTS)) {
failWithFullName("runtime.parser.invalidElement", reader);
}
List adapters = new ArrayList();
String version = getMandatoryNonEmptyAttribute(reader, ATTR_VERSION);
if (!version.equals(ATTRVALUE_VERSION_1_0)) {
failWithLocalName("sun-jaxws.xml's version attribut runtime.parser.invalidVersionNumber",
reader, version);
}
while (nextElementContent(reader) != XMLStreamConstants.END_ELEMENT) {
if (reader.getName().equals(QNAME_ENDPOINT)) {
String name = getMandatoryNonEmptyAttribute(reader, ATTR_NAME);
if (!names.add(name)) {
logger.log(Level.WARNING,"sun-jaxws.xml contains duplicate endpoint names. "+"The first duplicate name is = {0}", name);
}
String implementationName =
getMandatoryNonEmptyAttribute(reader, ATTR_IMPLEMENTATION);
Class implementorClass = getImplementorClass(implementationName, reader);
QName serviceName = getQNameAttribute(reader, ATTR_SERVICE);
QName portName = getQNameAttribute(reader, ATTR_PORT);
ArrayList features = new ArrayList();
//get enable-mtom attribute value
String enable_mtom = getAttribute(reader, ATTR_ENABLE_MTOM);
String mtomThreshold = getAttribute(reader, ATTR_MTOM_THRESHOLD_VALUE);
if (Boolean.valueOf(enable_mtom)) {
if (mtomThreshold != null) {
features.add(new MTOMFeature(true, Integer.parseInt(mtomThreshold)));
} else {
features.add(new MTOMFeature(true));
}
}
String bindingId = getAttribute(reader, ATTR_BINDING);
if (bindingId != null) {
// Convert short-form tokens to API's binding ids
bindingId = getBindingIdForToken(bindingId);
}
String urlPattern =
getMandatoryNonEmptyAttribute(reader, ATTR_URL_PATTERN);
//boolean handlersSetInDD = setHandlersAndRoles(binding, reader, serviceName, portName);
nextElementContent(reader);
ensureNoContent(reader);
List