最后我找到了解决方案,但解决方案仍然是一个黑匣子。如果有人对为什么它失败/成功有答案,请更新线程。
解决方案一目了然: 1. 将文件内容捕获为字节数组,并使用 FileOutputStream 将其写入 jboss tmp 文件夹中的 xml 文件
- 当发布到 jboss 消息队列时,我使用了明确编写的 xml 文件(第一步),使用 FileInputStream 作为字节数组并将其作为消息正文传递。
代码示例:
查看:带有 FormFile 的 JSP 页面
控制器类:UploadAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
...........
writeInitFile(theForm.getFile().getFileData()); // Obtain the uploaded file
Message msg = messageHelper.createMessage( readInitFile() ); // messageHelper is a customized factory method to create Message objects. Passing the newly
wrote file's byte array.
messageHelper.sendMsg(msg); // posting in the queue
...........
}
private void writeInitFile(byte[] fileData) throws Exception{
File someFile = new File("/jboss-5.1.0.GA-3/test/server/default/tmp/UploadTmp.xml"); // Write the uploaded file into a temporary file in jboss/tmp folder
FileOutputStream fos = new FileOutputStream(someFile);
fos.write( fileData );
fos.flush();
fos.close();
}
private byte[] readInitFile() throws Exception{
StringBuilder buyteArray=new StringBuilder();
File someFile = new File("/jboss-5.1.0.GA-3/test/server/default/tmp/UploadTmp.xml"); // Read the Newly created file in jboss/tmp folder
FileInputStream fstream = new FileInputStream(someFile);
int ch;
while( (ch = fstream.read()) != -1){
buyteArray.append((char)ch);
}
fstream.close();
return buyteArray.toString().getBytes(); // return the byte []
}
脚注:我认为这与 Linux/Windows 默认文件保存类型有关。例如:Windows 默认值:ANSI。