cxf 附件mtom方式

cxf附件传递:
spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xmlns:cxf="http://cxf.apache.org/core"
	xmlns:wsa="http://cxf.apache.org/ws/addressing"
	xsi:schemaLocation="   
	 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
	  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
	 http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
	http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<!-- 注解注入bean -->
	<context:component-scan base-package="ws.upload" />
	 <cxf:bus>
        <cxf:features>
        	<!--日志拦截功能,用于监控soap内容,开发后可以删除 --> 
            <cxf:logging/>
            <wsa:addressing/>
        </cxf:features>
    </cxf:bus>  
	<jaxws:endpoint id="fileUploadWebServiceEndpoint"
		implementor="#fileUploadWebService"
		address="/uploadwebservice" >
	<jaxws:properties>
              <!--开启mtom附件功能 --> 
		<entry key="mtom-enabled" value="true"/>
	</jaxws:properties>
	</jaxws:endpoint>
	
</beans>

服务接口就不说了,直接贴实现类:
package ws.upload;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataHandler;
import javax.jws.WebService;

import org.springframework.stereotype.Service;
@WebService(endpointInterface="ws.upload.IFileUploadWebService")
@Service("fileUploadWebService")
public class FileUploadWebServiceImp implements IFileUploadWebService {

	@Override
	public void upload(DataHandler dataHandler) {
		try {
			InputStream is=dataHandler.getInputStream();
			byte[] temp=new byte[1024];
			File file=new File("c:\\a.sql");
			OutputStream os=new FileOutputStream(file);
			int length=-1;
			while((length=is.read(temp))!=-1){
				System.out.println(length);
				os.write(temp);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

就完成服务段的编程了。

客户段附件里有。有兴趣的看一看看。
如果想了解mtom,可以看下面连接
http://boyingking.blog.sohu.com/27075328.html

你可能感兴趣的:(java,spring,编程,webservice,OS)