use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDLSOAPOperationExtractorImplTestCase method testGetWsdlDefinition.
@Test
public void testGetWsdlDefinition() throws Exception {
APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/phoneverify.wsdl").toExternalForm());
byte[] wsdlContent = wsdlReader.getWSDL();
WSDL11SOAPOperationExtractor processor = new WSDL11SOAPOperationExtractor(wsdlReader);
Assert.assertTrue("WSDL definition parsing failed", processor.init(wsdlContent));
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method validateWSDLAndReset.
/**
* Validates the provided WSDL and reset the streams as required
*
* @param fileInputStream file input stream
* @param fileDetail file details
* @param url WSDL url
* @throws APIManagementException when error occurred during the operation
*/
private WSDLValidationResponse validateWSDLAndReset(InputStream fileInputStream, Attachment fileDetail, String url) throws APIManagementException {
Map validationResponseMap = validateWSDL(url, fileInputStream, fileDetail, false);
WSDLValidationResponse validationResponse = (WSDLValidationResponse) validationResponseMap.get(RestApiConstants.RETURN_MODEL);
if (validationResponse.getWsdlInfo() == null) {
// Validation failure
RestApiUtil.handleBadRequest(validationResponse.getError(), log);
}
if (fileInputStream != null) {
if (fileInputStream.markSupported()) {
// For uploading the WSDL below will require re-reading from the input stream hence resetting
try {
fileInputStream.reset();
} catch (IOException e) {
throw new APIManagementException("Error occurred while trying to reset the content stream of the " + "WSDL", e);
}
} else {
log.warn("Marking is not supported in 'fileInputStream' InputStream type: " + fileInputStream.getClass() + ". Skipping validating WSDL to avoid re-reading from the " + "input stream.");
}
}
return validationResponse;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method validateWSDLDefinition.
/**
* Validate a provided WSDL definition via a URL or a file/zip
*
* @param url WSDL URL
* @param fileInputStream file/zip input stream
* @param fileDetail file/zip details
* @param messageContext messageContext object
* @return WSDL validation response
* @throws APIManagementException when error occurred during validation
*/
@Override
public Response validateWSDLDefinition(String url, InputStream fileInputStream, Attachment fileDetail, MessageContext messageContext) throws APIManagementException {
Map validationResponseMap = validateWSDL(url, fileInputStream, fileDetail, false);
WSDLValidationResponseDTO validationResponseDTO = (WSDLValidationResponseDTO) validationResponseMap.get(RestApiConstants.RETURN_DTO);
return Response.ok().entity(validationResponseDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method importWSDLDefinition.
/**
* Import a WSDL file/url or an archive and create an API. The API can be a SOAP or REST depending on the
* provided implementationType.
*
* @param fileInputStream file input stream
* @param fileDetail file details
* @param url WSDL url
* @param additionalProperties API object (json) including additional properties like name, version, context
* @param implementationType SOAP or SOAPTOREST
* @return Created API's payload
* @throws APIManagementException when error occurred during the operation
*/
@Override
public Response importWSDLDefinition(InputStream fileInputStream, Attachment fileDetail, String url, String additionalProperties, String implementationType, MessageContext messageContext) throws APIManagementException {
try {
WSDLValidationResponse validationResponse = validateWSDLAndReset(fileInputStream, fileDetail, url);
if (StringUtils.isEmpty(implementationType)) {
implementationType = APIDTO.TypeEnum.SOAP.toString();
}
boolean isSoapToRestConvertedAPI = APIDTO.TypeEnum.SOAPTOREST.toString().equals(implementationType);
boolean isSoapAPI = APIDTO.TypeEnum.SOAP.toString().equals(implementationType);
APIDTO additionalPropertiesAPI = null;
APIDTO createdApiDTO;
URI createdApiUri;
// Minimum requirement name, version, context and endpointConfig.
additionalPropertiesAPI = new ObjectMapper().readValue(additionalProperties, APIDTO.class);
String username = RestApiCommonUtil.getLoggedInUsername();
additionalPropertiesAPI.setProvider(username);
additionalPropertiesAPI.setType(APIDTO.TypeEnum.fromValue(implementationType));
String organization = RestApiUtil.getValidatedOrganization(messageContext);
API apiToAdd = PublisherCommonUtils.prepareToCreateAPIByDTO(additionalPropertiesAPI, RestApiCommonUtil.getLoggedInUserProvider(), username, organization);
apiToAdd.setWsdlUrl(url);
API createdApi = null;
if (isSoapAPI) {
createdApi = importSOAPAPI(validationResponse.getWsdlProcessor().getWSDL(), fileDetail, url, apiToAdd, organization, null);
} else if (isSoapToRestConvertedAPI) {
String wsdlArchiveExtractedPath = null;
if (validationResponse.getWsdlArchiveInfo() != null) {
wsdlArchiveExtractedPath = validationResponse.getWsdlArchiveInfo().getLocation() + File.separator + APIConstants.API_WSDL_EXTRACTED_DIRECTORY;
}
createdApi = importSOAPToRESTAPI(validationResponse.getWsdlProcessor().getWSDL(), fileDetail, url, wsdlArchiveExtractedPath, apiToAdd, organization);
} else {
RestApiUtil.handleBadRequest("Invalid implementationType parameter", log);
}
createdApiDTO = APIMappingUtil.fromAPItoDTO(createdApi);
// This URI used to set the location header of the POST response
createdApiUri = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + createdApiDTO.getId());
return Response.created(createdApiUri).entity(createdApiDTO).build();
} catch (IOException | URISyntaxException e) {
RestApiUtil.handleInternalServerError("Error occurred while importing WSDL", e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getWSDLOfAPI.
/**
* Retrieve the WSDL of an API
*
* @param apiId UUID of the API
* @param ifNoneMatch If-None-Match header value
* @return the WSDL of the API (can be a file or zip archive)
* @throws APIManagementException when error occurred while trying to retrieve the WSDL
*/
@Override
public Response getWSDLOfAPI(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// this will fail if user does not have access to the API or the API does not exist
// APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId, organization);
ResourceFile resource = apiProvider.getWSDL(apiId, organization);
return RestApiUtil.getResponseFromResourceFile(resource.getName(), resource);
} catch (APIManagementException e) {
// to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving wsdl of API: " + apiId, e, log);
} else {
throw e;
}
}
return null;
}
Aggregations