Java Code Examples for org.wso2.carbon.apimgt.api.model.API#getTransports()

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#getTransports() . 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: 103335311.java    From docs-apim with Apache License 2.0 4 votes vote down vote up
private List<NameValuePair> getParamsList(API api,String externalPublisher, String action) throws APIManagementException, UserStoreException{
    // Request parameters and other properties.
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(APIConstants.API_ACTION,action));
    params.add(new BasicNameValuePair("name", api.getId().getApiName()));
    params.add(new BasicNameValuePair("version", api.getId().getVersion()));
    params.add(new BasicNameValuePair("provider", externalPublisher));
    params.add(new BasicNameValuePair("description", api.getDescription()));
    params.add(new BasicNameValuePair("endpoint", api.getUrl()));
    params.add(new BasicNameValuePair("sandbox", api.getSandboxUrl()));
    params.add(new BasicNameValuePair("wsdl", api.getWadlUrl()));
    params.add(new BasicNameValuePair("wadl", api.getWsdlUrl()));
    params.add(new BasicNameValuePair("endpoint_config", api.getEndpointConfig()));

    StringBuilder tagsSet = new StringBuilder("");

    Iterator it = api.getTags().iterator();
    int j = 0;
    while (it.hasNext()) {
        Object tagObject = it.next();
        tagsSet.append((String) tagObject);
        if (j != api.getTags().size() - 1) {
            tagsSet.append(",");
        }
        j++;
    }
    params.add(new BasicNameValuePair("tags", checkValue(tagsSet.toString())));

    StringBuilder tiersSet = new StringBuilder("");
    Iterator tier = api.getAvailableTiers().iterator();
    int k = 0;
    while (tier.hasNext()) {
        Object tierObject = tier.next();
        Tier availTier=(Tier) tierObject;
        tiersSet.append(availTier.getName());
        if (k != api.getAvailableTiers().size() - 1) {
            tiersSet.append(",");
        }
        k++;
    }
    params.add(new BasicNameValuePair("tiersCollection", checkValue(tiersSet.toString())));
    params.add(new BasicNameValuePair("context", api.getContext()));
    params.add(new BasicNameValuePair("bizOwner", api.getBusinessOwner()));
    params.add(new BasicNameValuePair("bizOwnerMail", api.getBusinessOwnerEmail()));
    params.add(new BasicNameValuePair("techOwner", api.getTechnicalOwner()));
    params.add(new BasicNameValuePair("techOwnerMail", api.getTechnicalOwnerEmail()));
    params.add(new BasicNameValuePair("visibility", api.getVisibility()));
    params.add(new BasicNameValuePair("roles", api.getVisibleRoles()));
    params.add(new BasicNameValuePair("endpointType", String.valueOf(api.isEndpointSecured())));
    params.add(new BasicNameValuePair("epUsername", api.getEndpointUTUsername()));
    params.add(new BasicNameValuePair("epPassword", api.getEndpointUTPassword()));
    
    //Setting current API provider as the owner of the externally publishing API
    params.add(new BasicNameValuePair("apiOwner", api.getId().getProviderName()));
    params.add(new BasicNameValuePair("advertiseOnly", "true"));
    
    
    String tenantDomain = MultitenantUtils.getTenantDomain(
    		APIUtil.replaceEmailDomainBack(api.getId().getProviderName()));
    
    int tenantId = ServiceReferenceHolder.getInstance().getRealmService().
            getTenantManager().getTenantId(tenantDomain);

    params.add(new BasicNameValuePair("redirectURL", getExternalStoreRedirectURL(tenantId)));
    
    if(api.getTransports()==null){
        params.add(new BasicNameValuePair("http_checked",null));
        params.add(new BasicNameValuePair("https_checked",null));
    }else{
        String[] transports=api.getTransports().split(",");
        if(transports.length==1){
            if("https".equals(transports[0])){
                params.add(new BasicNameValuePair("http_checked",null));
                params.add(new BasicNameValuePair("https_checked",transports[0]));
            }else{
                params.add(new BasicNameValuePair("https_checked",null));
                params.add(new BasicNameValuePair("http_checked",transports[0]));
            }
        }else{
            params.add(new BasicNameValuePair("http_checked", "http"));
            params.add(new BasicNameValuePair("https_checked", "https"));
        }
    }
    params.add(new BasicNameValuePair("resourceCount", String.valueOf(api.getUriTemplates().size())));
    Iterator urlTemplate = api.getUriTemplates().iterator();
    int i=0;
    while (urlTemplate.hasNext()) {
        Object templateObject = urlTemplate.next();
        URITemplate template=(URITemplate)templateObject;
        params.add(new BasicNameValuePair("uriTemplate-" + i, template.getUriTemplate()));
        params.add(new BasicNameValuePair("resourceMethod-" + i, template.getMethodsAsString().replaceAll("\\s",",")));
        params.add(new BasicNameValuePair("resourceMethodAuthType-" + i, template.getAuthTypeAsString().replaceAll("\\s",",")));
        params.add(new BasicNameValuePair("resourceMethodThrottlingTier-" + i, template.getThrottlingTiersAsString().replaceAll("\\s",",")));
        i++;
    }
    return params;
}
 
Example 2
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Update OAS definition for API Publisher
 *
 * @param api           API
 * @param oasDefinition
 * @return OAS definition
 * @throws APIManagementException throws if an error occurred
 */
@Override
public String getOASDefinitionForPublisher(API api, String oasDefinition) throws APIManagementException {
    Swagger swagger = getSwagger(oasDefinition);
    if (api.getAuthorizationHeader() != null) {
        swagger.setVendorExtension(APIConstants.X_WSO2_AUTH_HEADER, api.getAuthorizationHeader());
    }
    if (api.getApiLevelPolicy() != null) {
        swagger.setVendorExtension(APIConstants.X_THROTTLING_TIER, api.getApiLevelPolicy());
    }
    swagger.setVendorExtension(APIConstants.X_WSO2_CORS, api.getCorsConfiguration());
    Object prodEndpointObj = OASParserUtil.generateOASConfigForEndpoints(api, true);
    if (prodEndpointObj != null) {
        swagger.setVendorExtension(APIConstants.X_WSO2_PRODUCTION_ENDPOINTS, prodEndpointObj);
    }
    Object sandEndpointObj = OASParserUtil.generateOASConfigForEndpoints(api, false);
    if (sandEndpointObj != null) {
        swagger.setVendorExtension(APIConstants.X_WSO2_SANDBOX_ENDPOINTS, sandEndpointObj);
    }
    swagger.setVendorExtension(APIConstants.X_WSO2_BASEPATH, api.getContext());
    if (api.getTransports() != null) {
        swagger.setVendorExtension(APIConstants.X_WSO2_TRANSPORTS, api.getTransports().split(","));
    }
    String apiSecurity = api.getApiSecurity();
    // set mutual ssl extension if enabled
    if (apiSecurity != null) {
        List<String> securityList = Arrays.asList(apiSecurity.split(","));
        if (securityList.contains(APIConstants.API_SECURITY_MUTUAL_SSL)) {
            String mutualSSLOptional = !securityList.contains(APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY) ?
                    APIConstants.OPTIONAL : APIConstants.MANDATORY;
            swagger.setVendorExtension(APIConstants.X_WSO2_MUTUAL_SSL, mutualSSLOptional);
        }
    }
    // This app security is should given in resource level,
    // otherwise the default oauth2 scheme defined at each resouce level will override application securities
    JsonNode appSecurityExtension = OASParserUtil.getAppSecurity(apiSecurity);
    for (String pathKey : swagger.getPaths().keySet()) {
        Path path = swagger.getPath(pathKey);
        Map<HttpMethod, Operation> operationMap = path.getOperationMap();
        for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) {
            Operation operation = entry.getValue();
            operation.setVendorExtension(APIConstants.X_WSO2_APP_SECURITY, appSecurityExtension);
        }
    }
    swagger.setVendorExtension(APIConstants.X_WSO2_APP_SECURITY, appSecurityExtension);
    swagger.setVendorExtension(APIConstants.X_WSO2_RESPONSE_CACHE,
            OASParserUtil.getResponseCacheConfig(api.getResponseCache(), api.getCacheTimeout()));

    return getSwaggerJsonString(swagger);
}
 
Example 3
Source File: OAS3Parser.java    From carbon-apimgt with Apache License 2.0 3 votes vote down vote up
/**
 * Update OAS definition with GW endpoints
 *
 * @param api               API
 * @param hostsWithSchemes  GW hosts with protocol mapping
 * @param openAPI           OpenAPI
 */
private void updateEndpoints(API api, Map<String, String> hostsWithSchemes, OpenAPI openAPI) {

    String basePath = api.getContext();
    String transports = api.getTransports();
    updateEndpoints(openAPI, basePath, transports, hostsWithSchemes);
}
 
Example 4
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 2 votes vote down vote up
/**
 * Update OAS definition with GW endpoints
 *
 * @param api            API
 * @param hostsWithSchemes  GW hosts with protocol mapping
 * @param swagger        Swagger
 */
private void updateEndpoints(API api, Map<String,String> hostsWithSchemes, Swagger swagger) {
    String basePath = api.getContext();
    String transports = api.getTransports();
    updateEndpoints(swagger, basePath, transports, hostsWithSchemes);
}