Skip to content

Commit

Permalink
changes due to swagger import
Browse files Browse the repository at this point in the history
  • Loading branch information
thushara35 committed Apr 9, 2015
1 parent 7a7ef5b commit 57f0c2c
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.wso2.carbon.registry.extensions.handlers;

import org.apache.axiom.om.OMElement;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.registry.core.RegistryConstants;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.config.RegistryContext;
Expand Down Expand Up @@ -138,11 +139,26 @@ public void put(RequestContext requestContext) throws RegistryException {
throw new RegistryException(CommonConstants.INVALID_CONTENT);
}

inputStream = new ByteArrayInputStream((byte[]) resourceContentObj);
SwaggerProcessor processor = new SwaggerProcessor(requestContext);
processor.processSwagger(inputStream, getChrootedLocation(requestContext.getRegistryContext()), null);
requestContext.setProcessingComplete(true);
} finally {
requestContext.setSourceURL(
requestContext.getResource().getProperty(CommonConstants.SOURCEURL_PARAMETER_NAME));
String sourceURL = requestContext.getSourceURL();


if (StringUtils.isBlank(sourceURL)) {
inputStream = new ByteArrayInputStream((byte[]) resourceContentObj);
SwaggerProcessor processor = new SwaggerProcessor(requestContext);
processor.processSwagger(inputStream, getChrootedLocation(requestContext.getRegistryContext()), null);
} else {
//Open a stream to the sourceURL
inputStream = new URL(sourceURL).openStream();

SwaggerProcessor processor = new SwaggerProcessor(requestContext);
processor.processSwagger(inputStream, getChrootedLocation(requestContext.getRegistryContext()), sourceURL);
}
requestContext.setProcessingComplete(true);
}catch (IOException e) {
throw new RegistryException("The URL " + requestContext.getSourceURL() + " is incorrect.", e);
} finally {
CommonUtil.closeInputStream(inputStream);
CommonUtil.releaseUpdateLock();
}
Expand Down

0 comments on commit 57f0c2c

Please sign in to comment.