基于CXF restwebservice
来源:互联网 发布:软件测试费 编辑:程序博客网 时间:2024/04/28 04:25
应用场景:
手机端使用apache的httpclient组件。
服务器端使用spring+cxf rest webservice
手机端代码:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
public class HttpClientTest {
private final static String REMOTE_FILE_URL = "http://localhost:8080/cxf_restful_webservice/rws/pdf/get";
private final static int BUFFER = 1024;
public static void main(String[] args) {
HttpClient client = new HttpClient();
PostMethod httpGet = new PostMethod(REMOTE_FILE_URL);
try {
client.executeMethod(httpGet);
InputStream in = httpGet.getResponseBodyAsStream();
Header[] h = httpGet.getResponseHeaders("Content-Disposition");
// NameValuePair ss = httpGet.getParameter("Content-Disposition");
// String name = ss.getName();
// String value = ss.getValue();
String dispositionValue = h[0].getValue();
int index = dispositionValue.indexOf("=");
String fileName = dispositionValue.substring(index+1);
System.out.println(h[0]);
System.out.println(fileName);
FileOutputStream out = new FileOutputStream(new File("D:\\upload\\"+fileName));
byte[] b = new byte[BUFFER];
int len = 0;
while((len=in.read(b))!= -1){
out.write(b,0,len);
}
in.close();
out.close();
}catch (HttpException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
httpGet.releaseConnection();
}
System.out.println("download, success!!");
}
}
服务端代码:
import java.io.File;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@Path("/zip")
public class PdfService {
private static final String FILE_PATH = "c:\\xxx.zip";
@POST
@Path("/get")
@Produces("application/pdf")
public Response getFile() {
File file = new File(FILE_PATH);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=xxx.zip");
return response.build();
}
}
- 基于CXF restwebservice
- 基于cxf的webservices
- CXF基于webcontainer
- 基于cxf webservice(1)
- 基于CXF webservice (2)
- 基于web的CXF实例
- 基于CXF的WebService实例
- cxf基于soap的webservice
- 基于CXF的webservice开发
- 基于Spring+CXF技术开发WebService
- CXF 创建 WebService (基于 java)
- CXF 创建 WebService (基于 Spring)
- 基于CXF框架的WebService
- 梦想Spring-MVC,Restful,GWT,RestWebService
- 基于CXF Web Service:Apache CXF简单部署
- 基于CXF Web Service:Apache CXF简单部署
- WebService-CXF-Spring基于web的cxf
- 基于Axis、XFire、CXF的webservice 客户端
- CentOS 6.3 如何将自动挂载的磁盘不显示在桌面上
- 计算机图形学平台 VTK
- 在Unity中引用Dll的两种方法
- Android开发项目:CloudShare
- 常用的linux 命令
- 基于CXF restwebservice
- 在内部类中可以访问其外部类的所有域,即使是私有域
- javascript之HTML(select option)详解
- AAuto - 抓取VOA 新闻
- 字符编码详解(ANSI,UNICODE,UTF-8,GB2312,GBK)
- linux定时器
- [备忘] 查看浏览器中flash swf的trace调试输出
- Java常用工具类——字段验证工具ValidatorUtil
- ORACLE 死锁处理