Author: keith
Date: Sun Jul 20 00:26:20 2008
New Revision: 19656
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19656

Log:
Fixing Mashup-1004. Did not attemp a refractor at this moment cause didnt want 
to touch JSDeployer so copied code over from JSDeployer to DBDeployer for now.


Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/deployers/DBDeployer.java

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/deployers/DBDeployer.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/deployers/DBDeployer.java?rev=19656&r1=19655&r2=19656&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/deployers/DBDeployer.java    
    (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/deployers/DBDeployer.java    
    Sun Jul 20 00:26:20 2008
@@ -16,6 +16,9 @@
 package org.wso2.mashup.deployers;
 
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axis2.transport.http.util.RESTUtil;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.DeploymentEngine;
 import org.apache.axis2.deployment.DeploymentErrorMsgs;
@@ -27,9 +30,18 @@
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.AxisEndpoint;
 import org.apache.axis2.description.AxisBinding;
+import org.apache.axis2.description.AxisBindingOperation;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.AxisMessage;
+import org.apache.axis2.description.AxisBindingMessage;
+import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
 import org.apache.axis2.i18n.Messages;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP11Constants;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
 import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.utils.MashupUtils;
@@ -46,12 +58,26 @@
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Comparator;
 
 public class DBDeployer extends org.wso2.ws.dataservice.DBDeployer {
 
     private static final Log log = LogFactory.getLog(DBDeployer.class);
 
+    private AxisBinding soap11Binding;
+    private AxisBinding soap12Binding;
+    private AxisBinding httpBinding;
+
+    private final String HTTP_TRANSPORT = "http";
+    private final String HTTPS_TRANSPORT = "https";
+
+    // This is the map that keeps the httpLocation to axisoperation mapping to 
be used by the
+    // httpLocationBasedDispatcher
+    Map httpLocationTable;
+
     public void init(ConfigurationContext configCtx) {
         this.configCtx = configCtx;
         axisConfig = this.configCtx.getAxisConfiguration();
@@ -192,13 +218,95 @@
                 fileName.substring(0, fileName.indexOf(".")));
         axisService.setName(username + MashupConstants.SEPARATOR_CHAR + name);
 
-        Collection endpoints = axisService.getEndpoints().values();
-        Iterator iterator = endpoints.iterator();
-        while (iterator.hasNext()) {
-            AxisEndpoint axisEndpoint = (AxisEndpoint) iterator.next();
-            AxisBinding binding = axisEndpoint.getBinding();
-            QName bindingName = binding.getName();
-            binding.setName(new QName(username + bindingName.getLocalPart()));
+        // The interfaceName is used by 
org.apache.axis2.description.AxisService2WSDL20 to
+        // set the interface during ?wsdl2
+        String interfaceName = name + WSDL2Constants.INTERFACE_PREFIX;
+        axisService.addParameter(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
+
+        // We create the AxisBinding Hierarchy in here. In the Mashup Server 
we take complete
+        // control of the Axis2 binding hierarchy cause we need to speficy 
some HTTPBinding
+        // properties such as httpMethod and httpLocation
+
+        // Set a comparator so tha httpLocations are stored in decending 
order. We want the
+        // HTTPLocationBasedDiapatcher to make the best match hence we need 
them in decending
+        // order
+        httpLocationTable = new TreeMap(new Comparator() {
+            public int compare(Object o1, Object o2) {
+                return (-1 * ((Comparable) o1).compareTo(o2));
+            }
+        });
+
+        String bindingPrefix = username + "-" + name + "-";
+        // Create a default SOAP 1.1 Binding
+        createDefaultSOAP11Binding(bindingPrefix, interfaceName);
+
+        // Create a default SOAP 1.2 Binding
+        createDefaultSOAP12Binding(bindingPrefix, interfaceName);
+
+        // Create a default HTTP Binding
+        createDefaultHTTPBinding(bindingPrefix, interfaceName);
+
+        // We need to get all transports from the axis2 engine and create 
endpoints for each of
+        // those in here.
+        createDefaultEndpoints(axisService);
+
+        String targetNamespace = axisService.getTargetNamespace();
+        String httpMethod = HTTPConstants.HEADER_POST;
+
+        Iterator axisOperations = axisService.getChildren();
+        while (axisOperations.hasNext()) {
+            AxisOperation axisOperation = (AxisOperation) 
axisOperations.next();
+
+            String httpLocation = axisOperation.getName().getLocalPart();
+            // Calculate the values for input and output actions according to
+            // http://www.w3.org/TR/ws-addr-wsdl/#defactionwsdl20
+            String inputAction =
+                    targetNamespace + WSDL2Constants.DEFAULT_INTERFACE_NAME +
+                            MashupConstants.FORWARD_SLASH + name + 
Java2WSDLConstants.REQUEST;
+            String outAction =
+                    targetNamespace + WSDL2Constants.DEFAULT_INTERFACE_NAME +
+                            MashupConstants.FORWARD_SLASH + name + 
Java2WSDLConstants.RESPONSE;
+            axisOperation.setSoapAction(inputAction);
+            axisOperation.setOutputAction(outAction);
+            // Create a default SOAP 1.1 Binding operation
+            AxisBindingOperation soap11BindingOperation =
+                    createDefaultSOAP11BindingOperation(axisOperation, 
httpLocation, inputAction);
+
+            // Create a default SOAP 1.2 Binding operation
+            AxisBindingOperation soap12BindingOperation =
+                    createDefaultSOAP12BindingOperation(axisOperation, 
httpLocation, inputAction);
+
+            // Create a default HTTP Binding operation
+            AxisBindingOperation httpBindingOperation =
+                    createDefaultHTTPBindingOperation(axisOperation, 
httpLocation, httpMethod);
+
+            AxisMessage inMessage = 
axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+
+            if (inMessage != null) {
+                createAxisBindingMessage(soap11BindingOperation, inMessage,
+                                         WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+                createAxisBindingMessage(soap12BindingOperation, inMessage,
+                                         WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+                createAxisBindingMessage(httpBindingOperation, inMessage,
+                                         WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+            }
+
+            AxisMessage outMessage =
+                    
axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+            if (outMessage != null) {
+                createAxisBindingMessage(soap11BindingOperation, outMessage,
+                                         
WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+                createAxisBindingMessage(soap12BindingOperation, outMessage,
+                                         
WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+                createAxisBindingMessage(httpBindingOperation, outMessage,
+                                         
WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+            }
+
+            // We need to extract a constant value from the httpLocation so 
that the
+            // httpLocationBasedDispatcher can use that value to dispatch to 
the correct operation
+            String httpLocationString =
+                    RESTUtil.getConstantFromHTTPLocation(httpLocation, 
httpMethod);
+            httpLocationTable.put(httpLocationString, axisOperation);
         }
 
         axisService.setParent(axisServiceGroup);
@@ -235,4 +343,180 @@
         axisService.addParameter(resourceFolderParameter);
         return serviceList;
     }
+
+    /**
+     * Creates AxisBindingOperation and populates it with HTTP properties
+     * @param axisOp The AxisOperation corresponding to this bindingOperation
+     * @param httpLocation The httpLocation annotation for this operation
+     * @param httpMethod The httpMethod annotation for this operation
+     * @return AxisBindingOperation having sdefault HTTP values
+     */
+    private AxisBindingOperation 
createDefaultHTTPBindingOperation(AxisOperation axisOp,
+                                                                   String 
httpLocation,
+                                                                   String 
httpMethod) {
+        AxisBindingOperation httpBindingOperation = new AxisBindingOperation();
+        httpBindingOperation.setAxisOperation(axisOp);
+        httpBindingOperation.setName(axisOp.getName());
+        httpBindingOperation.setParent(httpBinding);
+        httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
+        httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, 
httpMethod);
+        httpBinding.addChild(httpBindingOperation.getName(), 
httpBindingOperation);
+        return httpBindingOperation;
+    }
+
+    /**
+     * Creates AxisBindingOperation and populates it with SOAP 1.2 properties
+     * @param axisOp The AxisOperation corresponding to this bindingOperation
+     * @param httpLocation The httpLocation annotation for this operation
+     * @param inputAction The input action for this operation
+     * @return AxisBindingOperation having sdefault SOAP 1.2 values
+     */
+    private AxisBindingOperation 
createDefaultSOAP12BindingOperation(AxisOperation axisOp,
+                                                                     String 
httpLocation,
+                                                                     String 
inputAction) {
+        AxisBindingOperation soap12BindingOperation = new 
AxisBindingOperation();
+        soap12BindingOperation.setAxisOperation(axisOp);
+        soap12BindingOperation.setName(axisOp.getName());
+        soap12BindingOperation.setParent(soap12Binding);
+        soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
+        soap12Binding.addChild(soap12BindingOperation.getName(), 
soap12BindingOperation);
+        soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, 
inputAction);
+        return soap12BindingOperation;
+    }
+
+    /**
+     * Creates AxisBindingOperation and populates it with SOAP 1.1 properties
+     * @param axisOp The AxisOperation corresponding to this bindingOperation
+     * @param httpLocation The httpLocation annotation for this operation
+     * @param inputAction The input action for this operation
+     * @return AxisBindingOperation having sdefault SOAP 1.1 values
+     */
+    private AxisBindingOperation 
createDefaultSOAP11BindingOperation(AxisOperation axisOp,
+                                                                     String 
httpLocation,
+                                                                     String 
inputAction) {
+        AxisBindingOperation soap11BindingOperation = new 
AxisBindingOperation();
+        soap11BindingOperation.setAxisOperation(axisOp);
+        soap11BindingOperation.setName(axisOp.getName());
+        soap11BindingOperation.setParent(soap11Binding);
+        soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
+        soap11Binding.addChild(soap11BindingOperation.getName(), 
soap11BindingOperation);
+        soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, 
inputAction);
+        return soap11BindingOperation;
+    }
+
+    /**
+     * Creates a set of default endpoints for this service
+     * @param axisService The AxisService that the endpoints are created for
+     */
+    private void createDefaultEndpoints(AxisService axisService) {
+        HashMap transportsIn = axisConfig.getTransportsIn();
+        Iterator iterator = transportsIn.values().iterator();
+        while (iterator.hasNext()) {
+            // Used to indicate whather a HTTPEndpoint is needed. Http 
endpoint is needed only
+            // for http and https transports
+            boolean needHttp = false;
+
+            // The prefix is used to genarate endpoint names
+            String prefix = "";
+            TransportInDescription transportIn = (TransportInDescription) 
iterator.next();
+            String transportInName = transportIn.getName();
+            if (HTTP_TRANSPORT.equalsIgnoreCase(transportInName)) {
+                needHttp = true;
+            } else if (HTTPS_TRANSPORT.equalsIgnoreCase(transportInName)) {
+                needHttp = true;
+                prefix = WSDL2Constants.DEFAULT_HTTPS_PREFIX;
+            } else if (transportInName != null) {
+                prefix = transportInName.toUpperCase();
+            }
+
+            // Creates a default SOAP 1.1 endpoint
+            AxisEndpoint soap11Endpoint = new AxisEndpoint();
+            String soap11EndpointName =
+                    prefix + WSDL2Constants.DEFAULT_SOAP11_ENDPOINT_NAME;
+            soap11Endpoint.setName(soap11EndpointName);
+            soap11Endpoint.setBinding(soap11Binding);
+            soap11Endpoint.setParent(axisService);
+            soap11Endpoint.setTransportInDescription(transportInName);
+            axisService.addEndpoint(soap11EndpointName, soap11Endpoint);
+
+            // Creates a default SOAP 1.2 endpoint
+            AxisEndpoint soap12Endpoint = new AxisEndpoint();
+            String soap12EndpointName =
+                    prefix + WSDL2Constants.DEFAULT_SOAP12_ENDPOINT_NAME;
+            soap12Endpoint.setName(soap12EndpointName);
+            soap12Endpoint.setBinding(soap12Binding);
+            soap12Endpoint.setParent(axisService);
+            soap12Endpoint.setTransportInDescription(transportInName);
+            axisService.addEndpoint(soap12EndpointName, soap12Endpoint);
+
+            // Creates a HTTP endpoint if its http or https transport is used
+            if (needHttp) {
+                AxisEndpoint httpEndpoint = new AxisEndpoint();
+                String httpEndpointName =
+                        prefix + WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME;
+                httpEndpoint.setName(httpEndpointName);
+                httpEndpoint.setBinding(httpBinding);
+                httpEndpoint.setParent(axisService);
+                httpEndpoint.setTransportInDescription(transportInName);
+                axisService.addEndpoint(httpEndpointName, httpEndpoint);
+            }
+        }
+    }
+
+    /**
+     * Creates a AxisBinding and populates it with default HTTP properties
+     * @param name The name of the service
+     * @param interfaceName The interface name
+     */
+    private void createDefaultHTTPBinding(String name, String interfaceName) {
+        httpBinding = new AxisBinding();
+        httpBinding.setName(new QName(name + Java2WSDLConstants.HTTP_BINDING));
+        httpBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
+        httpBinding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
+        httpBinding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+    }
+
+    /**
+     * Creates a AxisBinding and populates it with default SOAP 1.2 properties
+     * @param name The name of the service
+     * @param interfaceName The interface name
+     */
+    private void createDefaultSOAP12Binding(String name, String interfaceName) 
{
+        soap12Binding = new AxisBinding();
+        soap12Binding.setName(new QName(name + 
Java2WSDLConstants.SOAP12BINDING_NAME_SUFFIX));
+        soap12Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
+        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);
+        soap12Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+    }
+
+    /**
+     * Creates a AxisBinding and populates it with default SOAP 1.1 properties
+     * @param name The name of the service
+     * @param interfaceName The interface name
+     */
+    private void createDefaultSOAP11Binding(String name, String interfaceName) 
{
+        soap11Binding = new AxisBinding();
+        soap11Binding.setName(new QName(name + 
Java2WSDLConstants.BINDING_NAME_SUFFIX));
+        soap11Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
+        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);
+        soap11Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+    }
+
+    private void createAxisBindingMessage(AxisBindingOperation 
bindingOperation,
+                                                        AxisMessage message, 
String direction) {
+        AxisBindingMessage inBindingMessage = new AxisBindingMessage();
+        inBindingMessage.setName(message.getName());
+        inBindingMessage.setAxisMessage(message);
+        inBindingMessage.setParent(bindingOperation);
+        bindingOperation
+                        .addChild(direction, inBindingMessage);
+    }
 }

_______________________________________________
Mashup-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to