INT-515
This commit is contained in:
@@ -73,15 +73,19 @@ public class FileWritingMessageHandler implements MessageHandler {
|
||||
Assert.notNull(payload, "message payload must not be null");
|
||||
File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message));
|
||||
try {
|
||||
if (payload instanceof byte[]) {
|
||||
FileCopyUtils.copy((byte[]) payload, file);
|
||||
}
|
||||
else if (payload instanceof File) {
|
||||
if (payload instanceof File) {
|
||||
FileCopyUtils.copy((File) payload, file);
|
||||
}
|
||||
else {
|
||||
else if (payload instanceof byte[]) {
|
||||
FileCopyUtils.copy((byte[]) payload, file);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), this.charset);
|
||||
FileCopyUtils.copy(payload.toString(), writer);
|
||||
FileCopyUtils.copy((String) payload, writer);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported Message payload type [" + payload.getClass().getName() + "]");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileWritingMessageHandlerTests {
|
||||
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void unsupportedType() {
|
||||
FileWritingMessageHandler handler = new FileWritingMessageHandler(
|
||||
new File(System.getProperty("java.io.tmpdir")));
|
||||
handler.handleMessage(new GenericMessage<Integer>(99));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user