use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.
the class RuntimeWSDLParser method resolveWSDL.
private Parser resolveWSDL(@Nullable URL wsdlLoc, @NotNull Source wsdlSource, Class serviceClass) throws IOException, SAXException, XMLStreamException {
String systemId = wsdlSource.getSystemId();
XMLEntityResolver.Parser parser = resolver.resolveEntity(null, systemId);
if (parser == null && wsdlLoc != null) {
String exForm = wsdlLoc.toExternalForm();
parser = resolver.resolveEntity(null, exForm);
if (parser == null && serviceClass != null) {
URL ru = serviceClass.getResource(".");
if (ru != null) {
String ruExForm = ru.toExternalForm();
if (exForm.startsWith(ruExForm)) {
parser = resolver.resolveEntity(null, exForm.substring(ruExForm.length()));
}
}
}
}
if (parser == null) {
// an additional time if a valid WSDL Source is provided - Deva Sagar 09/20/2011
if (isKnownReadableSource(wsdlSource)) {
parser = new Parser(wsdlLoc, createReader(wsdlSource));
} else if (wsdlLoc != null) {
parser = new Parser(wsdlLoc, createReader(wsdlLoc, serviceClass));
}
// parser since Source is not null
if (parser == null) {
parser = new Parser(wsdlLoc, createReader(wsdlSource));
}
}
return parser;
}
use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.
the class RuntimeWSDLParser method parse.
/**
* Parses the WSDL and gives WSDLModel. If wsdl parameter is null, then wsdlLoc is used to get the WSDL. If the WSDL
* document could not be obtained then {@link MetadataResolverFactory} is tried to get the WSDL document, if not found
* then as last option, if the wsdlLoc has no '?wsdl' as query parameter then it is tried by appending '?wsdl'.
*
* @param wsdlLoc
* Either this or {@code wsdl} parameter must be given.
* Null location means the system won't be able to resolve relative references in the WSDL,
*/
public static WSDLModel parse(@Nullable URL wsdlLoc, @NotNull Source wsdlSource, @NotNull EntityResolver resolver, boolean isClientSide, Container container, Class serviceClass, @NotNull PolicyResolver policyResolver, boolean isUseStreamFromEntityResolverWrapper, WSDLParserExtension... extensions) throws IOException, XMLStreamException, SAXException {
assert resolver != null;
RuntimeWSDLParser wsdlParser = new RuntimeWSDLParser(wsdlSource.getSystemId(), new EntityResolverWrapper(resolver, isUseStreamFromEntityResolverWrapper), isClientSide, container, policyResolver, extensions);
Parser parser;
try {
parser = wsdlParser.resolveWSDL(wsdlLoc, wsdlSource, serviceClass);
if (!hasWSDLDefinitions(parser.parser)) {
throw new XMLStreamException(ClientMessages.RUNTIME_WSDLPARSER_INVALID_WSDL(parser.systemId, WSDLConstants.QNAME_DEFINITIONS, parser.parser.getName(), parser.parser.getLocation()));
}
} catch (XMLStreamException e) {
// Try MEX if there is WSDLLoc available
if (wsdlLoc == null)
throw e;
return tryWithMex(wsdlParser, wsdlLoc, resolver, isClientSide, container, e, serviceClass, policyResolver, extensions);
} catch (IOException e) {
// Try MEX if there is WSDLLoc available
if (wsdlLoc == null)
throw e;
return tryWithMex(wsdlParser, wsdlLoc, resolver, isClientSide, container, e, serviceClass, policyResolver, extensions);
}
wsdlParser.extensionFacade.start(wsdlParser.context);
wsdlParser.parseWSDL(parser, false);
wsdlParser.wsdlDoc.freeze();
wsdlParser.extensionFacade.finished(wsdlParser.context);
wsdlParser.extensionFacade.postFinished(wsdlParser.context);
if (wsdlParser.wsdlDoc.getServices().isEmpty())
throw new WebServiceException(ClientMessages.WSDL_CONTAINS_NO_SERVICE(wsdlLoc));
return wsdlParser.wsdlDoc;
}
use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.
the class EndpointFactory method getWSDLPort.
/**
* Parses the primary WSDL and returns the {@link WSDLPort} for the given service and port names
*
* @param primaryWsdl Primary WSDL
* @param metadata it may contain imported WSDL and schema documents
* @param serviceName service name in wsdl
* @param portName port name in WSDL
* @param container container in which this service is running
* @return non-null wsdl port object
*/
@NotNull
private static WSDLPort getWSDLPort(SDDocumentSource primaryWsdl, Collection<? extends SDDocumentSource> metadata, @NotNull QName serviceName, @NotNull QName portName, Container container, EntityResolver resolver) {
URL wsdlUrl = primaryWsdl.getSystemId();
try {
// TODO: delegate to another entity resolver
WSDLModel wsdlDoc = RuntimeWSDLParser.parse(new Parser(primaryWsdl), new EntityResolverImpl(metadata, resolver), false, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
if (wsdlDoc.getServices().size() == 0) {
throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_NOSERVICE_IN_WSDLMODEL(wsdlUrl));
}
WSDLService wsdlService = wsdlDoc.getService(serviceName);
if (wsdlService == null) {
throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICE(serviceName, wsdlUrl));
}
WSDLPort wsdlPort = wsdlService.get(portName);
if (wsdlPort == null) {
throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICEPORT(serviceName, portName, wsdlUrl));
}
return wsdlPort;
} catch (IOException | ServiceConfigurationError | SAXException e) {
throw new ServerRtException("runtime.parser.wsdl", wsdlUrl, e);
} catch (XMLStreamException e) {
throw new ServerRtException("runtime.saxparser.exception", e.getMessage(), e.getLocation(), e);
}
}
use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.
the class RuntimeWSDLParser method parseImport.
private void parseImport(@NotNull URL wsdlLoc) throws XMLStreamException, IOException, SAXException {
String systemId = wsdlLoc.toExternalForm();
XMLEntityResolver.Parser parser = resolver.resolveEntity(null, systemId);
if (parser == null) {
parser = new Parser(wsdlLoc, createReader(wsdlLoc));
}
parseWSDL(parser, true);
}
use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.
the class RuntimeWSDLParser method parseUsingMex.
private WSDLModel parseUsingMex(@NotNull URL wsdlLoc, @NotNull EntityResolver resolver, boolean isClientSide, Container container, Class serviceClass, PolicyResolver policyResolver, WSDLParserExtension[] extensions) throws IOException, SAXException, XMLStreamException, URISyntaxException {
// try MEX
MetaDataResolver mdResolver = null;
ServiceDescriptor serviceDescriptor = null;
RuntimeWSDLParser wsdlParser = null;
// Currently we try the first available MetadataResolverFactory that gives us a WSDL document
for (MetadataResolverFactory resolverFactory : ServiceFinder.find(MetadataResolverFactory.class)) {
mdResolver = resolverFactory.metadataResolver(resolver);
serviceDescriptor = mdResolver.resolve(wsdlLoc.toURI());
// we got the ServiceDescriptor, now break
if (serviceDescriptor != null)
break;
}
if (serviceDescriptor != null) {
List<? extends Source> wsdls = serviceDescriptor.getWSDLs();
wsdlParser = new RuntimeWSDLParser(wsdlLoc.toExternalForm(), new MexEntityResolver(wsdls), isClientSide, container, policyResolver, extensions);
wsdlParser.extensionFacade.start(wsdlParser.context);
for (Source src : wsdls) {
String systemId = src.getSystemId();
Parser parser = wsdlParser.resolver.resolveEntity(null, systemId);
wsdlParser.parseWSDL(parser, false);
}
}
// it a last shot else fail
if ((mdResolver == null || serviceDescriptor == null) && (wsdlLoc.getProtocol().equals("http") || wsdlLoc.getProtocol().equals("https")) && (wsdlLoc.getQuery() == null)) {
String urlString = wsdlLoc.toExternalForm();
urlString += "?wsdl";
wsdlLoc = new URL(urlString);
wsdlParser = new RuntimeWSDLParser(wsdlLoc.toExternalForm(), new EntityResolverWrapper(resolver), isClientSide, container, policyResolver, extensions);
wsdlParser.extensionFacade.start(wsdlParser.context);
Parser parser = resolveWSDL(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), serviceClass);
wsdlParser.parseWSDL(parser, false);
}
if (wsdlParser == null)
return null;
wsdlParser.wsdlDoc.freeze();
wsdlParser.extensionFacade.finished(wsdlParser.context);
wsdlParser.extensionFacade.postFinished(wsdlParser.context);
return wsdlParser.wsdlDoc;
}
Aggregations