Search in sources :

Example 56 with StreamSource

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

the class DefaultBulkApiClient method unmarshalResponse.

private <T> T unmarshalResponse(InputStream response, Request request, Class<T> resultClass) throws SalesforceException {
    try {
        Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement<T> result = unmarshaller.unmarshal(new StreamSource(response), resultClass);
        return result.getValue();
    } catch (JAXBException e) {
        throw new SalesforceException(String.format("Error unmarshaling response {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new SalesforceException(String.format("Error unmarshaling response for {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 57 with StreamSource

use of javax.xml.transform.stream.StreamSource 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 58 with StreamSource

use of javax.xml.transform.stream.StreamSource 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 59 with StreamSource

use of javax.xml.transform.stream.StreamSource 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 60 with StreamSource

use of javax.xml.transform.stream.StreamSource 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)

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