0

我有以下接口,谁的实现将加密特定路径的文件。

package xx.messaging.fileTransfer;

import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.Payload;

/**
* <H1>FileEncryptionService</H1>
*/
public interface FileEncryptionService {

    /**
     * Generates a new encrypted filename based on the input, calls the default method and returns
     * the encrypted file name
     * @param srcFilename
     * @return
     * @throws Exception
     */
    @Gateway
    public String encryptFile(@Payload String srcFilename) throws Exception;

    /**
     * Encrypt the a file
     * @param srcFilename The source file name
     * @param destFilename The target file name
     */
    @Gateway
    public void encryptFile(@Payload String srcFilename, @Header("encryptedFilename") String destFilename); 
}

该服务将通过 spring 集成调用,并通过以下方式在上下文中注册为网关

<int:gateway service-interface="lu.scoteqint.messaging.fileTransfer.FileEncryptionService"/>

实现 bean 和 service-activator 注册为

<beans:bean id="fileEncryptionService" class="xx.messaging.fileTransfer.impl.CommandLineEncryptionService"/>

<int:service-activator 
    input-channel="file1"
    output-channel="file2"
    expression="@fileEncryptionService.encryptFile(payload)"/>

我期望消息有效负载是文件的字符串路径,因为线标签日志显示

2013-02-05 15:50:26,911 DEBUG [org.springframework.integration.handler.LoggingHandler] (task-scheduler-1) [Payload=.\src\test\resources\test\xx.xml][Headers={timestamp=1360079426907, id=1c3be020-fc6d-42ba-b3f0-5b963f76fb76}]

但似乎“服务激活器”表达式找到了一个文件。

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 31): Method call: Method encryptFile(java.io.File) cannot be found on lu.scoteqint.messaging.fileTransfer.impl.CommandLineEncryptionService type
    at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:182)
    at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:106)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:102)
    at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:126)
    at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:86)
    ... 30 more

编辑

日志详细信息

2013-02-05 16:26:42,737 DEBUG [org.springframework.integration.channel.DirectChannel] (task-scheduler-1) preSend on channel 'file1', message: [Payload=.\src\test\resources\test.xml][Headers={timestamp=1360081602736, id=877407f6-c5a2-4bea-9ec7-f970b09f08a8}]

有没有办法确保参数映射为字符串而不是文件?

4

0 回答 0