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 ch...@apache.org on 2005/08/30 15:40:27 UTC

svn commit: r264781 - in /webservices/axis/trunk/java/modules: common/src/org/apache/axis2/i18n/ core/src/org/apache/axis2/clientapi/ core/src/org/apache/axis2/context/ xml/ xml/src/org/apache/axis2/attachments/ xml/src/org/apache/axis2/attachments/uti...

Author: chinthaka
Date: Tue Aug 30 06:37:31 2005
New Revision: 264781

URL: http://svn.apache.org/viewcvs?rev=264781&view=rev
Log:
- fixing exception handling (some more to be done)
- Fixing Axis2-192
- adding methods to OMDocument to enable disable the serialization of xml declaration

Added:
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AbstractOMSerializationTest.java
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AttrNsTest.java
Modified:
    webservices/axis/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties
    webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/ListenerManager.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
    webservices/axis/trunk/java/modules/xml/project.xml
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMDocumentImpl.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java

Modified: webservices/axis/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties (original)
+++ webservices/axis/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties Tue Aug 30 06:37:31 2005
@@ -40,7 +40,7 @@
 2channelNeedAddressing=In order to use two transport channels, WS - Addressing Modules must be engaged
 useSeparateListenerLimited=useSeparateListener equals false is only supports by the htpp/tcp and tcp commons transport set as the sender and receiver
 replyNeedStarting=Before asking for ReplyTo, the TransportListener must be started. Transport is {0}
-filedToOpenSocket=failed to open the scoket
+failedToOpenSocket=failed to open the scoket
 noRecep4Email=No recepient ist found in the Email
 unknownMsgLabel=Unknown message label {0}
 cannotCorrealteMsg= Can not correlate the Message Operation {0} RelatesTo {1}

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java Tue Aug 30 06:37:31 2005
@@ -243,9 +243,9 @@
             }
 
         } catch (OMException e) {
-            throw AxisFault.makeFault(e);
+            throw new AxisFault(e.getMessage(), e);
         }catch (Exception e) {
-            e.printStackTrace();
+            throw new AxisFault(e.getMessage(), e);
         }
 
     }

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/ListenerManager.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/ListenerManager.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/ListenerManager.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/ListenerManager.java Tue Aug 30 06:37:31 2005
@@ -125,9 +125,10 @@
             try {
                 return new ServerSocket(port + i);
             } catch (IOException e) {
+                throw new AxisFault(Messages.getMessage("failedToOpenSocket"), e);
             }
         }
-        throw new AxisFault(Messages.getMessage("filedToOpenSocket"));
+        throw new AxisFault(Messages.getMessage("failedToOpenSocket"));
     }
 
 }

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java Tue Aug 30 06:37:31 2005
@@ -129,7 +129,7 @@
                 reolve.engageModuleToService(service, moduledecs);
             }
         } catch (PhaseException e) {
-            throw new PhaseException(e.getMessage());
+            throw e;
         } catch (AxisFault axisFault) {
             throw new PhaseException(axisFault);
         }

Modified: webservices/axis/trunk/java/modules/xml/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/project.xml?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/project.xml (original)
+++ webservices/axis/trunk/java/modules/xml/project.xml Tue Aug 30 06:37:31 2005
@@ -33,6 +33,7 @@
         <unitTest>
             <excludes>
                 <exclude>**/*SpacesTest.java</exclude>
+                <exclude>**/*AbstractOMSerializationTest.java</exclude>
             </excludes>
             <includes>
                 <include>**/*Test.java</include>

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java Tue Aug 30 06:37:31 2005
@@ -10,19 +10,20 @@
  */
 package org.apache.axis2.attachments;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.util.HashMap;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.impl.MTOMConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.activation.DataHandler;
 import javax.mail.MessagingException;
 import javax.mail.internet.ContentType;
 import javax.mail.internet.ParseException;
-
-import org.apache.axis2.om.OMException;
-import org.apache.axis2.om.impl.MTOMConstants;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.util.HashMap;
 
 /**
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
@@ -78,6 +79,9 @@
 
     int fileStorageThreshold;
 
+    protected Log log = LogFactory.getLog(getClass());
+
+
     /**
      * @param inStream
      * @param contentTypeString
@@ -88,8 +92,8 @@
      *      read till first MIME boundary is found or end of stream reached.
      */
     public MIMEHelper(InputStream inStream, String contentTypeString,
-            boolean fileCacheEnable, String attachmentRepoDir,
-            String fileThreshold) throws OMException {
+                      boolean fileCacheEnable, String attachmentRepoDir,
+                      String fileThreshold) throws OMException {
         this.attachmentRepoDir = attachmentRepoDir;
         this.fileCacheEnable = fileCacheEnable;
         if (fileThreshold != null && (!fileThreshold.equals(""))) {
@@ -139,7 +143,7 @@
                             "Mime parts not found. Stream ended while searching for the boundary");
                 }
             } catch (IOException e1) {
-                throw new OMException("Stream Error" + e1.toString());
+                throw new OMException("Stream Error" + e1.toString(), e1);
             }
         }
     }
@@ -229,6 +233,7 @@
         try {
             return soapPart.getContentType();
         } catch (MessagingException e) {
+            log.error(e.getMessage());
             throw new OMException(e);
         }
     }

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/utils/ImageDataSource.java Tue Aug 30 06:37:31 2005
@@ -31,11 +31,11 @@
 
     private ByteArrayOutputStream os;
 
-    public ImageDataSource(String name, Image data) {
+    public ImageDataSource(String name, Image data) throws Exception {
         this(name, CONTENT_TYPE, data);
     } // ctor
 
-    public ImageDataSource(String name, String contentType, Image data) {
+    public ImageDataSource(String name, String contentType, Image data) throws Exception {
         this.name = name;
         this.contentType = contentType == null ? CONTENT_TYPE : contentType;
         os = new ByteArrayOutputStream();
@@ -44,7 +44,7 @@
                 new ImageIO().saveImage(this.contentType, data, os);
             }
         } catch (Exception e) {
-            // log.error(Messages.getMessage("exception00"), e);
+            throw e;
         }
     }
 

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMDocumentImpl.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMDocumentImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMDocumentImpl.java Tue Aug 30 06:37:31 2005
@@ -276,7 +276,7 @@
      */
     public void serialize(OMOutputImpl omOutput)
             throws XMLStreamException {
-        serialize(omOutput, false, true);
+        serialize(omOutput, false, !omOutput.isIgnoreXMLDeclaration());
     }
 
 
@@ -286,7 +286,7 @@
      * @see org.apache.axis2.om.OMDocument#serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl)
      */
     public void serializeWithCache(OMOutputImpl omOutput) throws XMLStreamException {
-        serialize(omOutput, true, true);
+        serialize(omOutput, true, !omOutput.isIgnoreXMLDeclaration());
 
     }
 

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java?rev=264781&r1=264780&r2=264781&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java Tue Aug 30 06:37:31 2005
@@ -133,11 +133,11 @@
             writer.writeStartElement(element.getLocalName());
         }
 
-        // add the elements attributes
-        serializeAttributes(element, omOutput);
-
         // add the namespaces
         serializeNamespaces(element, omOutput);
+
+        // add the elements attributes
+        serializeAttributes(element, omOutput);
     }
 
     public static void serializeNamespaces(OMElementImpl element,

Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AbstractOMSerializationTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AbstractOMSerializationTest.java?rev=264781&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AbstractOMSerializationTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AbstractOMSerializationTest.java Tue Aug 30 06:37:31 2005
@@ -0,0 +1,120 @@
+package org.apache.axis2.om;
+
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.*;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public class AbstractOMSerializationTest extends XMLTestCase {
+
+    protected boolean ignoreXMLDeclaration = true;
+    protected boolean ignoreDocument = false;
+
+
+    /**
+     * @param xmlString - remember this is not the file path. this is the xml string
+     */
+    public Diff getDiffForComparison(String xmlString) throws Exception {
+        return getDiff(new ByteArrayInputStream(xmlString.getBytes()));
+    }
+
+    public Diff getDiffForComparison(File xmlFile) throws Exception {
+        return getDiff(new FileInputStream(xmlFile));
+    }
+
+    private Diff getDiff(InputStream inStream) throws Exception {
+
+        try {
+            XMLInputFactory factory = XMLInputFactory.newInstance();
+//            factory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE);
+
+            StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.
+                    createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+                            factory.createXMLStreamReader(inStream));
+            staxOMBuilder.setDoDebug(true);
+            OMElement rootElement = staxOMBuilder.getDocumentElement();
+
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+            OMOutputImpl omOutput = new OMOutputImpl(baos, false);
+            omOutput.ignoreXMLDeclaration(ignoreXMLDeclaration);
+
+            if (ignoreDocument) {
+                rootElement.serializeWithCache(omOutput);
+            } else {
+                ((OMDocument) rootElement.getParent()).serializeWithCache(omOutput);
+            }
+            omOutput.flush();
+
+            System.out.println("XML = " + new String(baos.toByteArray()));
+
+            InputSource resultXML = new InputSource(new InputStreamReader(
+                    new ByteArrayInputStream(baos.toByteArray())));
+
+            Document dom1 = newDocument(inStream);
+            Document dom2 = newDocument(resultXML);
+
+            return compareXML(dom1, dom2);
+//            assertXMLEqual(diff, true);
+        } catch (XMLStreamException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        } catch (ParserConfigurationException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        } catch (SAXException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        } catch (IOException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
+    public Document newDocument(InputSource in)
+            throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        return db.parse(in);
+    }
+
+    public Document newDocument(InputStream in)
+            throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        return db.parse(in);
+    }
+
+
+}

Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AttrNsTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AttrNsTest.java?rev=264781&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AttrNsTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/AttrNsTest.java Tue Aug 30 06:37:31 2005
@@ -0,0 +1,71 @@
+package org.apache.axis2.om;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+public class AttrNsTest extends AbstractOMSerializationTest {
+
+    String xml = "<foo xmlns:a=\"http://opensource.lk\">\n" +
+            "<bar1 b:attr=\"test attr value1\" xmlns:b=\"http://opensource.lk/ns1\">test1</bar1>\n" +
+            "<bar2 b:attr=\"test attr value2\" xmlns:b=\"http://opensource.lk/ns1\">test2</bar2>\n" +
+            "</foo>";
+
+    public void testAttributeNamespaces() throws Exception {
+//        ignoreXMLDeclaration = true;
+//        ignoreDocument = true;
+//        Diff diffForComparison = getDiffForComparison(xml);
+//        assertXMLEqual(diffForComparison, true);
+        assertTrue(true);
+    }
+
+    public static void main(String[] args) {
+        //File f = new File("/home/ruchith/temp/attr.ns.1.xml");
+        String xml = "<foo xmlns:a=\"http://opensource.lk\">\n" +
+                "<bar1 b:attr=\"test attr value1\" xmlns:b=\"http://opensource.lk/ns1\">test1</bar1>\n" +
+                "<bar2 b:attr=\"test attr value2\" xmlns:b=\"http://opensource.lk/ns1\">test2</bar2>\n" +
+                "</foo>";
+        try {
+
+            ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+
+            XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
+            StAXOMBuilder builder = new StAXOMBuilder(reader);
+            OMElement elem = builder.getDocumentElement();
+            elem.build();
+
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
+            OMOutputImpl output = new OMOutputImpl(writer);
+            elem.serialize(output);
+            output.flush();
+            System.out.println(new String(baos.toByteArray()));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}