use of javax.xml.stream.XMLStreamWriter in project oxCore by GluuFederation.
the class AuthRequest method getStreamedRequest.
public String getStreamedRequest(boolean useBase64) throws XMLStreamException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
writer.writeStartElement("samlp", "AuthnRequest", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeAttribute("ID", id);
writer.writeAttribute("Version", "2.0");
writer.writeAttribute("IssueInstant", this.issueInstant);
writer.writeAttribute("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
writer.writeAttribute("AssertionConsumerServiceURL", this.samlSettings.getAssertionConsumerServiceUrl());
writer.writeStartElement("saml", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeCharacters(this.samlSettings.getIssuer());
writer.writeEndElement();
writer.writeStartElement("samlp", "NameIDPolicy", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeAttribute("Format", this.samlSettings.getNameIdentifierFormat());
writer.writeAttribute("AllowCreate", "true");
writer.writeEndElement();
writer.writeStartElement("samlp", "RequestedAuthnContext", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeAttribute("Comparison", "exact");
writer.writeStartElement("saml", "AuthnContextClassRef", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeCharacters("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
writer.writeEndElement();
writer.writeEndElement();
writer.writeEndElement();
writer.flush();
if (log.isDebugEnabled()) {
log.debug("Genereated Saml Request " + new String(baos.toByteArray(), "UTF-8"));
}
if (useBase64) {
byte[] deflated = CompressionHelper.deflate(baos.toByteArray(), true);
String base64 = Base64.encodeBase64String(deflated);
String encoded = URLEncoder.encode(base64, "UTF-8");
return encoded;
}
return new String(baos.toByteArray(), "UTF-8");
}
use of javax.xml.stream.XMLStreamWriter in project midpoint by Evolveum.
the class CustomWrappedOutInterceptor method writeParts.
@Override
protected void writeParts(Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) {
// TODO Auto-generated method stub
OutputStream out = message.getContent(OutputStream.class);
XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
Service service = exchange.getService();
XMLStreamWriter xmlWriter = origXmlWriter;
CachingXmlEventWriter cache = null;
Object en = message.getContextualProperty(OUT_BUFFERING);
boolean allowBuffer = true;
boolean buffer = false;
if (en != null) {
buffer = Boolean.TRUE.equals(en) || "true".equals(en);
allowBuffer = !(Boolean.FALSE.equals(en) || "false".equals(en));
}
// need to cache the events in case validation fails or buffering is enabled
if (buffer || (allowBuffer && shouldValidate(message) && !isRequestor(message))) {
cache = new CachingXmlEventWriter();
try {
cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
} catch (XMLStreamException e) {
//ignorable, will just get extra namespace decls
}
xmlWriter = cache;
out = null;
}
if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.isTrue(message.getContextualProperty(DISABLE_OUTPUTSTREAM_OPTIMIZATION))) {
if (xmlWriter != null) {
try {
xmlWriter.writeCharacters("");
xmlWriter.flush();
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
osWriter.write(o, part, out);
}
}
} else {
DataWriter<XMLStreamWriter> dataWriter = new CustomDataWriter(prismContext);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
dataWriter.write(o, part, xmlWriter);
}
}
}
if (cache != null) {
try {
for (XMLEvent event : cache.getEvents()) {
StaxUtils.writeEvent(event, origXmlWriter);
}
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
}
use of javax.xml.stream.XMLStreamWriter in project voltdb by VoltDB.
the class JDBCSQLXML method createSAXResult.
/**
* Retrieves a new SAXResult for setting the XML value designated by this
* SQLXML instance.
*
* @param resultClass The class of the result, or null.
* @throws java.sql.SQLException if there is an error processing the XML
* value
* @return for setting the XML value designated by this SQLXML instance.
*/
@SuppressWarnings("unchecked")
protected <T extends Result> T createSAXResult(Class<T> resultClass) throws SQLException {
SAXResult result = null;
try {
result = (resultClass == null) ? new SAXResult() : (SAXResult) resultClass.newInstance();
} catch (SecurityException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (InstantiationException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (IllegalAccessException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (ClassCastException ex) {
throw Exceptions.resultInstantiation(ex);
}
StAXResult staxResult = createStAXResult(null);
XMLStreamWriter xmlWriter = staxResult.getXMLStreamWriter();
SAX2XMLStreamWriter handler = new SAX2XMLStreamWriter(xmlWriter);
result.setHandler(handler);
return (T) result;
}
use of javax.xml.stream.XMLStreamWriter in project aries by apache.
the class PersistenceContextHandler method handleFieldAnnotation.
@Override
public void handleFieldAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
final String nsJpa1 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_JPA1);
if (nsJpa1 != null) {
for (final Field field : fields) {
final String name = field.getName();
final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
beanEnricher.addBeanContentWriter("javax.persistence.field.context/" + name, new XmlWriter() {
@Override
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEmptyElement("context");
writer.writeDefaultNamespace(nsJpa1);
writer.writeAttribute("unitname", persistenceContext.unitName());
writer.writeAttribute("property", name);
}
});
}
}
final String nsJpa2 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_JPA2);
if (nsJpa2 != null) {
contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new XmlWriter() {
@Override
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEmptyElement("enable");
writer.writeDefaultNamespace(nsJpa2);
}
});
}
}
use of javax.xml.stream.XMLStreamWriter in project aries by apache.
the class PersistenceUnitHandler method handleFieldAnnotation.
@Override
public void handleFieldAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
final String nsJpa1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_JPA1);
if (nsJpa1 != null) {
for (final Field field : fields) {
final String name = field.getName();
final PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
beanEnricher.addBeanContentWriter("javax.persistence.field.unit/" + name, new XmlWriter() {
@Override
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEmptyElement("unit");
writer.writeDefaultNamespace(nsJpa1);
writer.writeAttribute("unitname", persistenceUnit.unitName());
writer.writeAttribute("property", name);
}
});
}
}
final String nsJpa2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_JPA2);
if (nsJpa2 != null) {
contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new XmlWriter() {
@Override
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEmptyElement("enable");
writer.writeDefaultNamespace(nsJpa2);
}
});
}
}
Aggregations