axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Grund" <andreas.gr...@kgu-consulting.de>
Subject Problem with SOAPElement
Date Tue, 16 Nov 2004 14:07:02 GMT
Hi,
 
i try to write an webservice, which gets two input-parameter, one String and one Datahandler.
I put the String as an Element in the body an the Datahandler as an attachment to the message.
But my Service says every time, that the String has no value.
 
Here is my code:
Client:
public boolean echoUsingSAAJ(String filename) throws Exception {
        String endPointURLString =  "http://localhost:" +opts.getPort() + "/EchoAttachmentServer/services/urn:EchoAttachmentsService";
        
        SOAPConnectionFactory soapConnectionFactory =
                javax.xml.soap.SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection =
                soapConnectionFactory.createConnection();
 
        MessageFactory messageFactory =
                MessageFactory.newInstance();
        SOAPMessage soapMessage =
                messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope requestEnvelope =
                soapPart.getEnvelope();
        SOAPBody body = requestEnvelope.getBody();
        SOAPBodyElement operation = body.addBodyElement
                (requestEnvelope.createName("echoFilename"));
        
        SOAPFactory factory = SOAPFactory.newInstance();
        
        //deleting the header:
        soapMessage.getSOAPPart().getEnvelope().getHeader().detachNode();
        
        Name bodyName = factory.createName("echo", "efn", endPointURLString);
        SOAPElement soapElement = body.addBodyElement(bodyName);
        Name name = factory.createName("name", "efn", endPointURLString);
        //SOAPElement stringElement = body.addBodyElement(name);
        SOAPElement stringElement = soapElement.addChildElement(name);
        stringElement.addTextNode(filename);
 
        Vector dataHandlersToAdd = new Vector();
        dataHandlersToAdd.add(new DataHandler(new FileDataSource(new
                File(filename))));
        //dataHandlersToAdd.add(new DataHandler(new StringDataSource(filename)));
        
        if (dataHandlersToAdd != null) {
            ListIterator dataHandlerIterator =
                    dataHandlersToAdd.listIterator();
 
            while (dataHandlerIterator.hasNext()) {
                DataHandler dataHandler = (DataHandler)
                        dataHandlerIterator.next();
                javax.xml.soap.SOAPElement element =
                        operation.addChildElement(requestEnvelope.createName("source"));
                javax.xml.soap.AttachmentPart attachment =
                        soapMessage.createAttachmentPart(dataHandler);
                soapMessage.addAttachmentPart(attachment);
                element.addAttribute(requestEnvelope.createName
                                     ("href"), "cid:" + attachment.getContentId());
            }
        }
        File file = new File("D:/temp/message.xml");
        OutputStream os = new FileOutputStream(file);
        soapMessage.writeTo(os);
        
        javax.xml.soap.SOAPMessage returnedSOAPMessage =
                soapConnection.call(soapMessage, endPointURLString);
        Iterator iterator = returnedSOAPMessage.getAttachments();
        if (!iterator.hasNext()) {
            //The wrong type of object that what was expected.
            System.out.println("Received problem response from server");
            throw new AxisFault("", "Received problem response from server", null, null);
 
        }
        //Still here, so far so good.
        //Now lets brute force compare the source attachment
        // to the one we received.
        DataHandler rdh = (DataHandler) ((AttachmentPart)iterator.next()).getDataHandler();
 
        //From here we'll just treat the data resource as file.
        String receivedfileName = rdh.getName();//Get the filename. 
 
        if (receivedfileName == null) {
            System.err.println("Could not get the file name.");
            throw new AxisFault("", "Could not get the file name.", null, null);
        }
 

        System.out.println("Going to compare the files..");
        boolean retv = compareFiles(filename, receivedfileName);
 
        java.io.File receivedFile = new java.io.File(receivedfileName);
 
        receivedFile.delete();
 
        return retv;
    }
 
webservice:
 public DataHandler echoFilename(DataHandler dh, String name){
        if (name == null ) logger.info("filename2 is null");
        else logger.info("Received \"" + name + "\".");
        return dh;
    }

wsdd:
<!-- This file can be used to deploy the echoAttachments sample -->
<!-- using this command: java org.apache.axis.client.AdminClient attachdeploy.wsdd -->
 
<!-- This deploys the echo attachment service.  -->
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:ns1="urn:EchoAttachmentsService" >
  <service name="urn:EchoAttachmentsService" provider="java:RPC" >
    <parameter name="className" value="samples.attachments.EchoAttachmentsService"/>
    <parameter name="allowedMethods" value="echo echoDir echoFilename attachments"/>
    <operation name="echo" returnQName="returnqname" returnType="ns1:DataHandler" >
        <parameter name="dh" type="ns1:DataHandler"/>
    </operation>
    <operation name="echoFilename" returnQName="returnqname" returnType="ns1:DataHandler">
     <parameter name="dh" type="ns1:DataHandler"/>
     <parameter name="name" type="xsd:String" />
    </operation>
 
 <typeMapping deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory"
   languageSpecificType="java:javax.activation.DataHandler" qname="ns1:DataHandler"
    serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory" 
    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
     />
  </service>
 
</deployment>

Where is my fault? Can anyone help me, please? Thanks in advance and best regards
 
mit freundlichen Grüßen,
 
Andreas Grund
Softwareentwickler
 
KGU-Consulting GmbH
Lise-Meitner-Straße 2
 
D - 24941 Flensburg
Tel.: 0461/3185213
Fax: 0461/3185220
Internet: www.kgu-consulting.de <http://www.kgu-consulting.de/> 
 
 
 

Mime
View raw message