org.apache.synapse.config.Entry Java Examples

The following examples show how to use org.apache.synapse.config.Entry. 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: LocalEntryResource.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the type of the specified local entry.
 *
 * @param localEntry local entry
 * @return entry type String
 */
private String getEntryType(Entry localEntry) {

    String entryType;
    switch (localEntry.getType()) {
        case Entry.REMOTE_ENTRY:
            entryType = "Registry Key";
            break;
        case Entry.INLINE_TEXT:
            entryType = "Inline Text";
            break;
        case Entry.INLINE_XML:
            entryType = "Inline XML";
            break;
        case Entry.URL_SRC:
            entryType = "Source URL";
            break;
        default:
            entryType = "Unknown - " + localEntry.getType();
            break;
    }
    return entryType;
}
 
Example #2
Source File: APIMgtLatencyStatsHandler.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private void setSwaggerToMessageContext(MessageContext messageContext) {
    // Read OpenAPI from local entry
    if (openAPI == null && apiUUID != null) {
        synchronized (this) {
            if (openAPI == null) {
                long startTime = System.currentTimeMillis();
                Entry localEntryObj = (Entry) messageContext.getConfiguration().getLocalRegistry().get(apiUUID);
                if (localEntryObj != null) {
                    swagger = localEntryObj.getValue().toString();
                    OpenAPIParser parser = new OpenAPIParser();
                    openAPI = parser.readContents(swagger,
                            null, null).getOpenAPI();
                }
                long endTime = System.currentTimeMillis();
                if (log.isDebugEnabled()) {
                    log.debug("Time to parse the swagger(ms) : " + (endTime - startTime));
                }
            }
        }
    }
    // Add OpenAPI to message context
    messageContext.setProperty(APIMgtGatewayConstants.OPEN_API_OBJECT, openAPI);
    // Add swagger String to message context
    messageContext.setProperty(APIMgtGatewayConstants.OPEN_API_STRING, swagger);
}
 
Example #3
Source File: LocalEntryResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the list of all available local entries to the response as json.
 *
 * @param axis2MessageContext axis2 message context
 * @param synapseConfiguration Synapse configuration object
 */
private void populateLocalEntries(org.apache.axis2.context.MessageContext axis2MessageContext,
                                  SynapseConfiguration synapseConfiguration) {

    Map<String, Entry> definedEntries = synapseConfiguration.getDefinedEntries();
    // (-2) to account for the 2 local entries defined by the server
    JSONObject jsonBody = Utils.createJSONList(definedEntries.size() - 2);
    definedEntries.forEach((key, entry) -> addLocalEntryToJsonList(entry, jsonBody.getJSONArray(Constants.LIST)));
    Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
}
 
Example #4
Source File: APIThrottleHandlerTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test(expected = SynapseException.class)
public void testInitThrottlingThrowsSynapseExceptionWhenThrottlingPolicyDefinitionInInvalid() throws XMLStreamException {
    apiThrottleHandler.setPolicyKey(THROTTLE_POLICY_KEY);
    ((Axis2MessageContext) messageContext).getAxis2MessageContext().setConfigurationContext(configurationContext);
    messageContext.getConfiguration().getLocalRegistry().put(THROTTLE_POLICY_KEY, new Entry());
    messageContext.setProperty(RESPONSE, "false");
    apiThrottleHandler.handleRequest(messageContext);
}
 
Example #5
Source File: TestUtils.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public static MessageContext loadAPIThrottlingPolicyEntry(String policyDefinition, String policyKey, boolean
        isDynamic, long version, MessageContext messageContext) throws XMLStreamException {
    OMElement parsedPolicy = null;
    parsedPolicy = AXIOMUtil.stringToOM(policyDefinition);
    Entry entry = new Entry();
    if(isDynamic) {
        entry.setType(3);
    }
    entry.setVersion(version);
    entry.setKey(policyKey);
    entry.setValue(parsedPolicy);
    messageContext.getConfiguration().getLocalRegistry().put(policyKey, entry);
    return messageContext;
}
 
Example #6
Source File: GraphQLAPIHandler.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method validate the payload
 *
 * @param messageContext message context of the request
 * @param document       graphQL schema of the request
 * @return true or false
 */
private boolean validatePayloadWithSchema(MessageContext messageContext, Document document) {
    ArrayList<String> validationErrorMessageList = new ArrayList<>();
    List<ValidationError> validationErrors;
    String validationErrorMessage;

    synchronized (apiUUID + CLASS_NAME_AND_METHOD) {
        if (schema == null) {
            Entry localEntryObj = (Entry) messageContext.getConfiguration().getLocalRegistry().get(apiUUID +
                    GRAPHQL_IDENTIFIER);
            if (localEntryObj != null) {
                SchemaParser schemaParser = new SchemaParser();
                schemaDefinition = localEntryObj.getValue().toString();
                TypeDefinitionRegistry registry = schemaParser.parse(schemaDefinition);
                schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(registry);
            }
        }
    }

    validationErrors = validator.validateDocument(schema, document);
    if (validationErrors != null && validationErrors.size() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Validation failed for " + document);
        }
        for (ValidationError error : validationErrors) {
            validationErrorMessageList.add(error.getDescription());
        }
        validationErrorMessage = String.join(",", validationErrorMessageList);
        handleFailure(messageContext, validationErrorMessage);
        return false;
    }
    return true;
}
 
Example #7
Source File: LocalEntryStore.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
protected OMElement saveToFile(Entry entry, SynapseConfiguration synapseConfiguration) {
    try {
        return serializer.serializeLocalEntry(entry, synapseConfiguration, null);
    } catch (Exception e) {
        handleException("Error while saving the local entry: " + entry.getKey() + " to the " +
                "file system", e);
    }
    return null;
}
 
Example #8
Source File: SynapseAppDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Deploy the local entries from lib
 *
 * @param axisConfig AxisConfiguration of the current tenant
 * */
private void deployingLocalEntries(Library library, SynapseConfiguration config, AxisConfiguration axisConfig) {
    if (log.isDebugEnabled()) {
        log.debug("Start : Adding Local registry entries to the configuration");
    }
    for (Map.Entry<String, Object> libararyEntryMap : library.getLocalEntryArtifacts()
            .entrySet()) {
        File localEntryFileObj = (File) libararyEntryMap.getValue();
        OMElement document = LocalEntryUtil.getOMElement(localEntryFileObj);
        addEntry(document.toString(), axisConfig);
    }
    if (log.isDebugEnabled()) {
        log.debug("End : Adding Local registry entries to the configuration");
    }
}
 
Example #9
Source File: SynapseAppDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 *
 * Undeploy the local entries deployed from the lib
 *
 * @param axisConfig AxisConfiguration of the current tenant
 * */
private void undeployingLocalEntries(Library library, SynapseConfiguration config, AxisConfiguration axisConfig) {
    if (log.isDebugEnabled()) {
        log.debug("Start : Removing Local registry entries from the configuration");
    }
    for (Map.Entry<String, Object> libararyEntryMap : library.getLocalEntryArtifacts()
            .entrySet()) {
        File localEntryFileObj = (File) libararyEntryMap.getValue();
        OMElement document = LocalEntryUtil.getOMElement(localEntryFileObj);
        deleteEntry(document.toString(), axisConfig);
    }
    if (log.isDebugEnabled()) {
        log.debug("End : Removing Local registry entries from the configuration");
    }
}
 
Example #10
Source File: LocalEntryResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the json representation of the local entry.
 *
 * @param localEntry local entry
 * @return JSONObject json representation of local entry
 */
private JSONObject getLocalEntryAsJson(Entry localEntry) {

    JSONObject jsonObject = new JSONObject();
    jsonObject.put(Constants.NAME, localEntry.getKey());
    jsonObject.put(TYPE_ATTRIBUTE, getEntryType(localEntry));
    jsonObject.put(VALUE_ATTRIBUTE, localEntry.getValue());
    jsonObject.put(DESCRIPTION_ATTRIBUTE, localEntry.getDescription());
    return jsonObject;
}
 
Example #11
Source File: LocalEntryResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the information of the specified local entry to the response as json.
 *
 * @param axis2MessageContext AXIS2 message context
 * @param synapseConfiguration Synapse configuration object
 * @param entryKey local entry name
 */
private void populateLocalEntryData(org.apache.axis2.context.MessageContext axis2MessageContext,
                                    SynapseConfiguration synapseConfiguration, String entryKey) {

    Map<String, Entry> definedEntries = synapseConfiguration.getDefinedEntries();
    Entry localEntry = definedEntries.get(entryKey);
    if (localEntry != null) {
        Utils.setJsonPayLoad(axis2MessageContext, getLocalEntryAsJson(localEntry));
    } else {
        LOG.warn("Reference for local entry " + entryKey + " could not be resolved.");
        Utils.setJsonPayLoad(axis2MessageContext, Utils.createJsonErrorObject("Reference for " + entryKey + "could not be resolved"));
    }
}
 
Example #12
Source File: LocalEntryResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the provided Entry to the json array provided.
 *
 * @param list  json array
 * @param entry Entry
 */
private void addLocalEntryToJsonList(Entry entry, JSONArray list) {

    // Escape local entries defined by the server
    String key = entry.getKey();
    if (SynapseConstants.SERVER_IP.equals(key) || SynapseConstants.SERVER_HOST.equals(key)) {
        return;
    }
    String entryType = getEntryType(entry);
    JSONObject entryObject = new JSONObject();
    entryObject.put(Constants.NAME, key);
    entryObject.put(TYPE_ATTRIBUTE, entryType);
    list.put(entryObject);

}
 
Example #13
Source File: RegistrySecretRepository.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * @param alias
 *            Alias name for look up a secret
 * @return Secret if there is any , otherwise ,alias itself
 * @see org.wso2.securevault.secret.SecretRepository
 */
public String getSecret(String alias) {

	Entry propEntry =
	                  synCtx.getConfiguration()
	                        .getEntryDefinition(SecureVaultConstants.CONF_CONNECTOR_SECURE_VAULT_CONFIG_PROP_LOOK);

	Registry registry = synCtx.getConfiguration().getRegistry();

	String propertyValue = "";

	if (registry != null) {
		registry.getResource(propEntry, new Properties());
		if (alias != null) {
			Properties reqProperties = propEntry.getEntryProperties();
			if (reqProperties != null && reqProperties.get(alias) != null) {
					propertyValue = reqProperties.getProperty(alias);
			}
		}
	}
	DecryptionProvider decyptProvider = CipherInitializer.getInstance().getDecryptionProvider();

	if (decyptProvider == null) {
		log.error("Can not proceed decyption due to the secret repository intialization error");
		return null;
	}

	String decryptedText = new String(decyptProvider.decrypt(propertyValue.trim().getBytes()));

	if (log.isDebugEnabled()) {
		log.info("evaluation completed succesfully " + decryptedText);
	}
	return decryptedText;

}
 
Example #14
Source File: SynapseAppDeployer.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Register synapse deployers to the deployment engine.
 *
 * @param axisConfig   - axisConfiguration to which this deployer belongs
 * @param artifactType - type of the artifact
 * @param deployer     - related deployer
 */
private void registerSynapseDeployer(AxisConfiguration axisConfig, String artifactType, Deployer deployer) {

    DeploymentEngine deploymentEngine = (DeploymentEngine) axisConfig.getConfigurator();
    String artifactDirName = getArtifactDirName(artifactType);

    if (artifactDirName != null) {
        SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration(axisConfig).getArtifactDeploymentStore();
        SynapseConfiguration synCfg = getSynapseConfiguration(axisConfig);
        String artifactDir = getArtifactDirPath(axisConfig, artifactDirName);

        switch (artifactType) {
            case SynapseAppDeployerConstants.SEQUENCE_TYPE:
                for (SequenceMediator seq : synCfg.getDefinedSequences().values()) {
                    if (seq.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + seq.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.ENDPOINT_TYPE:
                for (Endpoint ep : synCfg.getDefinedEndpoints().values()) {
                    if (ep.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + ep.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.PROXY_SERVICE_TYPE:
                for (ProxyService proxyService : synCfg.getProxyServices()) {
                    if (proxyService.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + proxyService.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.LOCAL_ENTRY_TYPE:
                for (Entry entry : synCfg.getDefinedEntries().values()) {
                    if (entry.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + entry.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.TASK_TYPE:
                for (Startup stp : synCfg.getStartups()) {
                    if (stp.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + stp.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.MESSAGE_STORE_TYPE:
                for (MessageStore messageStore : synCfg.getMessageStores().values()) {
                    if (messageStore.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + messageStore.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.MESSAGE_PROCESSOR_TYPE:
                for (MessageProcessor processor : synCfg.getMessageProcessors().values()) {
                    if (processor.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + processor.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.API_TYPE:
                for (API api : synCfg.getAPIs()) {
                    if (api.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + api.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.TEMPLATE_TYPE:
                for (TemplateMediator seqTempl : synCfg.getSequenceTemplates().values()) {
                    if (seqTempl.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + seqTempl.getFileName());
                    }
                }
                for (Template epTempl : synCfg.getEndpointTemplates().values()) {
                    if (epTempl.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + epTempl.getFileName());
                    }
                }
                break;
            case SynapseAppDeployerConstants.INBOUND_ENDPOINT_TYPE:
                for (InboundEndpoint inboundEndpoint : synCfg.getInboundEndpoints()) {
                    if (inboundEndpoint.getFileName() != null) {
                        deploymentStore.addRestoredArtifact(artifactDir + File.separator + inboundEndpoint.getFileName());
                    }
                }
                break;
            default:
                // do nothing

        }
        deploymentEngine.addDeployer(deployer, artifactDir, ServiceBusConstants.ARTIFACT_EXTENSION);
    }
}
 
Example #15
Source File: LocalEntryStore.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
protected String getFileName(Entry entry) {
    return entry.getFileName();
}
 
Example #16
Source File: LocalEntryStore.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
protected Entry getObjectToPersist(String name, SynapseConfiguration config) {
    return config.getDefinedEntries().get(name);
}
 
Example #17
Source File: LocalEntryStore.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
protected OMElement serialize(Entry entry) {
    return EntrySerializer.serializeEntry(entry, null);
}