Search in sources :

Example 6 with EndpointConfigContext

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EndpointConfigContext in project carbon-apimgt by wso2.

the class TemplateBuilderUtil method addWebSocketResourceEndpoints.

public static void addWebSocketResourceEndpoints(API api, APITemplateBuilder builder, GatewayAPIDTO gatewayAPIDTO) throws APITemplateException, XMLStreamException {
    Set<URITemplate> uriTemplates = api.getUriTemplates();
    Map<String, Map<String, String>> topicMappings = api.getWebSocketTopicMappingConfiguration().getMappings();
    List<GatewayContentDTO> endpointsToAdd = new ArrayList<>();
    for (URITemplate resource : uriTemplates) {
        String topic = resource.getUriTemplate();
        Map<String, String> endpoints = topicMappings.get(topic);
        // Production and Sandbox endpoints
        for (Map.Entry<String, String> endpointData : endpoints.entrySet()) {
            if (!"resourceKey".equals(endpointData.getKey())) {
                String endpointType = endpointData.getKey();
                String endpointUrl = endpointData.getValue();
                String endpointConfigContext = builder.getConfigStringForWebSocketEndpointTemplate(endpointType, getWebsocketResourceKey(topic), endpointUrl);
                GatewayContentDTO endpoint = new GatewayContentDTO();
                // For WS APIs, resource type is not applicable,
                // so we can just use the uriTemplate/uriMapping to identify the resource
                endpoint.setName(getEndpointName(endpointConfigContext));
                endpoint.setContent(endpointConfigContext);
                endpointsToAdd.add(endpoint);
            }
        }
        // once through resources is enough.
        if (APIConstants.GRAPHQL_API.equals(api.getType())) {
            break;
        }
    }
    gatewayAPIDTO.setEndpointEntriesToBeAdd(addGatewayContentsToList(endpointsToAdd, gatewayAPIDTO.getEndpointEntriesToBeAdd()));
}
Also used : URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)

Aggregations

StringWriter (java.io.StringWriter)3 Template (org.apache.velocity.Template)3 VelocityContext (org.apache.velocity.VelocityContext)3 VelocityEngine (org.apache.velocity.app.VelocityEngine)3 APITemplateException (org.wso2.carbon.apimgt.impl.template.APITemplateException)3 RegistryException (org.wso2.carbon.registry.api.RegistryException)3 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 GatewayContentDTO (org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)1 APIConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext)1 ConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext)1 EndpointConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EndpointConfigContext)1