Search in sources :

Example 51 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method updateEndpointsOfWSDLArchive.

/**
 * Update the endpoint information of the WSDL (WSDL archive scenario) when an API and the environment details are
 * provided
 *
 * @param api API
 * @param environmentName name of the gateway environment
 * @param environmentType type of the gateway environment
 * @throws APIMgtWSDLException when error occurred while updating the endpoints
 */
private void updateEndpointsOfWSDLArchive(API api, String environmentName, String environmentType) throws APIMgtWSDLException {
    for (Map.Entry<String, Description> entry : pathToDescriptionMap.entrySet()) {
        Description description = entry.getValue();
        if (log.isDebugEnabled()) {
            log.debug("Updating endpoints of WSDL: " + entry.getKey());
        }
        updateEndpointsOfSingleWSDL(api, environmentName, environmentType, 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.getId().getName() + ":" + api.getId().getVersion() + " for environment " + environmentName, e, ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
        }
    }
}
Also used : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.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 52 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getSoapMessageType.

/**
 * Gets message type for a given soap operation
 *
 * @param bindingOperation soap operation
 * @return String for message type
 * @throws APIMgtWSDLException
 */
private String getSoapMessageType(BindingOperation bindingOperation) throws APIMgtWSDLException {
    Operation operation = bindingOperation.getOperation();
    String messageType = "";
    boolean hasRPCMessages = false;
    if (operation != null) {
        Input input = operation.getInput();
        if (input != null) {
            Message message = input.getMessage();
            if (message != null) {
                Map map = message.getParts();
                for (Object obj : map.entrySet()) {
                    Map.Entry entry = (Map.Entry) obj;
                    Part part = (Part) entry.getValue();
                    if (part != null) {
                        if (part.getElementName() != null) {
                            messageType = "document";
                        } else if (part.getTypeName() != null) {
                            messageType = "rpc";
                            hasRPCMessages = true;
                        }
                    }
                }
            }
        }
    }
    if (hasRPCMessages) {
        return "rpc";
    } else {
        return messageType;
    }
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) Part(javax.wsdl.Part) Operation(javax.wsdl.Operation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) WSDLOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperation) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 53 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getSOAPBindingOperations.

/**
 * Retrieves all the operations defined in the provided Binding.
 *
 * @param binding WSDL binding
 * @return a set of {@link WSDLOperation} defined in the provided Binding
 */
private Set<WSDLSOAPOperation> getSOAPBindingOperations(Binding binding) throws APIMgtWSDLException {
    Set<WSDLSOAPOperation> allBindingOperations = new HashSet<>();
    if (binding.getExtensibilityElements() != null && binding.getExtensibilityElements().size() > 0) {
        List extensibilityElements = binding.getExtensibilityElements();
        for (Object extensibilityElement : extensibilityElements) {
            if (extensibilityElement instanceof SOAPBinding || extensibilityElement instanceof SOAP12Binding) {
                for (Object opObj : binding.getBindingOperations()) {
                    BindingOperation bindingOperation = (BindingOperation) opObj;
                    WSDLSOAPOperation wsdlSoapOperation = getSOAPOperation(bindingOperation);
                    if (wsdlSoapOperation != null) {
                        allBindingOperations.add(wsdlSoapOperation);
                    } else {
                        log.warn("Unable to get soap operation details from binding operation: " + bindingOperation.getName());
                    }
                }
            }
        }
    } else {
        throw new APIMgtWSDLException("Cannot further process to get soap binding operations");
    }
    return allBindingOperations;
}
Also used : SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) BindingOperation(javax.wsdl.BindingOperation) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) HashSet(java.util.HashSet)

Example 54 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getSoapInputParameterModel.

/**
 * Gets swagger input parameter model for a given soap operation
 *
 * @param bindingOperation soap operation
 * @return list of swagger models for the parameters
 * @throws APIMgtWSDLException
 */
private List<ModelImpl> getSoapInputParameterModel(BindingOperation bindingOperation) throws APIMgtWSDLException {
    List<ModelImpl> inputParameterModelList = new ArrayList<>();
    Operation operation = bindingOperation.getOperation();
    if (operation != null) {
        Input input = operation.getInput();
        if (input != null) {
            Message message = input.getMessage();
            if (message != null) {
                Map map = message.getParts();
                for (Object obj : map.entrySet()) {
                    Map.Entry entry = (Map.Entry) obj;
                    Part part = (Part) entry.getValue();
                    if (part != null) {
                        if (part.getElementName() != null) {
                            inputParameterModelList.add(parameterModelMap.get(part.getElementName().getLocalPart()));
                        } else {
                            if (part.getTypeName() != null && parameterModelMap.containsKey(part.getTypeName().getLocalPart())) {
                                inputParameterModelList.add(parameterModelMap.get(part.getTypeName().getLocalPart()));
                            } else if (part.getTypeName() != null && parameterModelMap.containsKey(message.getQName().getLocalPart())) {
                                ModelImpl model = parameterModelMap.get(message.getQName().getLocalPart());
                                model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
                                parameterModelMap.put(model.getName(), model);
                                inputParameterModelList.add(model);
                            } else {
                                ModelImpl model;
                                if (parameterModelMap.get(message.getQName().getLocalPart()) != null) {
                                    model = parameterModelMap.get(message.getQName().getLocalPart());
                                } else {
                                    model = new ModelImpl();
                                    model.setType(ObjectProperty.TYPE);
                                    model.setName(message.getQName().getLocalPart());
                                }
                                if (getPropertyFromDataType(part.getTypeName().getLocalPart()) instanceof RefProperty) {
                                    RefProperty property = (RefProperty) getPropertyFromDataType(part.getTypeName().getLocalPart());
                                    property.set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + part.getTypeName().getLocalPart());
                                    model.addProperty(part.getName(), property);
                                } else {
                                    model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
                                }
                                parameterModelMap.put(model.getName(), model);
                                inputParameterModelList.add(model);
                            }
                        }
                    }
                }
            }
        }
    }
    return inputParameterModelList;
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) Part(javax.wsdl.Part) ArrayList(java.util.ArrayList) Operation(javax.wsdl.Operation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) WSDLOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperation) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) RefProperty(io.swagger.models.properties.RefProperty)

Example 55 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class APIMWSDLReader method getWSDLProcessorForUrl.

/**
 * Returns the appropriate WSDL 1.1/WSDL 2.0 based on the url {@code url}.
 *
 * @param url WSDL url
 * @return WSDL 1.1/2.0 processor for the provided content
 * @throws APIManagementException If an error occurs while determining the processor
 */
public static WSDLProcessor getWSDLProcessorForUrl(URL url) throws APIManagementException {
    WSDLProcessor wsdl11Processor = new WSDL11ProcessorImpl();
    WSDLProcessor wsdl20Processor = new WSDL20ProcessorImpl();
    try {
        if (wsdl11Processor.canProcess(url)) {
            wsdl11Processor.init(url);
            return wsdl11Processor;
        } else if (wsdl20Processor.canProcess(url)) {
            wsdl20Processor.init(url);
            return wsdl20Processor;
        } else {
            // no processors found if this line reaches
            throw new APIManagementException("No WSDL processor found to process WSDL url: " + url, ExceptionCodes.URL_NOT_RECOGNIZED_AS_WSDL);
        }
    } catch (APIMgtWSDLException e) {
        throw new APIManagementException("Error while instantiating wsdl processor class", e);
    }
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDL20ProcessorImpl(org.wso2.carbon.apimgt.impl.wsdl.WSDL20ProcessorImpl) WSDL11ProcessorImpl(org.wso2.carbon.apimgt.impl.wsdl.WSDL11ProcessorImpl)

Aggregations

APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)22 IOException (java.io.IOException)15 File (java.io.File)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 WSDLException (javax.wsdl.WSDLException)9 WSDLException (org.apache.woden.WSDLException)9 InputStream (java.io.InputStream)8 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)8 FileInputStream (java.io.FileInputStream)7 WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)7 WSDLReader (javax.wsdl.xml.WSDLReader)5 ErrorItem (org.wso2.carbon.apimgt.api.ErrorItem)5 APIMWSDLReader (org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 ArrayList (java.util.ArrayList)4