I always use DIME outside the soap message itself. It's not automatic
but on the other hand it works well with gsoap and .NET too. Some
example code:

On the server side...

package validar;

import org.apache.axis.MessageContext;
import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.attachments.Attachments;
import java.util.Iterator;
import java.io.File;
import javax.activation.*;


public class Valida_cardSoapBindingImpl implements
validar.Valida_cartao{
    public java.lang.String[] valida(java.lang.String cartao, float
valor, int operacao) throws java.rmi.RemoteException {
        AttachmentPart att[] = getMessageAttachments();
        for (int k = 0; k < att.length; ++k) {
            System.out.println("Attachment " + k);
            try {
                System.out.println("File : " +
att[k].getAttachmentFile());
                System.out.println("ID   : " + att[k].getContentId());
            }
            catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
        }
        setMessageAttachments();
        return new String[]{cartao + "resp", String.valueOf(valor),
String.valueOf(operacao)};
    }
      
    /**
     * extract attachments from the current request
     * @return a list of attachmentparts or
     * an empty array for no attachments support in this axis
     * buid/runtime
     */
    private AttachmentPart[] getMessageAttachments() throws AxisFault {
        MessageContext msgContext = MessageContext.getCurrentContext();
        System.out.println("User: " + msgContext.getUsername());
        System.out.println("Pass: " + msgContext.getPassword());
        Message reqMsg = msgContext.getRequestMessage();
        Attachments messageAttachments = reqMsg.getAttachmentsImpl();
        if (messageAttachments == null) {
            return new AttachmentPart[0];
        }
        int attachmentCount =  messageAttachments.getAttachmentCount();
        AttachmentPart attachments[] = new
AttachmentPart[attachmentCount];
        Iterator it = messageAttachments.getAttachments().iterator();
        int count = 0;
        while(it.hasNext()) {
            AttachmentPart part = (AttachmentPart) it.next();
            attachments[count++] = part;
        }
        return attachments;
    }

    private void setMessageAttachments() throws AxisFault {
        MessageContext msgContext = MessageContext.getCurrentContext();
        Message msg = msgContext.getResponseMessage();
 
msg.getAttachmentsImpl().setSendType(Attachments.SEND_TYPE_DIME);
        AttachmentPart part = new AttachmentPart(new DataHandler(new
FileDataSource("c:\\Chap0101_4.pdf")));
        msg.addAttachmentPart(part);
        part = new AttachmentPart(new DataHandler(new
FileDataSource("c:\\korean.pdf")));
        msg.addAttachmentPart(part);
    }
}

On the client side...

package validar;

import java.net.URL;
import org.apache.axis.client.*;
import javax.activation.*;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.attachments.Attachments;
import java.util.Iterator;
import javax.activation.*;
import java.io.File;

public class Tester {
    
    public static void main(String[] args) {
        try {
            // Make a service
            Valida_cartaoService service = new
Valida_cartaoServiceLocator();

            // Now use the service to get a stub which implements the
SDI.
            Valida_cartao port = service.getvalida_card(new
URL("http://localhost:8084/axis/services/valida_card";));
            Valida_cardSoapBindingStub stub =
(Valida_cardSoapBindingStub)port;
            stub._setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
            stub.setUsername("calhariz");
            stub.setPassword("aardvark");
            DataHandler dt = new DataHandler(new
FileDataSource("c:\\sif2000_263.log"));
            stub.addAttachment(dt);
            dt = new DataHandler(new
FileDataSource("c:\\Chap0902_x3.pdf"));
            AttachmentPart part = new AttachmentPart(dt);
            part.setContentId("This file:c:\\Chap0902_x3.pdf");
            stub.addAttachment(part);
            
            // Make the actual call
            String s[] = port.valida("qualquEURerxx", 3.2f, 3);
            Object att[] = stub.getAttachments();
            for (int k = 0; k < att.length; ++k) {
                AttachmentPart at = (AttachmentPart)att[k];
                System.out.println("Attachment " + k);
                System.out.println("File : " + at.getAttachmentFile());
            }
            for (int k = 0; k < s.length; ++k)
                System.out.println(s[k]);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }    
}

Best Regards,
Paulo Soares

> -----Original Message-----
> From: Kenneth Lee [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, April 20, 2004 2:24 PM
> To: [EMAIL PROTECTED]
> Subject: DIME Example requested
> 
> Can anyone provide a few clues on what is required to add DIME
> functionality to a web service.  Specifically, if I return a simple
> string, how do I get the message to break into chunks using dime.  If
> there is a good HOWTO with samples link, that would be wonderful!
> 
> SimpleWS {
>       String sDocument = "Some big XML Document with 100,000
> characters";
>       return sDocument;
> }
> 
> File .wsdd 
> <deployment xmlns="http://xml.apache.org/axis/wsdd/";
>             
> xmlns:java="http://xml.apache.org/axis/wsdd/providers/java";>
>       <service name="SimpleWS" provider="java:RPC">
>               <parameter name="className" value="mypackage.SimpleWS"/>
>               <parameter name="allowedMethods" value="*"/>
>       </service>
> </deployment>
> 
> 
> Thanks,
> 
> Ken Lee
> 
> 
> 

Reply via email to