CXF在项目中的真实运用--WS访问客户端编写[java、.net]
一、首先,CXF的WS实现类由于实现了和Spring的无缝集成,因此可以采用Spring的单元测试来测试基本功能。
代码如下:
[java]
package com.defshare.sy.test.biz;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.UUID;
import javax.annotation.Resource;
import org.apache.commons.io.IOUtils;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Test;
import com.defshare.sy.ws.ISYWebService;
import com.defshare.sy.ws.po.Clinique;
import com.defshare.sy.ws.po.WorkList;
import com.defshare.sy.ws.po.WorkListPicFile;
public class SyWebServiceTest extends SpringTestTemplate{
@Test
public void testUploadWorkListPicFile(){
//JaxWsProxyFactoryBean proxy = new JaxWsProxyFactoryBean();
//proxy.setAddress("http://localhost:8090/sy/services/SYWebService");
//proxy.setServiceClass(ISYWebService.class);
//ISYWebService clientProxy = (ISYWebService)proxy.create();
//clientProxy.upLoadWorkListPic("", "",null);
WorkListPicFile file = new WorkListPicFile();
String serverFile = UUID.randomUUID().toString()+".DBF";
InputStream is = null;
try {
is = new FileInputStream("d:/QUESCTION.DBF");
file.setFileSize(is.available());
byte[] bytes = new byte[1024 * 1024];
int size=0;
do{
size = is.read(bytes);
if (size <= 0) {
break;
}
byte[] fixedBytes = Arrays.copyOfRange(bytes, 0, size);
file.setBytes(fixedBytes);
file.setServerFile(serverFile);
file.setWorkListId("WL0001");
int resp = syWebService.upLoadWorkListPic("WS访问账户","WS访问密码", file);
System.out.println(resp==0?"本次上传文件块成功":"本次上传文件块异常");
if (resp!=0)
break;
file.setPosition(file.getPosition() + fixedBytes.length);
}while(size>0);
} catch(IOException e) {
e.printStackTrace();
} finally {
if (is!=null)
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
IOUtils.closeQuietly(is);
}
}
@Test
public void testremoveWorkList(){
////正常输入数据1 &n
补充:Web开发 , ASP.Net ,