Search in sources :

Example 6 with StringReader

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

the class CxfRsConsumerSimpleBindingTest method testListVipCustomers.

@Test
public void testListVipCustomers() throws Exception {
    HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold");
    get.addHeader("Content-Type", "text/xml");
    get.addHeader("Accept", "text/xml");
    HttpResponse response = httpclient.execute(get);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CustomerList cl = (CustomerList) jaxb.createUnmarshaller().unmarshal(new StringReader(EntityUtils.toString(response.getEntity())));
    List<Customer> vips = cl.getCustomers();
    assertEquals(2, vips.size());
    assertEquals(123, vips.get(0).getId());
    assertEquals(456, vips.get(1).getId());
}
Also used : Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) HttpGet(org.apache.http.client.methods.HttpGet) StringReader(java.io.StringReader) HttpResponse(org.apache.http.HttpResponse) CustomerList(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList) Test(org.junit.Test)

Example 7 with StringReader

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

the class CxfMtomDisabledProducerPayloadModeTest method testProducer.

@Override
public void testProducer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
        return;
    }
    Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            List<Source> elements = new ArrayList<Source>();
            elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.MTOM_DISABLED_REQ_MESSAGE)).getDocumentElement()));
            CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null);
            exchange.getIn().setBody(body);
            exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
            exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
        }
    });
    // process response - verify response attachments
    CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
    Assert.assertEquals(1, out.getBody().size());
    DataHandler dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_PHOTO_CID);
    Assert.assertEquals("application/octet-stream", dr.getContentType());
    MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
    dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_IMAGE_CID);
    Assert.assertEquals("image/jpeg", dr.getContentType());
    BufferedImage image = ImageIO.read(dr.getInputStream());
    Assert.assertEquals(560, image.getWidth());
    Assert.assertEquals(300, image.getHeight());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Processor(org.apache.camel.Processor) CxfPayload(org.apache.camel.component.cxf.CxfPayload) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) DOMSource(javax.xml.transform.dom.DOMSource) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) AttachmentDataSource(org.apache.cxf.attachment.AttachmentDataSource) Source(javax.xml.transform.Source) DataSource(javax.activation.DataSource) BufferedImage(java.awt.image.BufferedImage) Exchange(org.apache.camel.Exchange) StringReader(java.io.StringReader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Example 8 with StringReader

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

the class CacheInputStreamInDeadLetterIssue520Test method testSendingSource.

public void testSendingSource() throws Exception {
    StreamSource message = new StreamSource(new StringReader("<hello>Willem</hello>"));
    sendingMessage(message);
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Example 9 with StringReader

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

the class CacheInputStreamInDeadLetterIssue520Test method testSendingReader.

public void testSendingReader() throws Exception {
    StringReader message = new StringReader("<hello>Willem</hello>");
    sendingMessage(message);
}
Also used : StringReader(java.io.StringReader)

Example 10 with StringReader

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

the class StreamCachingInterceptorTest method testConvertStreamSourceWithRouteOnlyStreamCaching.

public void testConvertStreamSourceWithRouteOnlyStreamCaching() throws Exception {
    b.expectedMessageCount(1);
    StreamSource message = new StreamSource(new StringReader(MESSAGE));
    template.sendBody("direct:b", message);
    assertMockEndpointsSatisfied();
    assertTrue(b.assertExchangeReceived(0).getIn().getBody() instanceof StreamCache);
    assertEquals(b.assertExchangeReceived(0).getIn().getBody(String.class), MESSAGE);
}
Also used : StreamCache(org.apache.camel.StreamCache) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Aggregations

StringReader (java.io.StringReader)3695 Test (org.junit.Test)837 IOException (java.io.IOException)488 Reader (java.io.Reader)402 InputSource (org.xml.sax.InputSource)369 TokenStream (org.apache.lucene.analysis.TokenStream)298 BufferedReader (java.io.BufferedReader)277 Tokenizer (org.apache.lucene.analysis.Tokenizer)238 StringWriter (java.io.StringWriter)226 ArrayList (java.util.ArrayList)225 JSONReader (com.alibaba.fastjson.JSONReader)195 Document (org.w3c.dom.Document)181 DocumentBuilder (javax.xml.parsers.DocumentBuilder)165 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)141 Map (java.util.Map)139 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120 HashMap (java.util.HashMap)117 Element (org.w3c.dom.Element)108 StreamSource (javax.xml.transform.stream.StreamSource)106