Search in sources :

Example 91 with StringReader

use of java.io.StringReader in project camel by apache.

the class ConsumerEndpointMappingByBeanNameRouteTest method testBeanName.

@Test
public void testBeanName() throws Exception {
    StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuote));
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    assertNotNull(result);
    TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 92 with StringReader

use of java.io.StringReader in project camel by apache.

the class ConsumerEndpointMappingResponseHandlingRouteTest method testRootQName.

@Test
public void testRootQName() throws Exception {
    StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuote));
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    assertNotNull(result);
    TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 93 with StringReader

use of java.io.StringReader in project camel by apache.

the class MixedStreamCachingInterceptorTest method testNoStreamCaching.

public void testNoStreamCaching() throws Exception {
    MockEndpoint b = getMockEndpoint("mock:b");
    b.expectedMessageCount(1);
    StreamSource message = new StreamSource(new StringReader("<hello>world!</hello>"));
    template.sendBody("direct:b", message);
    assertMockEndpointsSatisfied();
    Exchange exchange = b.getExchanges().get(0);
    StreamSource stream = assertIsInstanceOf(StreamSource.class, exchange.getIn().getBody());
    assertNotNull(stream);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Example 94 with StringReader

use of java.io.StringReader in project camel by apache.

the class NoStreamCachingInterceptorTest method testNoStreamCachingInterceptorEnabled.

public void testNoStreamCachingInterceptorEnabled() throws Exception {
    MockEndpoint a = getMockEndpoint("mock:a");
    a.expectedMessageCount(1);
    StreamSource message = new StreamSource(new StringReader("<hello>world!</hello>"));
    template.sendBody("direct:a", message);
    assertMockEndpointsSatisfied();
    Exchange exchange = a.getExchanges().get(0);
    StreamSource stream = assertIsInstanceOf(StreamSource.class, exchange.getIn().getBody());
    assertNotNull(stream);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Example 95 with StringReader

use of java.io.StringReader in project camel by apache.

the class XAdESSignatureProperties method createChildFromXmlFragmentOrText.

protected Element createChildFromXmlFragmentOrText(Document doc, Input input, String localElementName, String errorMessage, String elementOrText) throws IOException, ParserConfigurationException, XmlSignatureException {
    String ending = localElementName + ">";
    Element child;
    if (elementOrText.startsWith("<") && elementOrText.endsWith(ending)) {
        try {
            // assume xml
            InputSource source = new InputSource(new StringReader(elementOrText));
            source.setEncoding("UTF-8");
            Document parsedDoc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(source);
            replacePrefixes(parsedDoc, input);
            child = (Element) doc.adoptNode(parsedDoc.getDocumentElement());
            // check for correct namespace
            String ns = findNamespace(input.getMessage());
            if (!ns.equals(child.getNamespaceURI())) {
                throw new XmlSignatureException(String.format("The XAdES confguration is invalid. The root element '%s' of the provided XML fragment '%s' has the invalid namespace '%s'. The correct namespace is '%s'.", child.getLocalName(), elementOrText, child.getNamespaceURI(), ns));
            }
        } catch (SAXException e) {
            throw new XmlSignatureException(String.format(errorMessage, elementOrText, localElementName, namespace), e);
        }
    } else {
        child = createElement(localElementName, doc, input);
        child.setTextContent(elementOrText);
    }
    return child;
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

StringReader (java.io.StringReader)4150 Test (org.junit.Test)1003 IOException (java.io.IOException)589 Reader (java.io.Reader)445 InputSource (org.xml.sax.InputSource)408 BufferedReader (java.io.BufferedReader)342 TokenStream (org.apache.lucene.analysis.TokenStream)302 ArrayList (java.util.ArrayList)273 StringWriter (java.io.StringWriter)251 Tokenizer (org.apache.lucene.analysis.Tokenizer)241 Document (org.w3c.dom.Document)232 JSONReader (com.alibaba.fastjson.JSONReader)195 DocumentBuilder (javax.xml.parsers.DocumentBuilder)180 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)157 Map (java.util.Map)144 HashMap (java.util.HashMap)136 Element (org.w3c.dom.Element)134 StreamSource (javax.xml.transform.stream.StreamSource)132 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120