Author: sumedha
Date: Mon May 5 06:17:30 2008
New Revision: 16535
Log:
REST implementation,boolean data type
Modified:
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
Modified:
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
==============================================================================
---
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
(original)
+++
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
Mon May 5 06:17:30 2008
@@ -55,6 +55,7 @@
public static final String MONEY = "MONEY";
public static final String SMALLMONEY = "SMALLMONEY";
public static final String BIT = "BIT";
+ public static final String BOOLEAN = "BOOLEAN";
public static final String TINYINT = "TINYINT";
public static final String SMALLINT = "SMALLINT";
public static final String INTEGER = "INTEGER";
Modified:
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
==============================================================================
---
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
(original)
+++
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
Mon May 5 06:17:30 2008
@@ -23,11 +23,14 @@
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.TreeMap;
import javax.sql.DataSource;
import javax.xml.namespace.QName;
@@ -35,6 +38,8 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.Deployer;
@@ -43,19 +48,25 @@
import org.apache.axis2.deployment.DeploymentErrorMsgs;
import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.axis2.description.AxisBinding;
+import org.apache.axis2.description.AxisBindingOperation;
+import org.apache.axis2.description.AxisEndpoint;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.description.InOutAxisOperation;
import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.transport.http.util.RESTUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.commons.schema.utils.NamespaceMap;
import org.wso2.ws.dataservice.beans.Config;
+
public class DBDeployer implements Deployer, DeploymentConstants {
private static final Log log = LogFactory.getLog(DBDeployer.class);
private AxisConfiguration axisConfig;
@@ -66,6 +77,7 @@
private Config config;
private static HashMap conversionType = null;
private AxisService axisService = null;
+ Map httpLocationTable;
private static HashMap getConversionTable() {
if (conversionType == null) {
@@ -79,6 +91,7 @@
conversionType.put(DBConstants.DataTypes.MONEY,
"java.math.BigDecimal");
conversionType.put(DBConstants.DataTypes.SMALLMONEY,
"java.math.BigDecimal");
conversionType.put(DBConstants.DataTypes.BIT, "boolean");
+ conversionType.put(DBConstants.DataTypes.BOOLEAN, "boolean");
conversionType.put(DBConstants.DataTypes.TINYINT, "byte");
conversionType.put(DBConstants.DataTypes.SMALLINT, "short");
conversionType.put(DBConstants.DataTypes.INTEGER, "int");
@@ -319,6 +332,179 @@
}
+ //REST related processing
+ httpLocationTable = new TreeMap(new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return (-1 * ((Comparable) o1).compareTo(o2));
+ }
+ });
+
+ String interfaceName = serviceName +
WSDL2Constants.INTERFACE_PREFIX;
+ AxisEndpoint httpEndpoint = new AxisEndpoint();
+ String httpEndpointName = serviceName +
WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME;
+ httpEndpoint.setName(httpEndpointName);
+ AxisBinding httpBinding = new AxisBinding();
+ httpEndpoint.setBinding(httpBinding);
+ httpBinding.setName(new QName(serviceName +
Java2WSDLConstants.HTTP_BINDING));
+ httpBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
+ httpBinding.setParent(httpEndpoint);
+ httpBinding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME,
interfaceName);
+
+ //soap11
+ AxisEndpoint soap11Endpoint = new AxisEndpoint();
+ String soap11EndpointName = serviceName +
WSDL2Constants.DEFAULT_SOAP11_ENDPOINT_NAME;
+ soap11Endpoint.setName(soap11EndpointName);
+ AxisBinding soap11Binding = new AxisBinding();
+ soap11Endpoint.setBinding(soap11Binding);
+ soap11Binding.setName(new QName(serviceName +
Java2WSDLConstants.BINDING_NAME_SUFFIX));
+ soap11Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
+ soap11Binding.setParent(soap11Endpoint);
+ soap11Binding
+ .setProperty(WSDL2Constants.ATTR_WSOAP_PROTOCOL,
WSDL2Constants.HTTP_PROTOCAL);
+ soap11Binding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
+
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ soap11Binding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME,
interfaceName);
+
+ //soap12
+ AxisEndpoint soap12Endpoint = new AxisEndpoint();
+ String soap12EndpointName = serviceName +
WSDL2Constants.DEFAULT_SOAP12_ENDPOINT_NAME;
+ soap12Endpoint.setName(soap12EndpointName);
+ AxisBinding soap12Binding = new AxisBinding();
+ soap12Endpoint.setBinding(soap12Binding);
+ soap12Binding.setName(new QName(serviceName +
Java2WSDLConstants.SOAP12BINDING_NAME_SUFFIX));
+ soap12Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
+ soap12Binding.setParent(soap12Endpoint);
+ soap12Binding
+ .setProperty(WSDL2Constants.ATTR_WSOAP_PROTOCOL,
WSDL2Constants.HTTP_PROTOCAL);
+ soap12Binding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
+
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ soap12Binding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME,
interfaceName);
+
+ httpEndpoint = new AxisEndpoint();
+ httpEndpointName = serviceName +
WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME;
+ httpEndpoint.setName(httpEndpointName);
+ httpBinding = new AxisBinding();
+ httpEndpoint.setBinding(httpBinding);
+ httpBinding.setName(new QName(serviceName +
Java2WSDLConstants.HTTP_BINDING));
+ httpBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
+ httpBinding.setParent(httpEndpoint);
+ httpBinding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME,
interfaceName);
+
+
+ //Get resource definitions for queries
+ //If there are resource definitions
+ Iterator resources = configElement.getChildrenWithName(new
QName("resource"));
+ //HashMap queryResourceMapping = new HashMap();
+ //ArrayList resources = dataServiceConfig.getResources();
+ //for(int a = 0;a < resources.size();a++){
+ while(resources.hasNext()){
+ OMElement resourceEle = (OMElement) resources.next();
+ //Resource resource = (Resource)resources.get(a);
+ String method = resourceEle.getAttributeValue(new
QName("method"));
+ String path = resourceEle.getAttributeValue(new QName("path"));
+
+
+ //Create an axisoperation to serve resource request
+ String pathWithoutSlashes = path.replaceAll("/", "_");
+ String operationName = "_"+method+pathWithoutSlashes;
+
+ AxisOperation axisOperation = new InOutAxisOperation(new
QName(operationName.toLowerCase()));
+
+
+ axisOperation.setMessageReceiver(dbMessageReceiver);
+ axisOperation.setStyle("document");
+ axisConfig.getPhasesInfo().setOperationPhases(axisOperation);
+
+ axisOperation.addParameter(new
Parameter(DBConstants.DB_OPERATION_ELEMENT,
+ resourceEle));
+ //axisOperation.addParameter(DBConstants.DB_QUERY_OBJECT,
+ // resource.getCallQuery());
+
+ axisService.addOperation(axisOperation);
+
+ //getting the query element
+ OMElement callQuery = resourceEle.getFirstChildWithName(new
QName("call-query"));
+ String hrefVal = callQuery.getAttributeValue(new
QName("href"));
+ OMElement query = (OMElement) queryMap.get(hrefVal);
+ CallQuery callQueryElement = new CallQuery();
+
//callQueryElement.populateCallQuery(query,paramsPerCallQueryMap);
+ callQueryElement.populateCallQuery(query,axisService);
+
+ //creating a parameter to hold query object
+ Parameter callQueryParameter = new Parameter();
+ callQueryParameter.setName(DBConstants.CALL_QUERY_ELEMENT);
+ callQueryParameter.setValue(callQueryElement);
+ axisOperation.addParameter(callQueryParameter);
+
+
+ //iterate through with-params in callQuery element & append
parameter ids
+ //to resource path
+ Iterator withParamsItr = callQuery.getChildrenWithName(new
QName("with-param"));
+ while(withParamsItr.hasNext()){
+ OMElement withParamEle =
(OMElement)withParamsItr.next();
+ String name = withParamEle.getAttributeValue(new
QName("name"));
+ path +="/{"+name+"}";
+ }
+ //path = path +"/{id}/{name}";
+ log.info("Exposing query :" + hrefVal + " via
HTTP "
+ + method + " for URL : " +
path);
+
+ AxisBindingOperation soap11BindingOperation =
new AxisBindingOperation();
+
soap11BindingOperation.setAxisOperation(axisOperation);
+
soap11BindingOperation.setName(axisOperation.getName());
+ AxisBinding soap11Binding2 =
soap11Endpoint.getBinding();
+
soap11BindingOperation.setParent(soap11Binding2);
+ soap11BindingOperation.setProperty(
+
WSDL2Constants.ATTR_WHTTP_LOCATION,path);
+ soap11Binding.addChild(axisOperation.getName(),
+ soap11BindingOperation);
+
+ AxisBindingOperation soap12BindingOperation =
new AxisBindingOperation();
+
soap12BindingOperation.setAxisOperation(axisOperation);
+
soap12BindingOperation.setName(axisOperation.getName());
+ AxisBinding soap12Binding2 =
soap12Endpoint.getBinding();
+
soap12BindingOperation.setParent(soap12Binding2);
+ soap12BindingOperation.setProperty(
+
WSDL2Constants.ATTR_WHTTP_LOCATION, path);
+ soap12Binding.addChild(axisOperation.getName(),
+ soap12BindingOperation);
+
+ AxisBindingOperation httpBindingOperation = new
AxisBindingOperation();
+
httpBindingOperation.setAxisOperation(axisOperation);
+
httpBindingOperation.setName(axisOperation.getName());
+ httpBinding = httpEndpoint.getBinding();
+ httpBindingOperation.setParent(httpBinding);
+ httpBindingOperation.setProperty(
+
WSDL2Constants.ATTR_WHTTP_LOCATION, path);
+
httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, method);
+ httpBinding.addChild(axisOperation.getName(),
+ httpBindingOperation);
+
+
+ String httpLocationString = RESTUtil
+
.getConstantFromHTTPLocation(path, method);
+ //String httpLocationString = path;
+ httpLocationTable.put(httpLocationString,
axisOperation);
+
+
+ // OMElement resource = (OMElement) resources.next();
+ // OMElement callQuery = resource.getFirstChildWithName(new
+ // QName("call-query"));
+ // String queryRef = callQuery.getAttributeValue(new
+ // QName("href"));
+ // queryResourceMapping.put(queryRef, resource);
+ }
+
+ //set HTTP location table to axis service
+ //for REST support
+ httpBinding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE,
httpLocationTable);
+ soap11Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE,
httpLocationTable);
+ soap12Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE,
httpLocationTable);
+ axisService.addEndpoint(soap11EndpointName, soap11Endpoint);
+ axisService.addEndpoint(soap12EndpointName, soap12Endpoint);
+ axisService.addEndpoint(httpEndpointName, httpEndpoint);
+ //(End) REST related processing
+
Iterator ops = configElement.getChildrenWithName(new
QName("operation"));
while (ops.hasNext()) {
OMElement operation = (OMElement) ops.next();
Modified:
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
==============================================================================
---
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
(original)
+++
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
Mon May 5 06:17:30 2008
@@ -1441,6 +1441,19 @@
}else{
((CallableStatement)sqlQuery).registerOutParameter(i+1, java.sql.Types.TIME);
}
+ }else if
(DBConstants.DataTypes.BOOLEAN.equals(sqlType)) {
+ if("IN".equals(paramType)){
+ if("SQL".equals(callee)){
+ sqlQuery.setBoolean(i + 1,
Boolean.parseBoolean(value));
+ }else{
+
((CallableStatement)sqlQuery).setBoolean(i + 1, Boolean.parseBoolean(value));
+ }
+ }else if("INOUT".equals(paramType)){
+
((CallableStatement)sqlQuery).setBoolean(i + 1, Boolean.parseBoolean(value));
+
((CallableStatement)sqlQuery).registerOutParameter(i+1, java.sql.Types.BOOLEAN);
+ }else{
+
((CallableStatement)sqlQuery).registerOutParameter(i+1, java.sql.Types.BOOLEAN);
+ }
}else{
log.error("["+serviceName+"] Unsupported data
type : "+sqlType+" as input parameter.");
throw new AxisFault("["+serviceName+"] Found
Unsupported data type : "+sqlType+" as input parameter.");
_______________________________________________
Wsas-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev