Hi , forgot to mention we are using WebSphere 4.0.3 as app server. This is a block for us, any quick answer appreciated. -----Original Message----- From: Wei Li Sent: Thursday, June 05, 2003 12:22 PM To: [EMAIL PROTECTED] Subject: Soap attachment MarshalException
* Hi, We are trying to use soap attachment, and got MarshalException. Could you help to see what went wrong? We are using java client talking to ejbs through soap webservice. A. The error we got is: [SOAPException: faultCode=SOAP-ENV:Server; msg=RemoteException occurred in server thread; nested exception is: * java.rmi.MarshalException: Exception occurred in server thread; nested exception is: * java.io.NotSerializableException] * at com.rulespower.rlms.service.proxy.soap.RepositoryControllerProxy.addAttachmentByService(RepositoryControllerProxy.java:1021) * at com.rulespower.rlms.service.proxy.soap.RepositoryControllerProxy.addAttachment(RepositoryControllerProxy.java:978) * at com.rulespower.rlms.command.service.repository.AttachmentTest.testAddAttachment(AttachmentTest.java:65) * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) * at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) * at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) B. The RepositoryControllerProxy.addAttachmentByService method is shown as follows: protected synchronized String addAttachmentByService(RepositoryAttachment attach) throws Exception { String targetObjectURI = "http://tempuri.org/com.rulespower.rlms.server.repository.ejb.RepositoryController"; String SOAPActionURI = ""; Call call = createCall2(); myLog("addAttachment: fileName = " + attach.getFileName() + " idName = " + attach.getIdName()); if(getDynamicURL() == null) { throw new SOAPException(Constants.FAULT_CODE_CLIENT, "A URL must be specified via RepositoryControllerProxy.setEndPoint(URL)."); } //Create the data for the attached file. DataSource ds = new ByteArrayDataSource(new File( attach.getFileName()), null); DataHandler dhSource = new DataHandler( ds); call.setMethodName("addAttachment"); call.setTargetObjectURI(targetObjectURI); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); SOAPMappingRegistry smr = new SOAPMappingRegistry(); BeanSerializer beanSer = new BeanSerializer(); smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(targetObjectURI, "RepositoryAttachment"), attach.getClass(), beanSer, beanSer); call.setSOAPMappingRegistry(smr); Vector params = new Vector(); Parameter objectParam = new Parameter("attach", attach.getClass(), attach, null); params.addElement(objectParam); Parameter handlerParam = new Parameter("handler", dhSource.getClass(), dhSource, null); params.addElement(handlerParam); call.setParams(params); Response resp = call.invoke(getDynamicURL(), SOAPActionURI); //Check the response. if (resp.generatedFault()) { Fault fault = resp.getFault(); call.setFullTargetObjectURI(targetObjectURI); throw new SOAPException(fault.getFaultCode(), fault.getFaultString()); } else { Parameter refValue = resp.getReturnValue(); return (String)(refValue.getValue()); } } C. The following is the RepositoryAttachment class: package com.rulespower.rlms.repository.node; import java.io.Serializable; public class RepositoryAttachment implements Comparable, Serializable, Cloneable { private String fileName = null; private String idName = null; public RepositoryAttachment(){}; public RepositoryAttachment(String fileName, String idName){ this.fileName = fileName; this.idName = idName; } public void setFileName(String fileName){ this.fileName = fileName; } public void setIdName(String idName){ this.idName = idName; } public String getFileName(){ return this.fileName; } public String getIdName(){ return this.idName; } public int compareTo(Object obj){ int isEqual = -1; if (obj instanceof RepositoryAttachment) { RepositoryAttachment attach = (RepositoryAttachment) obj; if (this.fileName.equals(attach.getFileName()) && this.idName.equals(attach.getIdName())){ isEqual = 0; } } return isEqual; } public String toString(){ return fileName + ":" + idName; } } D. The entry for RepositoryAttachment in the dds.xml file is: <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:x="http://tempuri.org/com.rulespower.rlms.server.repository.ejb.RepositoryController" qname="x:RepositoryAttachment" javaType="com.rulespower.rlms.repository.node.RepositoryAttachment" xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer" java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/> E. The following is the ejb method: public String addAttachment (RepositoryAttachment attach, DataHandler handler) throws CommandException, RemoteException { final String methodName = "addAttachment"; String newFileName = "Error Occured"; myLog("addAttachment: DataHandler = " + handler); if (handler == null ) System.err.println("dh is null"); else myLog("Received \""+ handler.getClass().getName()+"\"."); try { DataSource ds = handler.getDataSource(); String fname = attach.getIdName(); ByteArrayDataSource bsource = new ByteArrayDataSource(ds.getInputStream(), handler.getContentType()); bsource.writeTo(new FileOutputStream(fname)); newFileName = fname; myLog("the file is stored in " + fname); } catch(Exception e) { ctx.setRollbackOnly(); throw new CommandException(e); } return newFileName; }