Search in sources :

Example 21 with ByteArrayInputStream

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

the class BlobServiceProducer method getInputStreamFromExchange.

private InputStream getInputStreamFromExchange(Exchange exchange) throws Exception {
    Object blobObject = exchange.getIn().getMandatoryBody();
    InputStream inputStream = null;
    if (blobObject instanceof String) {
        String charset = getCharsetName(exchange);
        inputStream = new ByteArrayInputStream(((String) blobObject).getBytes(charset));
    } else if (blobObject instanceof InputStream) {
        inputStream = (InputStream) blobObject;
    } else if (blobObject instanceof File) {
        inputStream = new FileInputStream((File) blobObject);
    } else {
        throw new IllegalArgumentException("Unsupported blob type:" + blobObject.getClass().getName());
    }
    return inputStream;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 22 with ByteArrayInputStream

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

the class BlobServiceProducerSpringTest method testUpdatePageBlob.

@Test
@Ignore
public void testUpdatePageBlob() throws Exception {
    result.expectedMessageCount(1);
    final byte[] data = new byte[512];
    Arrays.fill(data, (byte) 1);
    template.send("direct:updatePageBlob", ExchangePattern.InOnly, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(new ByteArrayInputStream(data));
        }
    });
    assertMockEndpointsSatisfied();
    assertResultExchange(result.getExchanges().get(0));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ByteArrayInputStream(java.io.ByteArrayInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with ByteArrayInputStream

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

the class RestContextRefDefinitionHelper method cloneRestDefinition.

private static RestDefinition cloneRestDefinition(JAXBContext jaxbContext, RestDefinition def) throws JAXBException {
    Marshaller marshal = jaxbContext.createMarshaller();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    marshal.marshal(def, bos);
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    Object clone = unmarshaller.unmarshal(bis);
    if (clone != null && clone instanceof RestDefinition) {
        RestDefinition def2 = (RestDefinition) clone;
        Iterator<VerbDefinition> verbit1 = def.getVerbs().iterator();
        Iterator<VerbDefinition> verbit2 = def2.getVerbs().iterator();
        while (verbit1.hasNext() && verbit2.hasNext()) {
            VerbDefinition verb1 = verbit1.next();
            VerbDefinition verb2 = verbit2.next();
            if (verb1.getToOrRoute() instanceof RouteDefinition && verb2.getToOrRoute() instanceof RouteDefinition) {
                RouteDefinition route1 = (RouteDefinition) verb1.getToOrRoute();
                RouteDefinition route2 = (RouteDefinition) verb2.getToOrRoute();
                // need to clone the namespaces also as they are not JAXB marshalled (as they are transient)
                Iterator<ExpressionNode> it = ProcessorDefinitionHelper.filterTypeInOutputs(route1.getOutputs(), ExpressionNode.class);
                Iterator<ExpressionNode> it2 = ProcessorDefinitionHelper.filterTypeInOutputs(route2.getOutputs(), ExpressionNode.class);
                while (it.hasNext() && it2.hasNext()) {
                    ExpressionNode node = it.next();
                    ExpressionNode node2 = it2.next();
                    NamespaceAwareExpression name = null;
                    NamespaceAwareExpression name2 = null;
                    if (node.getExpression() instanceof NamespaceAwareExpression) {
                        name = (NamespaceAwareExpression) node.getExpression();
                    }
                    if (node2.getExpression() instanceof NamespaceAwareExpression) {
                        name2 = (NamespaceAwareExpression) node2.getExpression();
                    }
                    if (name != null && name2 != null && name.getNamespaces() != null && !name.getNamespaces().isEmpty()) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.putAll(name.getNamespaces());
                        name2.setNamespaces(map);
                    }
                }
            }
        }
        return def2;
    }
    return null;
}
Also used : Marshaller(javax.xml.bind.Marshaller) RestDefinition(org.apache.camel.model.rest.RestDefinition) VerbDefinition(org.apache.camel.model.rest.VerbDefinition) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Unmarshaller(javax.xml.bind.Unmarshaller) NamespaceAwareExpression(org.apache.camel.model.language.NamespaceAwareExpression)

Example 24 with ByteArrayInputStream

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

the class FileDataSetProducerTest method createFileDatasetWithSystemEndOfLine.

private File createFileDatasetWithSystemEndOfLine() throws IOException {
    tempFolder.create();
    File fileDataset = tempFolder.newFile("file-dataset-test.txt");
    Files.copy(new ByteArrayInputStream(testPayload.getBytes()), fileDataset.toPath(), StandardCopyOption.REPLACE_EXISTING);
    return fileDataset;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File)

Example 25 with ByteArrayInputStream

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

the class ValidatorDtdAccessOnTest method testInvalidMessageWithExternalDTDStreamSource.

/** Tests that external DTD call is executed  for StreamSourceby expecting an UnkonwHostException. */
public void testInvalidMessageWithExternalDTDStreamSource() throws Exception {
    unknownHostExceptionEndpoint.expectedMessageCount(1);
    finallyEndpoint.expectedMessageCount(1);
    InputStream is = new ByteArrayInputStream(ssrfPayloud.getBytes(StandardCharsets.UTF_8));
    template.sendBody("direct:start", is);
    MockEndpoint.assertIsSatisfied(validEndpoint, unknownHostExceptionEndpoint, finallyEndpoint);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

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