axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis WSIFOperation_ApacheAxis.java
Date Tue, 07 Jan 2003 17:37:38 GMT
antelder    2003/01/07 09:37:38

  Modified:    java/src/org/apache/wsif/providers/soap/apacheaxis
                        WSIFOperation_ApacheAxis.java
  Log:
  Enable sending attachments when using messaging with the AXIS provider
  
  Revision  Changes    Path
  1.55      +54 -41    xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java
  
  Index: WSIFOperation_ApacheAxis.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- WSIFOperation_ApacheAxis.java	7 Jan 2003 12:03:02 -0000	1.54
  +++ WSIFOperation_ApacheAxis.java	7 Jan 2003 17:37:38 -0000	1.55
  @@ -57,8 +57,6 @@
   
   package org.apache.wsif.providers.soap.apacheaxis;
   
  -import java.io.IOException;
  -import java.io.StringReader;
   import java.rmi.RemoteException;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -130,9 +128,9 @@
   import org.apache.wsif.util.jms.WSIFJMSDestination;
   import org.apache.wsif.wsdl.extensions.jms.JMSProperty;
   import org.apache.wsif.wsdl.extensions.jms.JMSPropertyValue;
  -import org.apache.xerces.parsers.DOMParser;
   import org.w3c.dom.Element;
  -import org.xml.sax.InputSource;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NodeList;
   import org.xml.sax.SAXException;
   
   import com.ibm.wsdl.extensions.mime.MIMEConstants;
  @@ -1775,25 +1773,25 @@
   
   		boolean workedOK = false;
   
  +        List attachments = addAttachments(inMsg, call);
  +
   		Object[] inputValues = getInputMessageValues2(inMsg, null);
   		ArrayList soapBodies = new ArrayList();
   		for (int i = 0; i < inputValues.length; i++) {
   			if (inputValues[i] instanceof Element) {
  -				soapBodies.add(new SOAPBodyElement((Element) inputValues[i]));
  +				Element el = (Element) inputValues[i];
  +				
  +				if ((attachments.size() > 0) && (i == 0)) {
  +					fixAttachmentPartsCID(el, attachments);
  +				}
  +				
  +				soapBodies.add(new SOAPBodyElement(el));
   			} else {
   				throw new WSIFException(
   					"unexpected input type: " + inputValues[i]);
   			}
   		}
   		
  -        List attachments = addAttachments(inMsg, call);
  -        int mimePartIndex = 0;
  -        for (Iterator i = attachments.iterator(); i.hasNext(); ) {
  -        	AttachmentPart attachment = (AttachmentPart) i.next();
  -            Part part = (Part) inputMIMEParts.get(mimePartIndex);
  -            Element el = makeSOAPBodyPart(part, attachment);        	
  -			soapBodies.add(new SOAPBodyElement(el));
  -        }
   		
           Object[] axisInputs = soapBodies.toArray(); 
   
  @@ -1815,36 +1813,51 @@
   	}
   
       /**
  -     * This makes a DOM Element href part referencing an attachment
  -     * The SOAP body has an href referencing each attachment: 
  -     *  <soapenv:Body>
  -     *     <file href="cid:B4953A2DF527FD54DBA115A9BA32050D" xmlns="http://webservices.eraserver.net/"/>
  -     *  </soapenv:Body>
  -     * With AXIS when making the SOAPBody out of DOM Elements and
  -     * adding attachments with Call.addAttachment, this part must 
  -     * be added manually to the SOAP body (an AXIS bug?)
  +     * Fix the CID in the href of an attachment.
  +     * When sending an attachent with messaging two parts will
  +     * be in the WSIF input message, a DOM Element for the SOAP body contents,
  +     * and a DataHandler for the attachment. The contents Element must
  +     * include a href part for the attachment. This method will find
  +     * that href part and correct the CID value for the new AttachmentPart.
  +     * SOAPBody example with a href part named 'file':
  +     *	<ns1:bounceImage4 xmlns:ns1="http://mime/">
  +   	 *	   <ns1:shouldBounce xsi:type="xsd:boolean">true</ns1:shouldBounce>
  +   	 *	   <ns1:file href="cid:413B07CE410E48EB9D89DC0A4DDD715D"/>
  +  	 *  </ns1:bounceImage4>
        */
  -    private Element makeSOAPBodyPart(Part part, AttachmentPart attachment) throws WSIFException
{
  -    	
  -        StringBuffer sb = new StringBuffer("<");
  -        sb.append(part.getName());
  -        sb.append(" href=\"cid:");
  -        sb.append(attachment.getContentId());
  -        sb.append("\" xmlns=\"");
  -        sb.append(inputNamespace);
  -        sb.append("\"/>");
  -        
  -		DOMParser parser = new DOMParser();
  -		try {
  -            parser.parse(new InputSource(new StringReader(sb.toString())));
  -        } catch (SAXException e) {
  -        	throw new WSIFException("SAXException making attachment href", e);
  -        } catch (IOException e) {
  -        	throw new WSIFException("IOException making attachment href", e);
  -        }
  -		Element el = parser.getDocument().getDocumentElement();
  +    private void fixAttachmentPartsCID(Element body, List attachments) throws WSIFException
{
   
  -    	return el;
  +        NodeList childNodes = body.getChildNodes();
  +
  +        /* this isn't so nice: the AttachentPart has no name
  +         * but I know they were added to the attachments list 
  +         * in the same order as inputMIMEParts so I can get the 
  +         * part name from there.
  +         */ 
  +        int mimePartIndex = 0;
  +        for (Iterator i = attachments.iterator(); i.hasNext(); ) {
  +
  +        	AttachmentPart attachment = (AttachmentPart) i.next();
  +            Part part = (Part) inputMIMEParts.get(mimePartIndex);
  +            String partName = part.getName();
  +
  +            Element el = null;
  +            for(int j = 0; j < childNodes.getLength() && el == null; j++) {
  +    			Node n = childNodes.item(j);
  +    			if (partName.equals(n.getLocalName()) && n instanceof Element) {
  +                    el = (Element) n;
  +                    el.setAttribute("href", "cid:" + attachment.getContentId());      
              
  +    			}
  +            }
  +            
  +            if (el == null) {
  +            	throw new WSIFException(
  +            	    "could not find attachment part '"
  +            	    + partName
  +            	    + "' in body: " 
  +            	    + body);
  +            }
  +        }
       }
   
   	/**
  
  
  

Mime
View raw message