为了接受(在Camel WAR应用程序中)上传的文件,我需要公开一个码头端点,在码头配置中,我不想指定协议,主机,端口和上下文根(我想从容器WAR继承这些信息。
有可能这样做吗?我没有找到任何相关信息。
答案 0 :(得分:0)
解决如下:我使用servlet而不是使用码头
<camel:route id="servlet-route">
<camel:from id="servletfrom" uri="servlet://provaservlet?disableStreamCache=true"/>
<to id="servletto" uri="provaUploadProcessorId"/>
</camel:route>
在处理器provaUploadProcessorId
中,我从交换主体收到了servlet请求
HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
然后我能够读取参数和文件,如下所示
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input
// type="text|radio|checkbox|etc", select, etc).
String fieldName = item.getFieldName();
String fieldValue = item.getString();
log.info("param name " + fieldName + ", param value " + fieldValue);
} else {
// Process form file field (input type="file").
String fieldName = item.getFieldName();
String fileName = FilenameUtils.getName(item.getName());
log.info("file param name " + fieldName + ", file param value " + fileName);
InputStream fileContent = item.getInputStream();
// do what you want with the file content and then close it
fileContent.close();
}
}
请记住加载这些依赖项
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>