Java Code Examples for javax.xml.stream.XMLStreamWriter#writeNamespace()
The following examples show how to use
javax.xml.stream.XMLStreamWriter#writeNamespace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaxUtils.java From cxf with Apache License 2.0 | 6 votes |
public static void writeStartElement(XMLStreamWriter writer, String prefix, String name, String namespace) throws XMLStreamException { if (prefix == null) { prefix = ""; } if (!namespace.isEmpty()) { writer.writeStartElement(prefix, name, namespace); if (!prefix.isEmpty()) { writer.writeNamespace(prefix, namespace); writer.setPrefix(prefix, namespace); } else { writer.writeDefaultNamespace(namespace); writer.setDefaultNamespace(namespace); } } else { writer.writeStartElement(name); writer.writeDefaultNamespace(""); writer.setDefaultNamespace(""); } }
Example 2
Source File: EntityXMLWriter.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Serializes an entity to xml * @param entityResponse * @param entityStream * @throws XMLStreamException */ protected void writeEntity(EntityResponse entityResponse, OutputStream entityStream) throws XMLStreamException { XMLStreamWriter writer = null; try { //create the factory XMLOutputFactory factory = XMLOutputFactory.newInstance(); //get the stream writer writer = factory.createXMLStreamWriter(entityStream); String resourceName = entityResponse.getEntityCollectionName(); if (isList(entityResponse.getEntity())) { resourceName += "List"; } //start the document writer.writeStartDocument(); writer.writeStartElement(resourceName); writer.writeNamespace(PREFIX, NS); //recursively add the objects writeToXml(entityResponse.getEntity(), entityResponse.getEntityCollectionName(), writer); //end the document writer.writeEndElement(); writer.writeEndDocument(); } finally { if (writer != null) { writer.flush(); writer.close(); } } }
Example 3
Source File: SignedEncryptedElements.java From steady with Apache License 2.0 | 5 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { String localName = getRealName().getLocalPart(); String namespaceURI = getRealName().getNamespaceURI(); String prefix = writer.getPrefix(namespaceURI); if (prefix == null) { prefix = getRealName().getPrefix(); writer.setPrefix(prefix, namespaceURI); } // <sp:SignedElements> | <sp:EncryptedElements> writer.writeStartElement(prefix, localName, namespaceURI); // xmlns:sp=".." writer.writeNamespace(prefix, namespaceURI); if (xPathVersion != null) { writer.writeAttribute(prefix, namespaceURI, SPConstants.XPATH_VERSION, xPathVersion); } String xpathExpression; for (Iterator<String> iterator = xPathExpressions.iterator(); iterator.hasNext();) { xpathExpression = iterator.next(); // <sp:XPath ..> writer.writeStartElement(prefix, SPConstants.XPATH_EXPR, namespaceURI); writer.writeCharacters(xpathExpression); writer.writeEndElement(); } // </sp:SignedElements> | </sp:EncryptedElements> writer.writeEndElement(); }
Example 4
Source File: SourceUtils.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * sets undeclared prefixes on the writer * @param prefix * @param writer * @throws XMLStreamException */ private static void setUndeclaredPrefix(String prefix, String readerURI, XMLStreamWriter writer) throws XMLStreamException { String writerURI = null; if (writer.getNamespaceContext() != null) { writerURI = writer.getNamespaceContext().getNamespaceURI(prefix); } if (writerURI == null) { writer.setPrefix(prefix, readerURI != null ? readerURI : ""); writer.writeNamespace(prefix, readerURI != null ? readerURI : ""); } }
Example 5
Source File: XmlMetadataProducer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private static void writeAnnotationElements(final Collection<AnnotationElement> annotationElements, final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException { if (annotationElements != null) { for (AnnotationElement annotationElement : annotationElements) { ArrayList<String> setNamespaces = new ArrayList<String>(); if (annotationElement.getNamespace() != null) { if (annotationElement.getPrefix() != null) { xmlStreamWriter.writeStartElement(annotationElement.getPrefix(), annotationElement.getName(), annotationElement.getNamespace()); if (!predefinedNamespaces.containsValue(annotationElement.getNamespace())) { xmlStreamWriter.writeNamespace(annotationElement.getPrefix(), annotationElement.getNamespace()); setNamespaces.add(annotationElement.getNamespace()); } } else { xmlStreamWriter.writeStartElement("", annotationElement.getName(), annotationElement.getNamespace()); if (!predefinedNamespaces.containsValue(annotationElement.getNamespace())) { xmlStreamWriter.writeNamespace("", annotationElement.getNamespace()); setNamespaces.add(annotationElement.getNamespace()); } } } else { xmlStreamWriter.writeStartElement(annotationElement.getName()); } writeAnnotationAttributes(annotationElement.getAttributes(), predefinedNamespaces, setNamespaces, xmlStreamWriter); if (annotationElement.getChildElements() != null) { writeAnnotationElements(annotationElement.getChildElements(), predefinedNamespaces, xmlStreamWriter); } else { if (annotationElement.getText() != null) { xmlStreamWriter.writeCharacters(annotationElement.getText()); } } xmlStreamWriter.writeEndElement(); } } }
Example 6
Source File: StreamWriterBufferProcessor.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void writeInscopeNamespaces(XMLStreamWriter writer, Set<String> prefixSet) throws XMLStreamException { for (Map.Entry<String, String> e : _buffer.getInscopeNamespaces().entrySet()) { String key = fixNull(e.getKey()); // If the prefix is already written, do not write the prefix if (!prefixSet.contains(key)) { writer.writeNamespace(key, e.getValue()); } } }
Example 7
Source File: LogoutRequestGenerator.java From development with Apache License 2.0 | 5 votes |
private ByteArrayOutputStream producePureXMLLogoutRequest(String logoutUrl, String nameID, String format, String sessionIndex, String issuer, String issueInstant) throws XMLStreamException, UnsupportedEncodingException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(baos); writer.writeStartElement("saml2p", "LogoutRequest", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeNamespace("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeAttribute("ID", "_" + UUID.randomUUID().toString()); writer.writeAttribute("Version", "2.0"); writer.writeAttribute("Destination", logoutUrl); writer.writeAttribute("IssueInstant", issueInstant + "Z"); writer.writeStartElement("saml2", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeNamespace("saml2", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeCharacters(issuer); writer.writeEndElement(); writer.writeStartElement("saml", "NameID", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeAttribute("Format", format); writer.writeCharacters(nameID); writer.writeEndElement(); writer.writeStartElement("saml2p", "SessionIndex", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeCharacters(sessionIndex); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); return baos; }
Example 8
Source File: RequiredParts.java From steady with Apache License 2.0 | 5 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { String localName = getRealName().getLocalPart(); String namespaceURI = getRealName().getNamespaceURI(); String prefix = writer.getPrefix(namespaceURI); if (prefix == null) { prefix = getRealName().getPrefix(); writer.setPrefix(prefix, namespaceURI); } // <sp:RequiredParts> writer.writeStartElement(prefix, localName, namespaceURI); // xmlns:sp=".." writer.writeNamespace(prefix, namespaceURI); Header header; for (Iterator<Header> iterator = headers.iterator(); iterator.hasNext();) { header = iterator.next(); // <sp:Header Name=".." Namespace=".." /> writer.writeStartElement(prefix, SPConstants.HEADER, namespaceURI); // Name attribute is optional if (!StringUtils.isEmpty(header.getName())) { writer.writeAttribute("Name", header.getName()); } writer.writeAttribute("Namespace", header.getNamespace()); writer.writeEndElement(); } // </sp:RequiredParts> writer.writeEndElement(); }
Example 9
Source File: XMLWriterHelper.java From micro-integrator with Apache License 2.0 | 5 votes |
public void startWrapperElement(XMLStreamWriter xmlWriter, String namespace, String name, int resultType) throws XMLStreamException { if (xmlWriter == null) { return; } String nsPrefix; boolean writeNS; switch (resultType) { case DBConstants.ResultTypes.XML: if (name != null) { /* start result wrapper */ xmlWriter.writeStartElement(name); /* write default namespace */ nsPrefix = xmlWriter.getNamespaceContext().getPrefix(this.getNamespace()); writeNS = nsPrefix == null || !"".equals(nsPrefix); if (writeNS) { xmlWriter.setDefaultNamespace(namespace); xmlWriter.writeDefaultNamespace(namespace); } } break; case DBConstants.ResultTypes.RDF: xmlWriter.setDefaultNamespace(namespace); xmlWriter.writeStartElement(DBConstants.DEFAULT_RDF_PREFIX, DBConstants.DBSFields.RDF, DBConstants.RDF_NAMESPACE); xmlWriter.writeNamespace(DBConstants.DEFAULT_RDF_PREFIX, DBConstants.RDF_NAMESPACE); xmlWriter.writeDefaultNamespace(namespace); break; } }
Example 10
Source File: XmlPropertyEntityProducer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * * @param writer * @param prop * @param name * @throws XMLStreamException * @throws EntityProviderException */ private void writeStartElementWithCustomNamespace(final XMLStreamWriter writer, final EntityPropertyInfo prop, final String name) throws XMLStreamException, EntityProviderException { EdmCustomizableFeedMappings mapping = prop.getCustomMapping(); String nsPrefix = mapping.getFcNsPrefix(); String nsUri = mapping.getFcNsUri(); if (nsUri == null || nsPrefix == null) { throw new EntityProviderProducerException(EntityProviderException.INVALID_NAMESPACE.addContent(name)); } writer.writeStartElement(nsPrefix, name, nsUri); writer.writeNamespace(nsPrefix, nsUri); }
Example 11
Source File: DocumentMetadataPatchBuilderImpl.java From java-client-api with Apache License 2.0 | 5 votes |
@Override public void process(Object original, String type, String value) { XMLStreamWriter serializer = out.getSerializer(); if (original == null) return; try { serializer.writeNamespace("xs", XMLConstants.W3C_XML_SCHEMA_NS_URI); serializer.writeAttribute( "xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type", type); if(value != null) serializer.writeCharacters(value); } catch(XMLStreamException e) { throw new MarkLogicIOException(e); } }
Example 12
Source File: ProtectionToken.java From steady with Apache License 2.0 | 4 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { String localname = getRealName().getLocalPart(); String namespaceURI = getRealName().getNamespaceURI(); String prefix; String writerPrefix = writer.getPrefix(namespaceURI); if (writerPrefix == null) { prefix = getRealName().getPrefix(); writer.setPrefix(prefix, namespaceURI); } else { prefix = writerPrefix; } // <sp:ProtectionToken> writer.writeStartElement(prefix, localname, namespaceURI); if (writerPrefix == null) { // xmlns:sp=".." writer.writeNamespace(prefix, namespaceURI); } String policyLocalName = SPConstants.POLICY.getLocalPart(); String policyNamespaceURI = SPConstants.POLICY.getNamespaceURI(); String wspPrefix; String wspWriterPrefix = writer.getPrefix(policyNamespaceURI); if (wspWriterPrefix == null) { wspPrefix = SPConstants.POLICY.getPrefix(); writer.setPrefix(wspPrefix, policyNamespaceURI); } else { wspPrefix = wspWriterPrefix; } // <wsp:Policy> writer.writeStartElement(wspPrefix, policyLocalName, policyNamespaceURI); if (wspWriterPrefix == null) { // xmlns:wsp=".." writer.writeNamespace(wspPrefix, policyNamespaceURI); } if (token == null) { throw new RuntimeException("ProtectionToken is not set"); } token.serialize(writer); // </wsp:Policy> writer.writeEndElement(); // </sp:ProtectionToken> writer.writeEndElement(); }
Example 13
Source File: KerberosToken.java From steady with Apache License 2.0 | 4 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { QName name = constants.getSamlToken(); String localname = name.getLocalPart(); String namespaceURI = name.getNamespaceURI(); String prefix = writer.getPrefix(namespaceURI); if (prefix == null) { prefix = name.getPrefix(); writer.setPrefix(prefix, namespaceURI); } // <sp:KerberosToken writer.writeStartElement(prefix, localname, namespaceURI); writer.writeNamespace(prefix, namespaceURI); String inclusion; inclusion = constants.getAttributeValueFromInclusion(getInclusion()); if (inclusion != null) { writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion); } String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI()); if (pPrefix == null) { pPrefix = SPConstants.POLICY.getPrefix(); writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI()); } // <wsp:Policy> writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY .getNamespaceURI()); if (isRequireKeyIdentifierReference()) { // <sp:RequireKeyIdentifierReference /> writer.writeStartElement(prefix, SPConstants.REQUIRE_KEY_IDENTIFIER_REFERENCE, namespaceURI); writer.writeEndElement(); } if (isV5ApReqToken11()) { // <sp:WssKerberosV5ApReqToken11 /> writer.writeStartElement(prefix, SPConstants.KERBEROS_V5_AP_REQ_TOKEN_11, namespaceURI); writer.writeEndElement(); } else if (isGssV5ApReqToken11()) { // <sp:WssGssKerberosV5ApReqToken11 /> writer.writeStartElement(prefix, SPConstants.KERBEROS_GSS_V5_AP_REQ_TOKEN_11, namespaceURI); writer.writeEndElement(); } if (isDerivedKeys()) { // <sp:RequireDerivedKeys /> writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI); writer.writeEndElement(); } // </wsp:Policy> writer.writeEndElement(); writer.writeEndElement(); // </sp:KerberosToken> }
Example 14
Source File: ProtectionToken.java From steady with Apache License 2.0 | 4 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { String localname = getRealName().getLocalPart(); String namespaceURI = getRealName().getNamespaceURI(); String prefix; String writerPrefix = writer.getPrefix(namespaceURI); if (writerPrefix == null) { prefix = getRealName().getPrefix(); writer.setPrefix(prefix, namespaceURI); } else { prefix = writerPrefix; } // <sp:ProtectionToken> writer.writeStartElement(prefix, localname, namespaceURI); if (writerPrefix == null) { // xmlns:sp=".." writer.writeNamespace(prefix, namespaceURI); } String policyLocalName = SPConstants.POLICY.getLocalPart(); String policyNamespaceURI = SPConstants.POLICY.getNamespaceURI(); String wspPrefix; String wspWriterPrefix = writer.getPrefix(policyNamespaceURI); if (wspWriterPrefix == null) { wspPrefix = SPConstants.POLICY.getPrefix(); writer.setPrefix(wspPrefix, policyNamespaceURI); } else { wspPrefix = wspWriterPrefix; } // <wsp:Policy> writer.writeStartElement(wspPrefix, policyLocalName, policyNamespaceURI); if (wspWriterPrefix == null) { // xmlns:wsp=".." writer.writeNamespace(wspPrefix, policyNamespaceURI); } if (token == null) { throw new RuntimeException("ProtectionToken is not set"); } token.serialize(writer); // </wsp:Policy> writer.writeEndElement(); // </sp:ProtectionToken> writer.writeEndElement(); }
Example 15
Source File: StreamWriterBufferProcessor.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private int writeNamespaceAttributes(int item, XMLStreamWriter writer, boolean collectPrefixes, Set<String> prefixSet) throws XMLStreamException { do { switch(getNIIState(item)){ case STATE_NAMESPACE_ATTRIBUTE: // Undeclaration of default namespace writer.writeDefaultNamespace(""); if (collectPrefixes) { prefixSet.add(""); } break; case STATE_NAMESPACE_ATTRIBUTE_P: // Undeclaration of namespace // Declaration with prefix String prefix = readStructureString(); writer.writeNamespace(prefix, ""); if (collectPrefixes) { prefixSet.add(prefix); } break; case STATE_NAMESPACE_ATTRIBUTE_P_U: // Declaration with prefix prefix = readStructureString(); writer.writeNamespace(prefix, readStructureString()); if (collectPrefixes) { prefixSet.add(prefix); } break; case STATE_NAMESPACE_ATTRIBUTE_U: // Default declaration writer.writeDefaultNamespace(readStructureString()); if (collectPrefixes) { prefixSet.add(""); } break; } readStructure(); item = peekStructure(); } while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE); return item; }
Example 16
Source File: Soap11FaultSoapPayloadConverter.java From syndesis with Apache License 2.0 | 4 votes |
@Override protected void handleFault(XMLStreamWriter writer, SoapFault fault, SoapVersion soapVersion) { try { Map<String, String> namespaces = fault.getNamespaces(); for (Map.Entry<String, String> e : namespaces.entrySet()) { writer.writeNamespace(e.getKey(), e.getValue()); } final String soapNamespace = soapVersion.getNamespace(); writer.writeStartElement(SOAP_PREFIX, "Fault", soapNamespace); writer.writeStartElement("faultcode"); String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()), SOAP_PREFIX); writer.writeCharacters(codeString); writer.writeEndElement(); writer.writeStartElement("faultstring"); String lang = fault.getLang(); if (!StringUtils.isEmpty(lang)) { writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", lang); } writer.writeCharacters(getFaultMessage(fault)); writer.writeEndElement(); prepareStackTrace(soapNamespace, fault); if (fault.getRole() != null) { writer.writeStartElement("faultactor"); writer.writeCharacters(fault.getRole()); writer.writeEndElement(); } if (fault.hasDetails()) { Element detail = fault.getDetail(); writer.writeStartElement("detail"); Node node = detail.getFirstChild(); while (node != null) { StaxUtils.writeNode(node, writer, true); node = node.getNextSibling(); } // Details writer.writeEndElement(); } // Fault writer.writeEndElement(); } catch (Exception xe) { throw new RuntimeCamelException("XML write exception: " + xe.getMessage(), xe); } }
Example 17
Source File: OutTransformWriterTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testReadWithComplexTransformationNamespace2() throws Exception { Map<String, String> map = new HashMap<>(); map.put("{http://testbeans.com/double}*", "{http://testbeans.com/double/v2}*"); map.put("{http://testbeans.com}*", "{http://testbeans.com/v3}*"); // the namespaces are prefixed in the input XMLStreamReader reader = TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn1.xml", map, null, null, null, false, null); XMLStreamReader reader2 = StaxUtils.createXMLStreamReader( InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml")); TransformTestUtils.verifyReaders(reader2, reader, true, false); // the child elements with the default namespace that is declared in the elements reader = TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn2.xml", map, null, null, null, false, null); reader2 = StaxUtils.createXMLStreamReader( InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml")); TransformTestUtils.verifyReaders(reader2, reader, true, false); // the child elements with the default namespace that is declared in their parent element reader = TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn3.xml", map, null, null, null, false, null); reader2 = StaxUtils.createXMLStreamReader( InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml")); TransformTestUtils.verifyReaders(reader2, reader, true, false); // writing each child separately (as the soap header children are serialized) ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLStreamWriter writer = new OutTransformWriter(StaxUtils.createXMLStreamWriter(os, StandardCharsets.UTF_8.name()), map, null, null, null, false, null); boolean nsset = "ns3".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com/double")); writer.writeStartElement("ns3", "testDoubleBean", "http://testbeans.com/double"); if (!nsset) { writer.writeNamespace("ns3", "http://testbeans.com/double"); } nsset = "".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com")); writer.writeStartElement("", "bean", "http://testbeans.com"); if (!nsset) { writer.writeNamespace("", "http://testbeans.com"); } writer.writeEndElement(); nsset = "".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com")); writer.writeStartElement("", "beanNext", "http://testbeans.com"); if (!nsset) { writer.writeNamespace("", "http://testbeans.com"); } writer.writeEndElement(); writer.writeEndElement(); writer.flush(); reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(os.toByteArray())); reader2 = StaxUtils.createXMLStreamReader( InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml")); TransformTestUtils.verifyReaders(reader2, reader, true, false); }
Example 18
Source File: SpnegoContextToken.java From steady with Apache License 2.0 | 4 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { QName name = constants.getSpnegoContextToken(); String localname = name.getLocalPart(); String namespaceURI = name.getNamespaceURI(); String prefix; String writerPrefix = writer.getPrefix(namespaceURI); if (writerPrefix == null) { prefix = name.getPrefix(); writer.setPrefix(prefix, namespaceURI); } else { prefix = writerPrefix; } // <sp:SpnegoContextToken> writer.writeStartElement(prefix, localname, namespaceURI); if (writerPrefix == null) { // xmlns:sp=".." writer.writeNamespace(prefix, namespaceURI); } String inclusion; inclusion = constants.getAttributeValueFromInclusion(getInclusion()); if (inclusion != null) { writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion); } if (issuerEpr != null) { // <sp:Issuer> writer.writeStartElement(prefix, SPConstants.ISSUER, namespaceURI); StaxUtils.copy(issuerEpr, writer); writer.writeEndElement(); } if (isDerivedKeys()) { String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI(); String wspPrefix; String wspWriterPrefix = writer.getPrefix(wspNamespaceURI); if (wspWriterPrefix == null) { wspPrefix = SPConstants.POLICY.getPrefix(); writer.setPrefix(wspPrefix, wspNamespaceURI); } else { wspPrefix = wspWriterPrefix; } // <wsp:Policy> writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI); if (wspWriterPrefix == null) { // xmlns:wsp=".." writer.writeNamespace(wspPrefix, wspNamespaceURI); } if (isDerivedKeys()) { // <sp:RequireDerivedKeys /> writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI); } // </wsp:Policy> writer.writeEndElement(); } // </sp:SpnegoContextToken> writer.writeEndElement(); }
Example 19
Source File: Soap11FaultOutInterceptor.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(SoapMessage message) throws Fault { XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); Fault f = (Fault) message.getContent(Exception.class); SoapFault fault = SoapFault.createFault(f, message.getVersion()); try { Map<String, String> namespaces = fault.getNamespaces(); for (Map.Entry<String, String> e : namespaces.entrySet()) { writer.writeNamespace(e.getKey(), e.getValue()); } String ns = message.getVersion().getNamespace(); String defaultPrefix = writer.getPrefix(ns); if (defaultPrefix == null) { defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, false); writer.writeStartElement(defaultPrefix, "Fault", ns); writer.writeNamespace(defaultPrefix, ns); } else { writer.writeStartElement(defaultPrefix, "Fault", ns); } writer.writeStartElement("faultcode"); String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()), defaultPrefix); writer.writeCharacters(codeString); writer.writeEndElement(); writer.writeStartElement("faultstring"); String lang = f.getLang(); if (!StringUtils.isEmpty(lang)) { writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", lang); } writer.writeCharacters(getFaultMessage(message, fault)); writer.writeEndElement(); prepareStackTrace(message, fault); if (fault.getRole() != null) { writer.writeStartElement("faultactor"); writer.writeCharacters(fault.getRole()); writer.writeEndElement(); } if (fault.hasDetails()) { Element detail = fault.getDetail(); writer.writeStartElement("detail"); Node node = detail.getFirstChild(); while (node != null) { StaxUtils.writeNode(node, writer, true); node = node.getNextSibling(); } // Details writer.writeEndElement(); } // Fault writer.writeEndElement(); } catch (Exception xe) { LOG.log(Level.WARNING, "XML_WRITE_EXC", xe); throw f; } }
Example 20
Source File: UsernameToken.java From steady with Apache License 2.0 | 4 votes |
public void serialize(XMLStreamWriter writer) throws XMLStreamException { QName name = constants.getUserNameToken(); String localname = name.getLocalPart(); String namespaceURI = name.getNamespaceURI(); String prefix = writer.getPrefix(namespaceURI); if (prefix == null) { prefix = name.getPrefix(); writer.setPrefix(prefix, namespaceURI); } // <sp:UsernameToken writer.writeStartElement(prefix, localname, namespaceURI); writer.writeNamespace(prefix, namespaceURI); String inclusion; inclusion = constants.getAttributeValueFromInclusion(getInclusion()); if (inclusion != null) { writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion); } if (isUseUTProfile10() || isUseUTProfile11()) { String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI()); if (pPrefix == null) { pPrefix = SPConstants.POLICY.getPrefix(); writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI()); } // <wsp:Policy> writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY .getNamespaceURI()); // CHECKME if (isUseUTProfile10()) { // <sp:WssUsernameToken10 /> writer.writeStartElement(prefix, SPConstants.USERNAME_TOKEN10, namespaceURI); } else { // <sp:WssUsernameToken11 /> writer.writeStartElement(prefix, SPConstants.USERNAME_TOKEN11, namespaceURI); } if (constants.getVersion() == SPConstants.Version.SP_V12) { if (isNoPassword()) { writer.writeStartElement(prefix, SPConstants.NO_PASSWORD, namespaceURI); writer.writeEndElement(); } else if (isHashPassword()) { writer.writeStartElement(prefix, SPConstants.HASH_PASSWORD, namespaceURI); writer.writeEndElement(); } if (isDerivedKeys()) { writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI); writer.writeEndElement(); } else if (isExplicitDerivedKeys()) { writer.writeStartElement(prefix, SPConstants.REQUIRE_EXPLICIT_DERIVED_KEYS, namespaceURI); writer.writeEndElement(); } else if (isImpliedDerivedKeys()) { writer.writeStartElement(prefix, SPConstants.REQUIRE_IMPLIED_DERIVED_KEYS, namespaceURI); writer.writeEndElement(); } if (isRequireCreated()) { writer.writeStartElement(SP13Constants.SP_PREFIX, "Created", SP13Constants.SP_NS); writer.writeNamespace(SP13Constants.SP_PREFIX, SP13Constants.SP_NS); writer.writeEndElement(); } if (isRequireNonce()) { writer.writeStartElement(SP13Constants.SP_PREFIX, "Nonce", SP13Constants.SP_NS); writer.writeNamespace(SP13Constants.SP_PREFIX, SP13Constants.SP_NS); writer.writeEndElement(); } } writer.writeEndElement(); // </wsp:Policy> writer.writeEndElement(); } writer.writeEndElement(); // </sp:UsernameToken> }