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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations