You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2007/08/27 10:58:15 UTC

svn commit: r570044 - in /webservices/axis2/trunk/java/modules: adb/src/org/apache/axis2/transport/ adb/src/org/apache/axis2/transport/java/ json/test/org/apache/axis2/json/ kernel/conf/ kernel/src/org/apache/axis2/client/ kernel/src/org/apache/axis2/d...

Author: deepal
Date: Mon Aug 27 01:58:14 2007
New Revision: 570044

URL: http://svn.apache.org/viewvc?rev=570044&view=rev
Log:
getting Axis2 build working after a week ( :))
- adding support for WSIF in Axis2 with use of ServiceClient

Added:
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/java/
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/java/JavaTransportSender.java
Modified:
    webservices/axis2/trunk/java/modules/json/test/org/apache/axis2/json/Echo.java
    webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/namespace/Constants.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/TransportHeadersTest.java

Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/java/JavaTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/java/JavaTransportSender.java?rev=570044&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/java/JavaTransportSender.java (added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/transport/java/JavaTransportSender.java Mon Aug 27 01:58:14 2007
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.apache.axis2.transport.java;
+
+import org.apache.axis2.transport.TransportSender;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.rpc.receivers.RPCUtil;
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.engine.ObjectSupplier;
+import org.apache.axis2.engine.DefaultObjectSupplier;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMAbstractFactory;
+
+import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
+
+public class JavaTransportSender extends AbstractHandler implements TransportSender {
+
+    public void cleanup(MessageContext msgContext) throws AxisFault {
+    }
+    public void init(ConfigurationContext confContext, TransportOutDescription transportOut)
+            throws AxisFault {
+    }
+    public void stop() {
+    }
+    public InvocationResponse invoke(MessageContext msgContext)
+            throws AxisFault {
+        SOAPEnvelope resultEnvelope = invokeJavaMethod(msgContext);
+        Object responseMCObject = msgContext.getOperationContext().getMessageContext(
+                WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+        if (responseMCObject != null) {
+            MessageContext responseMC = (MessageContext) responseMCObject;
+            responseMC.setEnvelope(resultEnvelope);
+        }
+        return InvocationResponse.CONTINUE;
+    }
+    private SOAPEnvelope invokeJavaMethod(MessageContext inMessage)
+            throws AxisFault {
+        Class ImplClass;
+        Object obj;
+        Parameter implementationClass = inMessage.getParameter("className");
+        if (implementationClass == null) {
+            throw new AxisFault("Service Class Paramater does not find for the service : "
+                    + inMessage.getAxisService().getName());
+        }
+        Object serviceImpleClass = implementationClass.getValue();
+        try {
+            ImplClass = Class.forName(serviceImpleClass.toString());
+            obj = ImplClass.newInstance();
+        } catch (Exception e) {
+            throw new AxisFault("Exception occur while creating [ " + serviceImpleClass + " ]", e);
+        }
+        AxisService service = inMessage.getAxisService();
+        OMElement methodElement = inMessage.getEnvelope().getBody()
+                .getFirstElement();
+        String messageNameSpace = inMessage.getAxisService().getTargetNamespace();
+        String methodName = methodElement.getLocalName();
+        //Serive impplementation class
+        Method method = null;
+          Method[] methods = ImplClass.getMethods();
+	        for (int i = 0; i < methods.length; i++) {
+	            if (methods[i].getName().equals(methodName)) {
+	                method = methods[i];
+	                break;
+	            }
+	        }
+       if (method == null) {
+            throw new AxisFault("method : " + methodName +
+                    " : does not find in the service implementation class : " +
+                    serviceImpleClass);
+        }
+        //gets the object array from the request OMElement
+        ObjectSupplier obj1 = new DefaultObjectSupplier();
+        Object[] objectArray = RPCUtil.processRequest(methodElement, method, obj1);
+        //reflective invocation
+        Object resObject ;
+        try {
+            resObject = method.invoke(obj, objectArray);
+        } catch (Exception e) {
+            throw new AxisFault("Error occured while invoking the method [ " + methodName + " ]", e);
+        }
+        SOAPFactory fac = getSOAPFactory(inMessage);
+        OMNamespace ns = fac.createOMNamespace(messageNameSpace,
+                service.getSchemaTargetNamespacePrefix());
+        SOAPEnvelope envelope = fac.getDefaultEnvelope();
+        OMElement bodyContent = null;
+        if (resObject == null) {
+            //Send empty body
+            envelope.getBody().addChild(fac.createOMElement("item", ns));
+        } else if (resObject instanceof Object[]) {
+            QName resName = new QName(service.getSchematargetNamespace(),
+                    method.getName() + "Response",
+                    service.getSchemaTargetNamespacePrefix());
+            //create the omelement from the response array
+            OMElement bodyChild = RPCUtil.getResponseElement(resName,
+                    (Object[]) resObject, false, null);
+            //return type is sent with array size
+            bodyChild.addAttribute("returnType",
+                    method.getReturnType().getClass().getName() + ((Object[]) resObject).length,
+                    envelope.getBody().getDefaultNamespace());
+            envelope.getBody().addChild(bodyChild);
+        } else {
+            RPCUtil.processResponse(fac, resObject, bodyContent, ns, envelope, method, false, null);
+            envelope.getBody().getFirstElement().addAttribute("returnType",
+                    method.getReturnType().getClass().getName(), envelope.getBody().getDefaultNamespace());
+        }
+        return envelope;
+    }
+
+    private SOAPFactory getSOAPFactory(MessageContext msgContext) throws AxisFault {
+        String nsURI = msgContext.getEnvelope().getNamespace().getNamespaceURI();
+        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsURI)) {
+            return OMAbstractFactory.getSOAP12Factory();
+        } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsURI)) {
+            return OMAbstractFactory.getSOAP11Factory();
+        } else {
+            throw new AxisFault(Messages.getMessage("invalidSOAPversion"));
+        }
+    }
+}

Modified: webservices/axis2/trunk/java/modules/json/test/org/apache/axis2/json/Echo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/json/test/org/apache/axis2/json/Echo.java?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/json/test/org/apache/axis2/json/Echo.java (original)
+++ webservices/axis2/trunk/java/modules/json/test/org/apache/axis2/json/Echo.java Mon Aug 27 01:58:14 2007
@@ -18,17 +18,16 @@
  */
 package org.apache.axis2.json;
 
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
-import org.apache.axis2.wsdl.WSDLConstants;
-import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.context.MessageContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.wsdl.WSDLConstants;
 
 public class Echo {
-    private static final Log log = LogFactory.getLog(Echo.class);
 
     public Echo() {
     }
@@ -45,6 +44,9 @@
         } else if (messageType.indexOf("json") < 0) {
             throw new AxisFault("Type of the Received Message is not JSON");
         }
+        OMDataSource omdataOSuce = ((OMSourcedElement) omEle).getDataSource();
+        OMElement newOmEle = (OMElement) omEle.detach();
+        ((OMSourcedElement) newOmEle).setDataSource(omdataOSuce);
         return omEle;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml Mon Aug 27 01:58:14 2007
@@ -269,6 +269,9 @@
         <parameter name="PROTOCOL">HTTP/1.1</parameter>
         <parameter name="Transfer-Encoding">chunked</parameter>
     </transportSender>
+    <transportSender name="java"
+                     class="org.apache.axis2.transport.java.JavaTransportSender"/>
+
     <!--<transportSender name="jms"-->
                      <!--class="org.apache.axis2.transport.jms.JMSSender"/>-->
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java Mon Aug 27 01:58:14 2007
@@ -37,13 +37,7 @@
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.context.ServiceGroupContext;
-import org.apache.axis2.description.AxisModule;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.AxisServiceGroup;
-import org.apache.axis2.description.OutInAxisOperation;
-import org.apache.axis2.description.OutOnlyAxisOperation;
-import org.apache.axis2.description.RobustOutOnlyAxisOperation;
+import org.apache.axis2.description.*;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.ListenerManager;
 import org.apache.axis2.i18n.Messages;
@@ -216,6 +210,17 @@
                                                                                       wsdlServiceName,
                                                                                       portName,
                                                                                       options));
+        Parameter transportName = axisService.getParameter("TRANSPORT_NAME");
+        if(transportName != null ) {
+            TransportOutDescription transportOut = configContext.getAxisConfiguration().getTransportOut(
+                    transportName.getValue().toString());
+            if (transportOut == null) {
+                throw new AxisFault("Cannot load transport from binding, either defin in Axis2.config " +
+                        "or set it explicitely in ServiceClinet.Options");
+            } else {
+                options.setTransportOut(transportOut);
+            }
+        }
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml Mon Aug 27 01:58:14 2007
@@ -165,6 +165,8 @@
         <parameter name="PROTOCOL">HTTP/1.1</parameter>
         <parameter name="Transfer-Encoding">chunked</parameter>
     </transportSender>
+    <!--<transportSender name="java"-->
+                     <!--class="org.apache.axis2.transport.java.JavaTransportSender"/>-->
 
     <!-- ================================================= -->
     <!-- Phases  -->

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java Mon Aug 27 01:58:14 2007
@@ -38,9 +38,7 @@
 import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAP11Constants;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
+import org.w3c.dom.*;
 import org.xml.sax.SAXException;
 
 import javax.wsdl.*;
@@ -2150,8 +2148,51 @@
                                     axisOperation, anonymousValue);
                         }
                     }
+                }    else if (wsdl4jExtensibilityElement.getElementType() != null &&
+                        wsdl4jExtensibilityElement.getElementType().getNamespaceURI().equals(
+                                org.apache.axis2.namespace.Constants.FORMAT_BINDING)) {
+                    Element typeMapping = unknown.getElement();
+                    NodeList typeMaps = typeMapping.getElementsByTagNameNS(
+                            org.apache.axis2.namespace.Constants.FORMAT_BINDING,
+                            "typeMap");
+                    int count = typeMaps.getLength();
+                    HashMap typeMapper = new HashMap();
+                    for (int index = 0; index < count; index++) {
+                        Node node = typeMaps.item(index);
+                        NamedNodeMap attributes = node.getAttributes();
+                        Node typeName = attributes.getNamedItem("typeName");
+
+                        if (typeName != null) {
+                            String prefix = getPrefix(typeName.getNodeValue());
+
+                            if (prefix != null) {
+                                String ns = (String) wsdl4jDefinition.getNamespaces().get(prefix);
+                                if (ns != null) {
+                                    Node formatType = attributes.getNamedItem("formatType");
+                                    typeMapper.put(new QName(ns, getTypeName(
+                                            typeName.getNodeValue())), formatType.getNodeValue());
+                                }
 
-                } else {
+                            }
+                        }
+                    }
+                } else if (wsdl4jExtensibilityElement.getElementType() != null &&
+                        wsdl4jExtensibilityElement.getElementType().getNamespaceURI().equals(
+                                org.apache.axis2.namespace.Constants.JAVA_NS)) {
+                    Element unknowJavaElement = unknown.getElement();
+                    if (unknowJavaElement.getLocalName().equals("address") ) {
+                        NamedNodeMap nameAttributes = unknowJavaElement.getAttributes();
+                        Node node = nameAttributes.getNamedItem("className");
+                        Parameter serviceClass = new Parameter();
+                        serviceClass.setName("className");
+                        serviceClass.setValue(node.getNodeValue());
+                        axisService.addParameter(serviceClass);
+                        Parameter transportName = new Parameter();
+                        transportName.setName("TRANSPORT_NAME");
+                        transportName.setValue("java");
+                        axisService.addParameter(transportName);
+                    }
+                }  else {
                     // Ignore this element - it is a totally unknown element
                     if (isTraceEnabled) {
                         log.trace("copyExtensibleElements:: Unknown Extensibility Element found " +
@@ -2695,4 +2736,34 @@
 //            }
 //        }
 //    }
+
+    /**
+     * This method is to split attribute like abc:cde and get the prefix part of it
+     * so the method will retuen abc if the ":" is present in the the string else it
+     * will return null
+     *
+     * @param attributeValue  : String
+     * @return String
+     */
+    public static String getPrefix(String attributeValue) {
+        if (attributeValue != null) {
+            int splitIdex = attributeValue.indexOf(':');
+            if (splitIdex > 0) {
+                return attributeValue.substring(0, splitIdex);
+            }
+        }
+        return null;
+    }
+
+    public static String getTypeName(String attributeValue) {
+        if (attributeValue != null) {
+            int splitIdex = attributeValue.indexOf(':');
+            if (splitIdex > 0) {
+                return attributeValue.substring(splitIdex + 1);
+            } else {
+                return attributeValue;
+            }
+        }
+        return null;
+    }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/namespace/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/namespace/Constants.java?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/namespace/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/namespace/Constants.java Mon Aug 27 01:58:14 2007
@@ -112,6 +112,8 @@
 
     public static final String URI_POLICY =
             "http://schemas.xmlsoap.org/ws/2004/09/policy";
+    public static final String FORMAT_BINDING = "http://schemas.xmlsoap.org/wsdl/formatbinding/";
+    public static final String JAVA_NS = "http://schemas.xmlsoap.org/wsdl/java/";
     /**
      * WSDL Namespace.
      */

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/TransportHeadersTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/TransportHeadersTest.java?rev=570044&r1=570043&r2=570044&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/TransportHeadersTest.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/TransportHeadersTest.java Mon Aug 27 01:58:14 2007
@@ -133,6 +133,23 @@
         headers.put("header3", "h3Value");
     }
 
+
+    public int getRemotePort() {
+        return 0;
+    }
+
+    public String getLocalAddr() {
+        return null;
+    }
+
+    public String getLocalName() {
+        return null;
+    }
+
+    public int getLocalPort() {
+        return 0;
+    }
+
     public String getAuthType() {
         return null;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org