axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whitl...@apache.org
Subject cvs commit: xml-axis-wsif/java/test/util WSIFTestRunner.java
Date Mon, 21 Oct 2002 09:48:19 GMT
whitlock    2002/10/21 02:48:19

  Modified:    java/test/proposals/mime MimeTest.java
                        DeploymentDescriptor.xml Mime.wsdl MimeImpl.java
                        Mime.java
               java/test/util WSIFTestRunner.java
  Added:       java/test/proposals/mime WSIFJmsTransport.java
                        WSIFJmsSender.java
  Log:
  Mime fixes
  
  Revision  Changes    Path
  1.3       +96 -24    xml-axis-wsif/java/test/proposals/mime/MimeTest.java
  
  Index: MimeTest.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/MimeTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MimeTest.java	15 Oct 2002 13:55:31 -0000	1.2
  +++ MimeTest.java	21 Oct 2002 09:48:18 -0000	1.3
  @@ -62,6 +62,7 @@
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.util.Arrays;
   
   import javax.activation.DataHandler;
  @@ -77,23 +78,41 @@
   import util.TestUtilities;
   
   /**
  - * Junit test to test out the Mime test
  + * Junit test for Mime attachments
  + * 
  + * There should be tests here for...
  + * DataHandler, DataSource and other datatypes (not sure of the list)
  + * Sync and async
  + * rpc-style and doc-style
  + * Other mime types
  + * Axis and Soap 2.3
  + * Soap Http and Jms
  + * Does this function make sense for NativeJms, Java, EJB, etc?
  + * Sending attachments and receiving them
  + * 
    * @author Mark Whitlock
    */
   public class MimeTest extends TestCase {
       String wsdlLocation =
           TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "Mime.wsdl";
   
  -    private final static String FILE = "file";
  +    private final static String SEND = "SEND";
  +    private final static String RECEIVE = "RECEIVE";
  +
       private final static String filename =
           TestUtilities.getWsdlPath("java\\test\\proposals\\mime") + "test.txt";
   
  +    private final boolean SYNC = true;
  +    private final boolean ASYNC = false;
  +    
       public MimeTest(String name) {
           super(name);
       }
   
       public static void main(String[] args) {
  -        junit.textui.TestRunner.run(suite());
  +	   // TestUtilities.startListeners(TestUtilities.ADDRESSBOOK_LISTENER);	
  +	   junit.textui.TestRunner.run (suite());
  +	   // TestUtilities.stopListeners();	
       }
   
       public static Test suite() {
  @@ -104,11 +123,36 @@
           TestUtilities.setUpExtensionsAndProviders();
       }
   
  -    public void testAxis() {
  -        doit("SOAPPort", FILE);
  +    public void testAxisSendSync() {
  +        doit("SOAPPort", SEND, SYNC);
       }
   
  -    private void doit(String portName, String cmd) {
  +    /*
  +     * Sending MIME messages using Axis over Jms should be supported 
  +     * by WSIF, but currently this does not work. I think the problem
  +     * is that WSIFJmsSender does not set up the necessary headers needed
  +     * for MIME. I don't know whether these headers can go inline in the
  +     * message or whether they will have to go as JMS properties which 
  +     * will then get converted into HTTP headers by the JMS2HTTPBridge.
  +     * For more information about the headers please see 
  +     * org.apache.axis.transport.http.HTTPSender. For the moment I have 
  +     * commented out this Jms test (and omitted other JMS tests like 
  +     * the async tests) because it fails.
  +     *
  +     * public void testAxisJmsSendSync() {
  +     *   doit("SOAPJMSPort", SEND, SYNC);
  +     * }
  +     */
  +
  +//    public void testAxisReceiveSync() {
  +//        doit("SOAPPort", RECEIVE, SYNC);
  +//    }
  +//
  +//    public void testAxisJmsReceiveSync() {
  +//        doit("SOAPJMSPort", RECEIVE, SYNC);
  +//    }
  +//
  +    private void doit(String portName, String cmd, boolean blocking) {
   
           WSIFDynamicProvider_ApacheAxis provider =
               new WSIFDynamicProvider_ApacheAxis();
  @@ -132,8 +176,10 @@
   
               Mime stub = (Mime) service.getStub(portName, Mime.class);
   
  -            if (cmd.equals(FILE))
  -                file(stub);
  +            if (cmd.equals(SEND))
  +                send(stub);
  +            else if (cmd.equals(RECEIVE))
  +                receive(stub);
               else
                   assertTrue(false);
   
  @@ -150,40 +196,66 @@
   
       }
   
  -    private void file(Mime stub) throws Exception {
  +    private void send(Mime stub) throws Exception {
           DataHandler dh = new DataHandler(new FileDataSource(filename));
           String buff = stub.fileToString(dh);
           compareFiles(filename, buff);
       }
   
  -    protected boolean compareFiles(String one, String buff)
  +    private void receive(Mime stub) throws Exception {
  +        String rhyme =
  +            "The owl and the pussy cat went to sea in a beautiful pea-green boat";
  +        DataHandler dh = stub.stringToFile(rhyme);
  +        compareFiles(dh,rhyme);
  +    }
  +
  +    private boolean compareFiles(DataHandler dh, String buff)
           throws FileNotFoundException, IOException {
  +        InputStream is = dh.getInputStream();
  +        boolean success = false;
  +        try {
  +            success = compareFiles(is, buff);
  +        } finally {
  +            if (null != is)
  +                is.close();
  +        }
  +        return success;
  +    }
   
  +    private boolean compareFiles(String one, String buff)
  +        throws FileNotFoundException, IOException {
           BufferedInputStream oneStream = null;
           File f1 = new File(one);
   
  +        boolean success = false;
           try {
               oneStream =
                   new BufferedInputStream(
                       new FileInputStream(one),
                       buff.length());
  -
  -            byte[] bufOne = new byte[buff.length()];
  -            int bread = -1;
  -
  -            if (0 == oneStream.available())
  -                return false;
  -
  -            Arrays.fill(bufOne, (byte) 0);
  -
  -            bread = oneStream.read(bufOne, 0, bufOne.length);
  -            String sOne = new String(bufOne);
  -            if (!sOne.equals(buff))
  -                return false;
  -            return true;
  +            success = compareFiles(oneStream, buff);
           } finally {
               if (null != oneStream)
                   oneStream.close();
           }
  +        return success;
  +    }
  +
  +    private boolean compareFiles(InputStream is, String buff)
  +        throws FileNotFoundException, IOException {
  +
  +        byte[] bufOne = new byte[buff.length()];
  +        int bread = -1;
  +
  +        if (0 == is.available())
  +            return false;
  +
  +        Arrays.fill(bufOne, (byte) 0);
  +
  +        bread = is.read(bufOne, 0, bufOne.length);
  +        String sOne = new String(bufOne);
  +        if (!sOne.equals(buff))
  +            return false;
  +        return true;
       }
   }
  
  
  
  1.2       +1 -1      xml-axis-wsif/java/test/proposals/mime/DeploymentDescriptor.xml
  
  Index: DeploymentDescriptor.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/DeploymentDescriptor.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeploymentDescriptor.xml	15 Oct 2002 13:55:31 -0000	1.1
  +++ DeploymentDescriptor.xml	21 Oct 2002 09:48:18 -0000	1.2
  @@ -2,7 +2,7 @@
                id="http://proposals.mime/">
     <isd:provider type="java"
                   scope="Application"
  -                methods="fileToString">
  +                methods="fileToString stringToFile">
       <isd:java class="proposals.mime.MimeImpl" static="false"/>
     </isd:provider>
   
  
  
  
  1.2       +74 -6     xml-axis-wsif/java/test/proposals/mime/Mime.wsdl
  
  Index: Mime.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/Mime.wsdl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Mime.wsdl	15 Oct 2002 13:55:31 -0000	1.1
  +++ Mime.wsdl	21 Oct 2002 09:48:18 -0000	1.2
  @@ -21,10 +21,12 @@
     <!-- port type declns -->
     <portType name="Mime">
       <operation name="fileToString">
  -      <input name="FileToStringRequest" 
  -             message="tns:FileToStringRequestMessage"/>
  -      <output name="FileToStringResponse" 
  -              message="tns:FileToStringResponseMessage"/>
  +      <input message="tns:FileToStringRequestMessage"/>
  +      <output message="tns:FileToStringResponseMessage"/>
  +    </operation>
  +    <operation name="stringToFile">
  +      <input message="tns:FileToStringResponseMessage"/>
  +      <output message="tns:FileToStringRequestMessage"/>
       </operation>
     </portType>
   
  @@ -34,7 +36,48 @@
                     transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="fileToString">
         <soap:operation soapAction=""/>
  -      <input name="FileToStringRequest">
  +      <input>
  +        <mime:multipartRelated>
  +          <mime:part>
  +            <mime:content part="file" type="text/html"/>
  +            <soap:body use="encoded"
  +                       namespace="http://proposals.mime/"
  +                       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +          </mime:part>
  +        </mime:multipartRelated> 
  +      </input>
  +      <output>
  +        <soap:body use="encoded"
  +                   namespace="http://proposals.mime/"
  +                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +      </output>
  +    </operation>
  +    <operation name="stringToFile">
  +      <soap:operation soapAction=""/>
  +      <input>
  +        <soap:body use="encoded"
  +                   namespace="http://proposals.mime/"
  +                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +      </input>
  +      <output>
  +        <mime:multipartRelated>
  +          <mime:part>
  +            <mime:content part="file" type="text/html"/>
  +            <soap:body use="encoded"
  +                       namespace="http://proposals.mime/"
  +                       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +          </mime:part>
  +        </mime:multipartRelated> 
  +      </output>
  +    </operation>
  +  </binding>
  +
  +  <binding name="SOAPJmsBinding" type="tns:Mime">
  +    <soap:binding style="rpc"
  +                  transport="http://schemas.xmlsoap.org/soap/jms"/>
  +    <operation name="fileToString">
  +      <soap:operation soapAction=""/>
  +      <input>
           <mime:multipartRelated>
             <mime:part>
               <mime:content part="file" type="text/html"/>
  @@ -44,18 +87,43 @@
             </mime:part>
           </mime:multipartRelated> 
         </input>
  -      <output name="FileToStringResponse">
  +      <output>
           <soap:body use="encoded"
                      namespace="http://proposals.mime/"
                      encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
         </output>
       </operation>
  +    <operation name="stringToFile">
  +      <soap:operation soapAction=""/>
  +      <input>
  +        <soap:body use="encoded"
  +                   namespace="http://proposals.mime/"
  +                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +      </input>
  +      <output>
  +        <mime:multipartRelated>
  +          <mime:part>
  +            <mime:content part="file" type="text/html"/>
  +            <soap:body use="encoded"
  +                       namespace="http://proposals.mime/"
  +                       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +          </mime:part>
  +        </mime:multipartRelated> 
  +      </output>
  +    </operation>
     </binding>
   
     <!-- service decln -->
     <service name="MimeService">
       <port name="SOAPPort" binding="tns:SOAPHttpBinding">
         <soap:address location="http://localhost:8080/soap/servlet/rpcrouter"/>
  +    </port>
  +    <port name="SOAPJMSPort" binding="tns:SOAPJmsBinding">
  +      <jms:address jndiDestinationName="SoapJmsAddressBookQueue"
  +                   destinationStyle="queue"
  +                   jndiConnectionFactoryName="WSIFSampleQCF"
  +                   initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory"
  +                   jndiProviderURL="file:///JNDI-Directory"/>
       </port>
     </service>
   
  
  
  
  1.2       +30 -0     xml-axis-wsif/java/test/proposals/mime/MimeImpl.java
  
  Index: MimeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/MimeImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MimeImpl.java	15 Oct 2002 13:55:31 -0000	1.1
  +++ MimeImpl.java	21 Oct 2002 09:48:18 -0000	1.2
  @@ -57,16 +57,22 @@
   
   package proposals.mime;
   
  +import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.OutputStream;
   
   import javax.activation.DataHandler;
  +import javax.activation.FileDataSource;
   
   /**
    * Mime service used by MimeTest 
    * @author Mark Whitlock
    */
   public class MimeImpl implements Mime {
  +	
  +	private final String tempFileName = "MimeImplBackendFile.txt";
  +	
       public String fileToString(DataHandler dh) {
           try {
               InputStream is = dh.getInputStream();
  @@ -74,6 +80,30 @@
               is.read(bBuff);
               String sBuff = new String(bBuff);
               return sBuff;
  +        } catch (IOException ioe) {
  +            return null;
  +        }
  +    }
  +
  +    public DataHandler stringToFile(String buff) {
  +        try {
  +            FileDataSource fds = new FileDataSource(tempFileName);
  +            File f = fds.getFile();
  +            if (f.exists()) {
  +                System.out.println("Deleting an existing file");
  +                f.delete();
  +            }
  +                
  +            if (!f.createNewFile()) {
  +                System.out.println("Failed to create file");
  +                return null;
  +            }
  +
  +            fds = new FileDataSource(tempFileName);
  +            fds.getOutputStream().write(buff.getBytes());
  +
  +            DataHandler dh = new DataHandler(fds);
  +            return dh;
           } catch (IOException ioe) {
               return null;
           }
  
  
  
  1.2       +1 -0      xml-axis-wsif/java/test/proposals/mime/Mime.java
  
  Index: Mime.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/Mime.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Mime.java	15 Oct 2002 13:55:31 -0000	1.1
  +++ Mime.java	21 Oct 2002 09:48:18 -0000	1.2
  @@ -61,4 +61,5 @@
   
   public interface Mime {
           public String fileToString(DataHandler dh);
  +        public DataHandler stringToFile(String buff);
   }
  
  
  
  1.3       +37 -0     xml-axis-wsif/java/test/proposals/mime/WSIFJmsTransport.java
  
  
  
  
  1.3       +37 -6     xml-axis-wsif/java/test/proposals/mime/WSIFJmsSender.java
  
  
  
  
  1.17      +2 -0      xml-axis-wsif/java/test/util/WSIFTestRunner.java
  
  Index: WSIFTestRunner.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/util/WSIFTestRunner.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- WSIFTestRunner.java	10 Oct 2002 15:07:04 -0000	1.16
  +++ WSIFTestRunner.java	21 Oct 2002 09:48:19 -0000	1.17
  @@ -68,6 +68,7 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  +import proposals.mime.MimeTest;
   import providers.PlugableProvidersTest;
   import providers.ProvidersInitialisationTest;
   import shop.ShoppingCartTest;
  @@ -126,6 +127,7 @@
           suite.addTest(new TestSuite(InputPartsTest.class));
           suite.addTest(new TestSuite(OutputPartsTest.class));
           suite.addTest(new TestSuite(WildcardTest.class));
  +        suite.addTest(new TestSuite(MimeTest.class));
           if (TestUtilities.areWeTesting("jms")) {
               suite.addTest(new TestSuite(JmsTest.class));
               suite.addTest(new TestSuite(JmsFaultTest.class));
  
  
  

Mime
View raw message