Search in sources :

Example 46 with Definition

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");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Definition(javax.wsdl.Definition) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 47 with Definition

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) APIUtil.handleException(org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 48 with Definition

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ByteArrayInputStream(java.io.ByteArrayInputStream) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WSDLReader(javax.wsdl.xml.WSDLReader) WSDLReaderImpl(com.ibm.wsdl.xml.WSDLReaderImpl) APIUtil.handleException(org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 49 with Definition

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) File(java.io.File) WSDLReader(javax.wsdl.xml.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 50 with Definition

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;
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) Definition(javax.wsdl.Definition) Document(org.w3c.dom.Document) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) WSDLException(javax.wsdl.WSDLException)

Aggregations

Definition (javax.wsdl.Definition)226 Test (org.junit.Test)113 QName (javax.xml.namespace.QName)61 File (java.io.File)52 Document (org.w3c.dom.Document)44 Element (org.w3c.dom.Element)40 HashMap (java.util.HashMap)36 WSDLReader (javax.wsdl.xml.WSDLReader)35 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)31 JBossWSTest (org.jboss.wsf.test.JBossWSTest)31 Service (javax.wsdl.Service)24 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)23 URL (java.net.URL)21 ArrayList (java.util.ArrayList)21 Port (javax.wsdl.Port)21 WSDLToIDLAction (org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction)21 Bus (org.apache.cxf.Bus)20 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)20 WSDLManager (org.apache.cxf.wsdl.WSDLManager)20 IOException (java.io.IOException)18