axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s n <axis_2_u...@yahoo.com>
Subject Unable to retrieve attachment using AXIS2
Date Tue, 25 Sep 2007 15:27:11 GMT
Hi All,

I am a new AXIS 2 user. I am not too familiar with SOAP either.. 
I am trying to write a class which would connect to a web server which offers three services
namely,

1. getAnnotation
2. getLastUpdate 
3. getAllArrays

The first service requires two strings as input and returns a file. The second and third do
not require any input parameters and return a String.
I have been successful in using  the second and third service. The first one (getAnnotation)
is giving me a hard time. I have tried following the examples in the Axis2 examples directory,
but have not been able to retreive the file. I have attached the WSDL file in the email.
Any help would be highly appreciated.

Thanks!


The Error :


Response Envelope:

<?xml version='1.0' encoding='utf-8'?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<getAnnotationResponse xmlns="urn:rsrcSOAP">
<file xsi:type="xsd:string">affy_HG-U133A</file>
</getAnnotationResponse>
</soap:Body>
</soap:Envelope>

MessageID:urn:uuid:6EB4D3C78EEACF75631190730622370
Messagebody:[MessageContext: logID=urn:uuid:6EB4D3C78EEACF75631190730623746]
File Name : affy_HG-U133A
File element id:urn:uuid:6EB4D3C78EEACF75631190730623746 
java.lang.Exception: Cannot find the data handler.
    at org.tigr.remote.soap.SoapCall.main(SoapCall.java:120)





My code looks as follows:


public class SoapCall {
        
     private static EndpointReference targetEPR = new EndpointReference("http://web-dev.dfci.harvard.edu/tgi/cgi-bin/tgi/SOAP/rsrc.cgi");

     public static void main(String[] args) {

         try {
             SOAPFactory fac = (SOAPFactory) OMAbstractFactory.getSOAP11Factory();
             SOAPEnvelope envelope = (SOAPEnvelope) fac.getDefaultEnvelope();



             OMNamespace omNs = fac.createOMNamespace("urn:rsrcSOAP", "rsrcSOAP");

             //The method is getAnnotation and input parameters is the hardcoded value "affy_HG-U133A"
             // and "CLONE_ID". I have used "arrayName" and "fields" to denote the two OMElements
because
             //the "part name" fields in the WSDL file for the "message name = getAnnotationRequest"
             //were "arrayName" and "fields" respectively
             
             OMElement method = fac.createOMElement("getAnnotation", omNs);

             OMElement value1 = fac.createOMElement("arrayName", omNs);
             value1.setText("affy_HG-U133A");

             OMElement value2 = fac.createOMElement("fields", omNs);
             value2.setText("CLONE_ID");
             method.addChild(value1);
             method.addChild(value2);
             envelope.getBody().addChild(method);


             ServiceClient client = new ServiceClient();
             OperationClient operationClient = client.createClient(ServiceClient.ANON_OUT_IN_OP);

             //creating message context
             MessageContext outMsgCtx = new MessageContext();

             //assigning message context’s option object into instance variable
             Options opts = outMsgCtx.getOptions();
             
             //setting properties into option
             opts.setTo(targetEPR);
             opts.setAction("urn:rsrcSOAP#getAnnotation");



             outMsgCtx.setEnvelope(envelope);
             operationClient.addMessageContext(outMsgCtx);
             operationClient.execute(true);
             MessageContext response = operationClient.getMessageContext("In");
             SOAPBody body = (SOAPBody) response.getEnvelope().getBody();
             OMElement element = body.getFirstChildWithName(new QName("urn:rsrcSOAP","getAnnotationResponse"));




             System.out.println("File Name : "
                     + element.getFirstChildWithName(new QName("urn:rsrcSOAP","file")).getText());

             OMElement fileElement = element.getFirstChildWithName(new QName("urn:rsrcSOAP","file"));

             //retrieving the ID of the attachment. The ID string has a "]" character at the
end.
             String fileElementID=response.getLogIDString();


             String temp1=fileElementID.split("=")[1];
             String temp2=temp1.replace(']', ' ');


             DataHandler dataHandler = response.getAttachment(temp2);
             if (dataHandler!=null){
                 // Writing the attachment data (graph image) to a file
                 File graphFile = new File("response.txt");
                 FileOutputStream outputStream = new FileOutputStream(graphFile);
                 dataHandler.writeTo(outputStream);
                 outputStream.flush();
                 System.out.println("Download statistics graph saved to :" + graphFile.getAbsolutePath());
             }else
             {
                 throw new Exception("Cannot find the data handler.");
             }

    
            
            
        }catch(Exception e) {
            e.printStackTrace();
        }
        

        }
        
        
        
        
        





       
____________________________________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy)
at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow  
Mime
View raw message