Search in sources :

Example 51 with ByteArrayInputStream

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

the class HL7DataFormatTest method testUnmarshalWithImplicitBig5Charset.

@Test
public void testUnmarshalWithImplicitBig5Charset() throws Exception {
    String charset = "Big5";
    MockEndpoint mock = getMockEndpoint("mock:unmarshalBig5");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);
    mock.expectedHeaderReceived(HL7Constants.HL7_CHARSET, null);
    mock.expectedHeaderReceived(Exchange.CHARSET_NAME, charset);
    // Message without explicit encoding in MSH-18, but the unmarshaller "guesses"
    // this time that it is Big5
    byte[] body = createHL7AsString().getBytes(Charset.forName(charset));
    template.sendBody("direct:unmarshalBig5", new ByteArrayInputStream(body));
    assertMockEndpointsSatisfied();
    Message msg = mock.getExchanges().get(0).getIn().getBody(Message.class);
    assertEquals("2.4", msg.getVersion());
    QRD qrd = (QRD) msg.get("QRD");
    assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 52 with ByteArrayInputStream

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

the class HL7DataFormatTest method testUnmarshalWithExplicitUTF16Charset.

@Test
public void testUnmarshalWithExplicitUTF16Charset() throws Exception {
    String charset = "UTF-16";
    MockEndpoint mock = getMockEndpoint("mock:unmarshal");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);
    mock.expectedHeaderReceived(HL7Constants.HL7_CHARSET, HL7Charset.getHL7Charset(charset).getHL7CharsetName());
    mock.expectedHeaderReceived(Exchange.CHARSET_NAME, charset);
    // Message with explicit encoding in MSH-18
    byte[] body = createHL7WithCharsetAsString(HL7Charset.UTF_16).getBytes(Charset.forName(charset));
    template.sendBodyAndHeader("direct:unmarshal", new ByteArrayInputStream(body), Exchange.CHARSET_NAME, charset);
    assertMockEndpointsSatisfied();
    Message msg = mock.getExchanges().get(0).getIn().getBody(Message.class);
    assertEquals("2.4", msg.getVersion());
    QRD qrd = (QRD) msg.get("QRD");
    assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 53 with ByteArrayInputStream

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

the class HttpEntityConverter method asHttpEntity.

private static HttpEntity asHttpEntity(InputStream in, Exchange exchange) throws IOException {
    InputStreamEntity entity;
    if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
        String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
        InputStream stream = GZIPHelper.compressGzip(contentEncoding, in);
        entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream ? stream.available() != 0 ? stream.available() : -1 : -1);
    } else {
        Message inMessage = exchange.getIn();
        String length = inMessage.getHeader(Exchange.CONTENT_LENGTH, String.class);
        if (ObjectHelper.isEmpty(length)) {
            entity = new InputStreamEntity(in, -1);
        } else {
            entity = new InputStreamEntity(in, Long.parseLong(length));
        }
    }
    if (exchange != null) {
        String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
        String contentType = ExchangeHelper.getContentType(exchange);
        entity.setContentEncoding(contentEncoding);
        entity.setContentType(contentType);
    }
    return entity;
}
Also used : Message(org.apache.camel.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 54 with ByteArrayInputStream

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

the class HttpEntityConverter method asHttpEntity.

private static HttpEntity asHttpEntity(byte[] data, Exchange exchange) throws Exception {
    AbstractHttpEntity entity;
    if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
        String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
        InputStream stream = GZIPHelper.compressGzip(contentEncoding, data);
        entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream ? stream.available() != 0 ? stream.available() : -1 : -1);
    } else {
        // create the Repeatable HttpEntity
        entity = new ByteArrayEntity(data);
    }
    if (exchange != null) {
        String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
        String contentType = ExchangeHelper.getContentType(exchange);
        entity.setContentEncoding(contentEncoding);
        entity.setContentType(contentType);
    }
    return entity;
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 55 with ByteArrayInputStream

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

the class HttpBodyTest method httpPostWithInputStreamBody.

@Test
public void httpPostWithInputStreamBody() throws Exception {
    Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset)));
        }
    });
    assertExchange(exchange);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6879 Test (org.junit.Test)2274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1791 InputStream (java.io.InputStream)1531 IOException (java.io.IOException)1400 DataInputStream (java.io.DataInputStream)600 ObjectInputStream (java.io.ObjectInputStream)597 X509Certificate (java.security.cert.X509Certificate)397 CertificateFactory (java.security.cert.CertificateFactory)355 ObjectOutputStream (java.io.ObjectOutputStream)333 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Certificate (java.security.cert.Certificate)234 HashMap (java.util.HashMap)212 DataOutputStream (java.io.DataOutputStream)200 FileInputStream (java.io.FileInputStream)182 InputStreamReader (java.io.InputStreamReader)180 Test (org.testng.annotations.Test)171 Document (org.w3c.dom.Document)143 Map (java.util.Map)138