use of javax.wsdl.xml.WSDLReader in project carbon-business-process by wso2.
the class ArchiveBasedHumanTaskDeploymentUnitBuilder method buildWSDLs.
@Override
public void buildWSDLs() throws HumanTaskDeploymentException {
HashSet<Definition> tmpWsdlDefinitions = new HashSet<>();
URI baseUri = humantaskDir.toURI();
for (File file : FileUtils.directoryEntriesInPath(humantaskDir, wsdlFilter)) {
try {
URI uri = baseUri.relativize(file.toURI());
if (!uri.isAbsolute()) {
File f = new File(baseUri.getPath() + File.separator + uri.getPath());
URI abUri = f.toURI();
if (abUri.isAbsolute()) {
uri = abUri;
}
}
WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
reader.setFeature("javax.wsdl.importDocuments", true);
Definition definition = reader.readWSDL(new HumanTaskWSDLLocator(uri));
if (definition != null) {
tmpWsdlDefinitions.add(definition);
}
} catch (WSDLException e) {
log.error("Error processing wsdl " + file.getName());
throw new HumanTaskDeploymentException(" Error processing wsdl ", e);
} catch (URISyntaxException e) {
log.error("Invalid uri in reading wsdl ", e);
throw new HumanTaskDeploymentException(" Invalid uri in reading wsdl ", e);
}
}
// Optimizing WSDLs imports. Using HashSet to avoid duplicate entices.
HashSet<Definition> optimizedDefinitions = new HashSet<>();
HTDeploymentConfigDocument htDeploymentConfigDocument = getHTDeploymentConfigDocument();
// Iterating Tasks.
THTDeploymentConfig.Task[] taskArray = htDeploymentConfigDocument.getHTDeploymentConfig().getTaskArray();
if (taskArray != null) {
for (THTDeploymentConfig.Task task : taskArray) {
QName taskService = task.getPublish().getService().getName();
Definition taskServiceDefinition = getDefinition(taskService, tmpWsdlDefinitions);
if (log.isDebugEnabled()) {
log.debug("Optimizing WSDL import for Task : " + task.getName());
}
if (taskServiceDefinition != null) {
optimizedDefinitions.add(taskServiceDefinition);
if (log.isDebugEnabled()) {
log.debug("Added WSDL for Task : " + task.getName() + ", Service : " + taskService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
}
} else {
log.warn("Can't find valid WSDL definition for Task" + task.getName() + ", Service: " + taskService);
}
QName callbackService = task.getCallback().getService().getName();
Definition callbackServiceDefinition = getDefinition(callbackService, tmpWsdlDefinitions);
if (callbackServiceDefinition != null) {
optimizedDefinitions.add(callbackServiceDefinition);
if (log.isDebugEnabled()) {
log.debug("Added WSDL for Task : " + task.getName() + ", Callback Service : " + callbackService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
}
} else {
log.warn("Can't find valid WSDL definition for Task : " + task.getName() + ", Callback Service" + callbackService);
}
}
}
// Iterating Notifications.
THTDeploymentConfig.Notification[] notificationsArray = htDeploymentConfigDocument.getHTDeploymentConfig().getNotificationArray();
if (notificationsArray != null) {
for (THTDeploymentConfig.Notification notification : notificationsArray) {
QName notificationService = notification.getPublish().getService().getName();
Definition notificationServiceDefinition = getDefinition(notificationService, tmpWsdlDefinitions);
if (notificationServiceDefinition != null) {
optimizedDefinitions.add(notificationServiceDefinition);
if (log.isDebugEnabled()) {
log.debug("Added WSDL for Task : " + notification.getName() + ", Callback Service : " + notificationService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
}
} else {
log.warn("Can't find valid WSDL definition for Notification " + notification.getName() + ", Service: " + notificationService);
}
}
}
// Converting HashSet to ArrayList.
wsdlDefinitions = new ArrayList<>(optimizedDefinitions);
if (log.isDebugEnabled()) {
log.debug("Optimized Imported/Total definition : " + wsdlDefinitions.size() + "/" + tmpWsdlDefinitions.size());
}
}
use of javax.wsdl.xml.WSDLReader in project components by Talend.
the class JAXBConfigGen method run.
public void run(String... args) throws Exception {
String wsdlUrl = args[0];
String apiVersionPackageSuffix = args[1];
String apiVersionPackage = args[2];
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
Definition def = wsdlReader.readWSDL(wsdlUrl);
Collection<String> namespaceList = new HashSet<>();
processSchemas(def, namespaceList);
System.out.println("Found namespaces: " + namespaceList.size());
for (String namespaceUri : namespaceList) {
System.out.println(namespaceUri);
}
List<Map<String, String>> entries = new ArrayList<>();
for (String namespaceUri : namespaceList) {
// split "urn:<ns>"
String[] parts1 = namespaceUri.split("\\:");
String namespace = parts1[1].replace(apiVersionPackageSuffix, "");
String[] parts2 = namespace.split("\\.");
List<String> nameParts = Arrays.asList(parts2);
Collections.reverse(nameParts);
StringBuilder sb = new StringBuilder();
for (String namePart : nameParts) {
if (sb.length() != 0) {
sb.append(".");
}
sb.append(namePart);
}
String packageName = sb.toString().replace("com.netsuite.webservices.", "com.netsuite.webservices." + apiVersionPackage + ".");
Map<String, String> entry = new HashMap<>();
entry.put("uri", namespaceUri);
entry.put("package", packageName);
entries.add(entry);
}
System.out.println();
System.out.println("JAXB binding customization samples: ");
System.out.println();
String template = "<bindings scd=\"x-schema::tns\" xmlns:tns=\"${namespace}\">\n" + " <schemaBindings>\n" + " <package name=\"${package}\"/>\n" + " </schemaBindings>\n" + "</bindings>";
for (Map<String, String> nsEntry : entries) {
String namespaceUri = nsEntry.get("uri");
String packageName = nsEntry.get("package");
String result = template.replace("${namespace}", namespaceUri).replace("${package}", packageName);
System.out.println(result);
}
System.out.println();
System.out.println("Done.");
}
use of javax.wsdl.xml.WSDLReader in project tomee by apache.
the class WsDeployer method readWsdl.
// don't put it in ReadDescriptors to respect classloader dependencies (wsdl4j is optional)
public static Definition readWsdl(final URL url) throws OpenEJBException {
final Definition definition;
try {
final WSDLFactory factory = WSDLFactory.newInstance();
final WSDLReader reader = factory.newWSDLReader();
reader.setFeature("javax.wsdl.verbose", true);
reader.setFeature("javax.wsdl.importDocuments", true);
final WsdlResolver wsdlResolver = new WsdlResolver(new URL(url, ".").toExternalForm(), new InputSource(IO.read(url)));
definition = reader.readWSDL(wsdlResolver);
} catch (final IOException e) {
throw new OpenEJBException("Cannot read the wsdl file: " + url.toExternalForm(), e);
} catch (final Exception e) {
throw new OpenEJBException("Encountered unknown error parsing the wsdl file: " + url.toExternalForm(), e);
}
return definition;
}
use of javax.wsdl.xml.WSDLReader in project tomee by apache.
the class CommonsSchemaLoader method readWsdl.
private Definition readWsdl(URI wsdlURI) throws OpenEJBException {
Definition definition;
WSDLFactory wsdlFactory;
try {
wsdlFactory = WSDLFactory.newInstance();
} catch (WSDLException e) {
throw new OpenEJBException("Could not create WSDLFactory", e);
}
WSDLReader wsdlReaderNoImport = wsdlFactory.newWSDLReader();
wsdlReaderNoImport.setFeature("javax.wsdl.importDocuments", false);
ExtensionRegistry extensionRegistry = new PopulatedExtensionRegistry();
extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_1999, UnknownExtensibilityElement.class);
extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999, extensionRegistry.getDefaultDeserializer());
extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999, extensionRegistry.getDefaultSerializer());
extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2000, UnknownExtensibilityElement.class);
extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000, extensionRegistry.getDefaultDeserializer());
extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000, extensionRegistry.getDefaultSerializer());
extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2001, UnknownExtensibilityElement.class);
extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001, extensionRegistry.getDefaultDeserializer());
extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001, extensionRegistry.getDefaultSerializer());
wsdlReaderNoImport.setExtensionRegistry(extensionRegistry);
JarWSDLLocator wsdlLocator = new JarWSDLLocator(wsdlURI);
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
Thread thread = Thread.currentThread();
ClassLoader oldCl = thread.getContextClassLoader();
thread.setContextClassLoader(this.getClass().getClassLoader());
try {
try {
definition = wsdlReader.readWSDL(wsdlLocator);
} catch (WSDLException e) {
throw new OpenEJBException("Failed to read wsdl document", e);
} catch (RuntimeException e) {
throw new OpenEJBException(e.getMessage(), e);
}
} finally {
thread.setContextClassLoader(oldCl);
}
return definition;
}
use of javax.wsdl.xml.WSDLReader in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method init.
@Override
public boolean init(URL url) throws APIMgtWSDLException {
setMode(Mode.SINGLE);
WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
// switch off the verbose mode
wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
try {
wsdlDefinition = wsdlReader.readWSDL(url.toString(), getSecuredParsedDocumentFromURL(url));
if (log.isDebugEnabled()) {
log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
}
} catch (WSDLException | APIManagementException e) {
// This implementation class cannot process the WSDL.
log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
}
return !hasError;
}
Aggregations