Java Code Examples for org.wso2.carbon.apimgt.api.model.URITemplate#setHttpVerbs()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.URITemplate#setHttpVerbs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceConfigContext.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public VelocityContext getContext() { VelocityContext context = super.getContext(); if (api != null) { context.put("resources", api.getUriTemplates()); context.put("apiStatus", api.getStatus()); context.put("faultSequence", faultSeqExt != null ? faultSeqExt : api.getFaultSequence()); } else if (apiProduct != null) { //Here we aggregate duplicate resourceURIs of an API and populate httpVerbs set in the uri template List<APIProductResource> productResources = apiProduct.getProductResources(); List<APIProductResource> aggregateResources = new ArrayList<APIProductResource>(); List<String> uriTemplateNames = new ArrayList<String>(); for (APIProductResource productResource : productResources) { URITemplate uriTemplate = productResource.getUriTemplate(); String productResourceKey = productResource.getApiIdentifier() + ":" + uriTemplate.getUriTemplate(); if (uriTemplateNames.contains(productResourceKey)) { for (APIProductResource resource : aggregateResources) { String resourceKey = resource.getApiIdentifier() + ":" + resource.getUriTemplate().getUriTemplate(); if (resourceKey.equals(productResourceKey)) { resource.getUriTemplate().setHttpVerbs(uriTemplate.getHTTPVerb()); } } } else { uriTemplate.setHttpVerbs(uriTemplate.getHTTPVerb()); aggregateResources.add(productResource); uriTemplateNames.add(productResourceKey); } } context.put("apiStatus", apiProduct.getState()); context.put("aggregates", aggregateResources); } return context; //To change body of implemented methods use File | Settings | File Templates. }
Example 2
Source File: OASTestBase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public void testGetURITemplates(APIDefinition parser, String content) throws Exception { JSONObject jsonObject = new JSONObject(content); URITemplate exUriTemplate = new URITemplate(); exUriTemplate.setUriTemplate("/pets"); exUriTemplate.setAuthType("Application & Application User"); exUriTemplate.setAuthTypes("Application & Application User"); exUriTemplate.setHTTPVerb("GET"); exUriTemplate.setHttpVerbs("GET"); exUriTemplate.setThrottlingTier("Unlimited"); exUriTemplate.setThrottlingTiers("Unlimited"); exUriTemplate.setScope(extensionScope); exUriTemplate.setScopes(extensionScope); String scopesOnlyInSecurity = jsonObject.getJSONObject("scopesOnlyInSecurity").toString(); Set<URITemplate> uriTemplates = parser.getURITemplates(scopesOnlyInSecurity); Assert.assertEquals(1, uriTemplates.size()); Assert.assertTrue(uriTemplates.contains(petGet)); String scopesOnlyInExtension = jsonObject.getJSONObject("scopesOnlyInExtension").toString(); uriTemplates = parser.getURITemplates(scopesOnlyInExtension); Assert.assertEquals(1, uriTemplates.size()); Assert.assertTrue(uriTemplates.contains(exUriTemplate)); String scopesInExtensionAndSec = jsonObject.getJSONObject("scopesInExtensionAndSec").toString(); uriTemplates = parser.getURITemplates(scopesInExtensionAndSec); Assert.assertEquals(1, uriTemplates.size()); Assert.assertTrue(uriTemplates.contains(petGet)); }
Example 3
Source File: OASTestBase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public String testGenerateAPIDefinitionWithExtension(APIDefinition parser, String content) throws Exception { JSONObject jsonObject = new JSONObject(content); String equalNoOfResourcesWithExtension = jsonObject.getJSONObject("equalNoOfResourcesWithExtension").toString(); Scope newScope = new Scope(); newScope.setName("newScope"); newScope.setKey("newScope"); newScope.setRoles("admin"); newScope.setDescription("newScopeDescription"); URITemplate updatedItemGet = new URITemplate(); updatedItemGet.setUriTemplate("/items"); updatedItemGet.setAuthType("Application & Application User"); updatedItemGet.setAuthTypes("Application & Application User"); updatedItemGet.setHTTPVerb("GET"); updatedItemGet.setHttpVerbs("GET"); updatedItemGet.setThrottlingTier("Unlimited"); updatedItemGet.setThrottlingTiers("Unlimited"); updatedItemGet.setScope(newScope); updatedItemGet.setScopes(newScope); APIIdentifier identifier = new APIIdentifier("admin", "simple", "1.0.0"); API api = new API(identifier); api.setScopes(new HashSet<>(Arrays.asList(sampleScope, extensionScope, newScope))); api.setUriTemplates(new HashSet<>(Arrays.asList(petPost, updatedItemGet))); String definition = parser.generateAPIDefinition(new SwaggerData(api), equalNoOfResourcesWithExtension); APIDefinitionValidationResponse response = parser.validateAPIDefinition(definition, false); Assert.assertTrue(response.isValid()); return definition; }
Example 4
Source File: OASTestBase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
protected URITemplate getUriTemplate(String httpVerb, String authType, String uriTemplateString) { URITemplate uriTemplate = new URITemplate(); uriTemplate.setAuthTypes(authType); uriTemplate.setAuthType(authType); uriTemplate.setHTTPVerb(httpVerb); uriTemplate.setHttpVerbs(httpVerb); uriTemplate.setUriTemplate(uriTemplateString); uriTemplate.setThrottlingTier("Unlimited"); uriTemplate.setThrottlingTiers("Unlimited"); uriTemplate.setScope(null); return uriTemplate; }
Example 5
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method returns URI templates according to the given swagger file * * @param resourceConfigsJSON swaggerJSON * @return URI Templates * @throws APIManagementException */ @Override public Set<URITemplate> getURITemplates(String resourceConfigsJSON) throws APIManagementException { Swagger swagger = getSwagger(resourceConfigsJSON); Set<URITemplate> urlTemplates = new LinkedHashSet<>(); Set<Scope> scopes = getScopes(resourceConfigsJSON); String oauth2SchemeKey = getOAuth2SecuritySchemeKey(swagger); for (String pathString : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathString); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { Operation operation = entry.getValue(); URITemplate template = new URITemplate(); template.setHTTPVerb(entry.getKey().name().toUpperCase()); template.setHttpVerbs(entry.getKey().name().toUpperCase()); template.setUriTemplate(pathString); List<String> opScopes = getScopeOfOperations(oauth2SchemeKey, operation); if (!opScopes.isEmpty()) { if (opScopes.size() == 1) { String firstScope = opScopes.get(0); Scope scope = APIUtil.findScopeByKey(scopes, firstScope); if (scope == null) { throw new APIManagementException("Scope '" + firstScope + "' not found."); } template.setScope(scope); template.setScopes(scope); } else { template = OASParserUtil.setScopesToTemplate(template, opScopes, scopes); } } Map<String, Object> extensions = operation.getVendorExtensions(); if (extensions != null) { if (extensions.containsKey(APIConstants.SWAGGER_X_AUTH_TYPE)) { String authType = (String) extensions.get(APIConstants.SWAGGER_X_AUTH_TYPE); template.setAuthType(authType); template.setAuthTypes(authType); } else { template.setAuthType("Any"); template.setAuthTypes("Any"); } if (extensions.containsKey(APIConstants.SWAGGER_X_THROTTLING_TIER)) { String throttlingTier = (String) extensions.get(APIConstants.SWAGGER_X_THROTTLING_TIER); template.setThrottlingTier(throttlingTier); template.setThrottlingTiers(throttlingTier); } if (extensions.containsKey(APIConstants.SWAGGER_X_MEDIATION_SCRIPT)) { String mediationScript = (String) extensions.get(APIConstants.SWAGGER_X_MEDIATION_SCRIPT); template.setMediationScript(mediationScript); template.setMediationScripts(template.getHTTPVerb(), mediationScript); } } urlTemplates.add(template); } } return urlTemplates; }
Example 6
Source File: OAS3Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method returns URI templates according to the given swagger file * * @param resourceConfigsJSON swaggerJSON * @return URI Templates * @throws APIManagementException */ @Override public Set<URITemplate> getURITemplates(String resourceConfigsJSON) throws APIManagementException { OpenAPI openAPI = getOpenAPI(resourceConfigsJSON); Set<URITemplate> urlTemplates = new LinkedHashSet<>(); Set<Scope> scopes = getScopes(resourceConfigsJSON); for (String pathKey : openAPI.getPaths().keySet()) { PathItem pathItem = openAPI.getPaths().get(pathKey); for (Map.Entry<PathItem.HttpMethod, Operation> entry : pathItem.readOperationsMap().entrySet()) { Operation operation = entry.getValue(); URITemplate template = new URITemplate(); if (APIConstants.SUPPORTED_METHODS.contains(entry.getKey().name().toLowerCase())) { template.setHTTPVerb(entry.getKey().name().toUpperCase()); template.setHttpVerbs(entry.getKey().name().toUpperCase()); template.setUriTemplate(pathKey); List<String> opScopes = getScopeOfOperations(OPENAPI_SECURITY_SCHEMA_KEY, operation); if (!opScopes.isEmpty()) { if (opScopes.size() == 1) { String firstScope = opScopes.get(0); Scope scope = APIUtil.findScopeByKey(scopes, firstScope); if (scope == null) { throw new APIManagementException("Scope '" + firstScope + "' not found."); } template.setScope(scope); template.setScopes(scope); } else { template = OASParserUtil.setScopesToTemplate(template, opScopes, scopes); } } Map<String, Object> extensios = operation.getExtensions(); if (extensios != null) { if (extensios.containsKey(APIConstants.SWAGGER_X_AUTH_TYPE)) { String scopeKey = (String) extensios.get(APIConstants.SWAGGER_X_AUTH_TYPE); template.setAuthType(scopeKey); template.setAuthTypes(scopeKey); } else { template.setAuthType("Any"); template.setAuthTypes("Any"); } if (extensios.containsKey(APIConstants.SWAGGER_X_THROTTLING_TIER)) { String throttlingTier = (String) extensios.get(APIConstants.SWAGGER_X_THROTTLING_TIER); template.setThrottlingTier(throttlingTier); template.setThrottlingTiers(throttlingTier); } if (extensios.containsKey(APIConstants.SWAGGER_X_MEDIATION_SCRIPT)) { String mediationScript = (String) extensios.get(APIConstants.SWAGGER_X_MEDIATION_SCRIPT); template.setMediationScript(mediationScript); template.setMediationScripts(template.getHTTPVerb(), mediationScript); } } urlTemplates.add(template); } } } return urlTemplates; }
Example 7
Source File: OASTestBase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
public OASTestBase() { sampleScope = new Scope(); sampleScope.setName("sample"); sampleScope.setKey("sample"); sampleScope.setRoles("admin"); sampleScope.setDescription("sample description"); extensionScope = new Scope(); extensionScope.setName("extensionScope"); extensionScope.setKey("extensionScope"); extensionScope.setRoles("admin"); extensionScope.setDescription("extensionScope description"); petGet = new URITemplate(); petGet.setUriTemplate("/pets"); petGet.setAuthType("Application & Application User"); petGet.setAuthTypes("Application & Application User"); petGet.setHTTPVerb("GET"); petGet.setHttpVerbs("GET"); petGet.setThrottlingTier("Unlimited"); petGet.setThrottlingTiers("Unlimited"); petGet.setScope(sampleScope); petGet.setScopes(sampleScope); petPost = new URITemplate(); petPost.setUriTemplate("/pets"); petPost.setAuthType("Application & Application User"); petPost.setAuthTypes("Application & Application User"); petPost.setHTTPVerb("POST"); petPost.setHttpVerbs("POST"); petPost.setThrottlingTier("Unlimited"); petPost.setThrottlingTiers("Unlimited"); petPost.setScope(sampleScope); petPost.setScopes(sampleScope); itemPost = new URITemplate(); itemPost.setUriTemplate("/items"); itemPost.setAuthType("Application & Application User"); itemPost.setAuthTypes("Application & Application User"); itemPost.setHTTPVerb("POST"); itemPost.setHttpVerbs("POST"); itemPost.setThrottlingTier("Unlimited"); itemPost.setThrottlingTiers("Unlimited"); itemPost.setScope(sampleScope); itemPost.setScopes(sampleScope); itemGet = new URITemplate(); itemGet.setUriTemplate("/items"); itemGet.setAuthType("Application & Application User"); itemGet.setAuthTypes("Application & Application User"); itemGet.setHTTPVerb("GET"); itemGet.setHttpVerbs("GET"); itemGet.setThrottlingTier("Unlimited"); itemGet.setThrottlingTiers("Unlimited"); itemGet.setScope(sampleScope); itemGet.setScopes(sampleScope); }