use of javax.wsdl.Definition in project carbon-apimgt by wso2.
the class APIMWSDLReaderTest method testSetServiceDefinition.
@Test
public void testSetServiceDefinition() throws Exception {
doMockStatics();
PowerMockito.mockStatic(APIUtil.class);
API api = getAPIForTesting();
String environmentName = "Default";
String environmentType = "hybrid";
String organization = "61416403c40f086ad2dc5eed";
PowerMockito.when(APIUtil.getGatewayEndpoint(api.getTransports(), environmentName, environmentType, organization)).thenReturn("http://localhost:8280");
APIMWSDLReader wsdlReader = new APIMWSDLReader("");
byte[] content = IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("wsdls/stockQuote.wsdl"));
Definition definition = wsdlReader.getWSDLDefinitionFromByteContent(content, false);
try {
wsdlReader.setServiceDefinition(definition, api, environmentName, environmentType);
wsdlReader.getWSDL(definition);
Assert.assertNotNull(definition.getServices());
} catch (APIManagementException e) {
Assert.fail("Unexpected exception occurred while updating service endpoint address");
}
}
use of javax.wsdl.Definition in project carbon-apimgt by wso2.
the class APIMWSDLReader method getWSDL.
/**
* Gets WSDL definition as a byte array
*
* @return converted WSDL definition as byte array
* @throws APIManagementException
*/
@Deprecated
public byte[] getWSDL() throws APIManagementException {
try {
Definition wsdlDefinition = readWSDLFile();
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer.writeWSDL(wsdlDefinition, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (Exception e) {
String msg = "Error occurs when change the address URL of the WSDL";
throw new APIManagementException(msg, e);
}
}
use of javax.wsdl.Definition 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.Definition 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.Definition in project cxf by apache.
the class WSDLGetUtils method getDocument.
public Document getDocument(Message message, String base, Map<String, String> params, String ctxUri, EndpointInfo endpointInfo) {
Document doc = null;
try {
Bus bus = message.getExchange().getBus();
base = getPublishedEndpointURL(message, base, endpointInfo);
// making sure this are existing map objects for the endpoint.
Map<String, Definition> mp = getWSDLKeyDefinition(endpointInfo);
Map<String, SchemaReference> smp = getSchemaKeySchemaReference(endpointInfo);
updateWSDLKeyDefinition(bus, mp, message, smp, base, endpointInfo);
//
if (params.containsKey("wsdl")) {
String wsdl = URLDecoder.decode(params.get("wsdl"), "utf-8");
doc = writeWSDLDocument(message, mp, smp, wsdl, base, endpointInfo);
} else if (params.get("xsd") != null) {
String xsd = URLDecoder.decode(params.get("xsd"), "utf-8");
doc = readXSDDocument(bus, xsd, smp, base);
updateDoc(doc, base, mp, smp, message, xsd);
}
} catch (WSDLQueryException wex) {
throw wex;
} catch (Exception wex) {
LOG.log(Level.SEVERE, wex.getMessage(), wex);
throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, base), wex);
}
return doc;
}
Aggregations