当前位置: 代码迷 >> Web前端 >> xfire webservice兑现附件上传
  详细解决方案

xfire webservice兑现附件上传

热度:865   发布时间:2013-07-16 22:38:04.0
xfire webservice实现附件上传
不再集成spring,只需ifire即可。

思路是把上传文件转换成流,然后通过传byte[]来实现附件的上传.
在附件上传之前,需要鉴权,
soap方式鉴权。

功能看附件代码,可直接运行。


部分代码:
服务端:
public UserInfo editNews(NewsInfo info, List<UploadFileInfo> fileList) {
if(fileList==null||fileList.size()<1){

}else{
for(UploadFileInfo uploadFileInfo:fileList){
// 这里调用文件处理类来保存文件
FileUtil.byteToFile(uploadFileInfo.getBytes(), "D:/log", uploadFileInfo.getFileName());
}

}

System.out.println(""+info.getNewsTitle());
System.out.println(""+info.getNewsUrl());
System.out.println(""+info.getNewsText());


UserInfo u = new UserInfo();
u.setName(info.getNewsTitle()+","+info.getNewsUrl());
u.setNum(222);
return u;

}


//
客户端代码:

public  void uploadFile() throws IOException{
String url="http://localhost:8080/x1/services/HelloWord";


Service serviceModel = new ObjectServiceFactory().create(HelloWorldS.class);
HelloWorldS service = (HelloWorldS) new XFireProxyFactory().create(serviceModel,url);
XFireProxy proxy = (XFireProxy)Proxy.getInvocationHandler(service);
Client client = proxy.getClient();
client.addOutHandler(new ClientAuthenticationHandler("abcd","1234"));//鉴权用户名和密码

List<UploadFileInfo> fileList = new ArrayList<UploadFileInfo>();
File file = new File("D:/my");
File[] files = file.listFiles();
for(File f:files){
if(f.isFile()){
byte[] bytes =FileUtil.getBytesFromFile(f);
UploadFileInfo uplpadFileInfo = new UploadFileInfo();
uplpadFileInfo.setBytes(bytes);
uplpadFileInfo.setFileName(f.getName());
fileList.add(uplpadFileInfo);
}
}

NewsInfo newsInfo = new NewsInfo();
newsInfo.setNewsTitle("newsTitle");
newsInfo.setNewsUrl("newsUrl");
newsInfo.setNewsText("newsText");


UserInfo userInfo = service.editNews(newsInfo, fileList);  

System.out.print(userInfo.getName()+","+userInfo.getNum());


}
  相关解决方案