Search in sources :

Example 66 with StreamSource

use of javax.xml.transform.stream.StreamSource in project camel by apache.

the class ConsumerWSAEndpointMappingRouteTest method testWSAddressingToResponseActions.

@Test
public void testWSAddressingToResponseActions() throws Exception {
    StreamSource source = new StreamSource(new StringReader(xmlBody));
    webServiceTemplate.sendSourceAndReceive(source, new ActionCallback(new URI("http://doesn-not-matter.com"), new Addressing10(), new URI("http://urlOutputAndFault2.to")), TestUtil.NOOP_SOURCE_EXTRACTOR);
    resultOutputAndFault2.expectedMinimumMessageCount(1);
    resultOutputAndFault2.assertIsSatisfied();
}
Also used : SoapActionCallback(org.springframework.ws.soap.client.core.SoapActionCallback) ActionCallback(org.springframework.ws.soap.addressing.client.ActionCallback) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Addressing10(org.springframework.ws.soap.addressing.version.Addressing10) URI(java.net.URI) Test(org.junit.Test)

Example 67 with StreamSource

use of javax.xml.transform.stream.StreamSource in project camel by apache.

the class AbstractWSATests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    // initialize beans for catching results
    webServiceTemplate = applicationContext.getBean("webServiceTemplate", WebServiceTemplate.class);
    newReply = getMandatoryBean(OutputChannelReceiver.class, "replyReceiver");
    response = getMandatoryBean(OutputChannelReceiver.class, "responseReceiver");
    // sample data
    source = new StreamSource(new StringReader(xmlBody));
    result = new StreamResult(new StringWriter());
    // reset from previous test
    response.clear();
    newReply.clear();
    requestInputAction = null;
}
Also used : OutputChannelReceiver(org.apache.camel.component.spring.ws.utils.OutputChannelReceiver) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Before(org.junit.Before)

Example 68 with StreamSource

use of javax.xml.transform.stream.StreamSource in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method testSchema.

@Test
public void testSchema() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URL schemaResource = ClientDiscoverySpiTest.class.getClassLoader().getResource("hazelcast-client-config-3.9.xsd");
    Schema schema = factory.newSchema(schemaResource);
    InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Source source = new StreamSource(xmlResource);
    Validator validator = schema.newValidator();
    validator.validate(source);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) InputStream(java.io.InputStream) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Validator(javax.xml.validation.Validator) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 69 with StreamSource

use of javax.xml.transform.stream.StreamSource in project hazelcast by hazelcast.

the class ConfigXmlGenerator method format.

private String format(final String input, int indent) {
    if (!formatted) {
        return input;
    }
    StreamResult xmlOutput = null;
    try {
        final Source xmlInput = new StreamSource(new StringReader(input));
        xmlOutput = new StreamResult(new StringWriter());
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        /* Older versions of Xalan still use this method of setting indent values.
            * Attempt to make this work but don't completely fail if it's a problem.
            */
        try {
            transformerFactory.setAttribute("indent-number", indent);
        } catch (IllegalArgumentException e) {
            if (LOGGER.isFinestEnabled()) {
                LOGGER.finest("Failed to set indent-number attribute; cause: " + e.getMessage());
            }
        }
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        /* Newer versions of Xalan will look for a fully-qualified output property in order to specify amount of
            * indentation to use.  Attempt to make this work as well but again don't completely fail if it's a problem.
            */
        try {
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent));
        } catch (IllegalArgumentException e) {
            if (LOGGER.isFinestEnabled()) {
                LOGGER.finest("Failed to set indent-amount property; cause: " + e.getMessage());
            }
        }
        transformer.transform(xmlInput, xmlOutput);
        return xmlOutput.getWriter().toString();
    } catch (Exception e) {
        LOGGER.warning(e);
        return input;
    } finally {
        if (xmlOutput != null) {
            closeResource(xmlOutput.getWriter());
        }
    }
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 70 with StreamSource

use of javax.xml.transform.stream.StreamSource in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldBeAValidXSD.

@Test
public void shouldBeAValidXSD() throws Exception {
    SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    factory.newSchema(new StreamSource(getClass().getResourceAsStream("/cruise-config.xsd")));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StreamSource(javax.xml.transform.stream.StreamSource) Test(org.junit.Test)

Aggregations

StreamSource (javax.xml.transform.stream.StreamSource)338 Source (javax.xml.transform.Source)115 StringReader (java.io.StringReader)101 StreamResult (javax.xml.transform.stream.StreamResult)85 Transformer (javax.xml.transform.Transformer)74 Test (org.junit.Test)73 InputStream (java.io.InputStream)68 TransformerFactory (javax.xml.transform.TransformerFactory)58 ByteArrayInputStream (java.io.ByteArrayInputStream)56 IOException (java.io.IOException)52 DOMSource (javax.xml.transform.dom.DOMSource)49 TransformerException (javax.xml.transform.TransformerException)48 StringWriter (java.io.StringWriter)45 SchemaFactory (javax.xml.validation.SchemaFactory)44 InputSource (org.xml.sax.InputSource)44 Schema (javax.xml.validation.Schema)43 SAXException (org.xml.sax.SAXException)42 SAXSource (javax.xml.transform.sax.SAXSource)33 Validator (javax.xml.validation.Validator)31 File (java.io.File)27