whitlock    2002/11/06 06:12:35

  Modified:    java/test/proposals/mime MimeTest.java Mime.wsdl
                        WSIFFrame.java WSIFPort_ApacheAxis.java
                        WSIFOperation_ApacheAxis.java MimeImpl.java
                        Mime.java DeploymentDescriptor.xml
               java/src/org/apache/wsif/base WSIFClientProxy.java
               java/test wsif.test.properties
  Log:
  Attachment fixes including autoregistering DataHandler
  
  Revision  Changes    Path
  1.7       +153 -46   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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MimeTest.java     29 Oct 2002 11:13:10 -0000      1.6
  +++ MimeTest.java     6 Nov 2002 14:12:35 -0000       1.7
  @@ -57,11 +57,9 @@
   
   package proposals.mime;
   
  -import java.awt.Canvas;
  -import java.awt.Frame;
  -import java.awt.Graphics;
   import java.awt.Image;
   import java.io.BufferedInputStream;
  +import java.io.ByteArrayInputStream;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
  @@ -79,6 +77,9 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  +import org.apache.wsif.WSIFMessage;
  +import org.apache.wsif.WSIFOperation;
  +import org.apache.wsif.WSIFPort;
   import org.apache.wsif.WSIFService;
   import org.apache.wsif.WSIFServiceFactory;
   import org.apache.wsif.util.WSIFPluggableProviders;
  @@ -114,11 +115,18 @@
       private final static String SEND_PLAINTEXT = "SEND-PLAINTEXT";
       private final static String RECEIVE_PLAINTEXT = "RECEIVE-PLAINTEXT";
       private final static String BOUNCE_IMAGE = "BOUNCE-IMAGE";
  +    private final static String BOUNCE_IMAGE2 = "BOUNCE-IMAGE2";
  +    private final static String BOUNCE_IMAGE3 = "BOUNCE-IMAGE3";
       private final static String SEND_SOURCE = "SEND-SOURCE";
       private final static String RECEIVE_SOURCE = "RECEIVE-SOURCE";
       private final static String SEND_MIMEMULTIPART = "SEND-MIMEMULTIPART";
       private final static String RECEIVE_MIMEMULTIPART = "RECEIVE-MIMEMULTIPART";
   
  +    /** 
  +     * Milliseconds to sleep while the user looks at the displayed images.
  +     */
  +    private int SLEEPY_TIME = 0;
  +    
       private final static String[] rhyme =
           { "The owl and the pussy cat went to sea in a beautiful pea-green boat,",
             "They took some honey and plenty of money wrapped up in a five pound 
note" };
  @@ -128,6 +136,15 @@
       
       public MimeTest(String name) {
           super(name);
  +
  +        try {
  +            SLEEPY_TIME =
  +                Integer.parseInt(
  +                    TestUtilities.getWsifProperty("wsif.displaytime"));
  +        } finally {
  +            if (SLEEPY_TIME <= 0)
  +                SLEEPY_TIME = 2000;
  +        }
       }
   
       public static void main(String[] args) {
  @@ -156,29 +173,41 @@
           doit("SOAPPort", SEND_PLAINTEXT, SYNC);
       }
   
  -//    public void testAxisReceivePlainTextSync() {
  -//        doit("SOAPPort", RECEIVE_PLAINTEXT, SYNC);
  -//    }
  -//
  +    /*
  +     * public void testAxisReceivePlainTextSync() {
  +     *    doit("SOAPPort", RECEIVE_PLAINTEXT, SYNC);
  +     * }
  +     */
  +
       public void testAxisBounceImageSync() {
           doit("SOAPPort", BOUNCE_IMAGE, SYNC);
       }
  -//
  -//    public void testAxisSendSourceSync() {
  -//        doit("SOAPPort", SEND_SOURCE, SYNC);
  -//    }
  -//
  -//    public void testAxisReceiveSourceSync() {
  -//        doit("SOAPPort", RECEIVE_SOURCE, SYNC);
  -//    }
  -//
  -//    public void testAxisSendMimeMultipartSync() {
  -//        doit("SOAPPort", SEND_MIMEMULTIPART, SYNC);
  -//    }
  -//
  -//    public void testAxisReceiveMimeMultipartSync() {
  -//        doit("SOAPPort", RECEIVE_MIMEMULTIPART, SYNC);
  -//    }
  +
  +    public void testAxisBounceImage2Sync() {
  +        doit("SOAPPort", BOUNCE_IMAGE2, SYNC);
  +    }
  +
  +    public void testAxisBounceImage3Sync() {
  +        doit("SOAPPort", BOUNCE_IMAGE3, SYNC);
  +    }
  +
  +    /*
  +     * public void testAxisSendSourceSync() {
  +     *     doit("SOAPPort", SEND_SOURCE, SYNC);
  +     * }
  +     *
  +     * public void testAxisReceiveSourceSync() {
  +     *     doit("SOAPPort", RECEIVE_SOURCE, SYNC);
  +     * }
  +     *
  +     * public void testAxisSendMimeMultipartSync() {
  +     *     doit("SOAPPort", SEND_MIMEMULTIPART, SYNC);
  +     * }
  +     *
  +     * public void testAxisReceiveMimeMultipartSync() {
  +     *     doit("SOAPPort", RECEIVE_MIMEMULTIPART, SYNC);
  +     * }
  +     */
   
       /*
        * Sending MIME messages using Axis over Jms should be supported 
  @@ -225,10 +254,6 @@
                       "http://proposals.mime/";,
                       "Mime");
   
  -            service.mapType(
  -                new QName("http://proposals.mime/";, "datahandler"),
  -                DataHandler.class);
  -
               Mime stub = (Mime) service.getStub(portName, Mime.class);
   
               if (cmd.equals(SEND_DH))
  @@ -241,6 +266,10 @@
                   receive_plaintext(service,stub);
               else if (cmd.equals(BOUNCE_IMAGE))
                   bounce_image(service,stub);
  +            else if (cmd.equals(BOUNCE_IMAGE2))
  +                bounce_image2(service,stub,portName);
  +            else if (cmd.equals(BOUNCE_IMAGE3))
  +                bounce_image3(service,stub,portName);
               else if (cmd.equals(SEND_SOURCE))
                   send_source(service,stub);
               else if (cmd.equals(RECEIVE_SOURCE))
  @@ -268,14 +297,22 @@
       }
   
       private void send_dh(WSIFService service, Mime stub) throws Exception {
  +        service.mapType(
  +            new QName("http://proposals.mime/";, "datahandler"),
  +            DataHandler.class);
  +
           DataHandler dh = new DataHandler(new FileDataSource(flatfileLocation));
           String buff = stub.dataHandlerToString(dh);
           compareFiles(flatfileLocation, buff);
       }
   
       private void receive_dh(WSIFService service, Mime stub) throws Exception {
  +        service.mapType(
  +            new QName("http://proposals.mime/";, "datahandler"),
  +            DataHandler.class);
  +
           DataHandler dh = stub.stringToDataHandler(rhyme[0]);
  -        compareFiles(dh,rhyme[0]);
  +        compareFiles(dh, rhyme[0]);
       }
   
       private void send_plaintext(WSIFService service, Mime stub)
  @@ -312,16 +349,58 @@
           WSIFFrame.display(im2,"Bounced image");
   
        System.out.println("Sleeping");
  -     Thread.sleep(10000);
  +     Thread.sleep(SLEEPY_TIME);
        System.out.println("Woken up");
       }
   
  -    private void receive_image(WSIFService service, Mime stub) throws Exception {
  -            service.mapType(
  -                new QName("http://proposals.mime/";, "image"),
  -                Image.class);
  -//        String buff = stub.stringToImage(rhyme[1]);
  -//        assertTrue(rhyme[1].equals(buff));
  +    /**
  +     * This test does not do any mapTypes() to test that WSIF will 
  +     * automatically register mime parts as a DataHandler. 
  +     */
  +    private void bounce_image2(WSIFService service, Mime stub, String portName)
  +        throws Exception {
  +        DataHandler dh1 = new DataHandler(new FileDataSource(imageLocation));
  +        Image im1 = new ImageIcon(imageLocation).getImage();
  +        WSIFFrame.display(im1, "Original image");
  +
  +        WSIFPort port = service.getPort(portName);
  +        WSIFOperation op = port.createOperation("bounceImage2");
  +        WSIFMessage in = op.createInputMessage();
  +        WSIFMessage out = op.createOutputMessage();
  +        WSIFMessage fault = op.createFaultMessage();
  +        in.setObjectPart("file",dh1);
  +
  +        boolean success = op.executeRequestResponseOperation(in,out,fault);
  +        assertTrue(success);
  +
  +        DataHandler dh2 = (DataHandler)(out.getObjectPart("file2"));
  +
  +        InputStream is = dh2.getInputStream();
  +        byte[] bBuff = new byte[is.available()];
  +        is.read(bBuff);
  +        Image im2 = new ImageIcon(bBuff).getImage();
  +        WSIFFrame.display(im2, "Bounced image");
  +        System.out.println("Sleeping");
  +        Thread.sleep(SLEEPY_TIME);
  +        System.out.println("Woken up");
  +    }
  +
  +    private void bounce_image3(WSIFService service, Mime stub, String portName)
  +        throws Exception {
  +        DataHandler dh1 = new DataHandler(new FileDataSource(imageLocation));
  +        Image im1 = new ImageIcon(imageLocation).getImage();
  +        WSIFFrame.display(im1, "Original image");
  +
  +        DataHandler dh2 = stub.bounceImage2(dh1);
  +
  +        InputStream is = dh2.getInputStream();
  +        byte[] bBuff = new byte[is.available()];
  +        is.read(bBuff);
  +        Image im2 = new ImageIcon(bBuff).getImage();
  +        WSIFFrame.display(im2, "Bounced image");
  +        System.out.println("Sleeping");
  +        Thread.sleep(SLEEPY_TIME);
  +        System.out.println("Woken up");
       }
   
       private void send_source(WSIFService service, Mime stub) throws Exception {
  @@ -356,6 +435,22 @@
   //        assertTrue(rhyme[1].equals(buff));
       }
   
  +    private boolean compareFiles(DataHandler dh1, DataHandler dh2)
  +        throws FileNotFoundException, IOException {
  +        InputStream is1 = dh1.getInputStream();
  +        InputStream is2 = dh2.getInputStream();
  +        boolean success = false;
  +        try {
  +            success = compareFiles(is1, is2);
  +        } finally {
  +            if (null != is1)
  +                is1.close();
  +            if (null != is2)
  +                is2.close();
  +        }
  +        return success;
  +    }
  +
       private boolean compareFiles(DataHandler dh, String buff)
           throws FileNotFoundException, IOException {
           InputStream is = dh.getInputStream();
  @@ -390,18 +485,30 @@
   
       private boolean compareFiles(InputStream is, String buff)
           throws FileNotFoundException, IOException {
  +        return compareFiles(is, new ByteArrayInputStream(buff.getBytes()));
  +    }
  +    
  +    private boolean compareFiles(InputStream is1, InputStream is2) 
  +        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))
  +        int avail1 = is1.available();
  +        int avail2 = is2.available();
  +        if (avail1 != avail2) return false;
  +        if (avail1==0) return true;
  +
  +        byte[] buff1 = new byte[avail1];
  +        byte[] buff2 = new byte[avail2];
  +
  +        Arrays.fill(buff1, (byte) 0);
  +        Arrays.fill(buff2, (byte) 0);
  +
  +        int bread1 = -1;
  +        int bread2 = -1;
  +        bread1 = is1.read(buff1, 0, avail1);
  +        bread2 = is2.read(buff2, 0, avail2);
  +        String s1 = new String(buff1);
  +        String s2 = new String(buff2);
  +        if (!s1.equals(s2))
               return false;
           return true;
       }
  
  
  
  1.5       +31 -0     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Mime.wsdl 29 Oct 2002 11:13:10 -0000      1.4
  +++ Mime.wsdl 6 Nov 2002 14:12:35 -0000       1.5
  @@ -14,6 +14,10 @@
       <part name="file" type="tns:datahandler"/>
     </message>
   
  +  <message name="DataHandler2Message">
  +    <part name="file2" type="tns:datahandler"/>
  +  </message>
  +
     <message name="PlainTextMessage">
       <part name="plaintext" type="tns:plaintext"/>
     </message>
  @@ -52,6 +56,10 @@
         <input message="tns:Image1Message"/>
         <output message="tns:Image2Message"/>
       </operation>
  +    <operation name="bounceImage2">
  +      <input message="tns:DataHandlerMessage"/>
  +      <output message="tns:DataHandler2Message"/>
  +    </operation>
     </portType>
   
     <!-- binding declns -->
  @@ -146,6 +154,29 @@
           <mime:multipartRelated>
             <mime:part>
               <mime:content part="image2" type="image/jpeg"/>
  +            <soap:body use="encoded"
  +                       namespace="http://proposals.mime/";
  +                       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +          </mime:part>
  +        </mime:multipartRelated> 
  +      </output>
  +    </operation>
  +    <operation name="bounceImage2">
  +      <soap:operation soapAction=""/>
  +      <input>
  +        <mime:multipartRelated>
  +          <mime:part>
  +            <mime:content part="file" type="image/jpeg"/>
  +            <soap:body use="encoded"
  +                       namespace="http://proposals.mime/";
  +                       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  +          </mime:part>
  +        </mime:multipartRelated> 
  +      </input>
  +      <output>
  +        <mime:multipartRelated>
  +          <mime:part>
  +            <mime:content part="file2" type="image/jpeg"/>
               <soap:body use="encoded"
                          namespace="http://proposals.mime/";
                          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  
  
  
  1.2       +72 -3     xml-axis-wsif/java/test/proposals/mime/WSIFFrame.java
  
  Index: WSIFFrame.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/WSIFFrame.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSIFFrame.java    29 Oct 2002 11:13:10 -0000      1.1
  +++ WSIFFrame.java    6 Nov 2002 14:12:35 -0000       1.2
  @@ -1,3 +1,59 @@
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + *
  + * Copyright (c) 2002 The Apache Software Foundation.  All rights 
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer. 
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:  
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "WSIF" and "Apache Software Foundation" must
  + *    not be used to endorse or promote products derived from this
  + *    software without prior written permission. For written 
  + *    permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    nor may "Apache" appear in their name, without prior written
  + *    permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation and was
  + * originally based on software copyright (c) 2001, 2002, International
  + * Business Machines, Inc., http://www.apache.org.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
   package proposals.mime;
   
   import java.awt.Canvas;
  @@ -14,7 +70,9 @@
           Frame f = new WSIFFrame(im,title);
           frames[frameIndex] = f;
           frameIndex++;
  +        f.add(new WSIFCanvas(im));
           f.pack();
  +        f.setLocation(300*frameIndex,200);
           f.show();
       }
   
  @@ -23,9 +81,6 @@
           this.im = im;
       }
   
  -    public void paint(Graphics g) {
  -        g.drawImage(im, 0, 0, new Canvas());
  -    }
   
       public static void close() {
           for (int i = 0; i < frameIndex; i++) {
  @@ -41,6 +96,20 @@
               frames[i] = null;
           }
           frameIndex=0;
  +    }
  +    
  +    static class WSIFCanvas extends Canvas {
  +        Image im;
  +
  +        WSIFCanvas(Image im) {
  +            super();
  +            this.setSize(200,200);
  +            this.im = im;
  +        }
  +
  +        public void paint(Graphics g) {
  +            g.drawImage(im, 0, 0, this);
  +        }
       }
   }
   
  
  
  
  1.3       +6 -5      xml-axis-wsif/java/test/proposals/mime/WSIFPort_ApacheAxis.java
  
  Index: WSIFPort_ApacheAxis.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/proposals/mime/WSIFPort_ApacheAxis.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WSIFPort_ApacheAxis.java  15 Oct 2002 13:55:31 -0000      1.2
  +++ WSIFPort_ApacheAxis.java  6 Nov 2002 14:12:35 -0000       1.3
  @@ -292,7 +292,7 @@
               if (soapbody != null) {
                List list2 = 
parseSoapBody(wsifoperation_apacheaxis,soapoperation,soapbody,true);
                   if (list2 != null)
  -                    wsifoperation_apacheaxis.setPartNames(list2);
  +                    wsifoperation_apacheaxis.setPartNames(list2,null);
               } else {
                   MIMEMultipartRelated mimeMultipart =
                       (MIMEMultipartRelated) getExtElem(bindinginput,
  @@ -442,6 +442,7 @@
               soapoperation);
        
           Vector mimePartNames = new Vector();
  +        Vector soapPartNames = new Vector();
   
           List mimeParts = mimeMultipart.getMIMEParts();
           Iterator mimePartIt = mimeParts.iterator();
  @@ -478,19 +479,19 @@
   
                           mimePartNames.addElement(mimeContent.getPart());
                       } else if (nextChild instanceof SOAPBody) {
  -                        List soapPartNames =
  +                        List soapPartNameList =
                               parseSoapBody(
                                   wsifoperation_apacheaxis,
                                   soapoperation,
                                   (SOAPBody) nextChild,
                                   true);
  -                        if (soapPartNames != null)
  -                            mimePartNames.addAll(soapPartNames);
  +                        if (soapPartNameList != null)
  +                            soapPartNames.addAll(soapPartNameList);
                       }
                   }
               }
           }
  -        wsifoperation_apacheaxis.setPartNames(mimePartNames);
  +        wsifoperation_apacheaxis.setPartNames(soapPartNames, mimePartNames);
           
           Trc.exit();
       }
  
  
  
  1.6       +103 -30   
xml-axis-wsif/java/test/proposals/mime/WSIFOperation_ApacheAxis.java
  
  Index: WSIFOperation_ApacheAxis.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/test/proposals/mime/WSIFOperation_ApacheAxis.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WSIFOperation_ApacheAxis.java     29 Oct 2002 11:13:10 -0000      1.5
  +++ WSIFOperation_ApacheAxis.java     6 Nov 2002 14:12:35 -0000       1.6
  @@ -70,6 +70,7 @@
   
   import javax.activation.DataHandler;
   import javax.jms.TextMessage;
  +import javax.mail.MessagingException;
   import javax.mail.internet.MimeMultipart;
   import javax.swing.ImageIcon;
   import javax.wsdl.Definition;
  @@ -81,6 +82,9 @@
   import javax.xml.soap.AttachmentPart;
   import javax.xml.soap.SOAPException;
   import javax.xml.transform.Source;
  +import javax.xml.transform.dom.DOMSource;
  +import javax.xml.transform.sax.SAXSource;
  +import javax.xml.transform.stream.StreamSource;
   
   import org.apache.axis.AxisFault;
   import org.apache.axis.Message;
  @@ -124,6 +128,8 @@
       transient protected Operation operation;
       transient protected Definition definition;
       transient protected List partNames;
  +    transient protected List soapPartNames;
  +    transient protected List mimePartNames;
       transient protected String names[];
       transient protected Class types[];
       transient protected String inputEncodingStyle;
  @@ -174,7 +180,7 @@
           op.setInputNamespace(getInputNamespace());
           op.setInputEncodingStyle(getInputEncodingStyle());
           op.setOutputEncodingStyle(getOutputEncodingStyle());
  -        op.setPartNames(getPartNames());
  +        op.setPartNames(soapPartNames,mimePartNames);
           op.setReturnName(getReturnName());
           op.setAsyncOperation(isAsyncOperation());
           op.setResponseHandler(getResponseHandler());
  @@ -580,25 +586,35 @@
               } else if (
                   (String.class.equals(type)
                       || Image.class.equals(type)
  -                    || Source.class.equals(type)
  +                    || StreamSource.class.equals(type)
  +                    || DOMSource.class.equals(type)
  +                    || SAXSource.class.equals(type)
                       || MimeMultipart.class.equals(type))
                       && AttachmentPart.class.isAssignableFrom(value.getClass())) {
   
  -                    AttachmentPart ap = (AttachmentPart) value;
  -                    InputStream is = ap.getDataHandler().getInputStream();
  +                AttachmentPart ap = (AttachmentPart) value;
  +                InputStream is = ap.getDataHandler().getInputStream();
  +
  +                if (String.class.equals(type)) {
                       byte[] bBuff = new byte[is.available()];
                       is.read(bBuff);
  -
  -                    if (String.class.equals(type))
  -                        msg.setObjectPart(name, new String(bBuff));
  -                    else if (Image.class.equals(type))
  -                        msg.setObjectPart(
  -                            name,
  -                            new ImageIcon(bBuff).getImage());
  -//                    else if (Source.class.equals(type))
  -//                        msg.setObjectPart(name, new Source(bBuff));
  -//                    else if (MimeMultipart.class.equals(type))
  -//                        msg.setObjectPart(name, new MimeMultipart(bBuff));
  +                    msg.setObjectPart(name, new String(bBuff));
  +                } else if (Image.class.equals(type)) {
  +                    byte[] bBuff = new byte[is.available()];
  +                    is.read(bBuff);
  +                    msg.setObjectPart(name, new ImageIcon(bBuff).getImage());
  +                } else if (StreamSource.class.equals(type))
  +                    // Warning: this next line of code has never been tested.
  +                    msg.setObjectPart(name, new StreamSource(is));
  +                else if (DOMSource.class.equals(type))
  +                    throw new WSIFException("DOMSource is not supported");
  +                else if (SAXSource.class.equals(type))
  +                    throw new WSIFException("SAXSource is not supported");
  +                else if (MimeMultipart.class.equals(type))
  +                    // Warning: this next line of code has never been tested.
  +                    msg.setObjectPart(
  +                        name,
  +                        new MimeMultipart(ap.getDataHandler().getDataSource()));
               } else if (
                   type != null // will be null for async responses
                       && !type.isPrimitive()
  @@ -630,6 +646,15 @@
                       + name
                       + "  caught "
                       + ioe);
  +        } catch (MessagingException me) {
  +            Trc.exception(me);
  +            throw new WSIFException(
  +                "WSIFOperation_ApacheAxis.setMessagePart messageName="
  +                    + (msg.getName() == null ? "null" : msg.getName())
  +                    + " partName="
  +                    + name
  +                    + "  caught "
  +                    + me);
           }
   
           Trc.exit();
  @@ -841,6 +866,14 @@
               } else {
                   obj = input.getMessage().getOrderedParts(null);
               }
  +
  +            javax.xml.rpc.encoding.TypeMapping tm1 =
  +                registry.getTypeMapping(
  +                    "http://schemas.xmlsoap.org/soap/encoding/";);
  +            org.apache.axis.encoding.TypeMapping tm2 = null;
  +            if (tm1 instanceof org.apache.axis.encoding.TypeMapping)
  +                tm2 = (org.apache.axis.encoding.TypeMapping) tm1;
  +
               int i = ((List) (obj)).size();
               names = new String[i];
               types = new Class[i];
  @@ -849,14 +882,21 @@
                   names[j] = part2.getName();
                   QName qname1 = part2.getTypeName();
                   if (qname1 == null)
  -                    throw new WSIFException("part " + names[j] + " must have type 
name declared");
  +                    throw new WSIFException(
  +                        "part " + names[j] + " must have type name declared");
   
  -                javax.xml.rpc.encoding.TypeMapping tm =
  -                    
registry.getTypeMapping("http://schemas.xmlsoap.org/soap/encoding/";);
  -                if (tm instanceof org.apache.axis.encoding.TypeMapping) {
  -                    types[j] = ((org.apache.axis.encoding.TypeMapping) tm)
  -                        .getClassForQName(
  -                            new 
QName(qname1.getNamespaceURI(),qname1.getLocalPart()));
  +                if (tm2 != null)
  +                    types[j] = tm2.getClassForQName(qname1);
  +
  +                // Automatically register mime types as DataHandler (unless
  +                // the user has already typemapped them explicitly).
  +                if (types[j] == null && mimePartNames.contains(names[j])) {
  +                    types[j] = DataHandler.class;
  +                    call.registerTypeMapping(
  +                        DataHandler.class,
  +                        qname1,
  +                        JAFDataHandlerSerializerFactory.class,
  +                        JAFDataHandlerDeserializerFactory.class);
                   }
               }
   
  @@ -864,6 +904,7 @@
               names = new String[0];
               types = new Class[0];
           }
  +
           Output output = operation.getOutput();
           if (output != null) {
               Part part = null;
  @@ -881,14 +922,26 @@
               }
               if (part != null) {
                   QName qname = part.getTypeName();
  -                javax.xml.rpc.encoding.TypeMapping tm =
  +                javax.xml.rpc.encoding.TypeMapping tm1 =
                       
registry.getTypeMapping("http://schemas.xmlsoap.org/soap/encoding/";);
  -                if (tm instanceof org.apache.axis.encoding.TypeMapping) {
  -                    returnType =
  -                        ((org.apache.axis.encoding.TypeMapping) 
tm).getClassForQName(
  -                            new 
QName(qname.getNamespaceURI(),qname.getLocalPart()));
  +                if (tm1 instanceof org.apache.axis.encoding.TypeMapping) {
  +                    org.apache.axis.encoding.TypeMapping tm2 = 
  +                        (org.apache.axis.encoding.TypeMapping) tm1;
  +                    returnType = tm2.getClassForQName(qname);
  +                }
  +
  +                // Automatically register mime types as DataHandler (unless
  +                // the user has already typemapped them explicitly).
  +                if (returnType == null && mimePartNames.contains(returnName)) {
  +                    returnType = DataHandler.class;
  +                    call.registerTypeMapping(
  +                        DataHandler.class,
  +                        qname,
  +                        JAFDataHandlerSerializerFactory.class,
  +                        JAFDataHandlerDeserializerFactory.class);
                   }
               }
  +
               // setup any output paramter part names defined in the WSDL
               List list = output.getMessage().getOrderedParts(null);
               if ( list.size() > 1 ) {
  @@ -968,9 +1021,27 @@
           Trc.exit();
       }
   
  -    public void setPartNames(List list) {
  -        Trc.entry(this, list);
  -        partNames = list;
  +    public void setPartNames(List soapList, List mimeList) {
  +        Trc.entry(this, soapList, mimeList);
  +        if (soapList != null && !soapList.isEmpty())
  +            soapPartNames = soapList;
  +        else
  +            soapPartNames = null;
  +
  +        if (mimeList != null && !mimeList.isEmpty())
  +            mimePartNames = mimeList;
  +        else
  +            mimePartNames = null;
  +
  +        if (soapPartNames != null || mimePartNames != null) {
  +            partNames = new Vector();
  +            if (mimeList != null)
  +                partNames.addAll(mimeList);
  +            if (soapList != null)
  +                partNames.addAll(soapList);
  +        } else
  +            partNames = null;
  +
           Trc.exit();
       }
   
  @@ -1196,6 +1267,8 @@
               buff += " operation:" + Trc.brief(operation);
               buff += " definition:" + Trc.brief(definition);
               buff += " partNames:" + partNames;
  +            buff += " soapPartNames:" + soapPartNames;
  +            buff += " mimePartNames:" + mimePartNames;
               buff += " names:" + names;
               buff += " types:" + types;
               buff += " inputEncodingStyle:" + inputEncodingStyle;
  
  
  
  1.6       +17 -4     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MimeImpl.java     29 Oct 2002 11:13:10 -0000      1.5
  +++ MimeImpl.java     6 Nov 2002 14:12:35 -0000       1.6
  @@ -58,7 +58,6 @@
   package proposals.mime;
   
   import java.awt.Image;
  -import java.io.ByteArrayInputStream;
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  @@ -67,6 +66,8 @@
   import javax.activation.FileDataSource;
   import javax.swing.ImageIcon;
   
  +import util.TestUtilities;
  +
   /**
    * Mime service used by MimeTest 
    * @author Mark Whitlock
  @@ -128,9 +129,17 @@
               byte[] bBuff = new byte[is.available()];
               is.read(bBuff);
   
  -            Image im = new ImageIcon(bBuff).getImage();
  -            WSIFFrame.display(im, "Backend image");
  -            Thread.sleep(10000);
  +//            Image im = new ImageIcon(bBuff).getImage();
  +//            WSIFFrame.display(im, "Backend image");
  +//            int t = 0;
  +//            try {
  +//                t = Integer.parseInt(
  +//                    TestUtilities.getWsifProperty("wsif.displaytime"));
  +//            } finally {
  +//                if (t <= 0)
  +//                    t = 2000;
  +//            }
  +//            Thread.sleep(t);
   
               FileDataSource fds = getTempFile();
               fds.getOutputStream().write(bBuff);
  @@ -141,6 +150,10 @@
           } finally {
               WSIFFrame.close();
           }
  +    }
  +
  +    public DataHandler bounceImage2(DataHandler ds) {
  +        return bounceImage(ds);
       }
   
       private FileDataSource getTempFile() throws IOException {
  
  
  
  1.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Mime.java 29 Oct 2002 11:13:10 -0000      1.4
  +++ Mime.java 6 Nov 2002 14:12:35 -0000       1.5
  @@ -69,6 +69,7 @@
       public String stringToPlainText(String buff);
   
       public Image bounceImage(Image im);
  +    public DataHandler bounceImage2(DataHandler dh);
   
   //    public String dataSourceToString(DataSource ds);
   //    public DataSource stringToDataSource(String buff);
  
  
  
  1.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DeploymentDescriptor.xml  29 Oct 2002 11:13:10 -0000      1.4
  +++ DeploymentDescriptor.xml  6 Nov 2002 14:12:35 -0000       1.5
  @@ -2,7 +2,7 @@
                id="http://proposals.mime/";>
     <isd:provider type="java"
                   scope="Application"
  -                methods="dataHandlerToString stringToDataHandler plainTextToString 
stringToPlainText bounceImage">
  +                methods="dataHandlerToString stringToDataHandler plainTextToString 
stringToPlainText bounceImage bounceImage2">
       <isd:java class="proposals.mime.MimeImpl" static="false"/>
     </isd:provider>
   
  
  
  
  1.10      +34 -26    xml-axis-wsif/java/src/org/apache/wsif/base/WSIFClientProxy.java
  
  Index: WSIFClientProxy.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/base/WSIFClientProxy.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- WSIFClientProxy.java      15 Oct 2002 13:15:26 -0000      1.9
  +++ WSIFClientProxy.java      6 Nov 2002 14:12:35 -0000       1.10
  @@ -60,11 +60,12 @@
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Method;
   import java.lang.reflect.Proxy;
  -import java.util.Map;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   
  +import javax.activation.DataHandler;
   import javax.wsdl.Definition;
   import javax.wsdl.Input;
   import javax.wsdl.Message;
  @@ -78,7 +79,6 @@
   import org.apache.wsif.WSIFMessage;
   import org.apache.wsif.WSIFOperation;
   import org.apache.wsif.WSIFPort;
  -import org.apache.wsif.compiler.schema.tools.Schema2Java;
   import org.apache.wsif.compiler.util.TypeMapping;
   import org.apache.wsif.logging.Trc;
   import org.apache.wsif.providers.WSIFDynamicTypeMap;
  @@ -484,31 +484,39 @@
                   // Look for a simple type that matches
                   TypeMapping tm =
                       (TypeMapping) (simpleTypeReg.get(partTypeName));
  -                if (!foundThisArg && tm != null) {
  -                    String simpleType = tm.javaType;
  -                    if (types[argIndex].toString().equals(simpleType)) {
  -                        // this works for simple types (float, int)
  -                        foundThisArg = true;
  -                        exactMatchThisArg = true;
  -                    } else
  -                        try // this works for String, Date
  -                            {
  -                            Class simpleClass =
  -                                Class.forName(
  -                                    simpleType,
  -                                    true,
  -                                    Thread
  -                                        .currentThread()
  -                                        .getContextClassLoader());
  -                            if (simpleClass
  -                                .isAssignableFrom(types[argIndex])) {
  -                                foundThisArg = true;
  -                                if (simpleClass.equals(types[argIndex]))
  -                                    exactMatchThisArg = true;
  +                if (!foundThisArg) {
  +                    if (tm != null) {
  +                        String simpleType = tm.javaType;
  +                        if (types[argIndex].toString().equals(simpleType)) {
  +                            // this works for simple types (float, int)
  +                            foundThisArg = true;
  +                            exactMatchThisArg = true;
  +                        } else
  +                            try // this works for String, Date
  +                                {
  +                                Class simpleClass =
  +                                    Class.forName(
  +                                        simpleType,
  +                                        true,
  +                                        Thread
  +                                            .currentThread()
  +                                            .getContextClassLoader());
  +                                if (simpleClass
  +                                    .isAssignableFrom(types[argIndex])) {
  +                                    foundThisArg = true;
  +                                    if (simpleClass.equals(types[argIndex]))
  +                                        exactMatchThisArg = true;
  +                                }
  +                            } catch (ClassNotFoundException ignored) {
  +                                Trc.ignoredException(ignored);
                               }
  -                        } catch (ClassNotFoundException ignored) {
  -                            Trc.ignoredException(ignored);
  -                        }
  +                    } else if (types[argIndex].equals(DataHandler.class))
  +                        // There is no (simple or complex) type mapping for 
  +                        // this argument. If it's a DataHandler, then assume
  +                        // it's a mime type, since we do automatic registering
  +                        // of DataHandlers for Mime types. We should really look
  +                        // in the WSDL binding to make sure it is a mime part.
  +                        foundThisArg = true;
                   }
   
                   if (!foundThisArg)
  
  
  
  1.7       +5 -1      xml-axis-wsif/java/test/wsif.test.properties
  
  Index: wsif.test.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/wsif.test.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- wsif.test.properties      10 Jul 2002 15:34:07 -0000      1.6
  +++ wsif.test.properties      6 Nov 2002 14:12:35 -0000       1.7
  @@ -22,4 +22,8 @@
   #
   # wsif.jms.output=terse|verbose Controls how much output you get from the 
   # JMS2HTTPBridge when running the testcases. Default is terse.
  -wsif.jms.output=terse
  \ No newline at end of file
  +wsif.jms.output=terse
  +#
  +# wsif.displaytime is number of milliseconds that images are displayed for.
  +# The default is 2000ms.
  +wsif.displaytime=2000
  \ No newline at end of file
  
  
  


Reply via email to