Hi, I’m
an axis newbie and having trouble sending an image attachment (document style
message) from my client to the server. The attachment seems to go across fine,
but when I use AttachmentPart on the server, the
server hangs. It tries to write the
binary source to the console/screen and the PC beeps endlessly, and it hangs. I’ve been at this for ten days now
trying to figure out what the problem is. No one at work has much experience with
axis so I’m on my own on this one.
Any tips whatsoever on what it is I’m doing wrong would be very
much appreciated. I’ve
attached the following files: RemoteTaskResultService (client-side), RemoteTaskResultImpl
(server-side), remotetaskresult (wsdl) I’m
using Axis 1.1, Tomcat 4.1.x Thanx a million |
import java.io.ByteArrayInputStream; import java.rmi.RemoteException; import javax.activation.DataHandler; import javax.activation.FileDataSource; import javax.xml.parsers.ParserConfigurationException; import javax.xml.rpc.ServiceException;
import org.apache.axis.attachments.AttachmentPart; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.SOAPBodyElement; import org.w3c.dom.Document; import com.touchpoint.catapult.client.domain.Node; import com.touchpoint.catapult.client.message.RemoteTaskRequest; import com.touchpoint.catapult.client.message.xmlprocessing.ToXmlConverter; public final class RemoteTaskResultService extends CatapultService{ public RemoteTaskResultService(String serviceURI) { super(serviceURI); } public void returnRemoteTaskResult(int taskId, Node node, Object object) throws Exception, ServiceException, ParserConfigurationException, RemoteException { Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( "http://" + this.getServiceURI()); RemoteTaskRequest remoteTaskRequest = new RemoteTaskRequest(); remoteTaskRequest.setNodeId(node.getNodeId()); Document doc = ToXmlConverter.getXml(RemoteTaskRequest.class,remoteTaskRequest); SOAPBodyElement[] soapRequest = new SOAPBodyElement[1]; String positionHTTPHeader="Ordinal"; String refs; String setContentId="ScreenShot"; AttachmentPart ap= new AttachmentPart(new DataHandler(new FileDataSource("C:\\screenshot.jpg"))); ap.setContentId(setContentId); refs = "cid:" + setContentId; //reference the attachment by contentId. ap.setMimeHeader(positionHTTPHeader, "" + 1 ); //create a MIME header indicating postion. call.addAttachmentPart(ap); String namespace="urn:foo"; //needs to match name of service. StringBuffer msg = new StringBuffer("\n<attachments xmlns=\"" +namespace +"\">\n"); msg.append(" <attachment href=\"" + refs + "\"/>\n"); msg.append( "</attachments>"); soapRequest[0] = new SOAPBodyElement(new ByteArrayInputStream(msg.toString().getBytes())); call.invoke(soapRequest); } }
import java.io.StringReader; import java.util.Iterator; import org.apache.axis.AxisFault; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.attachments.AttachmentPart; import org.apache.axis.attachments.Attachments; import org.apache.axis.utils.XMLUtils; import org.w3c.dom.Element; public class RemoteTaskResultImpl implements RemoteTaskResultIF{ public Element[] setTaskResult(Element[] elems){ String requestAttachment = XMLUtils.ElementToString(elems[0]); StringReader requestAttachmentReader = new StringReader(requestAttachment); try { //This is where the server hangs AttachmentPart[] attachment = getMessageAttachments(); } catch (AxisFault e) { e.printStackTrace(); } return null; } /**====================================================================== * Private Methods *=======================================================================*/ private AttachmentPart[] getMessageAttachments() throws AxisFault { MessageContext msgContext = MessageContext.getCurrentContext(); Message reqMsg = msgContext.getRequestMessage(); Attachments messageAttachments = reqMsg.getAttachmentsImpl(); if (null == messageAttachments) { return new AttachmentPart[0]; } int attachmentCount= messageAttachments.getAttachmentCount(); AttachmentPart attachments[] = new AttachmentPart[attachmentCount]; Iterator it = messageAttachments.getAttachments().iterator(); int count = 0; while (it.hasNext()) { AttachmentPart part = (AttachmentPart) it.next(); attachments[count++] = part; } return attachments; } }
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://localhost:8080/catapult/services/remotetaskresult" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8080/catapult/services/remotetaskresult" xmlns:intf="http://localhost:8080/catapult/services/remotetaskresult" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://webservice.server.catapult.touchpoint.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><wsdl:types><schema targetNamespace="http://webservice.server.catapult.touchpoint.com" xmlns="http://www.w3.org/2001/XMLSchema"><element name="setTaskResult" type="xsd:anyType"/></schema><schema targetNamespace="http://localhost:8080/catapult/services/remotetaskresult" xmlns="http://www.w3.org/2001/XMLSchema"><element name="setTaskResultReturn" type="xsd:anyType"/></schema></wsdl:types> <wsdl:message name="setTaskResultRequest"> <wsdl:part element="tns1:setTaskResult" name="part"/> </wsdl:message> <wsdl:message name="setTaskResultResponse"> <wsdl:part element="impl:setTaskResultReturn" name="setTaskResultReturn"/> </wsdl:message> <wsdl:portType name="RemoteTaskResultImpl"> <wsdl:operation name="setTaskResult"> <wsdl:input message="impl:setTaskResultRequest" name="setTaskResultRequest"/> <wsdl:output message="impl:setTaskResultResponse" name="setTaskResultResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="remotetaskresultSoapBinding" type="impl:RemoteTaskResultImpl"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="setTaskResult"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="setTaskResultRequest"> <wsdlsoap:body namespace="http://webservice.server.catapult.touchpoint.com" use="literal"/> </wsdl:input> <wsdl:output name="setTaskResultResponse"> <wsdlsoap:body namespace="http://localhost:8080/catapult/services/remotetaskresult" use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="RemoteTaskResultImplService"> <wsdl:port binding="impl:remotetaskresultSoapBinding" name="remotetaskresult"> <wsdlsoap:address location="http://localhost:8080/catapult/services/remotetaskresult"/> </wsdl:port> </wsdl:service> </wsdl:definitions>