use of javax.wsdl.WSDLException in project cxf by apache.
the class SchemaFactory method newInstance.
/**
* Get a new instance of a WSDLFactory. This method
* returns an instance of the class factoryImplName.
* Once an instance of a WSDLFactory is obtained, invoke
* newDefinition(), newWSDLReader(), or newWSDLWriter(), to create
* the desired instances.
*
* @param factoryImplName the fully-qualified class name of the
* class which provides a concrete implementation of the abstract
* class WSDLFactory.
*/
public static SchemaFactory newInstance(String factoryImplName) throws WSDLException {
if (factoryImplName != null) {
try {
// get the appropriate class for the loading.
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> cl = loader.loadClass(factoryImplName);
return (SchemaFactory) cl.newInstance();
} catch (Exception e) {
/*
Catches:
ClassNotFoundException
InstantiationException
IllegalAccessException
*/
throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Problem instantiating factory " + "implementation.", e);
}
}
throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Unable to find name of factory " + "implementation.");
}
use of javax.wsdl.WSDLException in project cxf by apache.
the class WSDL11Generator method generate.
public Definition generate(final File dir) {
File file = getOutputBase();
if (file == null && dir != null) {
if (dir.isDirectory()) {
file = new File(dir, getServiceModel().getName().getLocalPart() + ".wsdl");
} else {
file = dir;
}
} else if (dir == null) {
file = new File(getServiceModel().getName().getLocalPart() + ".wsdl");
}
File outputdir = createOutputDir(file);
Definition def = null;
try {
Writer os = new FileWriterUtil(file.getParent(), getOutputStreamCreator()).getWriter(file, StandardCharsets.UTF_8.name());
WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(getBus(), getServiceModel());
builder.setUseSchemaImports(this.allowImports());
String name = file.getName();
if (name.endsWith(".wsdl")) {
name = name.substring(0, name.lastIndexOf(".wsdl"));
}
builder.setBaseFileName(name);
Map<String, SchemaInfo> imports = new HashMap<>();
def = builder.build(imports);
wsdlWriter.writeWSDL(def, os);
os.close();
if (!def.getImports().isEmpty()) {
for (Import wsdlImport : WSDLDefinitionBuilder.getImports(def)) {
Definition wsdlDef = wsdlImport.getDefinition();
final File wsdlFile;
if (!StringUtils.isEmpty(wsdlImport.getLocationURI())) {
wsdlFile = new File(outputdir, wsdlImport.getLocationURI());
} else {
wsdlFile = new File(outputdir, wsdlDef.getQName().getLocalPart() + ".wsdl");
}
try (OutputStream wsdlOs = new BufferedOutputStream(Files.newOutputStream(wsdlFile.toPath()))) {
wsdlWriter.writeWSDL(wsdlDef, wsdlOs);
}
}
}
for (Map.Entry<String, SchemaInfo> imp : imports.entrySet()) {
File impfile = new File(file.getParentFile(), imp.getKey());
Element el = imp.getValue().getElement();
updateImports(el, imports);
FileWriterUtil fileWriterUtil = new FileWriterUtil(impfile.getParent(), getToolContext().get(OutputStreamCreator.class));
os = fileWriterUtil.getWriter(impfile, StandardCharsets.UTF_8.name());
StaxUtils.writeTo(el, os, 2);
os.close();
}
customizing(outputdir, name, imports.keySet());
} catch (WSDLException wex) {
wex.printStackTrace();
} catch (FileNotFoundException fnfe) {
throw new ToolException("Output file " + file + " not found", fnfe);
} catch (IOException | XMLStreamException e) {
e.printStackTrace();
}
return def;
}
use of javax.wsdl.WSDLException in project cxf by apache.
the class WSDLToCorbaBinding method generateCORBABinding.
private Binding generateCORBABinding(Definition definition, PortType portType) throws Exception {
QName bqname;
if (extReg == null) {
extReg = def.getExtensionRegistry();
}
bindingNames = new ArrayList<>();
String interfaceName = portType.getQName().getLocalPart();
String bname = getMappedBindingName(interfaceName);
String prefix = definition.getPrefix(definition.getTargetNamespace());
if (prefix == null) {
prefix = "";
}
if (bname == null && !allbindings) {
bname = bindingName;
}
if (bname == null) {
bname = mangleInterfaceName(interfaceName) + "CORBABinding";
setBindingName(bname);
bqname = new QName(definition.getTargetNamespace(), bname, prefix);
int count = 0;
StringBuilder builder = new StringBuilder(bname);
while (WSDLToCorbaHelper.queryBinding(definition, bqname)) {
builder.append(count);
bqname = new QName(definition.getTargetNamespace(), builder.toString(), prefix);
}
bname = builder.toString();
} else {
bqname = new QName(definition.getTargetNamespace(), bname, prefix);
// Check if the Binding with name already exists
if (WSDLToCorbaHelper.queryBinding(definition, bqname)) {
String msgStr = "Binding " + bqname.getLocalPart() + " already exists in WSDL.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new ToolException(msg.toString());
}
}
// jwsdl model should have all other bindings in it.
String pfx = definition.getPrefix(CorbaConstants.NU_WSDL_CORBA);
if (pfx == null) {
pfx = "corba";
def.addNamespace(pfx, CorbaConstants.NU_WSDL_CORBA);
}
Binding binding = def.createBinding();
binding.setPortType(portType);
binding.setQName(bqname);
bindingNames.add(bname);
mapBindingToInterface(portType.getQName().getLocalPart(), bname);
addCorbaTypeMap(def);
try {
BindingType bindingType = (BindingType) extReg.createExtension(Binding.class, CorbaConstants.NE_CORBA_BINDING);
bindingType.setRepositoryID(WSDLToCorbaHelper.REPO_STRING + binding.getPortType().getQName().getLocalPart().replace('.', '/') + WSDLToCorbaHelper.IDL_VERSION);
binding.addExtensibilityElement((ExtensibilityElement) bindingType);
} catch (WSDLException ex) {
ex.printStackTrace();
}
try {
addBindingOperations(def, portType, binding);
binding.setUndefined(false);
definition.addBinding(binding);
} catch (Exception ex) {
binding.setUndefined(true);
}
cleanUpTypeMap(typeMappingType);
return binding;
}
use of javax.wsdl.WSDLException in project cxf by apache.
the class JAXBExtensionHelper method marshall.
/* (non-Javadoc)
* @see javax.wsdl.extensions.ExtensionSerializer#marshall(java.lang.Class,
* javax.xml.namespace.QName, javax.wsdl.extensions.ExtensibilityElement,
* java.io.PrintWriter, javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
*/
public void marshall(@SuppressWarnings("rawtypes") Class parent, QName qname, ExtensibilityElement obj, PrintWriter pw, final Definition wsdl, ExtensionRegistry registry) throws WSDLException {
try {
Marshaller u = createMarshaller();
u.setProperty("jaxb.encoding", StandardCharsets.UTF_8.name());
u.setProperty("jaxb.fragment", Boolean.TRUE);
u.setProperty("jaxb.formatted.output", Boolean.TRUE);
Object mObj = obj;
Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(typeClass) + ".ObjectFactory", true, obj.getClass().getClassLoader());
Method[] methods = objectFactory.getDeclaredMethods();
for (Method method : methods) {
if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(typeClass)) {
mObj = method.invoke(objectFactory.newInstance(), new Object[] { obj });
}
}
javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), 2, getIndentLevel(parent));
if (namespace != null && !namespace.equals(jaxbNamespace)) {
Map<String, String> outMap = new HashMap<>();
outMap.put("{" + jaxbNamespace + "}*", "{" + namespace + "}*");
writer = new OutTransformWriter(writer, outMap, Collections.<String, String>emptyMap(), Collections.<String>emptyList(), false, "");
}
Map<String, String> nspref = new HashMap<>();
for (Object ent : wsdl.getNamespaces().entrySet()) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) ent;
nspref.put((String) entry.getValue(), (String) entry.getKey());
}
JAXBUtils.setNamespaceMapper(bus, nspref, u);
u.marshal(mObj, writer);
writer.flush();
} catch (Exception ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, "", ex);
}
}
use of javax.wsdl.WSDLException in project cxf by apache.
the class JAXBExtensionHelper method unmarshall.
/* (non-Javadoc)
* @see javax.wsdl.extensions.ExtensionDeserializer#unmarshall(java.lang.Class,
* javax.xml.namespace.QName, org.w3c.dom.Element,
* javax.wsdl.Definition,
* javax.wsdl.extensions.ExtensionRegistry)
*/
public ExtensibilityElement unmarshall(@SuppressWarnings("rawtypes") Class parent, QName qname, Element element, Definition wsdl, ExtensionRegistry registry) throws WSDLException {
XMLStreamReader reader = null;
Unmarshaller u = null;
try {
u = createUnmarshaller();
Object o;
if (namespace == null) {
o = u.unmarshal(element, extensionClass);
} else {
reader = StaxUtils.createXMLStreamReader(element);
reader = new MappingReaderDelegate(reader);
o = u.unmarshal(reader, extensionClass);
}
if (o != null) {
o = ((JAXBElement<?>) o).getValue();
}
ExtensibilityElement el = o instanceof ExtensibilityElement ? (ExtensibilityElement) o : new JAXBExtensibilityElement(o);
el.setElementType(qname);
return el;
} catch (Exception ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, "Error reading element " + qname, ex);
} finally {
try {
StaxUtils.close(reader);
} catch (XMLStreamException ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, ex.getMessage(), ex);
}
JAXBUtils.closeUnmarshaller(u);
}
}
Aggregations