2017-10-26 13 views
0

먼저 multipart 파일이 있는데이를 낙타 파이프 라인으로 보내고 원래 이름으로이 파일을 저장하려고합니다.org.apache.camel.NoTypeConversionAvailableException : 형식 변환 할 수있는 형식 변환기가 없습니다.

내 코드 : ("Seda의 : rest_upload")에서

: .convertBodyTo (File.class가) .TO ("파일 : // rest_files") 또 다른 측면 내가 가진에

@Autowired 
ProducerTemplate producerTemplate; 
... 
     producerTemplate.sendBody("seda:rest_upload", multipartFile); 

;

Message History 
--------------------------------------------------------------------------------------------------------------------------------------- 
RouteId    ProcessorId   Processor                  Elapsed (ms) 
[route2   ] [route2   ] [seda://rest_upload               ] [   3] 
[route2   ] [convertBodyTo1 ] [convertBodyTo[java.io.File]             ] [   2] 

Stacktrace 
--------------------------------------------------------------------------------------------------------------------------------------- 

org.apache.camel.InvalidPayloadException: No body available of type: java.io.File but has value: org.springframework.web.multipart.su[email protected]24c9ecc7 of type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile on: Message[ID-ntkachev-1509013331141-0-13]. Caused by: No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7. Exchange[ID-ntkachev-1509013331141-0-14]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7] 
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:113) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.ConvertBodyProcessor.process(ConvertBodyProcessor.java:91) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:298) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:210) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:155) [camel-core-2.20.0.jar:2.20.0] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111] 
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] 
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7 
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:206) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:111) ~[camel-core-2.20.0.jar:2.20.0] 
    ... 12 common frames omitted 

2017-10-26 13:30:58.447 WARN 19608 --- [a://rest_upload] o.a.camel.component.seda.SedaConsumer : Error processing exchange. Exchange[]. Caused by: [org.apache.camel.InvalidPayloadException - No body available of type: java.io.File but has value: org.springframework.web.multipart.su[email protected]24c9ecc7 of type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile on: Message[ID-ntkachev-1509013331141-0-13]. Caused by: No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7. Exchange[ID-ntkachev-1509013331141-0-14]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7]] 

org.apache.camel.InvalidPayloadException: No body available of type: java.io.File but has value: org.springframework.web.multipart.su[email protected]24c9ecc7 of type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile on: Message[ID-ntkachev-1509013331141-0-13]. Caused by: No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7. Exchange[ID-ntkachev-1509013331141-0-14]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7] 
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:113) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.ConvertBodyProcessor.process(ConvertBodyProcessor.java:91) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:298) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:210) [camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:155) [camel-core-2.20.0.jar:2.20.0] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111] 
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] 
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile to the required type: java.io.File with value org.springframework.web.multipart.su[email protected]24c9ecc7 
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:206) ~[camel-core-2.20.0.jar:2.20.0] 
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:111) ~[camel-core-2.20.0.jar:2.20.0] 
    ... 12 common frames omitted 

어떻게이 문제를 해결하는 : 내가 스택 트레이스 다음을 참조하십시오 내 코드를 실행하면

@Converter 
public class MultiPartFileToFileConvertor { 
    @Converter 
    public static File toFile(MultipartFile multipartFile) throws IOException { 
     File convFile = new File(multipartFile.getOriginalFilename()); 
     multipartFile.transferTo(convFile); 
     return convFile; 
    } 
} 

:

그리고 또한 내가하려고 컨버터를 등록?

+0

그리고 파일 형식으로 변환하지 않으셨습니까? 그냥 그대로 보내어 구원받는 것입니까? –

+0

sendBody를 호출하기 전에 파일을 작성하여 보내시겠습니까? – gstackoverflow

+0

나는 from : ("seda : rest_upload") .convertBodyTo (File.class) .to ("file : // rest_files"); from ("seda : rest_upload") .to ("file : // rest_files"); –

답변

0

TypeConverter라는 서비스 검색 파일을 META-INF 디렉토리에 추가해야합니다.

src\main\resources\META-INF\services\org\apache\camel\TypeConverter 

이 파일은 @Converter 클래스의 완전한 이름이 포함되어 있습니다.

예컨대

mypackage.MultiPartFileToFileConvertor 

또한 Github에서 https://github.com/camelinaction/camelinaction2/tree/b6a43abf9e0d4ec4e3753ebd735bb3448f98194b/chapter3/converter 액션 카멜 2에서 예를 참조.

또한 제 3.6 장에서는 사용자 지정 변환기의 검색과 로딩을 자세히 설명합니다.

+0

을 얻지 않아야한다. – gstackoverflow

+0

귀하의 의견을 이해하지 못했습니다. 리소스에 파일을 추가 했습니까? – ltsallas

+0

Came은 자동으로이 https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java – ltsallas