[Ds-java-dev] svn commit r14404 - trunk/solutions/data-services/java/modules/core/src/main/java/org/wso2/ws/dataservice

svn at wso2.org svn at wso2.org
Sun Mar 2 00:53:34 PST 2008


Author: sumedha
Date: Sun Mar  2 00:53:30 2008
New Revision: 14404

Log:

REST processing now has seperate operations bearing the name _+HTTP_METHOD+RESOURCE_PATH. This allows user to define REST services without defining an operation

Modified:
   trunk/solutions/data-services/java/modules/core/src/main/java/org/wso2/ws/dataservice/DBDeployer.java

Modified: trunk/solutions/data-services/java/modules/core/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
==============================================================================
--- trunk/solutions/data-services/java/modules/core/src/main/java/org/wso2/ws/dataservice/DBDeployer.java	(original)
+++ trunk/solutions/data-services/java/modules/core/src/main/java/org/wso2/ws/dataservice/DBDeployer.java	Sun Mar  2 00:53:30 2008
@@ -65,6 +65,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.wso2.ws.dataservice.beans.Config;
+import org.wso2.ws.dataservice.beans.Data;
+import org.wso2.ws.dataservice.beans.Resource;
 
 public class DBDeployer implements Deployer, DeploymentConstants {
     private static final Log log = LogFactory.getLog(DBDeployer.class);
@@ -218,6 +220,10 @@
             configElement = (new StAXOMBuilder(fis)).getDocumentElement();
             configElement.build();
             
+            //populate object model
+            Data dataServiceConfig = new Data();
+            dataServiceConfig.populate(configElement);
+            
             Config config;
             
             //If configuration file is hosted on wso2 registry
@@ -426,18 +432,72 @@
 
             //Get resource definitions for queries
             //If there are resource definitions
-            Iterator resources = configElement.getChildrenWithName(new QName("resource"));
-            HashMap queryResourceMapping = new HashMap();  
-            while(resources.hasNext()){
-            	OMElement resource = (OMElement) resources.next();
-            	OMElement callQuery = resource.getFirstChildWithName(new QName("call-query"));
-            	String queryRef = callQuery.getAttributeValue(new QName("href"));
-            	queryResourceMapping.put(queryRef, resource);
+            //Iterator resources = configElement.getChildrenWithName(new QName("resource"));
+            //HashMap queryResourceMapping = new HashMap();  
+            ArrayList resources = dataServiceConfig.getResources();
+            for(int a = 0;a < resources.size();a++){
+            	Resource resource = (Resource)resources.get(a);
+            	
+            	//Create an axisoperation to serve resource request
+            	String pathWithoutSlashes = resource.getPath().replaceAll("/", "_");
+            	String operationName = "_"+resource.getMethod()+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,
+                //        operation));
+                
+                axisService.addOperation(axisOperation);
+
+				log.info("Exposing query :" + resource.getCallQuery().getHref() + " via HTTP "
+						+ resource.getMethod() + " for URL : " + resource.getPath());
+
+				AxisBindingOperation soap11BindingOperation = new AxisBindingOperation();
+				soap11BindingOperation.setAxisOperation(axisOperation);
+				soap11BindingOperation.setName(axisOperation.getName());
+				soap11BindingOperation.setName(axisOperation.getName());
+				AxisBinding soap11Binding2 = soap11Endpoint.getBinding();
+				soap11BindingOperation.setParent(soap11Binding2);
+				soap11BindingOperation.setProperty(
+						WSDL2Constants.ATTR_WHTTP_LOCATION,resource.getPath());
+				soap11Binding.addChild(soap11Binding.getName(),
+						soap11BindingOperation);
+
+				AxisBindingOperation soap12BindingOperation = new AxisBindingOperation();
+				soap12BindingOperation.setAxisOperation(axisOperation);
+				soap12BindingOperation.setName(axisOperation.getName());
+				soap12BindingOperation.setName(axisOperation.getName());
+				AxisBinding soap12Binding2 = soap12Endpoint.getBinding();
+				soap12BindingOperation.setParent(soap12Binding2);
+				soap12BindingOperation.setProperty(
+						WSDL2Constants.ATTR_WHTTP_LOCATION, resource.getPath());
+				soap12Binding.addChild(soap12Binding.getName(),
+						soap12BindingOperation);
+
+				String httpLocationString = RESTUtil
+						.getConstantFromHTTPLocation(resource.getPath(), resource.getMethod());
+				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);
             }
             
-            
-            //(End) REST related processing
-            
+            //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"));
             
@@ -450,7 +510,6 @@
                 }
                 //is it always InOutAxisOperation ??
                 AxisOperation axisOperation = new InOutAxisOperation(new QName(opName));
-                // axisOperation.
                 axisOperation.setMessageReceiver(dbMessageReceiver);
                 axisOperation.setStyle("document");
                 axisConfig.getPhasesInfo().setOperationPhases(axisOperation);
@@ -473,49 +532,8 @@
                 axisOperation.addParameter(callQueryParameter);
                 
                 
-                //REST related processing
-                //check if this query should be exposed via REST
-                OMElement resourceDefinition = (OMElement)queryResourceMapping.get(hrefVal);
-                if(resourceDefinition != null){
-                	//resource definition exists, expose this query(operation) via REST too
-                	String httpLocation = resourceDefinition.getAttributeValue(new QName("path"));
-                	String httpMethod = resourceDefinition.getAttributeValue(new QName("method"));
-                	log.info("Exposing query :"+hrefVal+" via HTTP "
-                			+httpMethod+" for URL : "+httpLocation);                	
-                    
-                    AxisBindingOperation soap11BindingOperation = new AxisBindingOperation();
-                    soap11BindingOperation.setAxisOperation(axisOperation);
-                    soap11BindingOperation.setName(axisOperation.getName());
-                    soap11BindingOperation.setName(axisOperation.getName());
-                    AxisBinding soap11Binding2 = soap11Endpoint.getBinding();
-                    soap11BindingOperation.setParent(soap11Binding2);
-                    soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation);
-                    soap11Binding.addChild(soap11Binding.getName(), soap11BindingOperation);
-                    
-                    AxisBindingOperation soap12BindingOperation = new AxisBindingOperation();
-                    soap12BindingOperation.setAxisOperation(axisOperation);
-                    soap12BindingOperation.setName(axisOperation.getName());
-                    soap12BindingOperation.setName(axisOperation.getName());
-                    AxisBinding soap12Binding2 = soap12Endpoint.getBinding();
-                    soap12BindingOperation.setParent(soap12Binding2);
-                    soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation);
-                    soap12Binding.addChild(soap12Binding.getName(), soap12BindingOperation);
-                    
-                    String httpLocationString =
-                        RESTUtil.getConstantFromHTTPLocation(httpLocation, httpMethod);
-                    httpLocationTable.put(httpLocationString, axisOperation); 
-                    //(End) REST related processing
-                }
             }          
             
-            //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);            
 
         } catch (FileNotFoundException e) {
             throw new AxisFault("Error reading service configuration file.", e);



More information about the Ds-java-dev mailing list