Difference between revisions of "Android client - OpenKM 5.1"

From OpenKM Documentation
Jump to: navigation, search
(Created page with '{{TOCright}} __TOC__ Although Android platform programming language is Java, it has some limitations respect the Oracle JDK. For example, the WeServices stuff. So, we need to us…')
(No difference)

Revision as of 07:52, 7 September 2011

Although Android platform programming language is Java, it has some limitations respect the Oracle JDK. For example, the WeServices stuff. So, we need to use an external library to make SOAP request. This library is called ksoap and can be located at http://code.google.com/p/ksoap2-android/.

Authentication

package com.openkm.ws.test;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

public class AuthClient {
    private static final String NAMESPACE = "http://endpoint.ws.openkm.com/";
    private static final String URL = "http://10.0.2.2:8080/OpenKM/OKMAuth";
    private static final String SOAP_ACTION = "\"\"";
    private static final String TAG = "OKM_AUTH_CLIENT";
	
    /**
     * Auth user login
     */
    public static String login(String user, String password) throws IOException {	
        try {
            SoapObject request = new SoapObject(NAMESPACE, "login");
            request.addProperty("user", user);
            request.addProperty("password", password);
            
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            
            HttpTransportSE transport = new HttpTransportSE(URL);
            transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            transport.call(SOAP_ACTION, envelope);
            
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            Log.i(TAG, "SOAP Result... " + response);
            String result = (String) response.toString();
            return result;
        } catch (SoapFault e) {
            Log.e(TAG, "Code: " + e.faultcode + ", String: " + e.faultstring);
            throw new IOException(e.faultstring);
        } catch (XmlPullParserException e) {
            throw new IOException(e.getMessage());
        }
    }
    
    /**
     * Auth user logout
     */
    public static void logout(String token) throws IOException {
        try {
            SoapObject request = new SoapObject(NAMESPACE, "logout");
            request.addProperty("token", token);
            
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            
            HttpTransportSE transport = new HttpTransportSE(URL);
            transport.call(SOAP_ACTION, envelope);
            
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            Log.i(TAG, "SOAP Result... " + response);
        } catch (SoapFault e) {
            Log.e(TAG, "Code: " + e.faultcode + ", String: " + e.faultstring);
            throw new IOException(e.faultstring);
        } catch (XmlPullParserException e) {
            throw new IOException(e.getMessage());
        }
    }
}

Create document