`
iaspecjack
  • 浏览: 4331 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

xfire--附件

阅读更多

 

---------spring+xfire进行附件传输

 

----------------------------------Server--------------------------------------------

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

 

import org.apache.log4j.Logger;

import org.codehaus.xfire.fault.XFireFault;

 

import com.cmhit.service.FileUpLoadService;

import com.cmhit.service.model.UploadFile;

 

public class FileUpLoadServiceImpl implements FileUpLoadService {

private static final Logger logger = Logger.getLogger(FileUpLoadServiceImpl.class);

private String fileSavePath;

public void setFileSavePath(String fileSavePath) {

this.fileSavePath = fileSavePath;

}

public boolean upload(UploadFile file)throws XFireFault{

logger.info("开始接收上传的文件...............");

if(file == null && file.getFile() == null){

throw new XFireFault(new Exception("上传文件不能为NULL"));

}

String title = file.getTitle();

 

try {

InputStream in = file.getFile().getInputStream();

if(this.fileSavePath != null && (!this.fileSavePath.equals(""))){

File fileDirectory = new File(this.fileSavePath);

if(!fileDirectory.exists()){

fileDirectory.mkdir();

}

}

OutputStream out = new FileOutputStream(new File(this.fileSavePath + title));

if(in != null){

int s = -1;

while((s = in.read())!= -1){

out.write(s);

}

in.close();

}

out.close();

logger.info("文件:"+title+"上传成功!");

return true;

} catch (IOException e) {

e.printStackTrace();

throw new XFireFault(new Exception("webservice服务产生异常!"));

}

 

}

}

 

 

---------------------------------CLIENT---------------------------------------------


import java.net.MalformedURLException;

import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.fault.XFireFault;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.transport.http.HttpTransport;

import com.cmhit.service.FileUpLoadService;
import com.cmhit.service.authentication.impl.ClientAuthHandler;
import com.cmhit.service.client.FileUpLoadServiceClient;
import com.cmhit.service.model.UploadFile;
import com.cmhit.services.exception.WebServiceAccessException;


public class FileUpLoadServiceClientImpl implements FileUpLoadServiceClient {

private String username;

private String password;
public FileUpLoadServiceClientImpl() {

}
public FileUpLoadServiceClientImpl(String username, String password) {

this.username = username;
this.password = password;

}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
public boolean upload(String hostAddress, int port, UploadFile file)
throws WebServiceAccessException {

try {

Service serviceModel = new ObjectServiceFactory().create(
FileUpLoadService.class, "jones",
"http://cmhit.jack.com", null);

FileUpLoadService service = (FileUpLoadService) new XFireProxyFactory()
.create(serviceModel, "http://" + hostAddress + ":" + port
+ "/spring_webservice/services/FileUpLoadService");

Client client = Client.getInstance(service);
client.setProperty("mtom-enabled", "true");
client.setProperty(HttpTransport.CHUNKING_ENABLED, "true");
client.addOutHandler(new ClientAuthHandler(this.username,this.password));

boolean result = service.upload(file);

return result;

} catch (MalformedURLException e) {

e.printStackTrace();

throw new WebServiceAccessException("无法连接到web服务!");

} catch (XFireFault e) {

e.printStackTrace();

throw new WebServiceAccessException("服务器端XFireFault异常!");

}

}

}

 

  • webs.rar (21.7 KB)
  • 描述: 源代码
  • 下载次数: 20
  • 大小: 24.9 KB
分享到:
评论

相关推荐

    xfire webservice实现附件上传

    NULL 博文链接:https://wentry.iteye.com/blog/1900188

    Spring XFire 实现webService

    spring和xfire集成的时候修要的jar文件,spring需要的jar文件自己另行下载。.

    XFire demo

    附件中是搭建的一个maven项目,使用jdk1.7,实现了XFire的简单使用。

    WebService开发入门(XFire)

    我整理了一下使用XFire1.2.6进行Web Service开发的思路,尝试完成了一个入门实例(完整的MyEclipse项目)。如果你正在学习Web Service或者对这个有兴趣,你可以下载该附件,导入MyEclipse中运行以查看示例效果。希望...

    Xfire 开发webservice与客户端调用教程与实例

    xfire开发webservice与调用 用起来比axis简单,容易上手。没有axis那么复杂。性能也比axis好。附件里面包含教程文档及实例代码

    web接口开发xfire实例

    web接口开发xfire实例工程,附件是已经搭建好的工程可试测,供大家学习借鉴

    java调用net开发的webservice实例

    问题终于解决了,之前加上?wsdl的时候报如下错: - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect...附件中包含测试类javaAxisCallnet.java和所需的jar包

    java url 访问 .net WebService 不使用 ksoap2,Axis或XFire

    java 通过 url 使用 soap 请求和获取 .net 开发的 webservice ,没有使用ksoap2,Axis或XFire。 附件包含 一个java文件(访问),一个.cs文件(webservice)。

    复杂邮件程序完整Java源码,支持添加附件,图片,HTML格式文本,支持远程WebService调用

    import org.codehaus.xfire.attachments.ByteDataSource; /** * HexiangMailServiceImpl 邮件接收发送接口实现类 * * @author 380595305@qq.com * Date 2010-05-11 * @version 1.0 */ public class ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    1. 简介 1.1. 概览 1.2. 使用场景 2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP ...

    WebServices基础培训视频与源码

    资源名称:WebServices基础培训视频与源码资源目录:【】1.WebService之AXIS即时发布【】10.WebService之创建自己ws站点进行调用操作【】11.WebService之...资源太大,传百度网盘了,链接在附件中,有需要的同学自取。

    spring chm文档

    使用XFire来暴露Web服务 17.6. 对远程接口不提供自动探测 17.7. 在选择这些技术时的一些考虑 18. Enterprise Java Bean(EJB)集成 18.1. 简介 18.2. 访问EJB 18.2.1. 概念 18.2.2. 访问本地的无状态Session ...

    Spring中文帮助文档

    2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 新的bean作用域 2.2.2. 更简单的XML配置 2.2.3. 可扩展的XML编写 2.2.4. Annotation(注解)驱动配置 ...2.2.5. 在classpath中自动搜索组件 ...2.3.3. 对bean命名pointcut( ...

    Spring API

    前言 1. 简介 1.1. 概览 1.1.1. 使用场景 2. Spring 2.0和 2.5的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 新的bean作用域 2.2.2. 更简单的XML配置 2.2.3. 可扩展的XML编写 2.2.4. Annotation(注解)...

    Spring 2.0 开发参考手册

    使用XFire来暴露Web服务 17.6. 对远程接口不提供自动探测 17.7. 在选择这些技术时的一些考虑 18. Enterprise Java Bean(EJB)集成 18.1. 简介 18.2. 访问EJB 18.2.1. 概念 18.2.2. 访问本地的无状态Session ...

Global site tag (gtag.js) - Google Analytics