Package org.apache.axiom.attachments

Examples of org.apache.axiom.attachments.Attachments


    protected void setUp() throws Exception {
        super.setUp();
        inFileName = "mtom/MTOMBuilderTestIn.txt";
        InputStream inStream = new FileInputStream(getTestResourceFile(inFileName));
        attachments = new Attachments(inStream, contentTypeString);
        XMLStreamReader reader = XMLInputFactory.newInstance()
                .createXMLStreamReader(new BufferedReader(new InputStreamReader(attachments
                        .getSOAPPartInputStream())));
        builder = new MTOMStAXSOAPModelBuilder(reader, attachments,
                                               SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
View Full Code Here


public class AttachmentService {

  public String uploadFile(String name, String attchmentID) throws IOException
  {
        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
        Attachments attachment = msgCtx.getAttachmentMap();
        DataHandler dataHandler = attachment.getDataHandler(attchmentID);
        File file = new File(
        name);
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    dataHandler.writeTo(fileOutputStream);
    fileOutputStream.flush();
View Full Code Here

        attachmentSizeThreshold = attachmentSizeThresholdParameter
            .getValue().toString();
      }
    }

    Attachments attachments = new Attachments(inStream, contentTypeString,
        fileCacheForAttachments, attachmentRepoDir,
        attachmentSizeThreshold);
    String charSetEncoding = getCharSetEncoding(attachments
        .getSOAPPartContentType());
    XMLStreamReader streamReader;

    if ((charSetEncoding == null)
        || "null".equalsIgnoreCase(charSetEncoding)) {
      charSetEncoding = MessageContext.UTF_8;
    }

    try {
      streamReader = StAXUtils.createXMLStreamReader(getReader(
          attachments.getSOAPPartInputStream(), charSetEncoding));
    } catch (IOException e) {
      throw new XMLStreamException(e);
    }

    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
        charSetEncoding);

    /*
     * Put a reference to Attachments Map in to the message context For
     * backword compatibility with Axis2 1.0
     */
    msgContext.setProperty(MTOMConstants.ATTACHMENTS, attachments);

    /*
     * Setting the Attachments map to new SwA API
     */
    msgContext.setAttachmentMap(attachments);

    String soapEnvelopeNamespaceURI = null;
    if (contentTypeString.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
      soapEnvelopeNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
    } else if (contentTypeString
        .indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
      soapEnvelopeNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
    }

    if (isSOAP) {
      if (attachments.getAttachmentSpecType().equals(
          MTOMConstants.MTOM_TYPE)
          & null != soapEnvelopeNamespaceURI) {

        /*
         * Creates the MTOM specific MTOMStAXSOAPModelBuilder
         */
        builder = new MTOMStAXSOAPModelBuilder(streamReader,
            attachments, soapEnvelopeNamespaceURI);

      } else if (attachments.getAttachmentSpecType().equals(
          MTOMConstants.SWA_TYPE)
          & null != soapEnvelopeNamespaceURI) {
        builder = new StAXSOAPModelBuilder(streamReader,
            soapEnvelopeNamespaceURI);
      }
    }
    // To handle REST XOP case
    else {
      if (attachments.getAttachmentSpecType().equals(
          MTOMConstants.MTOM_TYPE)) {
        XOPAwareStAXOMBuilder stAXOMBuilder = new XOPAwareStAXOMBuilder(
            streamReader, attachments);
        builder = stAXOMBuilder;

      } else if (attachments.getAttachmentSpecType().equals(
          MTOMConstants.SWA_TYPE)) {
        builder = new StAXOMBuilder(streamReader);
      }
    }

View Full Code Here

        this.attachments = attachments;
    }

    public Attachments getAttachmentMap() {
        if (attachments == null) {
            attachments = new Attachments();
        }
        return attachments;
    }
View Full Code Here

        return attachments;
    }

    public void addAttachment(String contentID, DataHandler dataHandler) {
        if (attachments == null) {
            attachments = new Attachments();
        }
        attachments.addDataHandler(contentID, dataHandler);
    }
View Full Code Here

        return contentID;
    }

    public DataHandler getAttachment(String contentID) {
        if (attachments == null) {
            attachments = new Attachments();
        }
        return attachments.getDataHandler(contentID);
    }
View Full Code Here

        newMC.setDoingMTOM(ori.isDoingMTOM());
        newMC.setDoingSwA(ori.isDoingSwA());

        // if the original request carries any attachments, copy them to the clone
        // as well, except for the soap part if any
        Attachments attachments = ori.getAttachmentMap();
        if (attachments != null && attachments.getAllContentIDs().length > 0) {
            String[] cIDs = attachments.getAllContentIDs();
            String soapPart = attachments.getSOAPPartContentID();
            for (String cID : cIDs) {
                if (!cID.equals(soapPart)) {
                    newMC.addAttachment(cID, attachments.getDataHandler(cID));
                }
            }
        }

        for (Object o : ori.getOptions().getProperties().keySet()) {
View Full Code Here

                getFirstChildWithName(new QName("http://services.samples/xsd", "uploadFileUsingSwAResponse")).
                getFirstChildWithName(new QName("http://services.samples/xsd", "response")).
                getFirstChildWithName(new QName("http://services.samples/xsd", "imageId")).
                getText();

        Attachments attachment = response.getAttachmentMap();
        dataHandler = attachment.getDataHandler(imageContentId);
        File tempFile = File.createTempFile("swa-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        dataHandler.writeTo(fos);
        fos.flush();
        fos.close();
View Full Code Here

       public static void deleteAttachments(MessageContext msgContext) {
         if (log.isDebugEnabled()) {
               log.debug("Entering deleteAttachments()");
           }
          
         Attachments attachments = msgContext.getAttachmentMap();
           if (attachments != null) {
               String [] keys = attachments.getAllContentIDs();
               if (keys != null) {
                 String key = null;
                 File file = null;
                 DataSource dataSource = null;
                   for (int i = 0; i < keys.length; i++) {
                       try {
                           key = keys[i];
                           dataSource = attachments.getDataHandler(key).getDataSource();
                           if(dataSource instanceof CachedFileDataSource){
                             file = ((CachedFileDataSource)dataSource).getFile();
                             if (log.isDebugEnabled()) {
                                   log.debug("Delete cache attachment file: "+file.getName());
                               }
View Full Code Here

        files = (OMElement) itr.next(); // Get the files element
        itr = files.getChildElements(); // Get iterator for file elements

        // Get attachements from the MessageContext
        Attachments attachment = (opcts.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)).getAttachmentMap();

        // loop through each file element
        int i = 1;
        String fileName;
        DataHandler dataHandler;
        while (itr.hasNext()) {
            file = (OMElement) itr.next();
            if (file == null) throw new AxisFault("File " + i + " is null");
            dataHandler = attachment.getDataHandler(file.getText()); // Get corresponding DataHandler
            fileName = createFileName(i);
            writeData(dataHandler.getDataSource().getInputStream(), fileName);
            i++;
        }
View Full Code Here

TOP

Related Classes of org.apache.axiom.attachments.Attachments

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.