Package javax.xml.soap

Examples of javax.xml.soap.AttachmentPart


            String keyStatus = (String)keyAccessStatus.get(key);
            if ("not-accessed".equals(keyStatus)) {
                //The value for this key has not been accessed in the
                //referencing attachment scenario.Hence it must be an
                //unreferenced one.
                AttachmentPart ap = ((AttachmentPart)attachments.get(key));
                unaccessedAttachments.put(key, ap);
                keyAccessStatus.put(key, "accessed");
            }
        }
        return unaccessedAttachments;
View Full Code Here


   public AttachmentPart removeAttachmentByContentId(String cid)
   {
      try
      {
         AttachmentPart part = getAttachmentByContentId(cid);
         if (part != null)
         {
            attachments.remove(part);
            return part;
         }
View Full Code Here

      return getAttachmentByRef(ref);
   }

   private AttachmentPart getAttachmentByRef(String ref) throws SOAPException
   {
      AttachmentPart attachment;
      if (ref.startsWith("cid:"))
      {
         /* SwA 2000-12-11 section 3: if a Content-ID header is present, then an absolute URI
          * label for the part is formed using the CID URI scheme
          *
 
View Full Code Here

      private void nextMatch()
      {
         while (iterator.hasNext())
         {
            AttachmentPart part = (AttachmentPart)iterator.next();
            if (containsAllHeaders(headers.getAllHeaders(), part))
            {
               lastMatch = part;
               break;
            }
View Full Code Here

      Object retValue = paramValue;

      // Handle attachment part
      if (paramValue instanceof AttachmentPart)
      {
         AttachmentPart part = (AttachmentPart)paramValue;

         Set mimeTypes = paramMetaData.getMimeTypes();
         if (DataHandler.class.isAssignableFrom(javaType) && !javaType.equals(Object.class))
         {
            DataHandler handler = part.getDataHandler();
            String mimeType = MimeUtils.getBaseMimeType(handler.getContentType());

            // JAX-WS 2.0, 2.6.3.1 MIME Content
            // Conformance (MIME type mismatch): On receipt of a message where the MIME type of a part does not
            // match that described in the WSDL an implementation SHOULD throw a WebServiceException.
            if (mimeTypes != null && !MimeUtils.isMemberOf(mimeType, mimeTypes))
               log.warn("Mime type " + mimeType + " not allowed for parameter " + xmlName + " allowed types are " + mimeTypes);

            retValue = part.getDataHandler();
         }
         else
         {
            retValue = part.getContent();
            String mimeType = MimeUtils.getBaseMimeType(part.getContentType());

            if (mimeTypes != null && !MimeUtils.isMemberOf(mimeType, mimeTypes))
               throw new SOAPException("Mime type " + mimeType + " not allowed for parameter " + xmlName + " allowed types are " + mimeTypes);

            if (retValue != null)
View Full Code Here

      // RFC2392 requires the 'cid:' part to be stripped from the cid
      if (cid.startsWith("cid:"))
         cid = cid.substring(4);
      cid = '<' + cid + '>';

      AttachmentPart part = soapMessage.getAttachmentByContentId(cid);
      if (part == null)
         throw new WSException("Cannot find attachment part for: " + cid);

      return part;
   }
View Full Code Here

                            ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache();
                        } catch (IOException e) {
                            throw new Fault(e);
                        }
                    }
                    AttachmentPart ap = soapMessage.createAttachmentPart(a.getDataHandler());
                    ap.setContentId(a.getId());
                    Iterator<String> i = a.getHeaderNames();
                    while (i != null && i.hasNext()) {
                        String h = i.next();
                        String val = a.getHeader(h);
                        ap.addMimeHeader(h, val);
                    }
                    soapMessage.addAttachmentPart(ap);
                }
            }
           
View Full Code Here

                        message.setAttachments(new ArrayList<Attachment>(soapMessage
                                .countAttachments()));
                    }
                    Iterator<AttachmentPart> it = CastUtils.cast(soapMessage.getAttachments());
                    while (it.hasNext()) {
                        AttachmentPart part = it.next();
                        AttachmentImpl att = new AttachmentImpl(part.getContentId());
                        try {
                            att.setDataHandler(part.getDataHandler());
                        } catch (SOAPException e) {
                            throw new Fault(e);
                        }
                        Iterator<MimeHeader> it2 = CastUtils.cast(part.getAllMimeHeaders());
                        while (it2.hasNext()) {
                            MimeHeader header = it2.next();
                            att.setHeader(header.getName(), header.getValue());
                        }
                        message.getAttachments().add(att);
View Full Code Here

                            ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache();
                        } catch (IOException e) {
                            throw new Fault(e);
                        }
                    }
                    AttachmentPart ap = soapMessage.createAttachmentPart(a.getDataHandler());
                    ap.setContentId(a.getId());
                    Iterator<String> i = a.getHeaderNames();
                    while (i != null && i.hasNext()) {
                        String h = i.next();
                        String val = a.getHeader(h);
                        ap.addMimeHeader(h, val);
                    }
                    soapMessage.addAttachmentPart(ap);
                }
            }
           
View Full Code Here

    }

    @Validated @Test
    public void testRemoveAttachements() {
        Iterator iterator = null;
        AttachmentPart ap1 = null;
        AttachmentPart ap2 = null;
        AttachmentPart ap3 = null;

        try {
            MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
            //MessageFactory fac = MessageFactory.newInstance();
            SOAPMessage msg = fac.createMessage();
            SOAPPart soapPart = msg.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            SOAPBody body = envelope.getBody();
            SOAPFault sf = body.addFault();


            InputStream in1 = TestUtils.getTestFile("attach.xml");
            ap1 = msg.createAttachmentPart(in1, "text/xml");
            msg.addAttachmentPart(ap1);

            InputStream in2 = TestUtils.getTestFile("axis2.xml");
            ap2 = msg.createAttachmentPart(in2, "text/xml");
            msg.addAttachmentPart(ap2);

            InputStream in3 = TestUtils.getTestFile("axis2.xml");
            ap3 = msg.createAttachmentPart(in3, "text/plain");
            msg.addAttachmentPart(ap3);

            //get all attachments
            iterator = msg.getAttachments();

            int cnt = 0;
            while (iterator.hasNext()) {
                cnt++;
                iterator.next();
            }
            assertEquals(cnt, 3);
            //remove just the text/xml attachments
            MimeHeaders mhs = new MimeHeaders();
            mhs.addHeader("Content-Type", "text/xml");
            msg.removeAttachments(mhs);

            //get all attachments
            iterator = msg.getAttachments();
            cnt = 0;
            iterator = msg.getAttachments();
            while (iterator.hasNext()) {
                cnt++;
                iterator.next();
            }
            assertEquals(cnt, 1);
            iterator = msg.getAttachments();
            AttachmentPart ap = (AttachmentPart)iterator.next();
            String ctype = ap.getContentType();
            assertTrue(ctype.equals("text/plain"));

        } catch (Exception e) {
            fail("Exception: " + e);
        }
View Full Code Here

TOP

Related Classes of javax.xml.soap.AttachmentPart

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.