ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sanjiva Weerawarana <sanj...@opensource.lk>
Subject Re: [Axis2]Re: svn commit: r202253 - in /webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om: MIMEOutputUtils.java OMOutput.java impl/llom/OMOutput.java
Date Tue, 28 Jun 2005 18:50:16 GMT
We should not have any o.a.a.attachments stuff .. that's all part of OM
now. 

IMO there's no need to move the MIME code out of OMOutput at all to make
this work.

Sanjiva.

On Tue, 2005-06-28 at 23:54 +0600, Thilina Gunarathne wrote:
> Hi,
> I'm not sure where to keep the MIMEOutputUtils class. For the moment
> it is in o,a,a.om
> Shall we keep it there or move to o.a.a.attachments
>  
> regards,
> ~Thilina
>  
> On 6/28/05, thilina@apache.org <thilina@apache.org> wrote: 
>         Author: thilina
>         Date: Tue Jun 28 10:43:09 2005
>         New Revision: 202253
>         
>         URL: http://svn.apache.org/viewcvs?rev=202253&view=rev
>         Log:
>         Moved the JavaMail dependent code pieces to
>         MIMEOutputUtils.java.So that in the run time OM will work
>         without JavaMail. 
>         
>         Added:
>         
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/MIMEOutputUtils.java
>         
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java
>         Removed:
>         
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom/OMOutput.java

>         
>         Added:
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/MIMEOutputUtils.java
>         URL:
>         http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/MIMEOutputUtils.java?rev=202253&view=auto
>         ==============================================================================

>         ---
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/MIMEOutputUtils.java
(added)
>         +++
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/MIMEOutputUtils.java
Tue Jun 28 10:43:09 2005
>         @@ -0,0 +1,136 @@ 
>         +/*
>         
>         + * Copyright 2004,2005 The Apache Software Foundation.
>         
>         + *
>         
>         + * Licensed under the Apache License, Version 2.0 (the
>         "License");
>         
>         + * you may not use this file except in compliance with the
>         License. 
>         
>         + * You may obtain a copy of the License at
>         
>         + *
>         
>         + *      http://www.apache.org/licenses/LICENSE-2.0
>         
>         + *
>         
>         + * Unless required by applicable law or agreed to in writing,
>         software 
>         
>         + * distributed under the License is distributed on an "AS IS"
>         BASIS,
>         
>         + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
>         express or implied.
>         
>         + * See the License for the specific language governing
>         permissions and 
>         
>         + * limitations under the License.
>         
>         + */
>         
>         +package org.apache.axis.om;
>         
>         +
>         
>         +import java.io.IOException;
>         
>         +import java.io.OutputStream;
>         
>         +import java.util.Iterator;
>         
>         +import java.util.LinkedList;
>         
>         +
>         
>         +import javax.activation.DataHandler;
>         
>         +import javax.mail.MessagingException;
>         
>         +import javax.mail.internet.ContentType;
>         
>         +import javax.mail.internet.MimeBodyPart ;
>         
>         +import javax.xml.stream.XMLStreamException;
>         
>         +/**
>         
>         + * @author <a href="mailto:thilina@opensource.lk">Thilina
>         Gunarathne </a>
>         
>         + */ 
>         
>         +public class MIMEOutputUtils {
>         
>         +
>         
>         +       private static byte[] CRLF = { 13, 10 };
>         
>         +
>         
>         +       static String SOAP_PART_CONTENT_ID = "<SOAPPart>";
>         
>         +
>         
>         +       public static void complete(OutputStream outStream, 
>         
>         +                       OutputStream bufferedSoapOutStream,
>         LinkedList binaryNodeList,
>         
>         +                       String boundary) throws
>         XMLStreamException {
>         
>         +               try {
>         
>         +                       startWritingMime(outStream,
>         boundary); 
>         
>         +
>         
>         +
>         
>         +               DataHandler dh = new
>         DataHandler(bufferedSoapOutStream.toString(),
>         
>         +                               "text/xml");
>         
>         +               MimeBodyPart rootMimeBodyPart = new
>         MimeBodyPart(); 
>         
>         +               rootMimeBodyPart.setDataHandler(dh);
>         
>         +               rootMimeBodyPart.addHeader("Content-Type",
>         "application/xop+xml");
>         
>         +
>         rootMimeBodyPart.addHeader("Content-Transfer-Encoding",
>         "8bit"); 
>         
>         +               rootMimeBodyPart.addHeader("Content-ID",
>         SOAP_PART_CONTENT_ID);
>         
>         +
>         
>         +               writeBodyPart(outStream, rootMimeBodyPart,
>         boundary);
>         
>         +
>         
>         +               Iterator binaryNodeIterator =
>         binaryNodeList.iterator();
>         
>         +               while (binaryNodeIterator.hasNext()) {
>         
>         +                       OMText binaryNode = (OMText)
>         binaryNodeIterator.next();
>         
>         +                       writeBodyPart(outStream,
>         createMimeBodyPart(binaryNode), boundary); 
>         
>         +               }
>         
>         +               finishWritingMime(outStream);
>         
>         +               } catch (IOException e) {
>         
>         +                       throw new OMException("Problem with
>         the OutputStream."+e.toString()); 
>         
>         +               } catch (MessagingException e) {
>         
>         +                       throw new OMException("Problem writing
>         Mime Parts."+e.toString());
>         
>         +               }
>         
>         +       }
>         
>         +
>         
>         +       private static MimeBodyPart createMimeBodyPart(OMText
>         node)
>         
>         +                       throws MessagingException {
>         
>         +               MimeBodyPart mimeBodyPart = new
>         MimeBodyPart();
>         
>         +
>         mimeBodyPart.setDataHandler(node.getDataHandler());
>         
>         +
>         mimeBodyPart.addHeader("Content-Transfer-Encoding", "binary");
>         
>         +               mimeBodyPart.addHeader("Content-ID", "<" +
>         node.getContentID() + ">");
>         
>         +               return mimeBodyPart;
>         
>         +
>         
>         +       }
>         
>         +
>         
>         +       /**
>         
>         +        * @throws IOException
>         
>         +        *             This will write the boundary to output
>         Stream 
>         
>         +        */
>         
>         +       private static void writeMimeBoundary(OutputStream
>         outStream,
>         
>         +                       String boundary) throws IOException {
>         
>         +               outStream.write(new byte[] { 45, 45 }); 
>         
>         +               outStream.write(boundary.getBytes());
>         
>         +       }
>         
>         +
>         
>         +       /**
>         
>         +        * @throws IOException
>         
>         +        *             This will write the boundary with CRLF
>         
>         +        */
>         
>         +       private static void startWritingMime(OutputStream
>         outStream, String boundary)
>         
>         +                       throws IOException {
>         
>         +               writeMimeBoundary(outStream, boundary);
>         
>         +               outStream.write(CRLF);
>         
>         +       }
>         
>         +
>         
>         +       /**
>         
>         +        * this will write a CRLF for the earlier boudary then
>         the BodyPart data
>         
>         +        * with headers followed by boundary. Writes only the
>         boundary. No more 
>         
>         +        * CRLF's are wriiting after that.
>         
>         +        *
>         
>         +        * @throws IOException
>         
>         +        * @throws MessagingException
>         
>         +        */
>         
>         +       private static void writeBodyPart(OutputStream
>         outStream, 
>         
>         +                       MimeBodyPart part, String boundary)
>         throws IOException,
>         
>         +                       MessagingException {
>         
>         +               outStream.write(CRLF);
>         
>         +               part.writeTo (outStream);
>         
>         +               outStream.write(CRLF);
>         
>         +               writeMimeBoundary(outStream, boundary);
>         
>         +       }
>         
>         +
>         
>         +       /**
>         
>         +        * @throws IOException
>         
>         +        *             This will write "--" to the end of last
>         boundary 
>         
>         +        */
>         
>         +       private static void finishWritingMime(OutputStream
>         outStream)
>         
>         +                       throws IOException {
>         
>         +               outStream.write(new byte[] { 45, 45 });
>         
>         +       } 
>         
>         +
>         
>         +       public static String getContentTypeForMime(String
>         boundary) {
>         
>         +               ContentType contentType = new ContentType();
>         
>         +               contentType.setPrimaryType("multipart"); 
>         
>         +               contentType.setSubType("related");
>         
>         +               contentType.setParameter("boundary",
>         boundary);
>         
>         +               contentType.setParameter("start",
>         MIMEOutputUtils.SOAP_PART_CONTENT_ID );
>         
>         +               contentType.setParameter("type",
>         "application/xop+xml");
>         
>         +               //TODO theres something called action that can
>         be set with
>         
>         +               // following. May be SOAPAction. Better
>         check. 
>         
>         +               contentType.setParameter("startinfo",
>         "application/xop+xml");
>         
>         +               return contentType.toString();
>         
>         +       }
>         
>         +
>         
>         +}
>         \ No newline at end of file 
>         
>         Added:
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java
>         URL:
>         http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java?rev=202253&view=auto
>         ==============================================================================
>         ---
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java
(added)
>         +++
>         webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/OMOutput.java
Tue Jun 28 10:43:09 2005
>         @@ -0,0 +1,135 @@
>         +/*
>         
>         + * Copyright 2004,2005 The Apache Software Foundation.
>         
>         + *
>         
>         + * Licensed under the Apache License, Version 2.0 (the
>         "License");
>         
>         + * you may not use this file except in compliance with the
>         License. 
>         
>         + * You may obtain a copy of the License at
>         
>         + *
>         
>         + *      http://www.apache.org/licenses/LICENSE-2.0
>         
>         + *
>         
>         + * Unless required by applicable law or agreed to in writing,
>         software 
>         
>         + * distributed under the License is distributed on an "AS IS"
>         BASIS,
>         
>         + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
>         express or implied.
>         
>         + * See the License for the specific language governing
>         permissions and 
>         
>         + * limitations under the License.
>         
>         + */
>         
>         +package org.apache.axis.om;
>         
>         +
>         
>         +import java.io.ByteArrayOutputStream;
>         
>         +import java.io.OutputStream ;
>         
>         +import java.util.LinkedList;
>         
>         +
>         
>         +import javax.xml.stream.FactoryConfigurationError;
>         
>         +import javax.xml.stream.XMLOutputFactory;
>         
>         +import javax.xml.stream.XMLStreamException;
>         
>         +import javax.xml.stream.XMLStreamWriter;
>         
>         +
>         
>         +
>         
>         +/**
>         
>         + * @author <a href="mailto:thilina@opensource.lk">Thilina
>         Gunarathne </a> For
>         
>         + *         the moment this assumes that transport takes the
>         decision of whether
>         
>         + *         to optimise or not by looking at whether the MTOM
>         optimise is enabled &
>         
>         + *         also looking at the OM tree whether it has any
>         optimisable content 
>         
>         + */
>         
>         +
>         
>         +public class OMOutput {
>         
>         +       private XMLStreamWriter xmlWriter;
>         
>         +
>         
>         +       private boolean doOptimise;
>         
>         +
>         
>         +       private OutputStream outStream;
>         
>         +
>         
>         +       private XMLStreamWriter writer;
>         
>         +
>         
>         +       private LinkedList binaryNodeList;
>         
>         +
>         
>         +       private ByteArrayOutputStream bufferedSoapOutStream;
>         
>         +
>         
>         +       private String mimeBoundary = null; 
>         
>         +
>         
>         +       private String contentType = null;
>         
>         +
>         
>         +       /**
>         
>         +        * @param xmlWriter
>         
>         +        *            if it is guaranteed for not using
>         attachments one can use this
>         
>         +        */
>         
>         +       public OMOutput(XMLStreamWriter xmlWriter) {
>         
>         +               this.xmlWriter = xmlWriter;
>         
>         +       }
>         
>         +
>         
>         +       /**
>         
>         +        * @throws FactoryConfigurationError
>         
>         +        * @throws XMLStreamException
>         
>         +        *
>         
>         +        */
>         
>         +       public OMOutput(OutputStream outStream, boolean
>         doOptimise)
>         
>         +                       throws XMLStreamException,
>         FactoryConfigurationError { 
>         
>         +               this.doOptimise = doOptimise;
>         
>         +               this.outStream = outStream;
>         
>         +               if (doOptimise) {
>         
>         +                       bufferedSoapOutStream = new
>         ByteArrayOutputStream(); 
>         
>         +                       xmlWriter =
>         XMLOutputFactory.newInstance().createXMLStreamWriter(
>         
>         +
>         bufferedSoapOutStream);
>         
>         +                       binaryNodeList = new LinkedList(); 
>         
>         +               } else {
>         
>         +                       xmlWriter =
>         XMLOutputFactory.newInstance().createXMLStreamWriter(
>         
>         +                                       outStream);
>         
>         +
>         
>         +               } 
>         
>         +
>         
>         +       }
>         
>         +
>         
>         +       public XMLStreamWriter getXmlStreamWriter() {
>         
>         +               return xmlWriter;
>         
>         +       }
>         
>         +
>         
>         +       public void flush() throws XMLStreamException { 
>         
>         +               //              if (doOptimise) {
>         
>         +               //                      try {
>         
>         +               //                              this.complete();
>         
>         +               //                      } catch (IOException
>         e) { 
>         
>         +               //                              //TODO this is
>         just a hack to avoid passing IOException. Must find a
>         
>         +               // better way to handle this
>         
>         +               //                              throw new
>         XMLStreamException("Error creating mime parts. Problem with 
>         
>         +               // Streams");
>         
>         +               //                      } catch
>         (MessagingException e) {
>         
>         +               //                              throw new
>         XMLStreamException("Error creating mime Body parts"); 
>         
>         +               //                      }
>         
>         +               //              } else {
>         
>         +               xmlWriter.flush();
>         
>         +               //              }
>         
>         +
>         
>         +       }
>         
>         +
>         
>         +       public boolean doOptimise() {
>         
>         +               return doOptimise;
>         
>         +       }
>         
>         +
>         
>         +       public String getContentType() {
>         
>         +               if (contentType == null && doOptimise) { 
>         
>         +
>         MIMEOutputUtils.getContentTypeForMime(getMimeBoundary());
>         
>         +               }
>         
>         +               return contentType.toString();
>         
>         +       }
>         
>         +
>         
>         +       public void writeOptimised(OMText node) { 
>         
>         +               binaryNodeList.add(node);
>         
>         +       }
>         
>         +
>         
>         +       public void complete() throws XMLStreamException {
>         
>         +               if (doOptimise) {
>         
>         +                       xmlWriter.flush ();
>         
>         +                       MIMEOutputUtils.complete(outStream,
>         bufferedSoapOutStream,
>         
>         +                                       binaryNodeList,
>         getMimeBoundary());
>         
>         +               }
>         
>         +       }
>         
>         +
>         
>         +       private String getMimeBoundary() {
>         
>         +               //TODO have to dynamically generate.
>         
>         +               if (mimeBoundary == null) {
>         
>         +                       mimeBoundary =
>         "----=_AxIs2_Def_boundary_=42214532"; 
>         
>         +               }
>         
>         +               return mimeBoundary;
>         
>         +       }
>         
>         +
>         
>         +}
>         \ No newline at end of file
>         
>         
> 
> 
> 
> -- 
> 
> "May the SourcE be with u" 


Mime
View raw message