use of com.sun.xml.ws.api.server.SDDocument in project metro-jax-ws by eclipse-ee4j.
the class HttpAdapter method handleGet.
public boolean handleGet(@NotNull WSHTTPConnection connection) throws IOException {
if (connection.getRequestMethod().equals("GET")) {
// metadata query. let the interceptor run
for (Component c : endpoint.getComponents()) {
HttpMetadataPublisher spi = c.getSPI(HttpMetadataPublisher.class);
if (spi != null && spi.handleMetadataRequest(this, connection)) {
return true;
}
// handled
}
if (isMetadataQuery(connection.getQueryString())) {
// Sends published WSDL and schema documents as the default action.
publishWSDL(connection);
return true;
}
Binding binding = getEndpoint().getBinding();
if (!(binding instanceof HTTPBinding)) {
// Writes HTML page with all the endpoint descriptions
writeWebServicesHtmlPage(connection);
return true;
}
} else if (connection.getRequestMethod().equals("HEAD")) {
connection.getInput().close();
Binding binding = getEndpoint().getBinding();
if (isMetadataQuery(connection.getQueryString())) {
SDDocument doc = wsdls.get(connection.getQueryString());
connection.setStatus(doc != null ? HttpURLConnection.HTTP_OK : HttpURLConnection.HTTP_NOT_FOUND);
connection.getOutput().close();
connection.close();
return true;
} else if (!(binding instanceof HTTPBinding)) {
connection.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
connection.getOutput().close();
connection.close();
return true;
}
// Let the endpoint handle for HTTPBinding
}
return false;
}
use of com.sun.xml.ws.api.server.SDDocument in project metro-jax-ws by eclipse-ee4j.
the class HttpAdapter method publishWSDL.
/**
* Sends out the WSDL (and other referenced documents)
* in response to the GET requests to URLs like "?wsdl" or "?xsd=2".
*
* @param con
* The connection to which the data will be sent.
*
* @throws java.io.IOException when I/O errors happen
*/
public void publishWSDL(@NotNull WSHTTPConnection con) throws IOException {
con.getInput().close();
SDDocument doc = wsdls.get(con.getQueryString());
if (doc == null) {
writeNotFoundErrorPage(con, "Invalid Request");
return;
}
con.setStatus(HttpURLConnection.HTTP_OK);
con.setContentTypeResponseHeader("text/xml;charset=utf-8");
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
PortAddressResolver portAddressResolver = getPortAddressResolver(con.getBaseAddress());
DocumentAddressResolver resolver = getDocumentAddressResolver(portAddressResolver);
doc.writeTo(portAddressResolver, resolver, os);
os.close();
}
use of com.sun.xml.ws.api.server.SDDocument in project metro-jax-ws by eclipse-ee4j.
the class AbstractSchemaValidationTube method getSchemaSources.
/*
* Using the following algorithm described in the xerces discussion thread:
*
* "If you're synthesizing schema documents to glue together the ones in
* the WSDL then you may not even need to use "honour-all-schemaLocations".
* Create a schema document for each namespace with <xs:include>s
* (for each schema document in the WSDL with that target namespace)
* and then combine those together with <xs:import>s for each of those
* namespaces in a "master" schema document.
*
* That should work with any schema processor, not just those which
* honour multiple imports for the same namespace."
*/
protected Source[] getSchemaSources(Iterable<SDDocument> docs, MetadataResolverImpl mdresolver) {
// All schema fragments in WSDLs are put inlinedSchemas
// systemID --> DOMSource
Map<String, DOMSource> inlinedSchemas = new HashMap<>();
// Consolidates all the schemas(inlined and external) for a tns
// tns --> list of systemId
Map<String, List<String>> multiSchemaForTns = new HashMap<>();
for (SDDocument sdoc : docs) {
if (sdoc.isWSDL()) {
Document dom = createDOM(sdoc);
// Get xsd:schema node from WSDL's DOM
addSchemaFragmentSource(dom, sdoc.getURL().toExternalForm(), inlinedSchemas);
} else if (sdoc.isSchema()) {
updateMultiSchemaForTns(((SDDocument.Schema) sdoc).getTargetNamespace(), sdoc.getURL().toExternalForm(), multiSchemaForTns);
}
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "WSDL inlined schema fragment documents(these are used to create a pseudo schema) = {0}", inlinedSchemas.keySet());
}
for (DOMSource src : inlinedSchemas.values()) {
String tns = getTargetNamespace(src);
updateMultiSchemaForTns(tns, src.getSystemId(), multiSchemaForTns);
}
if (multiSchemaForTns.isEmpty()) {
// WSDL doesn't have any schema fragments
return new Source[0];
} else if (multiSchemaForTns.size() == 1 && multiSchemaForTns.values().iterator().next().size() == 1) {
// It must be a inlined schema, otherwise there would be at least two schemas
String systemId = multiSchemaForTns.values().iterator().next().get(0);
return new Source[] { inlinedSchemas.get(systemId) };
}
// need to resolve these inlined schema fragments
mdresolver.addSchemas(inlinedSchemas.values());
// If there are multiple schema fragments for the same tns, create a
// pseudo schema for that tns by using <xsd:include> of those.
// tns --> systemId of a pseudo schema document (consolidated for that tns)
Map<String, String> oneSchemaForTns = new HashMap<>();
int i = 0;
for (Map.Entry<String, List<String>> e : multiSchemaForTns.entrySet()) {
String systemId;
List<String> sameTnsSchemas = e.getValue();
if (sameTnsSchemas.size() > 1) {
// SDDocumentSource should be changed to take String systemId
// String pseudoSystemId = "urn:x-jax-ws-include-"+i++;
systemId = "file:x-jax-ws-include-" + i++;
Source src = createSameTnsPseudoSchema(e.getKey(), sameTnsSchemas, systemId);
mdresolver.addSchema(src);
} else {
systemId = sameTnsSchemas.get(0);
}
oneSchemaForTns.put(e.getKey(), systemId);
}
// create a master pseudo schema with all the different tns
Source pseudoSchema = createMasterPseudoSchema(oneSchemaForTns);
return new Source[] { pseudoSchema };
}
use of com.sun.xml.ws.api.server.SDDocument in project metro-jax-ws by eclipse-ee4j.
the class AbstractSchemaValidationTube method createDOM.
private Document createDOM(SDDocument doc) {
// Get infoset
ByteArrayBuffer bab = new ByteArrayBuffer();
try {
doc.writeTo(null, resolver, bab);
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
// Convert infoset to DOM
Transformer trans = XmlUtil.newTransformer();
// doc.getURL().toExternalForm());
Source source = new StreamSource(bab.newInputStream(), null);
DOMResult result = new DOMResult();
try {
trans.transform(source, result);
} catch (TransformerException te) {
throw new WebServiceException(te);
}
return (Document) result.getNode();
}
use of com.sun.xml.ws.api.server.SDDocument in project metro-jax-ws by eclipse-ee4j.
the class MetadataUtil method getMetadataClosure.
/**
* Gets closure of all the referenced documents from the primary document(typically
* the service WSDL). It traverses the WSDL and schema imports and builds a closure
* set of documents.
*
* @param systemId primary wsdl or the any root document
* @param resolver used to get SDDocumentImpl for a document
* @param onlyTopLevelSchemas if true, the imported schemas from a schema would be ignored
* @return all the documents
*/
public static Map<String, SDDocument> getMetadataClosure(@NotNull String systemId, @NotNull SDDocumentResolver resolver, boolean onlyTopLevelSchemas) {
Map<String, SDDocument> closureDocs = new HashMap<>();
Set<String> remaining = new HashSet<>();
remaining.add(systemId);
while (!remaining.isEmpty()) {
Iterator<String> it = remaining.iterator();
String current = it.next();
remaining.remove(current);
SDDocument currentDoc = resolver.resolve(current);
SDDocument old = closureDocs.put(currentDoc.getURL().toExternalForm(), currentDoc);
assert old == null;
Set<String> imports = currentDoc.getImports();
if (!currentDoc.isSchema() || !onlyTopLevelSchemas) {
for (String importedDoc : imports) {
if (closureDocs.get(importedDoc) == null) {
remaining.add(importedDoc);
}
}
}
}
return closureDocs;
}
Aggregations