use of org.wso2.carbon.apimgt.api.model.Label in project carbon-business-process by wso2.
the class HTRenderingApiImpl method getRenderingInputElements.
/**
* @param taskIdentifier : interested task identifier
* @return set of input renderings wrapped within InputType
* @throws IllegalArgumentFault : error occured while retrieving renderings from task definition
* @throws IOException If an error occurred while reading from the input source
* @throws SAXException If the content in the input source is invalid
*/
private InputType getRenderingInputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException {
// TODO Chaching : check cache against task id for input renderings
QName renderingType = new QName(htRenderingNS, "input", "wso2");
String inputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
// Create input element
InputType renderingInputs = null;
// check availability of input renderings
if (inputRenderings != null && inputRenderings.length() > 0) {
// parse input renderings
Element inputRenderingsElement = DOMUtils.stringToDOM(inputRenderings);
// retrieve input elements
NodeList inputElementList = inputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
Element taskInputMsgElement = DOMUtils.stringToDOM((String) taskOps.getInput(taskIdentifier, null));
if (inputElementList != null && inputElementList.getLength() > 0) {
// hold number of input element
int inputElementNum = inputElementList.getLength();
InputElementType[] inputElements = new InputElementType[inputElementNum];
for (int i = 0; i < inputElementNum; i++) {
Element tempElement = (Element) inputElementList.item(i);
String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
String value = tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0).getTextContent();
// if the value starts with '/' then considered as an xpath and evaluate over received Input Message
if (value.startsWith("/") && taskInputMsgElement != null) {
// value represents xpath. evaluate against the input message
String xpathValue = evaluateXPath(value, taskInputMsgElement, inputRenderingsElement.getOwnerDocument());
if (xpathValue != null) {
value = xpathValue;
}
}
inputElements[i] = new InputElementType();
inputElements[i].setLabel(label);
inputElements[i].setValue(value);
}
renderingInputs = new InputType();
renderingInputs.setElement(inputElements);
// TODO cache renderingInputs against task instance id
}
}
return renderingInputs;
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class DBRetriever method retrieveAllArtifacts.
@Override
public List<String> retrieveAllArtifacts(String label, String tenantDomain) throws ArtifactSynchronizerException {
List<String> gatewayRuntimeArtifactsArray = new ArrayList<>();
try {
String endcodedgatewayLabel = URLEncoder.encode(label, APIConstants.DigestAuthConstants.CHARSET);
String path = APIConstants.GatewayArtifactSynchronizer.GATEAY_SYNAPSE_ARTIFACTS + "?gatewayLabel=" + endcodedgatewayLabel + "&type=Synapse";
String endpoint = baseURL + path;
try (CloseableHttpResponse httpResponse = invokeService(endpoint, tenantDomain)) {
JSONArray jsonArray = retrieveArtifact(httpResponse);
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
gatewayRuntimeArtifactsArray.add(jsonArray.getString(i));
}
}
}
return gatewayRuntimeArtifactsArray;
} catch (IOException e) {
String msg = "Error while executing the http client";
log.error(msg, e);
throw new ArtifactSynchronizerException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class DBRetriever method retrieveAttributes.
@Override
public Map<String, String> retrieveAttributes(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
CloseableHttpResponse httpResponse = null;
try {
String endcodedVersion = URLEncoder.encode(version, APIConstants.DigestAuthConstants.CHARSET);
String path = APIConstants.GatewayArtifactSynchronizer.SYNAPSE_ATTRIBUTES + "?apiName=" + apiName + "&tenantDomain=" + tenantDomain + "&version=" + endcodedVersion;
String endpoint = baseURL + path;
httpResponse = invokeService(endpoint, tenantDomain);
String responseString;
if (httpResponse.getEntity() != null) {
responseString = EntityUtils.toString(httpResponse.getEntity(), APIConstants.DigestAuthConstants.CHARSET);
httpResponse.close();
} else {
throw new ArtifactSynchronizerException("HTTP response is empty");
}
Map<String, String> apiAttribute = new HashMap<>();
JSONObject artifactObject = new JSONObject(responseString);
String label = null;
String apiId = null;
try {
apiId = (String) artifactObject.get(APIConstants.GatewayArtifactSynchronizer.API_ID);
String labelsStr = artifactObject.get(APIConstants.GatewayArtifactSynchronizer.LABELS).toString();
Set<String> labelsSet = new Gson().fromJson(labelsStr, new TypeToken<HashSet<String>>() {
}.getType());
Set<String> gatewaySubscribedLabel = gatewayArtifactSynchronizerProperties.getGatewayLabels();
if (!labelsSet.isEmpty() || !gatewaySubscribedLabel.isEmpty()) {
labelsSet.retainAll(gatewaySubscribedLabel);
if (!labelsSet.isEmpty()) {
label = labelsSet.iterator().next();
}
}
} catch (ClassCastException e) {
log.error("Unexpected response received from the storage." + e.getMessage());
}
apiAttribute.put(APIConstants.GatewayArtifactSynchronizer.API_ID, apiId);
apiAttribute.put(APIConstants.GatewayArtifactSynchronizer.LABEL, label);
return apiAttribute;
} catch (IOException e) {
String msg = "Error while executing the http client";
log.error(msg, e);
throw new ArtifactSynchronizerException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testcreateAPIArtifactContent.
@Test
public void testcreateAPIArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
API api = new API(new APIIdentifier("pubuser", "TestAPI", "1.0"));
Set<Tier> availableTiers = new HashSet<Tier>();
availableTiers.add(new Tier("Unlimited"));
availableTiers.add(new Tier("Gold"));
api.setAvailableTiers(availableTiers);
Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
URITemplate template = new URITemplate();
template.setHTTPVerb("GET");
template.setUriTemplate("/test");
template.setAuthType("None");
uriTemplates.add(template);
api.setUriTemplates(uriTemplates);
List<APICategory> categories = new ArrayList<APICategory>();
APICategory category = new APICategory();
category.setName("testcategory");
categories.add(category);
api.setApiCategories(categories);
List<Label> gatewayLabels = new ArrayList<Label>();
Label label = new Label();
label.setName("TestLabel");
gatewayLabels.add(label);
GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPI", ""), "application/vnd.wso2-api+xml");
genericArtifact.setAttribute("URITemplate", "/test");
GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIArtifactContent(genericArtifact, api);
Assert.assertEquals("API name does not match", api.getId().getApiName(), retArtifact.getAttribute("overview_name"));
Assert.assertEquals("API version does not match", api.getId().getVersion(), retArtifact.getAttribute("overview_version"));
Assert.assertEquals("API provider does not match", api.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class GatewayArtifactsMgtDAO method retrieveGatewayArtifacts.
public List<APIRuntimeArtifactDto> retrieveGatewayArtifacts(String tenantDomain) throws APIManagementException {
String query = SQLConstants.RETRIEVE_ARTIFACTS;
List<APIRuntimeArtifactDto> apiRuntimeArtifactDtoList = new ArrayList<>();
try (Connection connection = GatewayArtifactsMgtDBUtil.getArtifactSynchronizerConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, tenantDomain);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String apiId = resultSet.getString("API_ID");
String label = resultSet.getString("LABEL");
try {
APIRuntimeArtifactDto apiRuntimeArtifactDto = new APIRuntimeArtifactDto();
apiRuntimeArtifactDto.setTenantDomain(resultSet.getString("TENANT_DOMAIN"));
apiRuntimeArtifactDto.setApiId(apiId);
String resolvedVhost = VHostUtils.resolveIfNullToDefaultVhost(label, resultSet.getString("VHOST"));
apiRuntimeArtifactDto.setLabel(label);
apiRuntimeArtifactDto.setVhost(resolvedVhost);
apiRuntimeArtifactDto.setName(resultSet.getString("API_NAME"));
apiRuntimeArtifactDto.setVersion(resultSet.getString("API_VERSION"));
apiRuntimeArtifactDto.setProvider(resultSet.getString("API_PROVIDER"));
apiRuntimeArtifactDto.setRevision(resultSet.getString("REVISION_ID"));
apiRuntimeArtifactDto.setType(resultSet.getString("API_TYPE"));
apiRuntimeArtifactDto.setContext(resultSet.getString("CONTEXT"));
InputStream artifact = resultSet.getBinaryStream("ARTIFACT");
if (artifact != null) {
byte[] artifactByte = APIMgtDBUtil.getBytesFromInputStream(artifact);
try (InputStream newArtifact = new ByteArrayInputStream(artifactByte)) {
apiRuntimeArtifactDto.setArtifact(newArtifact);
}
}
apiRuntimeArtifactDto.setFile(true);
apiRuntimeArtifactDtoList.add(apiRuntimeArtifactDto);
} catch (APIManagementException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Error resolving vhost while retrieving runtime artifact for API %s, " + "gateway environment \"%s\", tenant: \"%s\"." + "Skipping runtime artifact for the API.", apiId, label, tenantDomain), e);
} catch (IOException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Error occurred retrieving input stream from byte array of " + "API: %s, gateway environment \"%s\", tenant: \"%s\".", apiId, label, tenantDomain), e);
} catch (SQLException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Failed to retrieve Gateway Artifact of API: %s, " + "gateway environment \"%s\", tenant: \"%s\".", apiId, label, tenantDomain), e);
}
}
}
} catch (SQLException e) {
handleException("Failed to retrieve Gateway Artifacts.", e);
}
return apiRuntimeArtifactDtoList;
}
Aggregations