<commit_before>/*
 *  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.core.dispatch;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.wso2.carbon.dataservices.common.DBConstants;
import org.wso2.carbon.dataservices.common.DBConstants.BoxcarringOps;
import org.wso2.carbon.dataservices.core.DBUtils;
import org.wso2.carbon.dataservices.core.DSSessionManager;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.DataServiceUser;
import org.wso2.carbon.dataservices.core.engine.CallableRequest;
import org.wso2.carbon.dataservices.core.engine.DataService;
import org.wso2.carbon.dataservices.core.engine.ParamValue;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Represents a data services request.
 */
public abstract class DataServiceRequest {
	
	/** 
	 * contains the username of the user who made the current message request 
	 */
	private String user;
	
	/** 
	 * contains the current user's user roles 
	 */
	private String[] userRoles;
	
	/**
	 * The data service object of the request that will be run against 
	 */
	private DataService dataService;
	
	/**
	 * The data service request name
	 */
	private String requestName;
	
	/**
	 * Disable streaming flag
	 */
	private boolean disableStreaming;
	
	protected DataServiceRequest(DataService dataService, String requestName) 
	        throws DataServiceFault {
		this.dataService = dataService;
		this.requestName = requestName;
		CallableRequest request = this.dataService.getCallableRequest(this.requestName);
		if (request == null) {
			throw new DataServiceFault("A data service request named '" + requestName + 
					"' does not exist in data service '" + dataService.getName() + "'");
		}
		this.disableStreaming = this.dataService.getCallableRequest(
				this.requestName).isDisableStreamingEffective();
	}
	
	public static DataServiceRequest createDataServiceRequest(
			MessageContext msgContext) throws DataServiceFault {
		AxisService axisService = msgContext.getAxisService();
		AxisOperation axisOp = msgContext.getAxisOperation();
		OMElement inputMessage = msgContext.getEnvelope().getBody().getFirstElement();
		/* get operation/request name */
		String requestName = axisOp.getName().getLocalPart();
		if (inputMessage != null && !requestName.equals(inputMessage.getLocalName())) {
			throw new DataServiceFault("Input Message and " + requestName + " Axis Operation didn't match.");
		}
		/* retrieve the DataService object representing the current data service */
		DataService dataService = (DataService) axisService.getParameter(
				DBConstants.DATA_SERVICE_OBJECT).getValue();
		
		DataServiceRequest dsRequest;
        /* Check whether the request is collection of requests (request box), if so create RequestBoxRequest */
        if (isRequestBoxRequest(requestName)) {
            dsRequest = createRequestBoxRequest(dataService, requestName, inputMessage);
            return dsRequest;
        }
		/* check if batch or single request */
		if (isBatchRequest(inputMessage)) {
			dsRequest = new BatchDataServiceRequest(
					dataService, requestName, getBatchInputValuesFromOM(inputMessage));
		} else {
			dsRequest = new SingleDataServiceRequest(
					dataService, requestName, getSingleInputValuesFromOM(inputMessage)); 
		}
		
		/* set user information */
		populateUserInfo(dataService, dsRequest, msgContext);
		
		/* checks if this is a boxcarring session */
		if (isBoxcarringRequest(requestName)) {
			/* wrap the current request in a boxcarring request */
			dsRequest = new BoxcarringDataServiceRequest(dsRequest);<commit_msg>Force xml request validation when the system property is set<commit_after>/*
 *  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.core.dispatch;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.wso2.carbon.dataservices.common.DBConstants;
import org.wso2.carbon.dataservices.common.DBConstants.BoxcarringOps;
import org.wso2.carbon.dataservices.core.DBUtils;
import org.wso2.carbon.dataservices.core.DSSessionManager;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.DataServiceUser;
import org.wso2.carbon.dataservices.core.engine.CallableRequest;
import org.wso2.carbon.dataservices.core.engine.DataService;
import org.wso2.carbon.dataservices.core.engine.ParamValue;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Represents a data services request.
 */
public abstract class DataServiceRequest {
	
	/** 
	 * contains the username of the user who made the current message request 
	 */
	private String user;
	
	/** 
	 * contains the current user's user roles 
	 */
	private String[] userRoles;
	
	/**
	 * The data service object of the request that will be run against 
	 */
	private DataService dataService;
	
	/**
	 * The data service request name
	 */
	private String requestName;
	
	/**
	 * Disable streaming flag
	 */
	private boolean disableStreaming;
	
	protected DataServiceRequest(DataService dataService, String requestName) 
	        throws DataServiceFault {
		this.dataService = dataService;
		this.requestName = requestName;
		CallableRequest request = this.dataService.getCallableRequest(this.requestName);
		if (request == null) {
			throw new DataServiceFault("A data service request named '" + requestName + 
					"' does not exist in data service '" + dataService.getName() + "'");
		}
		this.disableStreaming = this.dataService.getCallableRequest(
				this.requestName).isDisableStreamingEffective();
	}
	
	public static DataServiceRequest createDataServiceRequest(
			MessageContext msgContext) throws DataServiceFault {
		AxisService axisService = msgContext.getAxisService();
		AxisOperation axisOp = msgContext.getAxisOperation();
		OMElement inputMessage = msgContext.getEnvelope().getBody().getFirstElement();
		/* get operation/request name */
		String requestName = axisOp.getName().getLocalPart();
		if (Boolean.parseBoolean(System.getProperty("dss.force.xml.validation"))) {
			if (inputMessage != null && !requestName.equals(inputMessage.getLocalName())) {
				throw new DataServiceFault("Input Message and " + requestName + " Axis Operation didn't match.");
			}
		}
		/* retrieve the DataService object representing the current data service */
		DataService dataService = (DataService) axisService.getParameter(
				DBConstants.DATA_SERVICE_OBJECT).getValue();
		
		DataServiceRequest dsRequest;
        /* Check whether the request is collection of requests (request box), if so create RequestBoxRequest */
        if (isRequestBoxRequest(requestName)) {
            dsRequest = createRequestBoxRequest(dataService, requestName, inputMessage);
            return dsRequest;
        }
		/* check if batch or single request */
		if (isBatchRequest(inputMessage)) {
			dsRequest = new BatchDataServiceRequest(
					dataService, requestName, getBatchInputValuesFromOM(inputMessage));
		} else {
			dsRequest = new SingleDataServiceRequest(
					dataService, requestName, getSingleInputValuesFromOM(inputMessage)); 
		}
		
		/* set user information */
		populateUserInfo(dataService, dsRequest, msgContext);
		
		/* checks if this is a boxcarring session */
		if (isBoxcarringRequest(requestName)) {
			/* wrap the current request in a boxcarring request */
			dsRequest = new BoxcarringDataServiceRequest(dsRequest);
{'fraction_non_alphanumeric': 0.0935566460422445, 'fraction_numerical': 0.005973970556859398, 'mean_word_length': 4.338838268792711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5458093', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2595, 'n_words': 728}