fileserviceputclient.java

来自「精通Jboss——Ejb和Web Services开发精解的随书源代码」· Java 代码 · 共 32 行

JAVA
32
字号
package com.liuyang.axis.soapattachment;

import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;

public class FileServicePutClient {
	public static void main(String[] args) throws Exception {
		String filename = "./att/file.xml";
		DataHandler dhSource = new DataHandler(new FileDataSource(filename));
		Service service = new Service();
		Call call = (Call) service.createCall();
		String endpoint = "http://localhost:8080/axis/services/FileService";
		call.setTargetEndpointAddress(new URL(endpoint));
		call.setOperationName(new QName("FileService", "putFile")); 
		QName qnameAttachment = new QName("FileService", "DataHandler");
		call.registerTypeMapping(dhSource.getClass(),qnameAttachment,
			JAFDataHandlerSerializerFactory.class,JAFDataHandlerDeserializerFactory.class);
		call.addParameter("s1", qnameAttachment,ParameterMode.IN);
		call.addParameter("s2", XMLType.XSD_STRING,ParameterMode.IN);		
		call.setReturnType(XMLType.XSD_STRING );
		Object ret = call.invoke(new Object[]{dhSource,"test.txt"}); 
		System.out.println(ret);	
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?