axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r557641 - in /webservices/axis2/trunk/java/modules: kernel/src/org/apache/axis2/dataretrieval/ mex/src/org/apache/axis2/mex/ mex/src/org/apache/axis2/mex/om/
Date Thu, 19 Jul 2007 14:33:07 GMT
Author: sanka
Date: Thu Jul 19 07:33:06 2007
New Revision: 557641

URL: http://svn.apache.org/viewvc?view=rev&rev=557641
Log:
Fixed: 

WSDLDataLocator, SchemaDataLocator to provide Metadata with the correct 
Identifire.

Fixed the fromOM(OMElement) method of Metadata and MetadataSection classes
to check for the QName with the correct namespace.



Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/SchemaDataLocator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/Metadata.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/MetadataSection.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/SchemaDataLocator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/SchemaDataLocator.java?view=diff&rev=557641&r1=557640&r2=557641
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/SchemaDataLocator.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/SchemaDataLocator.java
Thu Jul 19 07:33:06 2007
@@ -19,13 +19,40 @@
 
 package org.apache.axis2.dataretrieval;
 
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.util.XMLUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.commons.schema.XmlSchema;
+
 /**
- * Axis 2 Data Locator responsibles for retrieving Schema metadata.
- * The class is created as model for schema specific data locator; and also
- * easier for any future implementation schema specific data retrieval logic.
+ * Axis 2 Data Locator responsibles for retrieving Schema metadata. The class is
+ * created as model for schema specific data locator; and also easier for any
+ * future implementation schema specific data retrieval logic.
  */
 
-public class SchemaDataLocator extends BaseAxisDataLocator implements AxisDataLocator {
+public class SchemaDataLocator extends BaseAxisDataLocator implements
+        AxisDataLocator {
+
+    private String requestIdentifier = null;
+
+    private String serviceEPR = null;
+
+    /**
+     * 
+     */
+    private static final Log LOG = LogFactory.getLog(SchemaDataLocator.class
+            .getClass().getName());
 
     protected SchemaDataLocator() {
 
@@ -38,4 +65,83 @@
         dataList = data;
     }
 
+    public Data[] getData(DataRetrievalRequest request,
+            MessageContext msgContext) throws DataRetrievalException {
+
+        requestIdentifier = request.getIdentifier();
+        serviceEPR = msgContext.getTo().getAddress();
+
+        OutputForm outputForm = request.getOutputForm();
+        if (outputForm == null) {
+            outputForm = OutputForm.INLINE_FORM;
+        }
+
+        Data[] data;
+
+        if (outputForm == OutputForm.INLINE_FORM) {
+            data = outputInlineForm(msgContext, dataList);
+
+        } else if (outputForm == OutputForm.LOCATION_FORM) {
+            data = outputLocationForm(dataList);
+
+        } else {
+            data = outputReferenceForm(msgContext, dataList);
+        }
+
+        return data;
+    }
+
+    protected Data[] outputInlineForm(MessageContext msgContext,
+            ServiceData[] serviceData) throws DataRetrievalException {
+
+        Data[] data = super.outputInlineForm(msgContext, serviceData);
+
+        if (data.length != 0) {
+            return data;
+        }
+
+        AxisService axisService = msgContext.getAxisService();
+        ArrayList schemaList = axisService.getSchema();
+
+        ArrayList results = new ArrayList();
+        XmlSchema schema;
+
+        for (Iterator iterator = schemaList.iterator(); iterator.hasNext();) {
+            schema = (XmlSchema) iterator.next();
+
+            if (requestIdentifier != null) {
+                if (requestIdentifier.equals(schema.getTargetNamespace())) {
+                    results.add(new Data(convertToOM(schema), requestIdentifier));
+                }
+            } else {
+                results.add(new Data(convertToOM(schema), null));
+            }
+        }
+
+        return (Data[]) results.toArray(new Data[results.size()]);
+    }
+
+    protected Data[] outputLocationForm(ServiceData[] serviceData)
+            throws DataRetrievalException {
+
+        Data[] data = super.outputLocationForm(serviceData);
+
+        if (data != null && data.length != 0) {
+            return data;
+        }
+        return new Data[] { new Data(serviceEPR + "?xsd", requestIdentifier) };
+    }
+
+    private OMNode convertToOM(XmlSchema schema) throws DataRetrievalException {
+        StringWriter writer = new StringWriter();
+        schema.write(writer);
+
+        StringReader reader = new StringReader(writer.toString());
+        try {
+            return XMLUtils.toOM(reader);
+        } catch (XMLStreamException e) {
+            throw new DataRetrievalException(
+                    "Can't convert XmlSchema object to an OMElement", e);
+        }
+    }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java?view=diff&rev=557641&r1=557640&r2=557641
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java
Thu Jul 19 07:33:06 2007
@@ -58,6 +58,7 @@
         log.trace("Default WSDL DataLocator getData starts");
 
         request_Identifier = request.getIdentifier();
+        serviceURL = msgContext.getTo().getAddress();
 
         OutputForm outputform = request.getOutputForm();
 
@@ -109,7 +110,8 @@
         // (1) this is to support ?wsdl request; 
         // (2) Data for specified Identifier must be available to satisfy the GetMetadata
request.
 
-        if (result.length == 0 && request_Identifier == null) {
+        if (result.length == 0) {
+            
             log.trace("Default WSDL DataLocator attempt to generates WSDL.");
 
             if (msgContext != null) {
@@ -119,24 +121,28 @@
                 throw new DataRetrievalException("MessageContext was not set!");
             }
 
-            AxisService2WSDL11 axisService2WOM;
-            OMElement wsdlElement;
+            if (request_Identifier == null || request_Identifier.equals(theService.getTargetNamespace()))
{
 
-            try {
-                axisService2WOM = new AxisService2WSDL11(theService);
-                wsdlElement = axisService2WOM.generateOM();
-            }
-            catch (Exception e) {
-                log.debug(e);
-                throw new DataRetrievalException(e);
-            }
+                AxisService2WSDL11 axisService2WOM;
+                OMElement wsdlElement;
 
-            if (wsdlElement != null) {
-                log.trace("Default WSDL DataLocator successfully generated WSDL.");
-                result = new Data[1];
-                result[0] = new Data(wsdlElement, null);
+                try {
+                    axisService2WOM = new AxisService2WSDL11(theService);
+                    wsdlElement = axisService2WOM.generateOM();
+                    
+                } catch (Exception e) {
+                    log.debug(e);
+                    throw new DataRetrievalException(e);
+                }
+
+                if (wsdlElement != null) {
+                    log.trace("Default WSDL DataLocator successfully generated WSDL.");
+                    result = new Data[1];
+                    result[0] = new Data(wsdlElement, null);
+                }
             }
         }
+        
         return result;
     }
 

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java?view=diff&rev=557641&r1=557640&r2=557641
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java
(original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java
Thu Jul 19 07:33:06 2007
@@ -33,13 +33,13 @@
 import org.apache.axis2.dataretrieval.OutputForm;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
-import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
 import org.apache.axis2.mex.om.Location;
 import org.apache.axis2.mex.om.Metadata;
 import org.apache.axis2.mex.om.MetadataReference;
 import org.apache.axis2.mex.om.MetadataSection;
 import org.apache.axis2.mex.om.MexOMException;
 import org.apache.axis2.mex.util.MexUtil;
+import org.apache.axis2.receivers.AbstractInOutMessageReceiver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -49,7 +49,7 @@
  * Message Receiver for processing WS-MEX GetMetadata request. 
  *
  */
-public class MexMessageReceiver extends AbstractInOutSyncMessageReceiver {
+public class MexMessageReceiver extends AbstractInOutMessageReceiver {
 	private static final Log log = LogFactory.getLog(MexMessageReceiver.class);
 	Parameter axisConfigMEXParm = null;
     Parameter serviceConfigMEXParm = null;
@@ -113,8 +113,10 @@
 		OMElement aReq = body.getFirstChildWithName(new QName(
                 MexConstants.Spec_2004_09.NS_URI,
 				MexConstants.SPEC.GET_METADATA));
+        
 		List metadata_request_list;
 		if (aReq != null) {
+            mexNamespaceValue = MexConstants.Spec_2004_09.NS_URI;
 			metadata_request_list = determineMetadataTypes(aReq);
 
 		} else {
@@ -136,27 +138,32 @@
 	
 	public Metadata processRequest(List metadata_request_list,
 			MessageContext msgContext, OMElement aReq) throws MexException {
-			
-		String identifier_value = null;
 		
+	    //  Instantiate Metadata instance to build the WS-Mex Metadata element
+        SOAPEnvelope envelope = msgContext.getEnvelope();
+        String soapNamespaceURI = envelope.getNamespace().getNamespaceURI();
+        SOAPFactory factory = MexUtil.getSOAPFactory(soapNamespaceURI);
+        
+        Metadata metadata = new Metadata(factory, mexNamespaceValue);
 		DataRetrievalRequest requestOptions = new DataRetrievalRequest();
+        
+        String identifier_value = null;
 		// Check if Identifier element included in request
-		OMElement identifier = aReq.getFirstChildWithName(new QName(
-				MexConstants.SPEC.IDENTIFIER));
-		if (identifier != null) {
-			identifier_value = identifier.getText();
-			if (identifier_value != null && identifier_value.length() > 0) {
-				requestOptions.putIdentifier(identifier_value);
-			}
-		}
-
-		// Instantiate Metadata instance to build the WS-Mex Metadata element
-		SOAPEnvelope envelope = msgContext.getEnvelope();
-		String soapNamespaceURI = envelope.getNamespace().getNamespaceURI();
-		SOAPFactory factory = MexUtil.getSOAPFactory(soapNamespaceURI);
-		mexNamespaceValue = MexConstants.Spec_2004_09.NS_URI;
-		Metadata metadata = new Metadata(factory, mexNamespaceValue);
-
+        OMElement dialectElem = aReq.getFirstChildWithName(new QName(
+                mexNamespaceValue, MexConstants.SPEC.DIALECT));
+        
+        if (dialectElem != null)  {
+    		OMElement identifier = dialectElem.getFirstChildWithName(new QName(
+                    mexNamespaceValue, MexConstants.SPEC.IDENTIFIER));
+            
+    		if (identifier != null) {
+    			identifier_value = identifier.getText();
+    			if (identifier_value != null && identifier_value.length() > 0) {
+    				requestOptions.putIdentifier(identifier_value);
+    			}
+    		}
+        }
+        
 		// Process the request and append MetadataSection to Metadata
 		// Loop through the metadata_request_list for Dialect(s)), and setup requestOptions.
 		// Basically, one requestOptions is setup for each supported outputForm for the Dialect
@@ -165,7 +172,8 @@
 		OutputForm[] outputforms;
 		
 		for (int i = 0; i < len; i++) { // metadata request
-			String dialect = "";
+
+            String dialect = "";
 			try {
 				dialect = (String) metadata_request_list.get(i);
 
@@ -195,6 +203,7 @@
 			} catch (Throwable e) {
 				
 				log.error("Throwable detected for dialect, " + dialect , e);
+                e.printStackTrace();
 
 				throw new MexException(e);
 			}
@@ -275,16 +284,18 @@
 
 		boolean allTypes = false;
 
-		OMElement dialect = aReq.getFirstChildWithName(new QName(
+		OMElement dialect = aReq.getFirstChildWithName(new QName(mexNamespaceValue,
 				MexConstants.SPEC.DIALECT));
 		if (dialect != null) {
 			String dialectText = dialect.getText();
 			if (dialectText != null && dialectText.length() > 0) {
 				metadata_request_list.add(dialectText.trim());
-			} else
+			} else {
 				allTypes = true;
-		} else
+            }
+		} else {
 			allTypes = true;
+        }
 
 		if (allTypes) { // retrieve all metadata
 			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_POLICY);

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/Metadata.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/Metadata.java?view=diff&rev=557641&r1=557640&r2=557641
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/Metadata.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/Metadata.java Thu
Jul 19 07:33:06 2007
@@ -165,7 +165,7 @@
 	  if (aFactory == null) {
 	     aFactory = factory;
 	   }
-	   Iterator mexSections = mexElement.getChildrenWithName(new QName(MexConstants.SPEC.METADATA_SECTION));
+	   Iterator mexSections = mexElement.getChildrenWithName(new QName(namespaceValue, MexConstants.SPEC.METADATA_SECTION));
         
            if (mexSections == null){
          	throw new MexOMException("Metadata element does not contain MetadataSection element.");

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/MetadataSection.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/MetadataSection.java?view=diff&rev=557641&r1=557640&r2=557641
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/MetadataSection.java
(original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/om/MetadataSection.java
Thu Jul 19 07:33:06 2007
@@ -101,7 +101,7 @@
 			setIdentifier(identifierAttr.getAttributeValue());		
 		}
 		// validate one of the following element must exist: Location, MetadataReference, inline
data
-		OMElement locationElem = element.getFirstChildWithName(new QName(MexConstants.SPEC.LOCATION));
+		OMElement locationElem = element.getFirstChildWithName(new QName(namespaceValue, MexConstants.SPEC.LOCATION));
 		Location location = null;
 		MetadataReference ref = null;
 		
@@ -110,7 +110,7 @@
 		    setLocation(location.fromOM(locationElem));	
 		}
 		else { // check for MetadataReference
-			OMElement refElem = element.getFirstChildWithName(new QName(MexConstants.SPEC.METADATA_REFERENCE));
+			OMElement refElem = element.getFirstChildWithName(new QName(namespaceValue, MexConstants.SPEC.METADATA_REFERENCE));
 			if (refElem != null ){
 				ref = new MetadataReference(factory, namespaceValue);
 				setMetadataReference(ref.fromOM(refElem));



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


Mime
View raw message