Search in sources :

Example 1 with XMLAttachmentUnmarshaller

use of org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller in project eclipselink by eclipse-ee4j.

the class LoadAndSaveBase64AttachmentTestCases method setUp.

@Override
public void setUp() {
    super.setUp();
    XMLMarshaller aMarshaller = ((SDOXMLHelper) xmlHelper).getXmlMarshaller();
    XMLUnmarshaller anUnmarshaller = ((SDOXMLHelper) xmlHelper).getXmlUnmarshaller();
    XMLAttachmentMarshaller anAttachmentMarshaller = new AttachmentMarshallerImpl("c_id0");
    XMLAttachmentUnmarshaller anAttachmentUnmarshaller = new AttachmentUnmarshallerImpl("Testing".getBytes());
    aMarshaller.setAttachmentMarshaller(anAttachmentMarshaller);
    anUnmarshaller.setAttachmentUnmarshaller(anAttachmentUnmarshaller);
}
Also used : XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLAttachmentMarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentMarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) XMLAttachmentUnmarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller)

Example 2 with XMLAttachmentUnmarshaller

use of org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller in project eclipselink by eclipse-ee4j.

the class LoadAndSaveMimeTypeOnPropertyTestCases method setUp.

@Override
public void setUp() {
    super.setUp();
    XMLMarshaller aMarshaller = ((SDOXMLHelper) xmlHelper).getXmlMarshaller();
    XMLUnmarshaller anUnmarshaller = ((SDOXMLHelper) xmlHelper).getXmlUnmarshaller();
    XMLAttachmentMarshaller anAttachmentMarshaller = new AttachmentMarshallerImpl("c_id0");
    XMLAttachmentUnmarshaller anAttachmentUnmarshaller = new AttachmentUnmarshallerImpl("Testing".getBytes());
    aMarshaller.setAttachmentMarshaller(anAttachmentMarshaller);
    anUnmarshaller.setAttachmentUnmarshaller(anAttachmentUnmarshaller);
}
Also used : XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLAttachmentMarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentMarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) XMLAttachmentUnmarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller)

Example 3 with XMLAttachmentUnmarshaller

use of org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller in project eclipselink by eclipse-ee4j.

the class ProviderHelper method invoke.

@SuppressWarnings({ "unchecked" })
public SOAPMessage invoke(SOAPMessage request) {
    Map<String, DataHandler> attachments = null;
    if (mtomEnabled) {
        attachments = (Map<String, DataHandler>) mc.get(INBOUND_MESSAGE_ATTACHMENTS);
    }
    SOAPMessage response;
    boolean usesSOAP12;
    DBWSAdapter dbwsAdapter = (DBWSAdapter) xrService;
    SOAPEnvelope envelope;
    try {
        envelope = request.getSOAPPart().getEnvelope();
    } catch (SOAPException se) {
        throw new WebServiceException(se.getMessage(), se);
    }
    // check soap 1.2 Namespace in envelope
    String namespaceURI = envelope.getNamespaceURI();
    usesSOAP12 = namespaceURI.equals(URI_NS_SOAP_1_2_ENVELOPE);
    SOAPElement body;
    try {
        body = getSOAPBodyElement(envelope);
    } catch (SOAPException se) {
        throw new WebServiceException(se.getMessage(), se);
    }
    if (body == null) {
        SOAPFault soapFault;
        try {
            SOAPFactory soapFactory;
            if (usesSOAP12) {
                soapFactory = SOAPFactory.newInstance(SOAP_1_2_PROTOCOL);
            } else {
                soapFactory = SOAPFactory.newInstance();
            }
            QName faultCodeQName;
            if (usesSOAP12) {
                faultCodeQName = SENDER_QNAME;
            } else {
                faultCodeQName = CLIENT_QNAME;
            }
            soapFault = soapFactory.createFault("SOAPMessage request format error - missing body element", faultCodeQName);
        } catch (SOAPException se) {
            throw new WebServiceException(se.getMessage(), se);
        }
        throw new SOAPFaultException(soapFault);
    }
    XMLRoot xmlRoot;
    try {
        XMLContext xmlContext = dbwsAdapter.getXMLContext();
        XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
        if (attachments != null && attachments.size() > 0) {
            unmarshaller.setAttachmentUnmarshaller(new XMLAttachmentUnmarshaller() {

                Map<String, DataHandler> attachments;

                public XMLAttachmentUnmarshaller setAttachments(Map<String, DataHandler> attachments) {
                    this.attachments = attachments;
                    return this;
                }

                @Override
                public boolean isXOPPackage() {
                    return true;
                }

                @Override
                public DataHandler getAttachmentAsDataHandler(String id) {
                    // strip off 'cid:' (Is this needed?)
                    String attachmentRefId = id;
                    if (attachmentRefId.startsWith("cid:")) {
                        attachmentRefId = attachmentRefId.substring(4);
                    }
                    return attachments.get(attachmentRefId);
                }

                @Override
                public byte[] getAttachmentAsByteArray(String id) {
                    ByteArrayOutputStream out = null;
                    try {
                        DataHandler dh = attachments.get(id);
                        if (dh == null) {
                            return null;
                        }
                        InputStream in = dh.getInputStream();
                        out = new ByteArrayOutputStream(1024);
                        byte[] buf = new byte[1024];
                        int len;
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                    } catch (IOException e) {
                    // e.printStackTrace();
                    }
                    if (out != null) {
                        return out.toByteArray();
                    }
                    return null;
                }
            }.setAttachments(attachments));
            dbwsAdapter.setCurrentAttachmentUnmarshaller(unmarshaller.getAttachmentUnmarshaller());
        }
        xmlRoot = (XMLRoot) unmarshaller.unmarshal(body, Invocation.class);
    } catch (Exception e) {
        SOAPFault soapFault;
        try {
            SOAPFactory soapFactory;
            if (usesSOAP12) {
                soapFactory = SOAPFactory.newInstance(SOAP_1_2_PROTOCOL);
            } else {
                soapFactory = SOAPFactory.newInstance();
            }
            QName faultCodeQName;
            if (usesSOAP12) {
                faultCodeQName = SENDER_QNAME;
            } else {
                faultCodeQName = CLIENT_QNAME;
            }
            Throwable e1 = e;
            if (e.getCause() != null) {
                e1 = e.getCause();
            }
            soapFault = soapFactory.createFault("SOAPMessage request format error - " + e1, faultCodeQName);
        } catch (SOAPException se) {
            throw new WebServiceException(se.getMessage(), se);
        }
        throw new SOAPFaultException(soapFault);
    }
    Invocation invocation = (Invocation) xmlRoot.getObject();
    invocation.setName(xmlRoot.getLocalName());
    Operation op = dbwsAdapter.getOperation(invocation.getName());
    /*
         * Fix up types for arguments - scan the extended schema for the operation's Request type.
         *
         * For most parameters, the textual node content is fine, but for date/time and
         * binary objects, we must convert
         */
    org.eclipse.persistence.internal.oxm.schema.model.Element invocationElement = dbwsAdapter.getExtendedSchema().getTopLevelElements().get(invocation.getName());
    String typeName = invocationElement.getType();
    int idx = typeName.indexOf(':');
    if (idx != -1) {
        // strip-off any namespace prefix
        typeName = typeName.substring(idx + 1);
    }
    ComplexType complexType = dbwsAdapter.getExtendedSchema().getTopLevelComplexTypes().get(typeName);
    if (complexType.getSequence() != null) {
        // which has the arguments to the operation
        for (Iterator<org.eclipse.persistence.internal.oxm.schema.model.Element> i = complexType.getSequence().getOrderedElements().iterator(); i.hasNext(); ) {
            org.eclipse.persistence.internal.oxm.schema.model.Element e = i.next();
            String argName = e.getName();
            Object argValue = invocation.getParameter(argName);
            String argType = e.getType();
            if (argType != null) {
                String argTypePrefix = null;
                String nameSpaceURI = null;
                idx = argType.indexOf(':');
                if (idx != -1) {
                    argTypePrefix = argType.substring(0, idx);
                    argType = argType.substring(idx + 1);
                    nameSpaceURI = dbwsAdapter.getSchema().getNamespaceResolver().resolveNamespacePrefix(argTypePrefix);
                }
                QName argQName = argTypePrefix == null ? new QName(nameSpaceURI, argType) : new QName(nameSpaceURI, argType, argTypePrefix);
                Class<?> clz = SCHEMA_2_CLASS.get(argQName);
                if (clz != null) {
                    argValue = ((XMLConversionManager) dbwsAdapter.getOXSession().getDatasourcePlatform().getConversionManager()).convertObject(argValue, clz, argQName);
                    invocation.setParameter(argName, argValue);
                }
            }
        // incoming attachments ?
        }
    }
    Object result;
    try {
        result = op.invoke(dbwsAdapter, invocation);
        if (result instanceof ValueObject) {
            result = ((ValueObject) result).value;
        }
        response = responseWriter.generateResponse(op, usesSOAP12, result);
    } catch (SOAPException se) {
        throw new WebServiceException(se.getMessage(), se);
    } catch (Exception e) {
        try {
            response = responseWriter.generateResponse(op, usesSOAP12, e);
        } catch (SOAPException soape1) {
            SOAPFault soapFault;
            try {
                SOAPFactory soapFactory;
                if (usesSOAP12) {
                    soapFactory = SOAPFactory.newInstance(SOAP_1_2_PROTOCOL);
                } else {
                    soapFactory = SOAPFactory.newInstance();
                }
                QName faultCodeQName;
                if (usesSOAP12) {
                    faultCodeQName = RECEIVER_QNAME;
                } else {
                    faultCodeQName = SERVER_QNAME;
                }
                soapFault = soapFactory.createFault("SOAPMessage response error - " + e.getMessage(), faultCodeQName);
            } catch (SOAPException soape2) {
                throw new WebServiceException(soape2.getMessage(), soape2);
            }
            throw new SOAPFaultException(soapFault);
        }
    }
    return response;
}
Also used : Invocation(org.eclipse.persistence.internal.xr.Invocation) SOAPElement(jakarta.xml.soap.SOAPElement) Element(org.w3c.dom.Element) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement) DataHandler(jakarta.activation.DataHandler) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) Operation(org.eclipse.persistence.internal.xr.Operation) SOAPMessage(jakarta.xml.soap.SOAPMessage) SOAPFactory(jakarta.xml.soap.SOAPFactory) XMLAttachmentUnmarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller) SOAPException(jakarta.xml.soap.SOAPException) SOAPElement(jakarta.xml.soap.SOAPElement) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) ValueObject(org.eclipse.persistence.internal.xr.ValueObject) WebServiceException(jakarta.xml.ws.WebServiceException) XMLContext(org.eclipse.persistence.oxm.XMLContext) QName(javax.xml.namespace.QName) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) InputStream(java.io.InputStream) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPException(jakarta.xml.soap.SOAPException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) WebServiceException(jakarta.xml.ws.WebServiceException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) DBWSException(org.eclipse.persistence.exceptions.DBWSException) SOAPFault(jakarta.xml.soap.SOAPFault) ValueObject(org.eclipse.persistence.internal.xr.ValueObject) Map(java.util.Map) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 4 with XMLAttachmentUnmarshaller

use of org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller in project eclipselink by eclipse-ee4j.

the class XMLBinaryAttachmentHandler method endElement.

@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    Field xmlField = null;
    if (isCollection) {
        xmlField = (Field) mapping.getField();
    } else {
        xmlField = (Field) mapping.getField();
    }
    if (INCLUDE_ELEMENT_NAME.equals(localName) || INCLUDE_ELEMENT_NAME.equals(qName)) {
        if (record.isNamespaceAware() && !Constants.XOP_URL.equals(namespaceURI)) {
            return;
        }
        // Get the attachment and set it in the object.
        XMLAttachmentUnmarshaller attachmentUnmarshaller = record.getUnmarshaller().getAttachmentUnmarshaller();
        Object data = null;
        Class<?> attributeClassification = null;
        if (isCollection) {
            attributeClassification = ((BinaryDataCollectionMapping) mapping).getAttributeElementClass();
        } else {
            attributeClassification = mapping.getAttributeClassification();
        }
        if (attachmentUnmarshaller == null) {
            // the attachment. Throw an exception.
            throw XMLMarshalException.noAttachmentUnmarshallerSet(this.c_id);
        }
        if (attributeClassification.equals(XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER)) {
            data = attachmentUnmarshaller.getAttachmentAsDataHandler(this.c_id);
        } else {
            data = attachmentUnmarshaller.getAttachmentAsByteArray(this.c_id);
        }
        CoreContainerPolicy cp = null;
        if (isCollection) {
            cp = mapping.getContainerPolicy();
        }
        data = XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(data, mapping.getAttributeClassification(), record.getSession(), cp);
        data = converter.convertDataValueToObjectValue(data, record.getSession(), unmarshaller);
        // check for collection case
        if (isCollection) {
            if (data != null) {
                record.addAttributeValue((ContainerValue) nodeValue, data);
            }
        } else {
            record.setAttributeValue(data, mapping);
        }
        // Return control to the UnmarshalRecord
        if (!xmlField.isSelfField()) {
            XMLReader xmlReader = record.getXMLReader();
            xmlReader.setContentHandler(record);
            xmlReader.setLexicalHandler(record);
        }
    } else if (c_id == null) {
        if (!xmlField.isSelfField()) {
            // Return control to the parent record
            XMLReader xmlReader = record.getXMLReader();
            xmlReader.setContentHandler(record);
            xmlReader.setLexicalHandler(record);
            record.endElement(namespaceURI, localName, qName);
        }
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) XMLAttachmentUnmarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller) XMLReader(org.eclipse.persistence.internal.oxm.record.XMLReader) CoreContainerPolicy(org.eclipse.persistence.internal.core.queries.CoreContainerPolicy)

Example 5 with XMLAttachmentUnmarshaller

use of org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller in project eclipselink by eclipse-ee4j.

the class LoadAndSaveMimeTypeOnPropertyManyTestCases method setUp.

@Override
public void setUp() {
    super.setUp();
    XMLMarshaller aMarshaller = ((SDOXMLHelper) xmlHelper).getXmlMarshaller();
    XMLUnmarshaller anUnmarshaller = ((SDOXMLHelper) xmlHelper).getXmlUnmarshaller();
    XMLAttachmentMarshaller anAttachmentMarshaller = new AttachmentMarshallerImpl("c_id0");
    XMLAttachmentUnmarshaller anAttachmentUnmarshaller = new AttachmentUnmarshallerImpl("Testing".getBytes());
    aMarshaller.setAttachmentMarshaller(anAttachmentMarshaller);
    anUnmarshaller.setAttachmentUnmarshaller(anAttachmentUnmarshaller);
}
Also used : XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLAttachmentMarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentMarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) XMLAttachmentUnmarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller)

Aggregations

XMLAttachmentUnmarshaller (org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller)7 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)6 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)5 XMLAttachmentMarshaller (org.eclipse.persistence.oxm.attachment.XMLAttachmentMarshaller)5 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)5 DataHandler (jakarta.activation.DataHandler)1 SOAPBodyElement (jakarta.xml.soap.SOAPBodyElement)1 SOAPElement (jakarta.xml.soap.SOAPElement)1 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)1 SOAPException (jakarta.xml.soap.SOAPException)1 SOAPFactory (jakarta.xml.soap.SOAPFactory)1 SOAPFault (jakarta.xml.soap.SOAPFault)1 SOAPMessage (jakarta.xml.soap.SOAPMessage)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1