如何从camel中的post请求传递文件?

时间:2017-10-25 09:31:30

标签: java spring apache-camel multipart spring-camel

我有以下代码:

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.restlet.RestletComponent;
import org.restlet.ext.spring.SpringServerServlet; 
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Map;
import java.util.HashMap;

@Component
public class DummyRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {

        rest("/upload").post().to("file://rest_files");
    }

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        SpringServerServlet serverServlet = new SpringServerServlet();
        ServletRegistrationBean regBean = new ServletRegistrationBean( serverServlet, "/rest/*");
        Map<String,String> params = new HashMap<>();
        params.put("org.restlet.component", "restletComponent");
        regBean.setInitParameters(params);
        return regBean;
    }


    @Bean
    public org.restlet.Component restletComponent() {
        return new org.restlet.Component();
    }

    @Bean
    public RestletComponent restletComponentService() {
        return new RestletComponent(restletComponent());
    }

}

我使用postman和app store文件在文件夹rest_files

中加载文件

但文件内容及其名称看起来很奇怪。

文件名:ID-username-1508923387747-0-2
内容:

enter image description here 如何使它至少存储正确的内容?

0 个答案:

没有答案