Java Code Examples for org.apache.synapse.MessageContext#getConfiguration()

The following examples show how to use org.apache.synapse.MessageContext#getConfiguration() . 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: TaskResource.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void populateTasksList(MessageContext messageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext =
                ((Axis2MessageContext) messageContext).getAxis2MessageContext();

        SynapseConfiguration configuration = messageContext.getConfiguration();

        Collection<Startup> tasks = configuration.getStartups();
        JSONObject jsonBody = Utils.createJSONList(tasks.size());
        for (Startup task : tasks) {
            JSONObject taskObject = new JSONObject();
            taskObject.put(Constants.NAME, task.getName());
            jsonBody.getJSONArray(Constants.LIST).put(taskObject);
        }
        Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
    }
 
Example 2
Source File: DataServiceResource.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void populateDataServiceList(MessageContext msgCtx) throws Exception {
    SynapseConfiguration configuration = msgCtx.getConfiguration();
    AxisConfiguration axisConfiguration = configuration.getAxisConfiguration();
    String[] dataServicesNames = DBUtils.getAvailableDS(axisConfiguration);

    // initiate list model
    DataServicesList dataServicesList = new DataServicesList(dataServicesNames.length);

    for (String dataServiceName : dataServicesNames) {
        DataService dataService = getDataServiceByName(msgCtx, dataServiceName);
        ServiceMetaData serviceMetaData = getServiceMetaData(dataService);
        // initiate summary model
        DataServiceSummary summary = null;
        if (serviceMetaData != null) {
            summary = new DataServiceSummary(serviceMetaData.getName(), serviceMetaData.getWsdlURLs());
        }
        dataServicesList.addServiceSummary(summary);
    }

    org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) msgCtx)
            .getAxis2MessageContext();

    String stringPayload = new Gson().toJson(dataServicesList);
    Utils.setJsonPayLoad(axis2MessageContext, new JSONObject(stringPayload));
}
 
Example 3
Source File: TemplateResource.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Override
public boolean invoke(MessageContext messageContext) {
    org.apache.axis2.context.MessageContext axis2MessageContext =
            ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    if (Objects.isNull(axis2MessageContext) || Objects.isNull(synapseConfiguration)) {
        return false;
    }

    String templateTypeParam = Utils.getQueryParameter(messageContext, TEMPLATE_TYPE_PARAM);
    if (Objects.nonNull(templateTypeParam)) {
        String templateNameParam = Utils.getQueryParameter(messageContext, TEMPLATE_NAME_PARAM);
        if (Objects.nonNull(templateNameParam)) {
            populateTemplateData(messageContext, templateNameParam, templateTypeParam);
        } else {
            populateTemplateListByType(messageContext, templateTypeParam);
        }
    } else {
        populateFullTemplateList(axis2MessageContext, synapseConfiguration);
    }
    axis2MessageContext.removeProperty(Constants.NO_ENTITY_BODY);
    return true;
}
 
Example 4
Source File: TaskResource.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void populateTaskData(MessageContext messageContext, String taskName) {

        org.apache.axis2.context.MessageContext axis2MessageContext =
                ((Axis2MessageContext) messageContext).getAxis2MessageContext();

        SynapseConfiguration configuration = messageContext.getConfiguration();
        Startup task = configuration.getStartup(taskName);
        SynapseEnvironment synapseEnvironment =
                getSynapseEnvironment(axis2MessageContext.getConfigurationContext().getAxisConfiguration());
        TaskDescription description =
                synapseEnvironment.getTaskManager().getTaskDescriptionRepository().getTaskDescription(task.getName());
        JSONObject jsonBody = getTaskAsJson(description);


        if (Objects.nonNull(jsonBody)) {
            Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
        } else {
            axis2MessageContext.setProperty(Constants.HTTP_STATUS_CODE, Constants.NOT_FOUND);
        }
    }
 
Example 5
Source File: SecureVaultLookupHandlerImpl.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Override
public String evaluate(String aliasPasword, SecretSrcData secretSrcData, MessageContext synCtx) {
	SynapseConfiguration synapseConfiguration = synCtx.getConfiguration();
	Map<String, Object> decryptedCacheMap = synapseConfiguration.getDecryptedCacheMap();
	if (decryptedCacheMap.containsKey(aliasPasword)) {
		SecureVaultCacheContext cacheContext =
		                                       (SecureVaultCacheContext) decryptedCacheMap.get(aliasPasword);
		if (cacheContext != null) {
			String cacheDurable = synCtx.getConfiguration().getRegistry().getConfigurationProperties().getProperty
					("cachableDuration");
			long cacheTime = (cacheDurable != null && !cacheDurable.isEmpty()) ? Long.parseLong(cacheDurable) :
					10000;
			if ((cacheContext.getDateTime().getTime() + cacheTime) >= System.currentTimeMillis()) {
				// which means the given value between the cachable limit
				return cacheContext.getDecryptedValue();
			} else {
				decryptedCacheMap.remove(aliasPasword);
				return vaultLookup(aliasPasword, secretSrcData, decryptedCacheMap);
			}
		} else {
			return vaultLookup(aliasPasword, secretSrcData, decryptedCacheMap);
		}
	} else {
		return vaultLookup(aliasPasword, secretSrcData, decryptedCacheMap);
	}
}
 
Example 6
Source File: EndpointResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private JSONObject getEndpointByName(MessageContext messageContext, String endpointName) {

        SynapseConfiguration configuration = messageContext.getConfiguration();
        Endpoint ep = configuration.getEndpoint(endpointName);
        if (Objects.nonNull(ep)) {
            return getEndpointAsJson(ep);
        } else {
            return null;
        }
    }
 
Example 7
Source File: ApiResourceAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Override
public boolean invoke(MessageContext messageContext) {
    buildMessage(messageContext);
    org.apache.axis2.context.MessageContext axis2MessageContext
            = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    if (Objects.isNull(axis2MessageContext) || Objects.isNull(synapseConfiguration)) {
        return false;
    }
    return apiResource.invoke(messageContext, axis2MessageContext, synapseConfiguration);
}
 
Example 8
Source File: MessageProcessorResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the processor state to the specified state.
 *
 * @param messageContext Axis2message context
 * @param jsonObject     message payload
 */
private void changeProcessorStatus(MessageContext messageContext, JsonObject jsonObject) {
    org.apache.axis2.context.MessageContext axis2MessageContext =
            ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    String processorName = jsonObject.get(NAME).getAsString();
    String status = jsonObject.get(STATUS).getAsString();

    MessageProcessor messageProcessor = synapseConfiguration.getMessageProcessors().get(processorName);
    if (Objects.nonNull(messageProcessor)) {
        JSONObject jsonResponse = new JSONObject();
        if (INACTIVE_STATUS.equalsIgnoreCase(status)) {
            messageProcessor.deactivate();
            jsonResponse.put(Constants.MESSAGE_JSON_ATTRIBUTE, processorName + " : is deactivated");
        } else if (ACTIVE_STATUS.equalsIgnoreCase(status)) {
            messageProcessor.activate();
            jsonResponse.put(Constants.MESSAGE_JSON_ATTRIBUTE, processorName + " : is activated");
        } else {
            jsonResponse = Utils.createJsonError("Provided state is not valid", axis2MessageContext, Constants.BAD_REQUEST);
        }
        Utils.setJsonPayLoad(axis2MessageContext, jsonResponse);
    } else {
        Utils.setJsonPayLoad(axis2MessageContext, Utils.createJsonError("Message processor does not exist",
                axis2MessageContext, Constants.NOT_FOUND));
    }

}
 
Example 9
Source File: MessageProcessorResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create JSON response with information related a defined message processor.
 *
 * @param messageContext synapse message context
 * @param name           name of the message processor
 */
private void populateMessageProcessorData(MessageContext messageContext, String name) {
    org.apache.axis2.context.MessageContext axis2MessageContext =
            ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    MessageProcessor messageProcessor = synapseConfiguration.getMessageProcessors().get(name);
    if (Objects.nonNull(messageProcessor)) {
        Utils.setJsonPayLoad(axis2MessageContext, getMessageProcessorAsJson(messageProcessor));
    } else {
        Utils.setJsonPayLoad(axis2MessageContext, Utils.createJsonErrorObject("Message processor does not exist"));
    }
}
 
Example 10
Source File: MessageProcessorResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create a JSON response with all available message processors.
 *
 * @param messageContext synapse message context
 */
private void populateMessageProcessorList(MessageContext messageContext) {
    org.apache.axis2.context.MessageContext axis2MessageContext =
            ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    Map<String, MessageProcessor> processorMap = synapseConfiguration.getMessageProcessors();
    JSONObject jsonBody = Utils.createJSONList(processorMap.size());
    processorMap.forEach((key, value) -> addToJSONList(value, jsonBody.getJSONArray(Constants.LIST)));
    Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
}
 
Example 11
Source File: ProxyServiceResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Change the state of the proxy based on the payload.
 *
 * @param messageContext      Synapse message context
 * @param axis2MessageContext AXIS2 message context
 * @param payload             json payload
 */
private void changeProxyState(MessageContext messageContext,
                              org.apache.axis2.context.MessageContext axis2MessageContext, JsonObject payload) {

    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    String name = payload.get(NAME).getAsString();
    String status = payload.get(STATUS).getAsString();
    ProxyService proxyService = synapseConfiguration.getProxyService(name);
    if (proxyService == null) {
        Utils.setJsonPayLoad(axis2MessageContext, Utils.createJsonError("Proxy service could not be found",
                axis2MessageContext, Constants.NOT_FOUND));
        return;
    }
    List pinnedServers = proxyService.getPinnedServers();
    JSONObject jsonResponse = new JSONObject();
    if (ACTIVE_STATUS.equalsIgnoreCase(status)) {
        if (pinnedServers.isEmpty() ||
                pinnedServers.contains(getServerConfigInformation(synapseConfiguration).getServerName())) {
            proxyService.start(synapseConfiguration);
            jsonResponse.put("Message", "Proxy service " + name + " started successfully");
            Utils.setJsonPayLoad(axis2MessageContext, jsonResponse);
        }
    } else if (INACTIVE_STATUS.equalsIgnoreCase(status)) {
        if (pinnedServers.isEmpty() ||
                pinnedServers.contains(getServerConfigInformation(synapseConfiguration).getSynapseXMLLocation())) {
            proxyService.stop(synapseConfiguration);
            jsonResponse.put("Message", "Proxy service " + name + " stopped successfully");
            Utils.setJsonPayLoad(axis2MessageContext, jsonResponse);
        }
    } else {
        Utils.setJsonPayLoad(axis2MessageContext,
                Utils.createJsonError("Provided state is not valid", axis2MessageContext, Constants.BAD_REQUEST));
    }
}
 
Example 12
Source File: TemplateResource.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Set the information related to a specific template to the Axis2MessageContext as a JSON object
 *
 * @param templateName   name of the template
 * @param templateType   type of the template
 */
private void populateTemplateData(MessageContext messageContext, String templateName, String templateType) {
    org.apache.axis2.context.MessageContext axis2MessageContext =
            ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    SynapseConfiguration synapseConfiguration = messageContext.getConfiguration();
    if (ENDPOINT_TEMPLATE_TYPE.equalsIgnoreCase(templateType)) {
        Template endpointTemplate = synapseConfiguration.getEndpointTemplate(templateName);
        Utils.setJsonPayLoad(axis2MessageContext, getEndpointTemplateAsJson(endpointTemplate));
    } else if (SEQUENCE_TEMPLATE_TYPE.equalsIgnoreCase(templateType)) {
        TemplateMediator sequenceTemplate = synapseConfiguration.getSequenceTemplate(templateName);
        Utils.setJsonPayLoad(axis2MessageContext, getSequenceTemplateAsJson(sequenceTemplate));
    }
}
 
Example 13
Source File: ProxyServiceResource.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private JSONObject getProxyServiceByName(MessageContext messageContext, String proxyServiceName) {

        SynapseConfiguration configuration = messageContext.getConfiguration();
        ProxyService proxyService = configuration.getProxyService(proxyServiceName);
        return convertProxyServiceToJsonObject(proxyService);
    }
 
Example 14
Source File: InboundEndpointResource.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private JSONObject getInboundEndpointByName(MessageContext messageContext, String inboundEndpointName) {

        SynapseConfiguration configuration = messageContext.getConfiguration();
        InboundEndpoint ep = configuration.getInboundEndpoint(inboundEndpointName);
        return convertInboundEndpointToJsonObject(ep);
    }
 
Example 15
Source File: InboundEndpointResource.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private void populateInboundEndpointList(MessageContext messageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext =
                ((Axis2MessageContext) messageContext).getAxis2MessageContext();

        SynapseConfiguration configuration = messageContext.getConfiguration();

        Collection<InboundEndpoint> inboundEndpoints = configuration.getInboundEndpoints();

        JSONObject jsonBody = Utils.createJSONList(inboundEndpoints.size());

        for (InboundEndpoint inboundEndpoint : inboundEndpoints) {

            JSONObject inboundObject = new JSONObject();

            inboundObject.put(Constants.NAME, inboundEndpoint.getName());
            inboundObject.put("protocol", inboundEndpoint.getProtocol());

            jsonBody.getJSONArray(Constants.LIST).put(inboundObject);
        }
        Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
    }
 
Example 16
Source File: ApiResource.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private JSONObject getApiByName(MessageContext messageContext, String apiName) {

        SynapseConfiguration configuration = messageContext.getConfiguration();
        API api = configuration.getAPI(apiName);
        return convertApiToJsonObject(api, messageContext);
    }
 
Example 17
Source File: SequenceResource.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private JSONObject getSequenceByName(MessageContext messageContext, String sequenceName) {

        SynapseConfiguration configuration = messageContext.getConfiguration();
        SequenceMediator sequence = configuration.getDefinedSequences().get(sequenceName);
        return convertSequenceToJsonObject(sequence);
    }
 
Example 18
Source File: ProxyServiceResource.java    From micro-integrator with Apache License 2.0 3 votes vote down vote up
private void populateProxyServiceList(MessageContext messageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext =
                ((Axis2MessageContext) messageContext).getAxis2MessageContext();

        SynapseConfiguration configuration = messageContext.getConfiguration();

        Collection<ProxyService> proxyServices = configuration.getProxyServices();

        JSONObject jsonBody = Utils.createJSONList(proxyServices.size());

        for (ProxyService proxyService : proxyServices) {

            JSONObject proxyObject = new JSONObject();

            try {

                ServiceMetaData data = serviceAdmin.getServiceData(proxyService.getName());

                proxyObject.put(Constants.NAME, proxyService.getName());

                String[] wsdlUrls = data.getWsdlURLs();
                proxyObject.put("wsdl1_1", wsdlUrls[0]);
                proxyObject.put("wsdl2_0", wsdlUrls[1]);

            } catch (Exception e) {
                LOG.error("Error occurred while processing service data", e);
            }

            jsonBody.getJSONArray(Constants.LIST).put(proxyObject);
        }
        Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
    }
 
Example 19
Source File: ApiResource.java    From micro-integrator with Apache License 2.0 3 votes vote down vote up
private void populateApiList(MessageContext messageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext =
                ((Axis2MessageContext) messageContext).getAxis2MessageContext();

        SynapseConfiguration configuration = messageContext.getConfiguration();

        Collection<API> apis = configuration.getAPIs();

        JSONObject jsonBody = Utils.createJSONList(apis.size());

        String serverUrl = getServerContext(axis2MessageContext.getConfigurationContext().getAxisConfiguration());

        for (API api: apis) {

            JSONObject apiObject = new JSONObject();

            String apiUrl = serverUrl.equals("err") ? api.getContext() : serverUrl + api.getContext();

            apiObject.put(Constants.NAME, api.getName());
            apiObject.put(Constants.URL, apiUrl);

            jsonBody.getJSONArray(Constants.LIST).put(apiObject);

        }
        Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
    }
 
Example 20
Source File: SequenceResource.java    From micro-integrator with Apache License 2.0 3 votes vote down vote up
private void populateSequenceList(MessageContext messageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext =
                ((Axis2MessageContext) messageContext).getAxis2MessageContext();

        SynapseConfiguration configuration = messageContext.getConfiguration();

        Map<String, SequenceMediator> sequenceMediatorMap = configuration.getDefinedSequences();

        JSONObject jsonBody = Utils.createJSONList(sequenceMediatorMap.size());

        for (SequenceMediator sequence: sequenceMediatorMap.values()) {

            JSONObject sequenceObject = new JSONObject();

            sequenceObject.put(Constants.NAME, sequence.getName());
            sequenceObject.put(Constants.CONTAINER, sequence.getArtifactContainerName());

            String statisticState = sequence.getAspectConfiguration().isStatisticsEnable() ? Constants.ENABLED : Constants.DISABLED;
            sequenceObject.put(Constants.STATS, statisticState);

            String tracingState = sequence.getAspectConfiguration().isTracingEnabled() ? Constants.ENABLED : Constants.DISABLED;
            sequenceObject.put(Constants.TRACING, tracingState);

            jsonBody.getJSONArray(Constants.LIST).put(sequenceObject);
        }
        Utils.setJsonPayLoad(axis2MessageContext, jsonBody);
    }