Hi
I am investigating using the Flickr API with axis SOAP and am still at an 
early stage. My first block is this
The flickr API asks for a different version of the soap-envelope to that 
generated by Axis, but generates correct Schema and Schema instance. Is 
this my problem?
Am I doing this the hard way, or should I be able to do this easier with 
my own wsdl file and if so how would this look? Is axis the right tool to 
use or should I go with apache SOAP or java Webservices sdk?


Here is the example flickr SOAP request
The SOAP Server Endpoint URL is http://www.flickr.com/services/soap/

To request the flickr.echo service, send an envelope like this:

<s:Envelope
        xmlns:s="http://www.w3.org/2001/06/soap-envelope";
        xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
        xmlns:xsd="http://www.w3.org/1999/XMLSchema";
>
        <s:Body>
                <x:FlickrRequest xmlns:x="urn:flickr">
                        <method>flickr.echo</method>
                        <name>value</name>
                </x:FlickrRequest>
        </s:Body>
</s:Envelope>

Here is the documentation for the test.echo
Flickr API Documentation
spacer image    
flickr.test.echo

A testing method which echo's all paramaters back in the response.
Arguments

api_key (Required)
    You API application key. See here for more details.

Example Response

<method>echo</method>
<foo>bar</foo>

Error Codes

100: Invalid API Key
    The API key passed was not valid or has expired.




Here is my code

package thehallfamily.soap;


import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPBody;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.soap.SOAPConstants;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.utils.XMLUtils;
import org.apache.axis.schema.SchemaVersion;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.sun.org.apache.xml.internal.utils.NameSpace;


/**
 * @author keith
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SoapConnector {
    public static String doit() throws Exception {
        //Create a call
        Service  service = new Service();
        Call call    = (Call) service.createCall();

        call.setTargetEndpointAddress( new 
URL("http://www.flickr.com/services/soap/";) );
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().
newDocumentBuilder();
        Document doc            = builder.newDocument();
        SOAPEnvelope env = new  SOAPEnvelope(SOAPConstants.SOAP12_CONSTANTS, 
SchemaVersion.SCHEMA_1999) ;
        //create the body
        SOAPBody body = env.getBody();
        Element requestElem = doc.createElementNS("urn:flickr", 
"x:FlickrRequest");

        //create the method parameters
        Element methodElem       = doc.createElement("method");
        Node requestValue      = doc.createTextNode("flickr.test.echo");
        methodElem.appendChild(requestValue);
        //add to body
        requestElem.appendChild(methodElem);
        //next method parameter
        Element nameElem       = doc.createElement("api_key");
        //real key not included here
        Node valueValue      = 
doc.createTextNode("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        nameElem.appendChild(valueValue);
        //add to body
        requestElem.appendChild(nameElem);

        SOAPBodyElement bodyElement = new SOAPBodyElement(requestElem);
        body.addChildElement(bodyElement);
        System.out.println( XMLUtils.ElementToString(env.getAsDOM()) );
        //invoke SOAP call
        SOAPEnvelope returnenv =  call.invoke( env );
        return( XMLUtils.ElementToString(returnenv.getAsDOM()) );
    }
    public static void main(String[] args) {
        try{
            System.out.println( doit());
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}


Here is the output
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2002/12/soap-envelope"; 
xmlns:xsd="http://www.
w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";>
 <soapenv:Body><ns1:FlickrRequest xmlns:ns1="urn:flickr"><method>flickr.
test.echo</method><api_key>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</api_key></ns1:
FlickrRequest> </soapenv:Body>
</soapenv:Envelope>

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}VersionMismatch
 faultSubcode: 
 faultString: Version Mismatch
 faultActor: 
 faultNode: 
 faultDetail: 
        {http://xml.apache.org/axis/}stackTrace: AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}VersionMismatch
 faultSubcode: 
 faultString: Version Mismatch
 faultActor: 
 faultNode: 
 faultDetail: 

Version Mismatch
        at 
org.apache.axis.message.EnvelopeBuilder.startElement(EnvelopeBuilder.java:141)
        at 
org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.
java:976)
        at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.
java:533)
        at 
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.
java:330)
        at 
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.
java:779)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.
java:1794)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.
java:368)
        at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.
java:834)
        at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.
java:764)
        at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:
148)
        at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:
1242)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
        at 
org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.
java:242)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
        at org.apache.axis.client.Call.invoke(Call.java:2553)
        at org.apache.axis.client.Call.invoke(Call.java:1753)
        at thehallfamily.soap.SoapConnector.doit(SoapConnector.java:65)
        at thehallfamily.soap.SoapConnector.main(SoapConnector.java:70)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)


Any help would be gratefully appreciated. 

Thanks

Keith

Reply via email to