use of org.apache.cxf.resource.URIResolver in project cxf by apache.
the class AbstractServiceFactoryBean method fillDataBindingSchemas.
private void fillDataBindingSchemas() {
ResourceManager rr = getBus().getExtension(ResourceManager.class);
List<DOMSource> schemas = new ArrayList<>();
for (String l : schemaLocations) {
URL url = rr.resolveResource(l, URL.class);
if (url == null) {
try (URIResolver res = new URIResolver(l)) {
if (!res.isResolved()) {
throw new ServiceConstructionException(new Message("INVALID_SCHEMA_URL", LOG, l));
}
url = res.getURL();
} catch (IOException e) {
throw new ServiceConstructionException(new Message("INVALID_SCHEMA_URL", LOG, l), e);
}
}
Document d;
try (InputStream in = url.openStream()) {
d = StaxUtils.read(in);
} catch (Exception e) {
throw new ServiceConstructionException(new Message("ERROR_READING_SCHEMA", LOG, l), e);
}
schemas.add(new DOMSource(d, url.toString()));
}
((AbstractDataBinding) getDataBinding()).setSchemas(schemas);
}
use of org.apache.cxf.resource.URIResolver in project cxf by apache.
the class WSDL11Validator method addDefaultSchemas.
private void addDefaultSchemas(String location, List<InputSource> xsdList) throws IOException {
ClassLoader clzLoader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> urls = clzLoader.getResources(location);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
// from jar files
if (url.toString().startsWith("jar")) {
JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
JarFile jarFile = jarConnection.getJarFile();
Enumeration<JarEntry> entry = jarFile.entries();
while (entry.hasMoreElements()) {
JarEntry ele = entry.nextElement();
if (ele.getName().endsWith(".xsd") && ele.getName().indexOf(ToolConstants.CXF_SCHEMAS_DIR_INJAR) > -1) {
URIResolver resolver = new URIResolver(ele.getName());
if (resolver.isResolved()) {
InputSource is = new InputSource(resolver.getInputStream());
// the id to the relative path.
if (resolver.getURI() != null) {
is.setSystemId(resolver.getURI().toString());
} else {
is.setSystemId(ele.getName());
}
xsdList.add(is);
}
}
}
// from class path direcotry
} else if (url.toString().startsWith("file")) {
URI loc = null;
try {
loc = url.toURI();
} catch (URISyntaxException e) {
//
}
if (loc != null) {
java.io.File file = new java.io.File(loc);
if (file.exists()) {
File[] files = file.listFiles(new FileFilter() {
public boolean accept(File pathname) {
if (pathname.getAbsolutePath().endsWith(".xsd")) {
return true;
}
return false;
}
});
if (files != null) {
for (int i = 0; i < files.length; i++) {
InputSource is = new InputSource(files[i].toURI().toURL().openStream());
is.setSystemId(files[i].toURI().toURL().toString());
xsdList.add(is);
}
}
}
}
}
}
sort(xsdList);
}
use of org.apache.cxf.resource.URIResolver in project cxf by apache.
the class JAXWSContainer method validate.
public void validate(ToolContext env) throws ToolException {
env.put("service.target", getServiceTarget());
env.put("service.superclass", getServiceSuperclass());
super.validate(env);
if (env.containsKey(ToolConstants.CFG_BINDING)) {
String[] bindings = (String[]) env.get(ToolConstants.CFG_BINDING);
for (int i = 0; i < bindings.length; i++) {
try (URIResolver resolver = new URIResolver(bindings[i])) {
if (!resolver.isResolved()) {
Message msg = new Message("FILE_NOT_EXIST", LOG, bindings[i]);
throw new ToolException(msg);
}
} catch (IOException ioe) {
throw new ToolException(ioe);
}
}
env.put(ToolConstants.CFG_BINDING, bindings);
}
cleanArrays(env, ToolConstants.CFG_ASYNCMETHODS);
cleanArrays(env, ToolConstants.CFG_BAREMETHODS);
cleanArrays(env, ToolConstants.CFG_MIMEMETHODS);
}
use of org.apache.cxf.resource.URIResolver in project cxf by apache.
the class CustomizationParser method addBinding.
private void addBinding(String bindingFile) throws XMLStreamException {
final Element root;
try (URIResolver resolver = new URIResolver(bindingFile)) {
root = StaxUtils.read(resolver.getInputStream()).getDocumentElement();
} catch (Exception e1) {
Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { bindingFile });
throw new ToolException(msg, e1);
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(root);
StaxUtils.toNextTag(reader);
if (isValidJaxbBindingFile(reader)) {
String schemaLocation = root.getAttribute("schemaLocation");
String resolvedSchemaLocation = resolveByCatalog(schemaLocation);
if (resolvedSchemaLocation == null) {
resolvedSchemaLocation = schemaLocation.isEmpty() ? wadlPath : getBaseWadlPath() + schemaLocation;
}
try {
jaxbBindings.add(convertToTmpInputSource(root, resolvedSchemaLocation));
} catch (Exception e1) {
Message msg = new Message("FAILED_TO_ADD_SCHEMALOCATION", LOG, bindingFile);
throw new ToolException(msg, e1);
}
}
}
use of org.apache.cxf.resource.URIResolver in project cxf by apache.
the class CustomizationParser method addBinding.
private void addBinding(String bindingFile) throws XMLStreamException {
final Element root;
XMLStreamReader xmlReader = null;
try (URIResolver resolver = new URIResolver(bindingFile)) {
xmlReader = StaxUtils.createXMLStreamReader(resolver.getURI().toString(), resolver.getInputStream());
root = StaxUtils.read(xmlReader, true).getDocumentElement();
} catch (Exception e1) {
Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { bindingFile });
throw new ToolException(msg, e1);
} finally {
StaxUtils.close(xmlReader);
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(root);
StaxUtils.toNextTag(reader);
if (isValidJaxwsBindingFile(bindingFile, reader)) {
String wsdlLocation = root.getAttribute("wsdlLocation");
Element targetNode;
if (!StringUtils.isEmpty(wsdlLocation)) {
String wsdlURI = getAbsoluteURI(wsdlLocation, bindingFile);
targetNode = getTargetNode(wsdlURI);
String resolvedLoc = wsdlURI;
if (targetNode == null && env.get(ToolConstants.CFG_CATALOG) != null) {
resolvedLoc = resolveByCatalog(wsdlURI);
targetNode = getTargetNode(resolvedLoc);
}
if (targetNode == null) {
Message msg = new Message("POINT_TO_WSDL_DOES_NOT_EXIST", LOG, new Object[] { bindingFile, resolvedLoc });
throw new ToolException(msg);
}
root.setAttributeNS(null, "wsdlLocation", wsdlURI);
} else {
targetNode = wsdlNode;
root.setAttributeNS(null, "wsdlLocation", wsdlURL);
}
jaxwsBindingsMap.put(root, targetNode);
} else if (isValidJaxbBindingFile(reader)) {
String schemaLocation = root.getAttribute("schemaLocation");
String resolvedSchemaLocation = resolveByCatalog(schemaLocation);
if (resolvedSchemaLocation != null) {
final InputSource tmpIns;
try {
tmpIns = convertToTmpInputSource(root, resolvedSchemaLocation);
} catch (Exception e1) {
Message msg = new Message("FAILED_TO_ADD_SCHEMALOCATION", LOG, bindingFile);
throw new ToolException(msg, e1);
}
jaxbBindings.add(tmpIns);
} else {
jaxbBindings.add(new InputSource(bindingFile));
}
}
}
Aggregations