Package org.apache.axiom.mime

Examples of org.apache.axiom.mime.ContentTypeBuilder


     * @throws SOAPException if there was a problem saving changes to this message.
     */
    public void saveChanges() throws SOAPException {
        try {
            String contentTypeValue = getSingleHeaderValue(HTTPConstants.HEADER_CONTENT_TYPE);
            ContentTypeBuilder contentType;
            if (isEmptyString(contentTypeValue)) {
                contentType = new ContentTypeBuilder(attachmentParts.size() > 0 ? MediaType.MULTIPART_RELATED : getMediaType());
            } else {
                contentType = new ContentTypeBuilder(contentTypeValue);
                //Use configures the baseType with multipart/related while no attachment exists or all the attachments are removed
                if (contentType.getMediaType().equals(MediaType.MULTIPART_RELATED) && attachmentParts.size() == 0) {
                    contentType.setMediaType(getMediaType());
                    contentType.clearParameters();
                }
            }
          
            //If it is of multipart/related, initialize those required values in the content-type, including boundary etc.
            if (contentType.getMediaType().equals(MediaType.MULTIPART_RELATED)) {
               
                //Configure boundary
                String boundaryParam = contentType.getParameter("boundary");
                if (isEmptyString(boundaryParam)) {
                    contentType.setParameter("boundary", UIDGenerator.generateMimeBoundary());
                }

                //Configure start content id, always get it from soapPart in case it is changed
                String soapPartContentId = soapPart.getContentId();
                if (isEmptyString(soapPartContentId)) {
                    soapPartContentId = "<" + UIDGenerator.generateContentId() + ">";
                    soapPart.setContentId(soapPartContentId);
                }
                contentType.setParameter("start", soapPartContentId);
               
                //Configure contentId for each attachments
                for(AttachmentPart attachmentPart : attachmentParts) {
                    if(isEmptyString(attachmentPart.getContentId())) {
                        attachmentPart.setContentId("<" + UIDGenerator.generateContentId() + ">");
                    }
                }
               
                //Configure type               
                contentType.setParameter("type", getMediaType().toString());
               
                //Configure charset
                String soapPartContentTypeValue = getSingleHeaderValue(soapPart.getMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE));
                ContentTypeBuilder soapPartContentType = null;
                if (isEmptyString(soapPartContentTypeValue)) {
                    soapPartContentType = new ContentTypeBuilder(soapPartContentTypeValue);
                } else {
                    soapPartContentType = new ContentTypeBuilder(getMediaType());
                }               
                setCharsetParameter(soapPartContentType);
            } else {
                //Configure charset
                setCharsetParameter(contentType);
View Full Code Here


           
            SOAPEnvelope envelope = ((SOAPEnvelopeImpl) soapPart.getEnvelope()).getOMTarget();
            if (attachmentParts.isEmpty()) {
                envelope.serialize(out, format);
            } else {
                ContentTypeBuilder contentType = new ContentTypeBuilder(getSingleHeaderValue(HTTPConstants.HEADER_CONTENT_TYPE));
                String boundary = contentType.getParameter("boundary");
                if(isEmptyString(boundary)) {
                    boundary = UIDGenerator.generateMimeBoundary();
                    contentType.setParameter("boundary", boundary);
                }
                format.setMimeBoundary(boundary);

                String rootContentId = soapPart.getContentId();
                if(isEmptyString(rootContentId)) {
                    rootContentId = "<" + UIDGenerator.generateContentId() + ">";
                    soapPart.setContentId(rootContentId);
                }               
                contentType.setParameter("start", rootContentId);
                if ((rootContentId.indexOf("<") > -1) & (rootContentId.indexOf(">") > -1)) {
                    rootContentId = rootContentId.substring(1, (rootContentId.length() - 1));
                }
                format.setRootContentId(rootContentId);

                format.setSOAP11(((SOAPFactory)((SOAPEnvelopeImpl) soapPart.getEnvelope()).omTarget.getOMFactory()).getSOAPVersion() == SOAP11Version.getSingleton());
               
                //Double save the content-type in case anything is updated
                mimeHeaders.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentType.toString());

                OMMultipartWriter mpw = new OMMultipartWriter(out, format);
                OutputStream rootPartOutputStream = mpw.writeRootPart();
                envelope.serialize(rootPartOutputStream);
                rootPartOutputStream.close();
View Full Code Here

TOP

Related Classes of org.apache.axiom.mime.ContentTypeBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.