Difference between revisions of "Java client - OpenKM 6.2"

From OpenKM Documentation
Jump to: navigation, search
m (Authentication)
(PropertyGroups)
Line 69: Line 69:
 
                 // login
 
                 // login
 
Auth_Service authService = new Auth_Service();
 
Auth_Service authService = new Auth_Service();
Auth auth = authService.getAuthPort();
+
Auth authOkm = authService.getAuthPort();
 
String token = auth.login("okmAdmin", "admin");
 
String token = auth.login("okmAdmin", "admin");
 
 
 
                 // property groups
 
                 // property groups
 
PropertyGroup_Service pgservice = new PropertyGroup_Service();
 
PropertyGroup_Service pgservice = new PropertyGroup_Service();
PropertyGroup pg = pgservice.getPropertyGroupPort();
+
PropertyGroup pgOkm = pgservice.getPropertyGroupPort();
 
 
 
List<StringPair> spList = new ArrayList<StringPair>();
 
List<StringPair> spList = new ArrayList<StringPair>();
Line 81: Line 81:
 
sp.setValue("Other comment from PHP");
 
sp.setValue("Other comment from PHP");
 
spList.add(sp);
 
spList.add(sp);
pg.setPropertiesSimple(token, "/okm:root/test/hosts.txt", "okg:technology", spList);
+
pgOkm.setPropertiesSimple(token, "/okm:root/test/hosts.txt", "okg:technology", spList);
 
 
 
                 // logout
 
                 // logout
auth.logout(token);
+
authOkm.logout(token);
 
}
 
}
 
}
 
}

Revision as of 09:36, 22 June 2012

First, we need to generate the client stuff using this command. Keep on mind that you need JDK 1.6 to run it:

$ wsimport -d client -s client http://localhost:8080/OpenKM/services/Auth?wsdl

You can use the following script to generate a complete OpenKM webservices client library:

#/bin/bash

wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Auth?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Document?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Folder?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Search?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Notification?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Repository?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/PropertyGroup?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/services/Workflow?wsdl

jar cvf okm-ws-client-6.0.jar com

rm -rf com

Authentication

package com.openkm.ws.test;

import com.openkm.ws.client.Auth;
import com.openkm.ws.client.Auth_Service;

public class Authentication {
    public static void main(String[] args) {
        try {
            Auth_Service authService = new Auth_Service();
            Auth authOkm = authService.getAuthPort();

            // Login
            String token = authOkm.login("okmAdmin", "admin");
            System.out.println("Token: " + token);

            // Logout
            authOkm.logout(token);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

PropertyGroups

package com.openkm.ws.test;

import java.util.ArrayList;
import java.util.List;

import com.openkm.ws.client.Auth;
import com.openkm.ws.client.Auth_Service;
import com.openkm.ws.client.PropertyGroup;
import com.openkm.ws.client.PropertyGroup_Service;
import com.openkm.ws.client.StringPair;

public class PropertyGroups {
	public static void main(String[] args) throws Exception {
                // login
		Auth_Service authService = new Auth_Service();
		Auth authOkm = authService.getAuthPort();
		String token = auth.login("okmAdmin", "admin");
		
                // property groups
		PropertyGroup_Service pgservice = new PropertyGroup_Service();
		PropertyGroup pgOkm = pgservice.getPropertyGroupPort();
		
		List<StringPair> spList = new ArrayList<StringPair>();
		StringPair sp = new StringPair();
		sp.setKey("okp:technology.comment");
		sp.setValue("Other comment from PHP");
		spList.add(sp);
		pgOkm.setPropertiesSimple(token, "/okm:root/test/hosts.txt", "okg:technology", spList);
		
                // logout
		authOkm.logout(token);
	}
}