Search in sources :

Example 21 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method updateEndpointsOfSingleWSDL.

/**
 * Update the endpoint information of the provided WSDL definition 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
 * @param wsdlDescription WSDL 2.0 definition
 * @throws APIMgtWSDLException when error occurred while updating the endpoints
 */
private void updateEndpointsOfSingleWSDL(API api, String environmentName, String environmentType, Description wsdlDescription) throws APIMgtWSDLException {
    Service[] serviceMap = wsdlDescription.getServices();
    String organization = api.getOrganization();
    try {
        for (Service svc : serviceMap) {
            Endpoint[] portMap = svc.getEndpoints();
            for (Endpoint endpoint : portMap) {
                EndpointElement element = endpoint.toElement();
                String endpointTransport = determineURLTransport(endpoint.getAddress().getScheme(), api.getTransports());
                setAddressUrl(element, new URI(APIUtil.getGatewayEndpoint(endpointTransport, environmentName, environmentType, organization) + api.getContext()));
            }
        }
    } catch (URISyntaxException | APIManagementException e) {
        throw new APIMgtWSDLException("Error while setting gateway access URLs in the WSDL", e);
    }
}
Also used : Endpoint(org.apache.woden.wsdl20.Endpoint) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) Service(org.apache.woden.wsdl20.Service) URISyntaxException(java.net.URISyntaxException) EndpointElement(org.apache.woden.wsdl20.xml.EndpointElement) URI(java.net.URI)

Example 22 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method init.

@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader reader;
    try {
        reader = getWsdlFactoryInstance().newWSDLReader();
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while initializing the WSDL reader", e);
    }
    reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
    Document document = getSecuredParsedDocumentFromContent(wsdlContent);
    WSDLSource wsdlSource = getWSDLSourceFromDocument(document, reader);
    try {
        wsdlDescription = reader.readWSDL(wsdlSource);
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException 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;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLSource(org.apache.woden.WSDLSource) Document(org.w3c.dom.Document) WSDLReader(org.apache.woden.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 23 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class APIMWSDLReader method getWSDLProcessor.

/**
 * Gets WSDL processor WSDL 1.1/WSDL 2.0 based on the content {@code content}.
 *
 * @param content WSDL content
 * @return {@link WSDLProcessor}
 * @throws APIManagementException
 */
public static WSDLProcessor getWSDLProcessor(byte[] content) throws APIManagementException {
    WSDLProcessor wsdl11Processor = new WSDL11ProcessorImpl();
    WSDLProcessor wsdl20Processor = new WSDL20ProcessorImpl();
    try {
        if (wsdl11Processor.canProcess(content)) {
            wsdl11Processor.init(content);
            return wsdl11Processor;
        } else if (wsdl20Processor.canProcess(content)) {
            wsdl20Processor.init(content);
            return wsdl20Processor;
        } else {
            // no processors found if this line reaches
            throw new APIManagementException("No WSDL processor found to process WSDL content.", ExceptionCodes.CONTENT_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)

Example 24 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class APIMWSDLReader method getWsdlValidationResponse.

/**
 * Gets WSDL validation response from the WSDL processor
 *
 * @param processor WSDL processor
 * @return WSDL validation response
 * @throws APIMgtWSDLException if error occurred while retrieving WSDL info
 */
public static WSDLValidationResponse getWsdlValidationResponse(WSDLProcessor processor) throws APIMgtWSDLException {
    WSDLValidationResponse wsdlValidationResponse = new WSDLValidationResponse();
    if (processor.hasError()) {
        wsdlValidationResponse.setValid(false);
        wsdlValidationResponse.setError(processor.getError());
    } else {
        wsdlValidationResponse.setValid(true);
        wsdlValidationResponse.setWsdlInfo(processor.getWsdlInfo());
        wsdlValidationResponse.setWsdlProcessor(processor);
    }
    return wsdlValidationResponse;
}
Also used : WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)

Example 25 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException 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)

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