• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Desperate newbie - problem with image attachment

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Below are the following files:
-RemoteTaskResultService (client-side)
-RemoteTaskResultImpl (server-side)
-remotetaskresult (wsdl)

I�m using Axis 1.1, Tomcat 4.1.x

Thanx a million

-----------------------------------------

RemoteTaskResultService:

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);

}
}

________________________________________

RemoteTaskResultImpl:

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;
}
}

------------------------------------------------

remotetaskservice:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl efinitions 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 art element="tns1:setTaskResult" name="part"/>
</wsdl:message>
<wsdl:message name="setTaskResultResponse">
<wsdl art element="impl:setTaskResultReturn" name="setTaskResultReturn"/>
</wsdl:message>
<wsdl ortType name="RemoteTaskResultImpl">
<wsdl peration name="setTaskResult">
<wsdl:input message="impl:setTaskResultRequest" name="setTaskResultRequest"/>
<wsdl utput message="impl:setTaskResultResponse" name="setTaskResultResponse"/>
</wsdl peration>
</wsdl ortType>
<wsdl:binding name="remotetaskresultSoapBinding" type="impl:RemoteTaskResultImpl">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl peration name="setTaskResult">
<wsdlsoap peration soapAction=""/>
<wsdl:input name="setTaskResultRequest">
<wsdlsoap:body namespace="http://webservice.server.catapult.touchpoint.com" use="literal"/>
</wsdl:input>
<wsdl utput name="setTaskResultResponse">
<wsdlsoap:body namespace="http://localhost:8080/catapult/services/remotetaskresult" use="literal"/>
</wsdl utput>
</wsdl peration>
</wsdl:binding>
<wsdl:service name="RemoteTaskResultImplService">
<wsdl ort binding="impl:remotetaskresultSoapBinding" name="remotetaskresult">
<wsdlsoap:address location="http://localhost:8080/catapult/services/remotetaskresult"/>
</wsdl ort>
</wsdl:service>
</wsdl efinitions>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic