Search in sources :

Example 96 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-business-process by wso2.

the class UnifiedEndpointFactory method createEndpoint.

public UnifiedEndpoint createEndpoint(OMElement uEPConfigEle) throws AxisFault {
    UnifiedEndpoint unifiedEndpoint = new UnifiedEndpoint();
    EndpointReferenceHelper.fromOM(unifiedEndpoint, uEPConfigEle, AddressingConstants.Final.WSA_NAMESPACE);
    OMElement metadataElem = uEPConfigEle.getFirstChildWithName(UnifiedEndpointConstants.METADATA_Q);
    if (metadataElem != null) {
        OMElement idElem = metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_ID_Q);
        if (idElem != null) {
            unifiedEndpoint.setUepId(idElem.getText());
        } else {
            log.error("UEP Configuration violation: " + UnifiedEndpointConstants.METADATA_ID_Q + " not found");
        }
        /**
         * Discovery
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_DISCOVERY_Q) != null) {
            extractDiscoveryConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_DISCOVERY_Q));
        }
        /**
         * Timeout
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TIMEOUT_Q) != null) {
            extractTimeoutConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TIMEOUT_Q));
        }
        /**
         * WSDL Definitions
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_WSDL11_DEFINITIONS_Q) != null) {
            unifiedEndpoint.setWsdl11Definitions(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_WSDL11_DEFINITIONS_Q));
        }
        /**
         * MessageOutput
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MESSAGE_OUTPUT_Q) != null) {
            extractMessageOutPutConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MESSAGE_OUTPUT_Q));
        }
        /**
         * Transport
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q) != null) {
            extractTransportConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q));
            if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_USERNAME_Q) != null) {
                unifiedEndpoint.setAuthorizationUserName(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_USERNAME_Q).getText());
            }
            if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q) != null) {
                OMElement transport_auth_password = metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q);
                String secretAlias = transport_auth_password.getAttributeValue(new QName(UnifiedEndpointConstants.SECURE_VAULT_NS, UnifiedEndpointConstants.SECRET_ALIAS_ATTR_NAME));
                if (secretAlias != null && secretAlias.trim().length() > 0) {
                    secretAlias = secretAlias.trim();
                    SecretResolver secretResolver = SecretResolverFactory.create(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q), false);
                    /* Setting the secured password */
                    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(secretAlias)) {
                        String adminPassword = secretResolver.resolve(secretAlias);
                        unifiedEndpoint.setAuthorizationPassword(adminPassword);
                    } else {
                        /* If secure vault is not configured properly, Reading plain text password */
                        unifiedEndpoint.setAuthorizationPassword(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q).getText());
                    }
                } else {
                    unifiedEndpoint.setAuthorizationPassword(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q).getText());
                }
            }
        }
        /**
         * Monitoring
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MONITORING_Q) != null) {
            extractMetadataMonitoringConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MONITORING_Q));
        }
        /**
         * QoS
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.QOS_Q) != null) {
            extractQoSConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.QOS_Q));
        }
        /**
         * Session
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.SESSION_Q) != null) {
            if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.SESSION_Q).getAttributeValue(UnifiedEndpointConstants.SESSION_TYPE_Q) != null) {
                unifiedEndpoint.setSessionType(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.SESSION_Q).getAttributeValue(UnifiedEndpointConstants.SESSION_TYPE_Q));
            }
        }
    }
    return unifiedEndpoint;
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 97 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-business-process by wso2.

the class ArchiveBasedHumanTaskDeploymentUnitBuilder method readInTheWSDLFile.

/**
 * Read the WSDL file given the input stream for the WSDL source
 *
 * @param in           WSDL input stream
 * @param entryName    ZIP file entry name
 * @param fromRegistry whether the wsdl is read from registry
 * @return WSDL Definition
 * @throws javax.wsdl.WSDLException at parser error
 */
public static Definition readInTheWSDLFile(InputStream in, String entryName, boolean fromRegistry) throws WSDLException {
    WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
    // switch off the verbose mode for all usecases
    reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
    reader.setFeature("javax.wsdl.importDocuments", true);
    Definition def;
    Document doc;
    try {
        doc = XMLUtils.newDocument(in);
    } catch (ParserConfigurationException e) {
        throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Configuration Error", e);
    } catch (SAXException e) {
        throw new WSDLException(WSDLException.PARSER_ERROR, "Parser SAX Error", e);
    } catch (IOException e) {
        throw new WSDLException(WSDLException.INVALID_WSDL, "IO Error", e);
    }
    // Log when and from where the WSDL is loaded.
    if (log.isDebugEnabled()) {
        log.debug("Reading 1.1 WSDL with base uri = " + entryName);
        log.debug("  the document base uri = " + entryName);
    }
    if (fromRegistry) {
        throw new UnsupportedOperationException("This operation is not currently " + "supported in this version of WSO2 BPS.");
    } else {
        def = reader.readWSDL(entryName, doc.getDocumentElement());
    }
    def.setDocumentBaseURI(entryName);
    return def;
}
Also used : WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HumanInteractionsDocument(org.wso2.carbon.humantask.HumanInteractionsDocument) HTDeploymentConfigDocument(org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument) Document(org.w3c.dom.Document) WSDLReader(javax.wsdl.xml.WSDLReader) SAXException(org.xml.sax.SAXException)

Example 98 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method updateEndpoints.

/**
 * Updates the endpoints of the {@code definition} based on the provided {@code endpointURLs} and {@code api}.
 *
 * @param endpointURLs Endpoint URIs
 * @param api          Provided API object
 * @param definition   WSDL Definition
 * @throws APIMgtWSDLException If an error occurred while updating endpoints
 */
private void updateEndpoints(List<String> endpointURLs, API api, Definition definition) throws APIMgtWSDLException {
    String context = api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext();
    String selectedUrl;
    try {
        selectedUrl = APIMWSDLUtils.getSelectedEndpoint(endpointURLs) + context;
        if (log.isDebugEnabled()) {
            log.debug("Selected URL for updating endpoints of WSDL:" + selectedUrl);
        }
    } catch (MalformedURLException e) {
        throw new APIMgtWSDLException("Error while selecting endpoints for WSDL", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
    if (!StringUtils.isBlank(selectedUrl)) {
        updateEndpoints(selectedUrl, definition);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 99 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method getUpdatedWSDLPath.

/**
 * Updates the endpoints of all the WSDL files in the path based on the provided API (context) and Label (host).
 *
 * @param api Provided API object
 * @param label Provided label object
 * @return Updated WSDL file path
 * @throws APIMgtWSDLException Error while updating WSDL files
 */
@Override
public String getUpdatedWSDLPath(API api, Label label) throws APIMgtWSDLException {
    if (label != null) {
        for (Map.Entry<String, Description> entry : pathToDescriptionMap.entrySet()) {
            Description description = entry.getValue();
            if (log.isDebugEnabled()) {
                log.debug("Updating endpoints of WSDL: " + entry.getKey());
            }
            updateEndpoints(label.getAccessUrls(), api, description);
            if (log.isDebugEnabled()) {
                log.debug("Successfully updated endpoints of WSDL: " + entry.getKey());
            }
            try (FileOutputStream wsdlFileOutputStream = new FileOutputStream(new File(entry.getKey()))) {
                WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
                writer.writeWSDL(description.toElement(), wsdlFileOutputStream);
            } catch (IOException | WSDLException e) {
                throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getName() + ":" + api.getVersion() + " for label " + label.getName(), ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
            }
        }
    }
    return wsdlArchiveExtractedPath;
}
Also used : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) FileOutputStream(java.io.FileOutputStream) WSDLWriter(org.apache.woden.WSDLWriter) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 100 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method initPath.

/**
 * {@inheritDoc}
 * Will return true if all the provided WSDL files in the initialized path is of 2.0 and can be successfully
 * parsed by woden.
 */
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    pathToDescriptionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    try {
        WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
        File folderToImport = new File(path);
        Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
        if (log.isDebugEnabled()) {
            log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
        }
        for (File file : foundWSDLFiles) {
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + file.getAbsolutePath());
            }
            Description description = reader.readWSDL(file.getAbsolutePath());
            pathToDescriptionMap.put(file.getAbsolutePath(), description);
        }
        if (foundWSDLFiles.size() > 0) {
            canProcess = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        canProcess = false;
    }
    return canProcess;
}
Also used : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) File(java.io.File) WSDLReader(org.apache.woden.WSDLReader)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)64 IOException (java.io.IOException)42 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)33 Test (org.junit.Test)30 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 API (org.wso2.carbon.apimgt.core.models.API)28 File (java.io.File)27 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)23 FileInputStream (java.io.FileInputStream)23 InputStream (java.io.InputStream)22 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 WSDLException (javax.wsdl.WSDLException)21 HashMap (java.util.HashMap)20 Resource (org.wso2.carbon.registry.core.Resource)20 MalformedURLException (java.net.MalformedURLException)18 Map (java.util.Map)16 Response (javax.ws.rs.core.Response)16 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)16 SAXException (org.xml.sax.SAXException)16