axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r513354 [2/2] - in /webservices/axis2/trunk/java/modules: saaj-api/src/javax/xml/soap/ saaj/src/org/apache/axis2/saaj/ saaj/test/org/apache/axis2/saaj/
Date Thu, 01 Mar 2007 14:49:46 GMT
Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java?view=diff&rev=513354&r1=513353&r2=513354
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java
Thu Mar  1 06:49:44 2007
@@ -22,6 +22,13 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+
 import com.sun.mail.util.BASE64EncoderStream;
 
 public class AttachmentTest extends TestCase {
@@ -304,36 +311,66 @@
 			SOAPMessage msg = factory.createMessage();
 			AttachmentPart ap = msg.createAttachmentPart();
 
-			URL url = new URL("http://ws.apache.org/images/project-logo.jpg");
-			DataHandler dh = new DataHandler(url);
-			//Create InputStream from DataHandler's InputStream
-			InputStream is = dh.getInputStream();
-
-			//Setting Content via InputStream for image/jpeg mime type
-			ByteArrayOutputStream bos = new ByteArrayOutputStream();
-			OutputStream ret = new BASE64EncoderStream(bos);
-			int count;
-			byte buf[] = new byte[8192];
-			while ((count = is.read(buf, 0, 8192)) != -1) {
-				ret.write(buf, 0, count);
-			}
-			ret.flush();
-			buf = bos.toByteArray();
-			InputStream stream = new ByteArrayInputStream(buf);
-			ap.setBase64Content(stream,"image/jpeg");
-
-			//Getting Content.. should return InputStream object
-			InputStream r = ap.getBase64Content();
-			if(r != null) {
-				if(r instanceof InputStream){
-					//InputStream object was returned (ok)
-				}else {
-					fail("Unexpected object was returned");
+			String urlString = "http://ws.apache.org/images/project-logo.jpg";
+			if(isNetworkedResourceAvailable(urlString)){
+				URL url = new URL(urlString);
+				DataHandler dh = new DataHandler(url);
+				//Create InputStream from DataHandler's InputStream
+				InputStream is = dh.getInputStream();
+
+				//Setting Content via InputStream for image/jpeg mime type
+				ByteArrayOutputStream bos = new ByteArrayOutputStream();
+				OutputStream ret = new BASE64EncoderStream(bos);
+				int count;
+				byte buf[] = new byte[8192];
+				while ((count = is.read(buf, 0, 8192)) != -1) {
+					ret.write(buf, 0, count);
 				}
+				ret.flush();
+				buf = bos.toByteArray();
+				InputStream stream = new ByteArrayInputStream(buf);
+				ap.setBase64Content(stream,"image/jpeg");
+
+				//Getting Content.. should return InputStream object
+				InputStream r = ap.getBase64Content();
+				if(r != null) {
+					if(r instanceof InputStream){
+						//InputStream object was returned (ok)
+					}else {
+						fail("Unexpected object was returned");
+					}
+				}				
 			}
 		} catch(Exception e) {
 			fail("Exception: " + e);
 		}
+	}
+	
+	private boolean isNetworkedResourceAvailable(String url){
+		HttpClient client = new HttpClient();
+		GetMethod method = new GetMethod(url);
+
+		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
+				new DefaultHttpMethodRetryHandler(3, false));
+
+		try {
+			int statusCode = client.executeMethod(method);
+			if (statusCode != HttpStatus.SC_OK) {
+				//System.err.println("Method failed: " + method.getStatusLine());
+				return false;
+			}
+			byte[] responseBody = method.getResponseBody();
+
+		} catch (HttpException e) {
+			e.printStackTrace();
+			return false;
+		} catch (IOException e) {
+			e.printStackTrace();
+			return false;	      
+		} finally {
+			method.releaseConnection();
+		} 		
+		return true;
 	}
 
 }

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java?view=diff&rev=513354&r1=513353&r2=513354
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
Thu Mar  1 06:49:44 2007
@@ -124,7 +124,7 @@
         MessageFactory mf = MessageFactory.newInstance();
         final ByteArrayInputStream baIS = new ByteArrayInputStream(XML_STRING.getBytes());
         final MimeHeaders mimeheaders = new MimeHeaders();
-        mimeheaders.addHeader("Content-Type", "multipart/related");
+        mimeheaders.addHeader("Content-Type", "text/xml");
         SOAPMessage smsg =
                 mf.createMessage(mimeheaders, baIS);
 

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java?view=diff&rev=513354&r1=513353&r2=513354
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java
Thu Mar  1 06:49:44 2007
@@ -204,8 +204,8 @@
     		assertNotNull(reason);
     		assertTrue(reason.contains("This is the fault reason."));
     		assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
-    	} catch(UnsupportedOperationException e) {
-    		//Caught expected UnsupportedOperationException
+    	} catch(SOAPException e) {
+    		//Caught expected SOAPException
     	} catch(Exception e) {
     		fail("Exception: " + e);
     	}

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java?view=diff&rev=513354&r1=513353&r2=513354
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
Thu Mar  1 06:49:44 2007
@@ -29,14 +29,17 @@
 import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.Name;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPConnection;
 import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 import javax.xml.transform.stream.StreamSource;
@@ -242,7 +245,7 @@
 			URL url4 = new URL("http://localhost:8080/SOAPMessage/attach.html");
 			URL url5 = new URL("http://localhost:8080/SOAPMessage/attach.jpeg");
 
-			System.out.println("Add various mime type attachments to SOAP message");
+			//Add various mime type attachments to SOAP message
 			AttachmentPart ap1 = msg.createAttachmentPart(new DataHandler(url1));
 			AttachmentPart ap2 = msg.createAttachmentPart(new DataHandler(url2));
 			AttachmentPart ap3 = msg.createAttachmentPart(new DataHandler(url3));
@@ -299,12 +302,11 @@
 	/*
 	 * Do not add this test unless below mentioned resources are accessible
 	 */
-	public void _testGetAttachmentByHREF2(){
+	public void testGetAttachmentByHREF2(){
 		String NS_PREFIX="mypre";
 		String NS_URI="http://myuri.org/";
 
 		try {
-			System.out.println("Create SOAP message from message factory");
 			MessageFactory fac = MessageFactory.newInstance();
 			SOAPMessage msg = fac.createMessage();
 
@@ -394,6 +396,199 @@
 			fail("Exception: " + e);
 		}
 	}
+	
+	public void testMessageCreation(){
+		try {
+			final String NS_PREFIX = "ns-prefix";
+		    final String NS_URI = "ns-uri";
+		    			
+			MessageFactory fac = MessageFactory.newInstance();
+			SOAPMessage msg = fac.createMessage();
+
+		    SOAPPart sp = msg.getSOAPPart();
+		    SOAPEnvelope envelope = sp.getEnvelope();
+            SOAPHeader hdr = envelope.getHeader();
+            SOAPBody bdy = envelope.getBody();
+
+		    SOAPElement se = hdr.addHeaderElement(
+	            	envelope.createName("Header1", NS_PREFIX, NS_URI))
+	            .addTextNode("This is Header1");
+		    SOAPHeaderElement she = (SOAPHeaderElement) se;
+		    she.setMustUnderstand(true);
+
+		    se = hdr.addHeaderElement(
+	            	envelope.createName("Header2", NS_PREFIX, NS_URI))
+	            .addTextNode("This is Header2");
+		    she = (SOAPHeaderElement) se;
+		    she.setMustUnderstand(false);
+
+		    se = hdr.addHeaderElement(
+	            	envelope.createName("Header3", NS_PREFIX, NS_URI))
+	            .addTextNode("This is Header3");
+		    she = (SOAPHeaderElement) se;
+		    she.setMustUnderstand(true);
+
+		    se = hdr.addHeaderElement(
+	            	envelope.createName("Header4", NS_PREFIX, NS_URI))
+	            .addTextNode("This is Header4");
+		    she = (SOAPHeaderElement) se;
+		    she.setMustUnderstand(false);
+	        
+            SOAPBodyElement sbe = bdy.addBodyElement(
+			envelope.createName("Body1", NS_PREFIX, NS_URI));
+	        
+            sbe.addChildElement(envelope.createName(
+			"Child1", NS_PREFIX, NS_URI)).addTextNode("This is Child1");
+            sbe.addChildElement(envelope.createName(
+			"Child2", NS_PREFIX, NS_URI)).addTextNode("This is Child2");
+	        
+
+            URL url1 = new URL("http://localhost:8080/SOAPMessage/attach.xml");	        
   
+            AttachmentPart ap = msg.createAttachmentPart(new DataHandler(url1));
+            ap.setContentType("text/xml");
+            msg.addAttachmentPart(ap);
+		    msg.saveChanges();
+
+		    // Create a url endpoint for the recipient of the message.
+		    URL urlEndpoint = new URL("http://localhost:8080/ReceivingSOAP11Servlet");
+
+		    // Send the message to the endpoint using the connection.
+		    SOAPConnection con = new SOAPConnectionImpl();
+		    SOAPMessage replymsg = con.call(msg, urlEndpoint);
+
+		    // Check if reply message
+		    if(ValidateReplyMessage(replymsg, 1)) {
+		        //TestUtil.logMsg("Reply message is correct (PASSED)");
+		    } else {
+			    //TestUtil.logErr("Reply message is incorrect (FAILED)");
+		    }
+
+		} catch(Exception e) {
+		    System.err.println("SendSyncReqRespMsgTest2 Exception: " + e);
+	            e.printStackTrace(System.err);
+		}
+	}
+	
+    private boolean ValidateReplyMessage(SOAPMessage msg, int num) 
+    {
+	try {
+	    boolean pass = true;
+	    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+
+	    boolean foundHeader1 = false;
+	    boolean foundHeader2 = false;
+	    boolean foundHeader3 = false;
+	    boolean foundHeader4 = false;
+	    Iterator i = envelope.getHeader().examineAllHeaderElements();
+	    while(i.hasNext()) {
+		SOAPElement se = (SOAPElement)i.next();
+		Name name = se.getElementName();
+		String value = se.getValue();
+		if(value == null || name == null) 
+		    continue;
+		else if(value.equals("This is Header1") 
+				&& name.getLocalName().equals("Header1"))
+		    foundHeader1 = true;
+		else if(value.equals("This is Header2") 
+				&& name.getLocalName().equals("Header2"))
+		    foundHeader2 = true;
+		else if(value.equals("This is Header3") 
+				&& name.getLocalName().equals("Header3"))
+		    foundHeader3 = true;
+		else if(value.equals("This is Header4") 
+				&& name.getLocalName().equals("Header4"))
+		    foundHeader4 = true;
+	    }
+	    if(!foundHeader1 || !foundHeader2 || 	
+				!foundHeader3 || !foundHeader4) {
+	          //"Did not find expected soap headers in reply message"
+	        pass = false;
+	    } else{
+	          //"Did find expected soap headers in reply message");
+	    }
+	    //TestUtil.logMsg("Verify soap body");
+	    boolean foundBody1 = false;
+	    boolean foundChild1 = false;
+	    boolean foundChild2 = false;
+	    SOAPBody bdy = envelope.getBody();
+	    i = bdy.getChildElements();
+	    while (i.hasNext()) {
+		SOAPBodyElement sbe = (SOAPBodyElement)i.next();
+		Name name = sbe.getElementName();
+		if(name.getLocalName().equals("Body1"))
+		    foundBody1 = true;
+		Iterator c = sbe.getChildElements();
+	        while (c.hasNext()) {
+		    SOAPElement se = (SOAPElement)c.next();
+		    name = se.getElementName();
+		    String value = se.getValue();
+		    if(value.equals("This is Child1") 
+			    && name.getLocalName().equals("Child1"))
+		        foundChild1 = true;
+		    else if(value.equals("This is Child2") 
+			    && name.getLocalName().equals("Child2"))
+		        foundChild2 = true;
+	        }
+	    }
+	    if(!foundBody1) {
+		//TestUtil.logErr("Did not find expected soap body in reply message");
+		pass = false;
+	    } else
+		//TestUtil.logMsg("Did find expected soap body in reply message");
+	    if(!foundChild1 || !foundChild2) {
+		//TestUtil.logErr("Did not find expected soap body " +ild elements in reply message");
+		pass = false;
+	    } else{
+	    	//TestUtil.logMsg("Did find expected soap body child " +
+	    }
+	    //TestUtil.logMsg("Verify attachments");
+	    int count = msg.countAttachments();
+	    if(count == num) {
+		//TestUtil.logMsg("Got expected " + count +" attachments in reply message");
+
+	    	i = msg.getAttachments();
+		boolean gifFound = false;
+		boolean xmlFound = false;
+		boolean textFound = false;
+		boolean htmlFound = false;
+		boolean jpegFound = false;
+		while(i.hasNext()) {
+		    AttachmentPart a = (AttachmentPart)i.next();
+		    String type = a.getContentType();
+		    //TestUtil.logMsg("MIME type of attachment = " + type);
+		    if(type.equals("image/gif"))
+			gifFound = true;
+		    else if(type.equals("text/xml"))
+			xmlFound = true;
+		    else if(type.equals("text/plain"))
+			textFound = true;
+		    else if(type.equals("text/html"))
+			htmlFound = true;
+		    else if(type.equals("image/jpeg"))
+			jpegFound = true;
+		    else {
+			//TestUtil.logErr("Got unexpected MIME type: " + type);
+			pass = false;
+		    }
+		}
+		if(num == 1 && xmlFound) {
+		    //TestUtil.logMsg("Did find expected MIME types in reply message");
+		} else if(num == 3 && xmlFound && jpegFound && textFound) {
+		   // TestUtil.logMsg("Did find expected MIME types in reply message");
+		} else if (num > 0) {
+		    //TestUtil.logErr("Did not find expected MIME types in reply message");
+		    pass = false;
+		}
+		return pass;
+	    } else {
+		//TestUtil.logErr("Got unexpected " + count +" attachments in reply message, expected 5");
+		return false;
+	    }
+	} catch(Exception e) {
+	    return false;
+	}
+    }
+	
 
 }
 

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java?view=diff&rev=513354&r1=513353&r2=513354
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java
Thu Mar  1 06:49:44 2007
@@ -16,6 +16,7 @@
 package org.apache.axis2.saaj;
 
 import java.io.File;
+import java.io.FileReader;
 import java.util.Iterator;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -29,10 +30,15 @@
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 import javax.xml.soap.Text;
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.transform.dom.DOMSource;
 
 import junit.framework.TestCase;
 
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
@@ -44,6 +50,15 @@
     public void testAddSource() {
         DOMSource domSource;
         try {
+        	/*
+            FileReader testFile = new FileReader(new File(System.getProperty("basedir",".")+"/test-resources"
+ File.separator + "soap-part.xml"));
+            StAXOMBuilder stAXOMBuilder =
+                    OMXMLBuilderFactory.createStAXOMBuilder(
+                            OMAbstractFactory.getSOAP11Factory(),
+                            XMLInputFactory.newInstance().createXMLStreamReader(
+                                    testFile));
+            */
+            
             DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             Document document = builder.parse(new File(System.getProperty("basedir",".")+"/test-resources"
+ File.separator + "soap-part.xml"));
             domSource = new DOMSource(document);



---------------------------------------------------------------------
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