use of javax.wsdl.xml.WSDLReader in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method init.
@Override
public boolean init(byte[] wsdlContent) 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(null, getSecuredParsedDocumentFromContent(wsdlContent));
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;
}
use of javax.wsdl.xml.WSDLReader in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method initPath.
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
setMode(Mode.ARCHIVE);
pathToDefinitionMap = new HashMap<>();
wsdlArchiveExtractedPath = path;
WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
try {
// switch off the verbose mode
wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
File folderToImport = new File(path);
Collection<File> foundWSDLFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, "wsdl");
if (log.isDebugEnabled()) {
log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
}
for (File file : foundWSDLFiles) {
String absWSDLPath = file.getAbsolutePath();
if (log.isDebugEnabled()) {
log.debug("Processing WSDL file: " + absWSDLPath);
}
Definition definition = wsdlReader.readWSDL(path, getSecuredParsedDocumentFromPath(absWSDLPath));
pathToDefinitionMap.put(absWSDLPath, definition);
// set the first found WSDL as wsdlDefinition variable assuming that it is the root WSDL
if (wsdlDefinition == null) {
wsdlDefinition = definition;
}
}
if (foundWSDLFiles.isEmpty()) {
setError(ExceptionCodes.NO_WSDL_FOUND_IN_WSDL_ARCHIVE);
}
if (log.isDebugEnabled()) {
log.debug("Successfully processed all WSDL files in path " + path);
}
} catch (WSDLException | APIManagementException e) {
// This implementation class cannot process the WSDL. Continuing after setting canProcess = false
log.debug(this.getClass().getName() + " was unable to process the WSDL Files for the path: " + path, 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;
}
use of javax.wsdl.xml.WSDLReader in project carbon-apimgt by wso2.
the class APIMWSDLReader method updateWSDL.
/**
* Update WSDL 1.0 service definitions saved in registry
*
* @param wsdl byte array of registry content
* @param api API object
* @return the OMElemnt of the new WSDL content
* @throws APIManagementException
*/
public OMElement updateWSDL(byte[] wsdl, API api) throws APIManagementException {
try {
// Generate wsdl document from registry data
WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
// switch off the verbose mode
wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
if (wsdlReader instanceof WSDLReaderImpl) {
((WSDLReaderImpl) wsdlReader).setIgnoreSchemaContent(true);
}
Definition wsdlDefinition = wsdlReader.readWSDL(null, getSecuredParsedDocumentFromContent(wsdl));
// Update transports
setServiceDefinition(wsdlDefinition, api);
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer.writeWSDL(wsdlDefinition, byteArrayOutputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
return APIUtil.buildOMElement(byteArrayInputStream);
} catch (Exception e) {
String msg = " Error occurs when updating WSDL ";
log.error(msg);
throw new APIManagementException(msg, e);
}
}
use of javax.wsdl.xml.WSDLReader in project carbon-apimgt by wso2.
the class APIMWSDLReader method readWSDLFile.
/**
* Create the WSDL definition <javax.wsdl.Definition> from the baseURI of
* the WSDL
*
* @return {@link Definition} - WSDL4j definition constructed form the wsdl
* original baseuri
* @throws APIManagementException
* @throws WSDLException
*/
@Deprecated
private Definition readWSDLFile() throws APIManagementException, WSDLException {
WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
// switch off the verbose mode
reader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
reader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
if (reader instanceof WSDLReaderImpl) {
((WSDLReaderImpl) reader).setIgnoreSchemaContent(true);
}
if (log.isDebugEnabled()) {
log.debug("Reading the WSDL. Base uri is " + baseURI);
}
return reader.readWSDL(null, getSecuredParsedDocumentFromURL(baseURI));
}
use of javax.wsdl.xml.WSDLReader in project cxf by apache.
the class ServiceModelUtilTest method setUp.
@Before
public void setUp() throws Exception {
String wsdlUrl = getClass().getResource(WSDL_PATH).toString();
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
Definition def = wsdlReader.readWSDL(wsdlUrl);
for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
if (serv != null) {
service = serv;
break;
}
}
control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
}
Aggregations