Package org.apache.cxf.staxutils

Examples of org.apache.cxf.staxutils.W3CDOMStreamWriter


                if (isDOMSupported(db)) {
                    DataWriter<Node> writer = db.createWriter(Node.class);
   
                    writer.write(bean, part, f.getOrCreateDetail());
                } else {
                    XMLStreamWriter xsw = new W3CDOMStreamWriter(f.getOrCreateDetail());
   
                    DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
   
                    writer.write(bean, part, xsw);
                }
View Full Code Here


            String namespace = requestEl.getNamespaceURI();
            String prefix = requestEl.getPrefix();
            SecurityToken cancelToken = null;
            if ("RequestSecurityToken".equals(requestEl.getLocalName())) {
                try {
                    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
                    writer.setNsRepairing(true);
                    if (STSUtils.WST_NS_05_12.equals(namespace)) {
                        writer.writeStartElement(prefix, "RequestSecurityTokenResponseCollection",
                                                 namespace);
                    }
                    writer.writeStartElement(prefix, "RequestSecurityTokenResponse", namespace);
                   
                    String requestType = null;
                    Element el = DOMUtils.getFirstElement(requestEl);
                    while (el != null) {
                        String localName = el.getLocalName();
                        if (namespace.equals(el.getNamespaceURI())) {
                            if ("RequestType".equals(localName)) {
                                requestType = el.getTextContent();
                            } else if ("CancelTarget".equals(localName)) {
                                cancelToken = findCancelToken(exchange, el);
                            }
                        }
                       
                        el = DOMUtils.getNextElement(el);
                    }
                    if (requestType == null) {
                        requestType = "/Issue";
                    }
                   
                    if (requestType.endsWith("/Issue")) {
                        doIssue(requestEl, exchange, writer, prefix, namespace);
                    } else if (requestType.endsWith("/Cancel")) {
                        TokenStore store = (TokenStore)exchange.get(Endpoint.class).getEndpointInfo()
                            .getProperty(TokenStore.class.getName());
                        cancelToken.setState(SecurityToken.State.CANCELLED);
                        store.update(cancelToken);
                        writer.writeEmptyElement(prefix, "RequestedTokenCancelled", namespace);
                        exchange.put(SecurityConstants.TOKEN, cancelToken);
                    } else if (requestType.endsWith("/Renew")) {
                        //REVISIT - implement
                    }
                    writer.writeEndElement();
                    if (STSUtils.WST_NS_05_12.equals(namespace)) {
                        writer.writeEndElement();
                    }
                    return new MessageContentsList(new DOMSource(writer.getDocument()));
                } catch (RuntimeException ex) {
                    throw ex;
                } catch (Exception ex) {
                    throw new Fault(ex);
                }
View Full Code Here

        } else {
            client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION,
                                           namespace + "/RST/Issue");
        }

        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        writer.writeStartElement("wst", "RequestSecurityToken", namespace);
        writer.writeNamespace("wst", namespace);
        boolean wroteKeySize = false;
       
        String keyType = null;
       
        if (template != null) {
            if (this.useSecondaryParameters()) {
                writer.writeStartElement("wst", "SecondaryParameters", namespace);
            }
           
            Element tl = DOMUtils.getFirstElement(template);
            while (tl != null) {
                StaxUtils.copy(tl, writer);
                if ("KeyType".equals(tl.getLocalName())) {
                    keyType = DOMUtils.getContent(tl);
                } else if ("KeySize".equals(tl.getLocalName())) {
                    wroteKeySize = true;
                    keySize = Integer.parseInt(DOMUtils.getContent(tl));
                }
                tl = DOMUtils.getNextElement(tl);
            }
           
            if (this.useSecondaryParameters()) {
                writer.writeEndElement();
            }
        }

        addRequestType(requestType, writer);
        addAppliesTo(writer, appliesTo);
        keyType = writeKeyType(writer, keyType);

        byte[] requestorEntropy = null;
        X509Certificate cert = null;
        Crypto crypto = null;

        if (keySize <= 0) {
            keySize = 256;
        }
        if (keyType.endsWith("SymmetricKey")) {
            requestorEntropy = writeElementsForRSTSymmetricKey(writer, wroteKeySize);
        } else if (keyType.endsWith("PublicKey")) {
            crypto = createCrypto(false);
            cert = getCert(crypto);
            writeElementsForRSTPublicKey(writer, cert);
        }
       
        if (target != null) {
            writer.writeStartElement("wst", "RenewTarget", namespace);
            Element el = target.getUnattachedReference();
            if (el == null) {
                el = target.getAttachedReference();
            }
            StaxUtils.copy(el, writer);
            writer.writeEndElement();
        }
       
        addActAs(writer);
       
        writer.writeEndElement();

        Object obj[] = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));

        SecurityToken token = createSecurityToken(getDocumentElement((DOMSource)obj[0]), requestorEntropy);
        if (cert != null) {
            token.setX509Certificate(cert, crypto);
        }
View Full Code Here

       
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION,
                                       namespace + "/RST/Validate");

       
        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        writer.writeStartElement("wst", "RequestSecurityToken", namespace);
        writer.writeNamespace("wst", namespace);
        writer.writeStartElement("wst", "RequestType", namespace);
        writer.writeCharacters(namespace + "/Validate");
        writer.writeEndElement();

        writer.writeStartElement("wst", "ValidateTarget", namespace);
        Element el = tok.getUnattachedReference();
        if (el == null) {
            el = tok.getAttachedReference();
        }
        StaxUtils.copy(el, writer);

        writer.writeEndElement();
        writer.writeEndElement();

        client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
       
        return false;
    }
View Full Code Here

            client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION,
                                           namespace + "/RST/Cancel");           
        }


        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        writer.writeStartElement("wst", "RequestSecurityToken", namespace);
        writer.writeNamespace("wst", namespace);
        writer.writeStartElement("wst", "RequestType", namespace);
        writer.writeCharacters(namespace + "/Cancel");
        writer.writeEndElement();

        writer.writeStartElement("wst", "CancelTarget", namespace);
        Element el = token.getUnattachedReference();
        if (el == null) {
            el = token.getAttachedReference();
        }
        StaxUtils.copy(el, writer);

        writer.writeEndElement();
        writer.writeEndElement();

        try {
            client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
            token.setState(SecurityToken.State.CANCELLED);
        } catch (Exception ex) {
            LOG.log(Level.WARNING, "Problem cancelling token", ex);
        }
    }
View Full Code Here

            Document node = (Document) message.getContent(Node.class);
            if (node == null) {
                // replicate 2.1 behavior.
                part.setContent(new DOMSource(null));
            } else {
                StaxUtils.copy(node, new W3CDOMStreamWriter(part));
            }
            message.setContent(Node.class, soapMessage.getSOAPPart());

            Collection<Attachment> atts = message.getAttachments();
            if (atts != null) {
View Full Code Here

        // read header portion of SOAP document into DOM
        SoapVersion version = message.getVersion();
        XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, version.getBody());
        Node nd = message.getContent(Node.class);
        W3CDOMStreamWriter writer = message.get(W3CDOMStreamWriter.class);
        Document doc = null;
        if (writer != null) {
            StaxUtils.copy(filteredReader, writer);
            doc = writer.getDocument();
        } else if (nd instanceof Document) {
            doc = (Document)nd;
            StaxUtils.readDocElements(doc, doc, filteredReader, false, false);
        } else {
            doc = StaxUtils.read(filteredReader);
View Full Code Here

        BindingOperationInfo boi = findOperation("/BatchIssue");

        client.getRequestContext().putAll(ctx);
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action);

        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        writer.writeStartElement("wst", "RequestSecurityTokenCollection", namespace);
        writer.writeNamespace("wst", namespace);

        for (BatchRequest batchRequest : batchRequestList) {
            writer.writeStartElement("wst", "RequestSecurityToken", namespace);
            writer.writeNamespace("wst", namespace);
           
            addRequestType(requestType, writer);
            if (enableAppliesTo) {
                addAppliesTo(writer, batchRequest.getAppliesTo());
            }
           
            writeKeyType(writer, batchRequest.getKeyType());
           
            addLifetime(writer);
           
            addTokenType(writer, batchRequest.getTokenType());
           
            writer.writeEndElement();
        }
        writer.writeEndElement();

        Object obj[] = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));

        Element responseCollection = getDocumentElement((DOMSource)obj[0]);
        Node child = responseCollection.getFirstChild();
        List<SecurityToken> tokens = new ArrayList<SecurityToken>();
        while (child != null) {
View Full Code Here

        BindingOperationInfo boi = findOperation("/BatchValidate");

        client.getRequestContext().putAll(ctx);
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action);

        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        writer.writeStartElement("wst", "RequestSecurityTokenCollection", namespace);
        writer.writeNamespace("wst", namespace);

        for (BatchRequest batchRequest : batchRequestList) {
            writer.writeStartElement("wst", "RequestSecurityToken", namespace);
            writer.writeNamespace("wst", namespace);
           
            addRequestType(requestType, writer);
           
            addTokenType(writer, batchRequest.getTokenType());
           
            writer.writeStartElement("wst", "ValidateTarget", namespace);

            Element el = batchRequest.getValidateTarget();
            StaxUtils.copy(el, writer);

            writer.writeEndElement();
           
            writer.writeEndElement();
        }
        writer.writeEndElement();

        Object obj[] = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
       
        Element responseCollection = getDocumentElement((DOMSource)obj[0]);
        Node child = responseCollection.getFirstChild();
        List<SecurityToken> tokens = new ArrayList<SecurityToken>();
        while (child != null) {
View Full Code Here

    }
   
    public static String elementToString(Element element) throws Exception {
        Map<String, String> namespaces = new HashMap<String, String>();
        visitNodesForNameSpace(element, namespaces);
        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        writeElement(element, writer, namespaces);
        XmlConverter converter = new XmlConverter();
        return converter.toString(converter.toDOMSource(writer.getDocument()), null);
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.staxutils.W3CDOMStreamWriter

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.