camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manishpillai1540 <manishpillai1...@gmail.com>
Subject Re: Reading Binary Files and Passing to HTTP Component
Date Fri, 15 Jul 2016 04:21:21 GMT
Hi,

Thanks for the reply!!!!
Yes i have created a dummy web service to test it.

After apply few patches i have fixed the issue with the following code
snippet.

package com.camelinaction;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;

import java.io.File;
import java.util.logging.Logger;

/**
 * Created by Manish.Pillai on 7/15/2016.
 */
public class TestMain {

    public static void main(String[] args) throws Exception {
        CamelContext camelContext = new DefaultCamelContext();
        try {
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() throws Exception {
                   
from("file:C:\\temp?delay=5000&move=processed&moveFailed=error&antExclude=**/processed/**,**/error/**")
                            .process(new Processor() {
                                public void process(Exchange exchange)
throws Exception {
                                    StringBody username = new
StringBody("username", ContentType.MULTIPART_FORM_DATA);
                                    StringBody password = new
StringBody("password", ContentType.MULTIPART_FORM_DATA);

                                    MultipartEntityBuilder
multipartEntityBuilder = MultipartEntityBuilder.create();
                                   
multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
                                   
multipartEntityBuilder.addPart("username", username);
                                   
multipartEntityBuilder.addPart("password", password);

                                    String filename = (String)
exchange.getIn().getHeader(Exchange.FILE_NAME);
                                    File file =
exchange.getIn().getBody(File.class);
                                    multipartEntityBuilder.addPart("upload",
new FileBody(file, ContentType.MULTIPART_FORM_DATA, filename));

                                   
exchange.getIn().setBody(multipartEntityBuilder.build());
                                }
                            })
                           
.to("http4://localhost:8080/JAX_RS_Application/resource/restwb/upload");
                }
            });

            camelContext.getRestConfiguration();
            camelContext.start();
            Thread.sleep(5000);
            camelContext.stop();

        } catch (Exception e) {
            //logger.error(e.getMessage());
        }
    }

}





--
View this message in context: http://camel.465427.n5.nabble.com/Reading-Binary-Files-and-Passing-to-HTTP-Component-tp510207p5785116.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message