Search in sources :

Example 1 with UnknownResource

use of org.apache.cxf.ws.transfer.shared.faults.UnknownResource in project cxf by apache.

the class MemoryResourceManager method get.

@Override
public Representation get(ReferenceParametersType ref) {
    String uuid = getUUID(ref);
    if (!storage.containsKey(uuid)) {
        throw new UnknownResource();
    }
    String resource = storage.get(uuid);
    if (resource.isEmpty()) {
        return new Representation();
    }
    Document doc = null;
    try {
        doc = StaxUtils.read(new StringReader(storage.get(uuid)));
    } catch (XMLStreamException e) {
        LOG.severe(e.getLocalizedMessage());
        throw new SoapFault("Internal Error", getSoapVersion().getReceiver());
    }
    Representation representation = new Representation();
    representation.setAny(doc.getDocumentElement());
    return representation;
}
Also used : UnknownResource(org.apache.cxf.ws.transfer.shared.faults.UnknownResource) SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) Representation(org.apache.cxf.ws.transfer.Representation) Document(org.w3c.dom.Document)

Example 2 with UnknownResource

use of org.apache.cxf.ws.transfer.shared.faults.UnknownResource in project cxf by apache.

the class MemoryResourceManager method put.

@Override
public void put(ReferenceParametersType ref, Representation newRepresentation) {
    String uuid = getUUID(ref);
    if (!storage.containsKey(uuid)) {
        throw new UnknownResource();
    }
    Element representationEl = (Element) newRepresentation.getAny();
    if (representationEl == null) {
        storage.put(uuid, "");
    } else {
        storage.put(uuid, StaxUtils.toString(representationEl));
    }
}
Also used : UnknownResource(org.apache.cxf.ws.transfer.shared.faults.UnknownResource) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element)

Example 3 with UnknownResource

use of org.apache.cxf.ws.transfer.shared.faults.UnknownResource in project cxf by apache.

the class MemoryResourceManager method getUUID.

private String getUUID(ReferenceParametersType ref) {
    for (Object object : ref.getAny()) {
        if (object instanceof JAXBElement) {
            JAXBElement<?> element = (JAXBElement<?>) object;
            QName qName = element.getName();
            if (REF_NAMESPACE.equals(qName.getNamespaceURI()) && REF_LOCAL_NAME.equals(qName.getLocalPart())) {
                return (String) element.getValue();
            }
        } else if (object instanceof Element) {
            Element element = (Element) object;
            if (REF_NAMESPACE.equals(element.getNamespaceURI()) && REF_LOCAL_NAME.equals(element.getLocalName())) {
                return element.getTextContent();
            }
        }
    }
    throw new UnknownResource();
}
Also used : UnknownResource(org.apache.cxf.ws.transfer.shared.faults.UnknownResource) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

UnknownResource (org.apache.cxf.ws.transfer.shared.faults.UnknownResource)3 JAXBElement (javax.xml.bind.JAXBElement)2 Element (org.w3c.dom.Element)2 StringReader (java.io.StringReader)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 Representation (org.apache.cxf.ws.transfer.Representation)1 Document (org.w3c.dom.Document)1