soap에서 DataHandler를 이용한 파일 전송문제!!
글쓴이: cho6005 / 작성시간: 수, 2010/09/15 - 2:43오후
안녕하세요. soap의 attachment를 이용한 파일 전송을 구현중인데요
FileDataSource fileDataSource = new FileDataSource(file);
DataHandler dhSource = new DataHandler(fileDataSource);
//매개변수를 넣어 메소드 호출
Object ret = call.invoke(new Object[] {dhSource});
위와 같은 방식으로 웹 서비스에 올려진 함수를 호출하면서
DataHandler객체를 전달하려 합니다~
다른 int 변수를 인자로 전달하거나 하면 잘 호출되는데
DataHandler객체만 인자로 전달하려면..
[ERROR] Exception occurred while trying to invoke service method setFile
org.apache.axis2.AxisFault: Invalid reference :cid:3FADBA0B6A23491DF324C50DC39617DC
....
에러가 뜨네요..
왜 그럴까요 ㅠㅠ
소스 첨부해서 질문드립니다~
고수님들 부탁드려요!
import javax.activation.DataHandler; import javax.activation.FileDataSource; import java.io.FileOutputStream; import java.io.File; public class AttachmentTest { FileOutputStream fos; public void test(int a){ System.out.println(a + "test!!!"); } public void test2(DataHandler dhSource){ System.out.println("test2!"); } public void setFile(DataHandler dh){ if(dh == null) System.out.println("attachment is null"); else System.out.println("Server got File"); try{ fos = new FileOutputStream("FromClientFile.gif"); dh.writeTo(fos); fos.flush(); } catch( java.io.FileNotFoundException e) { e.printStackTrace(); } catch( java.io.IOException e) { e.printStackTrace(); } } }
import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.ser.*; import javax.activation.DataHandler; import javax.activation.FileDataSource; import javax.xml.namespace.QName; import java.io.FileOutputStream; public class SetFileTestClient { public SetFileTestClient() { try { //매개변수 있는 경우 파일을 찾아 서버로 전송한다. if(true) { String argFile = "a.gif"; java.io.File file = new java.io.File(argFile); if(!file.exists()) { System.err.println("error: file not found~!!!"); System.exit(8); } //서버로 파일을 전송한다. sendFile(file); } }catch(javax.xml.soap.SOAPException se) { se.printStackTrace(); } } //서버로 파일을 전송한다. @SuppressWarnings({ "unused", "rawtypes" }) private void sendFile(java.io.File file) throws javax.xml.soap.SOAPException { try { String endpoint = "http://localhost:8080/web.webservice6/services/AttachmentTest"; Service service = new Service(); //call 객체 생성 Call call = (Call)service.createCall(); //서비스를 제공하는 서버의 위치 지정 call.setTargetEndpointAddress(new java.net.URL(endpoint)); //Serializer, deSerializer 등록 java.lang.Class jafsf = JAFDataHandlerSerializerFactory.class; java.lang.Class jafdf = JAFDataHandlerDeserializerFactory.class; java.lang.Class cls = DataHandler.class; javax.xml.namespace.QName qName = new javax.xml.namespace.QName("http://ws.apache.org/axis2", "DataHandler"); call.registerTypeMapping(cls, qName, jafsf, jafdf, false); //serializer, deSerializer 등록 //호출할 메소드 등록 call.setOperationName(new QName("http://ws.apache.org/axis2", "setFile")); // call.setOperationName(new QName("http://ws.apache.org/axis2", "test")); int a = 3; //파일 객체를 FileDataSource에 담는다. FileDataSource fileDataSource = new FileDataSource(file); //DataHandler에 FileDataSource를 담아 전달한다. DataHandler dhSource = new DataHandler(fileDataSource); //매개변수를 넣어 메소드 호출 Object ret = call.invoke(new Object[] {dhSource}); System.out.println("File send~!"); }catch(Exception e) { System.err.println(e.toString()); } } public static void main(String[] args) { System.out.println("ddddd"); new SetFileTestClient(); } }
[ERROR] Exception occurred while trying to invoke service method setFile org.apache.axis2.AxisFault: Invalid reference :cid:3FADBA0B6A23491DF324C50DC39617DC at org.apache.axis2.databinding.utils.MultirefHelper.processRef(MultirefHelper.java:115) at org.apache.axis2.databinding.utils.BeanUtil.processObject(BeanUtil.java:702) at org.apache.axis2.databinding.utils.BeanUtil.ProcessElement(BeanUtil.java:670) at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:602) at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java:153) at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:188) at org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver.invokeBusinessLogic(RPCInOnlyMessageReceiver.java:63) at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:100) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176) at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275) at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:131) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Unknown Source) [ERROR] org.apache.axis2.AxisFault: Exception occurred while trying to invoke service method setFile
File attachments:
첨부 | 파일 크기 |
---|---|
SetFileTestClient.txt | 2.34 KB |
AttatchmentTset.txt | 766바이트 |
Forums:
댓글 달기