Package org.wso2.carbon.dataservices.taskscheduler

Source Code of org.wso2.carbon.dataservices.taskscheduler.SchedulingTask

/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing,
*  software distributed under the License is distributed on an
*  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
*  KIND, either express or implied.  See the License for the
*  specific language governing permissions and limitations
*  under the License.
*
*/
package org.wso2.carbon.dataservices.taskscheduler;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.task.Task;
import org.wso2.carbon.dataservices.taskscheduler.constants.TaskSchedulerConstants;
import org.wso2.carbon.utils.ConfigurationContextService;

import java.util.Map;

/**
* @scr.reference name="carbon.core.configurationContextService"
* interface="org.wso2.carbon.utils.ConfigurationContextService"
* cardinality="1..1" policy="dynamic" bind="setConfigurationContextService"
* unbind="unsetConfigurationContextService"
*/
public class SchedulingTask implements Task, TaskSchedulerLifeCycleCallback {

    private Map jobDataMap;

    private ConfigurationContext configurationContext;

    private static final Log log = LogFactory.getLog(SchedulingTask.class);

    /**
     * This method implements the logic associated with the execution of the required synapse task.
     */
    public void execute() {

        String operationName = (String) jobDataMap.get(TaskSchedulerConstants.OPERATION_NAME);
        String serviceName = (String) jobDataMap.get(TaskSchedulerConstants.DATA_SERVICE_NAME);
        String backendServerUrl = (String) jobDataMap.get(TaskSchedulerConstants.BACK_END_URL);

        ServiceClient serviceClient;
        try {
            serviceClient = new ServiceClient();
            OperationClient opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
            //creating message context
            MessageContext outMsgCtx = new MessageContext();
            Options opts = outMsgCtx.getOptions();
            //setting properties into option
            opts.setTo(new EndpointReference(backendServerUrl + serviceName + ".SOAP12Endpoint"));
            opts.setAction("urn:" + operationName);

            SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();

            outMsgCtx.setEnvelope(soapEnvelope);
            opClient.addMessageContext(outMsgCtx);
            opClient.execute(true);

            MessageContext inMsgtCtx = opClient.getMessageContext("In");
            SOAPEnvelope response = inMsgtCtx.getEnvelope();
        } catch (AxisFault axisFault) {
            //log.error("Error while sending the request to the DataService", axisFault);
        }
    }

    /**
     * This method initializes the Job Data Map of the task.
     *
     * @param jobDataMap jobDataMap
     */
    public void init(Map jobDataMap) {
        this.jobDataMap = jobDataMap;
    }

    /**
     * This method resets the job data map associated to a particular quartz job.
     */
    public void destroy() {
        this.jobDataMap = null;
    }

    /**
     * This method is used to bind the ConfigurationContext which is being used in order to access
     * it in this particular class
     *
     * @param configurationContextService configurationContextService required to grab the current
     *                                    configurationContext
     */
    public void setConfigurationContextService(
            ConfigurationContextService configurationContextService) {
        this.configurationContext = configurationContextService.getServerConfigContext();
    }

    /**
     * This method is used to unbind the ConfigurationContext which is being used from the context
     * of this particular class
     *
     * @param configurationContextService configurationContextService
     */
    public void unsetConfigurationContextService(
            ConfigurationContextService configurationContextService) {
        this.configurationContext = null;
    }
}
TOP

Related Classes of org.wso2.carbon.dataservices.taskscheduler.SchedulingTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.