SOAP이용한 파일전송 소스로 정말 간단하게 전송할수있다..
이걸로 삽질하시는분들께 큰 도움이 되길...~^^;
server-config.wsdd 설정
<service name="fileDown" provider="java:RPC">
<parameter name="className" value="ybtech.fileDownloader"/>
<parameter name="allowedMethods" value="getFiles"/>
<operation name="getFiles" returnQName="returnqname" returnType="DataHandler"/>
<typeMapping deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory"
serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory"
languageSpecificType="java:javax.activation.DataHandler"
qname="DataHandler" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</service>
서버
FileDownloader.java
public DataHandler getFiles() throws RemoteException,MetadataVerifyException, TransferException, JDOMException, IOException{
DataHandler dh = null;
File file = new File("c:/test.txt"); //첨부할 파일
DataSource fSource = new FileDataSource(file);
dh = new DataHandler(fSource);
return dh;
}
클라이언트 구현소스
public void fileDown() throws Exception{
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress( new URL("http://localhost:8181/hello/services/fileDown?wsdl") );
//call.setUsername("admin");
//call.setPassword("admin");
Class jafsf = JAFDataHandlerSerializerFactory.class;
Class jafdf = JAFDataHandlerDeserializerFactory.class;
Class cls = DataHandler.class;
QName qname = new QName("","DataHandler");
call.registerTypeMapping(cls, qname, jafsf, jafdf, false);
call.setReturnType(new QName("","DataHandler"));
call.setOperationName(new QName("","getFiles"));
Object rect = call.invoke(new Object[]{});
if((rect instanceof DataHandler)){
DataHandler dh = (DataHandler)rect;
String fileName = "c:/ya.txt";
FileOutputStream fos = new FileOutputStream(fileName);
dh.writeTo(fos);
fos.flush();
}
System.out.println("다운완료");
}
'Programming > Webservice' 카테고리의 다른 글
웹서비스 method 호출시 파라미터주기 (0) | 2009.10.16 |
---|---|
webservice 메소드 만들때 주의할점 (0) | 2009.10.16 |