use of org.apache.ws.commons.schema.XmlSchemaException in project cxf by apache.
the class CatalogXmlSchemaURIResolver method resolveEntity.
public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
String resolvedSchemaLocation = null;
OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
try {
resolvedSchemaLocation = new OASISCatalogManagerHelper().resolve(catalogResolver, schemaLocation, baseUri);
} catch (Exception e) {
throw new RuntimeException("Catalog resolution failed", e);
}
InputSource in = null;
if (resolvedSchemaLocation == null) {
in = this.resolver.resolve(schemaLocation, baseUri);
} else {
resolved.put(schemaLocation, resolvedSchemaLocation);
in = this.resolver.resolve(resolvedSchemaLocation, baseUri);
}
// but without any nice error message. So let's just throw a nice error here.
if (in == null) {
throw new XmlSchemaException("Unable to locate imported document " + "at '" + schemaLocation + "'" + (baseUri == null ? "." : ", relative to '" + baseUri + "'."));
} else if (in.getByteStream() != null && !(in.getByteStream() instanceof ByteArrayInputStream)) {
// file handles. We'll just load the file into a byte[] and return that.
try {
InputStream ins = IOUtils.loadIntoBAIS(in.getByteStream());
in.setByteStream(ins);
} catch (IOException e) {
throw new XmlSchemaException("Unable to load imported document " + "at '" + schemaLocation + "'" + (baseUri == null ? "." : ", relative to '" + baseUri + "'."), e);
}
}
return in;
}
use of org.apache.ws.commons.schema.XmlSchemaException in project cxf by apache.
the class WSDLServiceFactory method create.
public Service create() {
List<ServiceInfo> services;
if (serviceName == null) {
try {
WSDLServiceBuilder builder = new WSDLServiceBuilder(getBus());
builder.setAllowElementRefs(allowRefs);
services = builder.buildServices(definition);
} catch (XmlSchemaException ex) {
throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
}
if (services.isEmpty()) {
throw new ServiceConstructionException(new Message("NO_SERVICE_EXC", LOG));
}
// @@TODO - this isn't good, need to return all the services
serviceName = services.get(0).getName();
// get all the service info's that match that first one.
Iterator<ServiceInfo> it = services.iterator();
while (it.hasNext()) {
if (!it.next().getName().equals(serviceName)) {
it.remove();
}
}
} else {
javax.wsdl.Service wsdlService = definition.getService(serviceName);
if (wsdlService == null) {
if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName)) && (!PartialWSDLProcessor.isBindingExisted(definition, serviceName)) && (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
try {
Map<QName, PortType> portTypes = CastUtils.cast(definition.getAllPortTypes());
String existPortName = null;
PortType portType = null;
for (Map.Entry<QName, PortType> entry : portTypes.entrySet()) {
existPortName = entry.getKey().getLocalPart();
if (serviceName.getLocalPart().contains(existPortName)) {
portType = entry.getValue();
break;
}
}
WSDLFactory factory = WSDLFactory.newInstance();
ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
Binding binding = PartialWSDLProcessor.doAppendBinding(definition, existPortName, portType, extReg);
definition.addBinding(binding);
wsdlService = PartialWSDLProcessor.doAppendService(definition, existPortName, extReg, binding);
definition.addService(wsdlService);
} catch (Exception e) {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
} else {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
}
try {
services = new WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService, endpointName);
if (services.isEmpty()) {
throw new ServiceConstructionException(new Message("NO_SUCH_ENDPOINT_EXC", LOG, endpointName));
}
} catch (XmlSchemaException ex) {
throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
}
}
ServiceImpl service = new ServiceImpl(services);
setService(service);
return service;
}
use of org.apache.ws.commons.schema.XmlSchemaException in project cxf by apache.
the class AegisDatabinding method createSchemas.
private void createSchemas(Service s, Set<AegisType> deps) {
Map<String, Set<AegisType>> tns2Type = new HashMap<>();
for (AegisType t : deps) {
String ns = t.getSchemaType().getNamespaceURI();
Set<AegisType> types = tns2Type.get(ns);
if (types == null) {
types = new HashSet<>();
tns2Type.put(ns, types);
}
types.add(t);
}
for (ServiceInfo si : s.getServiceInfos()) {
SchemaCollection col = si.getXmlSchemaCollection();
if (col.getXmlSchemas().length > 1) {
// someone has already filled in the types
continue;
}
}
Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
for (ServiceInfo si : s.getServiceInfos()) {
// these two must be recalculated per-service-info!
boolean needXmimeSchema = false;
boolean needTypesSchema = false;
for (Map.Entry<String, Set<AegisType>> entry : tns2Type.entrySet()) {
String schemaNamespaceUri = entry.getKey();
if (Constants.URI_2001_SCHEMA_XSD.equals(schemaNamespaceUri)) {
continue;
}
if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schemaNamespaceUri)) {
// we handle this separately.
continue;
}
if (AbstractXOPType.XML_MIME_NS.equals(schemaNamespaceUri)) {
// similiarly.
continue;
}
SchemaInfo schemaInfo = si.addNewSchema(entry.getKey());
XmlSchema schema = schemaInfo.getSchema();
NamespaceMap xmlsNamespaceMap = new NamespaceMap();
// user-requested prefix mappings.
if (namespaceMap != null) {
for (Map.Entry<String, String> e : namespaceMap.entrySet()) {
xmlsNamespaceMap.add(e.getValue(), e.getKey());
}
}
// tns: is conventional, and besides we have unit tests that are hardcoded to it.
if (!xmlsNamespaceMap.containsKey(WSDLConstants.CONVENTIONAL_TNS_PREFIX) && // if some wants something other than TNS, they get it.
!xmlsNamespaceMap.containsValue(entry.getKey())) {
xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, entry.getKey());
}
// ditto for xsd: instead of just namespace= for the schema schema.
if (!xmlsNamespaceMap.containsKey("xsd") && !xmlsNamespaceMap.containsValue(Constants.URI_2001_SCHEMA_XSD)) {
xmlsNamespaceMap.add("xsd", Constants.URI_2001_SCHEMA_XSD);
}
schema.setNamespaceContext(xmlsNamespaceMap);
schema.setTargetNamespace(entry.getKey());
schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
schema.setAttributeFormDefault(XmlSchemaForm.QUALIFIED);
for (AegisType t : entry.getValue()) {
try {
t.writeSchema(schema);
} catch (XmlSchemaException ex) {
QName name = t.getSchemaType();
String expected = " Schema for namespace '" + name.getNamespaceURI() + "' already contains type '" + name.getLocalPart() + "'";
String message = ex.getMessage();
if (expected.equals(message)) {
continue;
}
throw ex;
}
}
if (schemaImportsXmime(schema)) {
needXmimeSchema = true;
}
if (AegisContext.schemaImportsUtilityTypes(schema)) {
needTypesSchema = true;
}
}
if (needXmimeSchema) {
XmlSchema schema = aegisContext.addXmimeSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
schemaInfo.setSchema(schema);
si.addSchema(schemaInfo);
}
if (needTypesSchema) {
XmlSchema schema = aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
schemaInfo.setSchema(schema);
si.addSchema(schemaInfo);
}
// it's quite likely that the code in Aegis missed at least one ...
si.getXmlSchemaCollection().addCrossImports();
}
}
Aggregations