CXF是一個不錯的開源的WS框架
實現上傳一個WORD的文件到服務端
首先是服務端WS的實現
Resume
import javax
public class Resume
{
private String candidateName;
private String resumeFileType;
private DataHandler resume;
這裡注意使用DataHandler來處理待上傳的簡歷WORD文件
接口
import javax
import javax
import com
@WebService
public interface ResumeUploadService {
void uploadResume(@WebParam(name=
}
這裡使用了jax
實現類
import java
import java
import java
import java
import java
import javax
import javax
import com
@WebService(endpointInterface =
serviceName =
public class ResumeUploadServiceImpl implements ResumeUploadService {
public void uploadResume(Resume resume) {
DataHandler handler = resume
try {
InputStream is = handler
OutputStream os = new FileOutputStream(new File(
+ resume
resume
byte[] b = new byte[
int bytesRead =
while ((bytesRead = is
os
}
os
os
is
} catch (IOException e) {
e
}
}
}
然後在src目錄下建立cxf
<beans xmlns=
xmlns:xsi=
xmlns:jaxws=
xsi:schemaLocation=
<import resource=
<import resource=
<import resource=
<jaxws:endpoint id=
implementor=
address=
<jaxws:properties>
<entry key=
</jaxws:properties>
</jaxws:endpoint>
</beans>
這裡注意使用了 <entry key=
接下來設計客戶端
作為客戶端
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory
factory
factory
factory
(//localhost:
ResumeUploadService client = (ResumeUploadService) factory
Resume resume=new Resume();
resume
resume
DataSource source = new FileDataSource(new File(
resume
client
System
}
注意這裡由於使用了JaxWsProxyFactoryBean
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27050.html